mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-22 13:50:11 -06:00
cart: ensure each set of commands can only be run in the correct command mode.
fixes #1083 (there was a chance an encrypted KEY1 command could be interpreted as something else and fuck things up)
This commit is contained in:
@ -235,6 +235,8 @@ void CartCommon::FlushSRAMFile()
|
||||
|
||||
int CartCommon::ROMCommandStart(u8* cmd, u8* data, u32 len)
|
||||
{
|
||||
if (CmdEncMode == 0)
|
||||
{
|
||||
switch (cmd[0])
|
||||
{
|
||||
case 0x9F:
|
||||
@ -254,7 +256,6 @@ int CartCommon::ROMCommandStart(u8* cmd, u8* data, u32 len)
|
||||
return 0;
|
||||
|
||||
case 0x90:
|
||||
case 0xB8:
|
||||
for (u32 pos = 0; pos < len; pos += 4)
|
||||
*(u32*)&data[pos] = ChipID;
|
||||
return 0;
|
||||
@ -273,7 +274,10 @@ int CartCommon::ROMCommandStart(u8* cmd, u8* data, u32 len)
|
||||
return 0;
|
||||
|
||||
default:
|
||||
if (CmdEncMode == 1 || CmdEncMode == 11)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (CmdEncMode == 1 || CmdEncMode == 11)
|
||||
{
|
||||
// decrypt the KEY1 command as needed
|
||||
// (KEY2 commands do not need decrypted because KEY2 is handled entirely by hardware,
|
||||
@ -320,8 +324,8 @@ int CartCommon::ROMCommandStart(u8* cmd, u8* data, u32 len)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CartCommon::ROMCommandFinish(u8* cmd, u8* data, u32 len)
|
||||
@ -509,6 +513,8 @@ void CartRetail::FlushSRAMFile()
|
||||
|
||||
int CartRetail::ROMCommandStart(u8* cmd, u8* data, u32 len)
|
||||
{
|
||||
if (CmdEncMode != 2) return CartCommon::ROMCommandStart(cmd, data, len);
|
||||
|
||||
switch (cmd[0])
|
||||
{
|
||||
case 0xB7:
|
||||
@ -527,6 +533,11 @@ int CartRetail::ROMCommandStart(u8* cmd, u8* data, u32 len)
|
||||
}
|
||||
return 0;
|
||||
|
||||
case 0xB8:
|
||||
for (u32 pos = 0; pos < len; pos += 4)
|
||||
*(u32*)&data[pos] = ChipID;
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return CartCommon::ROMCommandStart(cmd, data, len);
|
||||
}
|
||||
@ -871,6 +882,8 @@ int CartRetailNAND::ImportSRAM(const u8* data, u32 length)
|
||||
|
||||
int CartRetailNAND::ROMCommandStart(u8* cmd, u8* data, u32 len)
|
||||
{
|
||||
if (CmdEncMode != 2) return CartCommon::ROMCommandStart(cmd, data, len);
|
||||
|
||||
switch (cmd[0])
|
||||
{
|
||||
case 0x81: // write data
|
||||
@ -1005,6 +1018,8 @@ int CartRetailNAND::ROMCommandStart(u8* cmd, u8* data, u32 len)
|
||||
|
||||
void CartRetailNAND::ROMCommandFinish(u8* cmd, u8* data, u32 len)
|
||||
{
|
||||
if (CmdEncMode != 2) return CartCommon::ROMCommandFinish(cmd, data, len);
|
||||
|
||||
switch (cmd[0])
|
||||
{
|
||||
case 0x81: // write data
|
||||
@ -1163,6 +1178,8 @@ void CartHomebrew::DoSavestate(Savestate* file)
|
||||
|
||||
int CartHomebrew::ROMCommandStart(u8* cmd, u8* data, u32 len)
|
||||
{
|
||||
if (CmdEncMode != 2) return CartCommon::ROMCommandStart(cmd, data, len);
|
||||
|
||||
switch (cmd[0])
|
||||
{
|
||||
case 0xB7:
|
||||
@ -1204,6 +1221,8 @@ int CartHomebrew::ROMCommandStart(u8* cmd, u8* data, u32 len)
|
||||
|
||||
void CartHomebrew::ROMCommandFinish(u8* cmd, u8* data, u32 len)
|
||||
{
|
||||
if (CmdEncMode != 2) return CartCommon::ROMCommandFinish(cmd, data, len);
|
||||
|
||||
// TODO: delayed SD writing? like we have for SRAM
|
||||
|
||||
switch (cmd[0])
|
||||
|
Reference in New Issue
Block a user