new boot:

- now boot unencrypted ROMs from firmware;
This commit is contained in:
mtabachenko 2013-08-10 18:35:56 +00:00
parent 6ff5f84243
commit 44898881ca
3 changed files with 66 additions and 0 deletions

View File

@ -2534,6 +2534,11 @@ void NDS_Reset()
#ifdef _NEW_BOOT
gameInfo.restoreSecureArea();
// Firmware boot only encrypted ROMs
#ifndef WORDS_BIGENDIAN
EncryptSecureArea((u8*)gameInfo.romdata,gameInfo.romsize);
#endif
armcpu_init(&NDS_ARM7, 0x00000000);
armcpu_init(&NDS_ARM9, 0xFFFF0000);

View File

@ -448,6 +448,39 @@ static void decrypt_arm9(u32 cardheader_gamecode, unsigned char *data)
}
}
static void encrypt_arm9(u32 cardheader_gamecode, unsigned char *data)
{
u32 *p = (u32*)data;
if (p[0] != 0xE7FFDEFF || p[1] != 0xE7FFDEFF)
{
fprintf(stderr, "Encryption failed!\n");
return;
}
p += 2;
init1(cardheader_gamecode);
arg2[1] <<= 1;
arg2[2] >>= 1;
init2(card_hash, arg2);
u32 size = 0x800 - 8;
while (size > 0)
{
encrypt(card_hash, p+1, p);
p += 2;
size -= 8;
}
p = (u32*)data;
p[0] = MAGIC30;
p[1] = MAGIC34;
encrypt(card_hash, p+1, p);
init1(cardheader_gamecode);
encrypt(card_hash, p+1, p);
}
bool DecryptSecureArea(u8 *romdata, long romlen)
{
@ -504,3 +537,30 @@ bool DecryptSecureArea(u8 *romdata, long romlen)
return true;
}
bool EncryptSecureArea(u8 *romdata, long romlen)
{
//this looks like it will only work on little endian hosts
Header* header = (Header*)romdata;
int romType = DetectRomType(*header,(char*)romdata);
if(romType == ROMTYPE_INVALID)
return false;
if (romType == ROMTYPE_NDSDUMPED)
{
unsigned char data[0x4000];
memcpy(data,romdata+0x4000,0x4000);
encrypt_arm9(*(u32 *)header->gamecode, data);
// clear data after header
memset(romdata+0x200,0,(0x4000-0x200));
// write secure 0x800
memcpy(romdata+0x4000,data,0x800);
printf("Encrypted.\n");
}
return true;
}

View File

@ -22,5 +22,6 @@
#define _DECRYPT_H_
bool DecryptSecureArea(u8 *romdata, long romlen);
bool EncryptSecureArea(u8 *romdata, long romlen);
#endif