mirror of
https://github.com/rvtr/GodMode9i.git
synced 2025-06-18 19:05:30 -04:00
Only dump the RSA key on trimmed ROMs when it exists (#215)
* Only dump the RSA key on trimmed ROMs when it exists * Check for 'ac' magic number instead of 0xFF Thanks @bWFpbA
This commit is contained in:
parent
088fd0d383
commit
d588ac07a4
@ -892,10 +892,23 @@ void ndsCardDump(void) {
|
||||
for (u32 i = 0; i < 0x8000; i += 0x200) {
|
||||
cardRead (src+i, copyBuf+i, false);
|
||||
}
|
||||
if (fwrite(copyBuf, 1, (currentSize>=0x8000 ? 0x8000 : currentSize), destinationFile) < 1) {
|
||||
|
||||
if (currentSize < 0x8000) {
|
||||
if (romSize == ndsCardHeader.romSize + 0x88) {
|
||||
// Trimming, check for RSA key
|
||||
// 'ac', auth code -- magic number
|
||||
if (*(u16 *)(copyBuf + (ndsCardHeader.romSize % 0x8000)) != 0x6361) {
|
||||
romSize -= 0x88;
|
||||
currentSize -= 0x88;
|
||||
}
|
||||
}
|
||||
|
||||
fwrite(copyBuf, 1, currentSize, destinationFile);
|
||||
} else if (fwrite(copyBuf, 1, 0x8000, destinationFile) < 1) {
|
||||
dumpFailMsg(STR_FAILED_TO_DUMP_ROM);
|
||||
break;
|
||||
}
|
||||
|
||||
currentSize -= 0x8000;
|
||||
}
|
||||
fclose(destinationFile);
|
||||
|
@ -136,12 +136,27 @@ int trimNds(const char *fileName) {
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
u32 fileSize = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
u32 romSize;
|
||||
if((ndsCardHeader.unitCode != 0) && (ndsCardHeader.twlRomSize > 0)) {
|
||||
romSize = ndsCardHeader.twlRomSize;
|
||||
} else {
|
||||
romSize = ndsCardHeader.romSize;
|
||||
|
||||
// Check if it has an RSA key or not
|
||||
fseek(file, romSize, SEEK_SET);
|
||||
u16 magic;
|
||||
if(fread(&magic, sizeof(u16), 1, file) == 1) {
|
||||
// 'ac', auth code -- magic number
|
||||
if(magic == 0x6361)
|
||||
romSize += 0x88;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
u32 romSize = ((ndsCardHeader.unitCode != 0) && (ndsCardHeader.twlRomSize > 0))
|
||||
? ndsCardHeader.twlRomSize : ndsCardHeader.romSize + 0x88;
|
||||
|
||||
if(fileSize == romSize) {
|
||||
font->clear(false);
|
||||
font->print(firstCol, 0, false, STR_FILE_ALREADY_TRIMMED + "\n\n" + STR_A_OK, alignStart);
|
||||
|
Loading…
Reference in New Issue
Block a user