Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Assets/dll/melonDS.wbx.zst
Binary file not shown.
23 changes: 22 additions & 1 deletion waterbox/melon/BizConsoleCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ static std::unique_ptr<T> CreateBiosImage(u8* biosData, u32 biosLength, std::opt
return std::move(bios);
}

static bool isValidMacAddress(const melonDS::MacAddress& mac)
{
// 48bit MAC address v1–v5: 00:09:BF:XX:XX:XX
const bool isV1toV5 = mac[0] == 0x00 && mac[1] == 0x09 && mac[2] == 0xBF;

// 48bit MAC address v6–v7: 00:16:56:XX:XX:XX
const bool isV6toV7 = mac[0] == 0x00 && mac[1] == 0x16 && mac[2] == 0x56;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks appear to be non-exhastive.

For DSi, A4 C0 E1 is valid.
For DS Lite, 00 25 A0 is valid.
For iQue DS Lite, 00 1D BC is valid.

In theory, there's potentially a ton of other valid MAC addresses, as Nintendo has registered a ton of MAC prefixes. It might be better to just make sure it's not all 0xFFs (not uncommon to find with "no-intro" matching dumps which 0xFF wifi area) along with not being 03:09:BF (broadcast channel, not valid)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


return isV1toV5 || isV6toV7;
}

static void SanitizeExternalFirmware(melonDS::Firmware& firmware)
{
auto& header = firmware.GetHeader();
Expand All @@ -84,7 +95,17 @@ static void SanitizeExternalFirmware(melonDS::Firmware& firmware)
memset(&header.Bytes[0x28], 0xFF, 2);
}

memcpy(&header.Bytes[0x2C], &defaultHeader.Bytes[0x2C], 0x136);
memcpy(&header.Bytes[0x2C], &defaultHeader.Bytes[0x2C], 10);

// MAC address offset is 0x36, so we skip writing from 0x36 to 0x3B (48 bit)
// to avoid copying melonDS default MAC address 0x0009BF112233
// only if the external firmware MAC address is valid
if (!isValidMacAddress(header.MacAddr))
{
memcpy(&header.Bytes[0x36], &defaultHeader.Bytes[0x36], 6);
}

memcpy(&header.Bytes[0x3C], &defaultHeader.Bytes[0x3C], 0x126);
memset(&header.Bytes[0x162], 0xFF, 0x9E);

if (isDSiFw)
Expand Down