Switched to 32-bit variables when possible, removed unneeded casts

Thanks @Fix94 for the tip
This commit is contained in:
Aurora 2016-03-06 18:29:47 +01:00
parent 4bdba9f8e9
commit 13fd33a61d
9 changed files with 65 additions and 65 deletions

View File

@ -233,14 +233,14 @@ u8 key2[0x10] = {
}; };
//Get Nand CTR key //Get Nand CTR key
void getNandCTR(u8 *buf, u8 console){ void getNandCTR(u8 *buf, u32 console){
u8 *addr = (console ? (u8 *)0x080D8BBC : (u8 *)0x080D797C) + 0x0F; u8 *addr = (console ? (u8 *)0x080D8BBC : (u8 *)0x080D797C) + 0x0F;
for(u8 keyLen = 0x10; keyLen; keyLen--) for(u8 keyLen = 0x10; keyLen; keyLen--)
*(buf++) = *(addr--); *(buf++) = *(addr--);
} }
//Read firm0 from NAND and write to buffer //Read firm0 from NAND and write to buffer
void nandFirm0(u8 *outbuf, u32 size, u8 console){ void nandFirm0(u8 *outbuf, u32 size, u32 console){
u8 CTR[0x10]; u8 CTR[0x10];
getNandCTR(CTR, console); getNandCTR(CTR, console);
aes_advctr(CTR, 0x0B130000/0x10, AES_INPUT_BE | AES_INPUT_NORMAL); aes_advctr(CTR, 0x0B130000/0x10, AES_INPUT_BE | AES_INPUT_NORMAL);
@ -250,7 +250,7 @@ void nandFirm0(u8 *outbuf, u32 size, u8 console){
} }
//Decrypts the N3DS arm9bin //Decrypts the N3DS arm9bin
void decArm9Bin(void *armHdr, u8 mode){ void decArm9Bin(void *armHdr, u32 mode){
//Firm keys //Firm keys
u8 keyY[0x10]; u8 keyY[0x10];

View File

@ -49,8 +49,8 @@
#define AES_KEYY 2 #define AES_KEYY 2
//NAND/FIRM stuff //NAND/FIRM stuff
void nandFirm0(u8 *outbuf, u32 size, u8 console); void nandFirm0(u8 *outbuf, u32 size, u32 console);
void decArm9Bin(void *armHdr, u8 mode); void decArm9Bin(void *armHdr, u32 mode);
void setKeyXs(void *armHdr); void setKeyXs(void *armHdr);
#endif #endif

View File

@ -26,10 +26,10 @@ void getSDMMC(void *pos, u32 *off, u32 size){
*off = (u32)memsearch(pos, pattern, size, 4) - 1; *off = (u32)memsearch(pos, pattern, size, 4) - 1;
//Get DCD values //Get DCD values
u8 buf[4], u8 buf[4];
p;
u32 addr = 0, u32 addr = 0,
additive = 0; additive = 0,
p;
memcpy(buf, (void *)(*off+0x0A), 4); memcpy(buf, (void *)(*off+0x0A), 4);
for (p = 0; p < 4; p++) addr |= ((u32) buf[p]) << (8 * p); for (p = 0; p < 4; p++) addr |= ((u32) buf[p]) << (8 * p);
memcpy(buf, (void *)(*off+0x0E), 4); memcpy(buf, (void *)(*off+0x0E), 4);

View File

@ -14,8 +14,8 @@
firmHeader *firmLocation = (firmHeader *)0x24000000; firmHeader *firmLocation = (firmHeader *)0x24000000;
firmSectionHeader *section; firmSectionHeader *section;
u32 firmSize = 0; u32 firmSize = 0,
u8 mode = 1, mode = 1,
console = 1, console = 1,
emuNAND = 0, emuNAND = 0,
a9lhSetup = 0, a9lhSetup = 0,
@ -30,7 +30,7 @@ void setupCFW(void){
u8 a9lhBoot = (*(u8 *)0x101401C0 == 0x0) ? 1 : 0; u8 a9lhBoot = (*(u8 *)0x101401C0 == 0x0) ? 1 : 0;
//Retrieve the last booted FIRM via CFG_BOOTENV //Retrieve the last booted FIRM via CFG_BOOTENV
u8 previousFirm = *(u8 *)0x10010000; u8 previousFirm = *(u8 *)0x10010000;
u8 overrideConfig = 0; u32 overrideConfig = 0;
const char lastConfigPath[] = "rei/lastbootcfg"; const char lastConfigPath[] = "rei/lastbootcfg";
//Detect the console being used //Detect the console being used
@ -93,7 +93,7 @@ void setupCFW(void){
} }
//Load firm into FCRAM //Load firm into FCRAM
u8 loadFirm(void){ u32 loadFirm(void){
//If not using an A9LH setup or the patched FIRM, load 9.0 FIRM from NAND //If not using an A9LH setup or the patched FIRM, load 9.0 FIRM from NAND
if(!usePatchedFirm && !a9lhSetup && !mode){ if(!usePatchedFirm && !a9lhSetup && !mode){
@ -101,7 +101,7 @@ u8 loadFirm(void){
firmSize = console ? 0xF2000 : 0xE9000; firmSize = console ? 0xF2000 : 0xE9000;
nandFirm0((u8 *)firmLocation, firmSize, console); nandFirm0((u8 *)firmLocation, firmSize, console);
//Check for correct decryption //Check for correct decryption
if(memcmp((u8*)firmLocation, "FIRM", 4) != 0) return 0; if(memcmp(firmLocation, "FIRM", 4) != 0) return 0;
} }
//Load FIRM from SD //Load FIRM from SD
else{ else{
@ -118,13 +118,13 @@ u8 loadFirm(void){
if((((u32)section[2].address >> 8) & 0xFF) != (console ? 0x60 : 0x68)) return 0; if((((u32)section[2].address >> 8) & 0xFF) != (console ? 0x60 : 0x68)) return 0;
if(console && !usePatchedFirm) if(console && !usePatchedFirm)
decArm9Bin((u8*)firmLocation + section[2].offset, mode); decArm9Bin((void *)firmLocation + section[2].offset, mode);
return 1; return 1;
} }
//Nand redirection //Nand redirection
u8 loadEmu(void){ u32 loadEmu(void){
u32 emuOffset = 0, u32 emuOffset = 0,
emuHeader = 0, emuHeader = 0,
@ -145,9 +145,9 @@ u8 loadEmu(void){
fileRead((u8 *)emuCodeOffset, path, size); fileRead((u8 *)emuCodeOffset, path, size);
//Find and patch emunand related offsets //Find and patch emunand related offsets
u32 *pos_sdmmc = (u32 *)memsearch((u32*)emuCodeOffset, "SDMC", size, 4); u32 *pos_sdmmc = (u32 *)memsearch((void *)emuCodeOffset, "SDMC", size, 4);
u32 *pos_offset = (u32 *)memsearch((u32*)emuCodeOffset, "NAND", size, 4); u32 *pos_offset = (u32 *)memsearch((void *)emuCodeOffset, "NAND", size, 4);
u32 *pos_header = (u32 *)memsearch((u32*)emuCodeOffset, "NCSD", size, 4); u32 *pos_header = (u32 *)memsearch((void *)emuCodeOffset, "NCSD", size, 4);
getSDMMC(firmLocation, &sdmmcOffset, firmSize); getSDMMC(firmLocation, &sdmmcOffset, firmSize);
getEmunandSect(&emuOffset, &emuHeader); getEmunandSect(&emuOffset, &emuHeader);
getEmuRW(firmLocation, firmSize, &emuRead, &emuWrite); getEmuRW(firmLocation, firmSize, &emuRead, &emuWrite);
@ -158,7 +158,7 @@ u8 loadEmu(void){
//Patch emuNAND code in memory for O3DS and 9.0 N3DS //Patch emuNAND code in memory for O3DS and 9.0 N3DS
if(!console || !mode){ if(!console || !mode){
void *pos_instr = memsearch((u32*)emuCodeOffset, "\xA6\x01\x08\x30", size, 4); void *pos_instr = memsearch((void *)emuCodeOffset, "\xA6\x01\x08\x30", size, 4);
memcpy(pos_instr, emuInstr, sizeof(emuInstr)); memcpy(pos_instr, emuInstr, sizeof(emuInstr));
} }
@ -173,7 +173,7 @@ u8 loadEmu(void){
} }
//Patches //Patches
u8 patchFirm(void){ u32 patchFirm(void){
//Skip patching //Skip patching
if(usePatchedFirm) return 1; if(usePatchedFirm) return 1;
@ -216,13 +216,13 @@ u8 patchFirm(void){
fileRead((u8 *)rebootOffset, path, size); fileRead((u8 *)rebootOffset, path, size);
//Calculate the fOpen offset and put it in the right location //Calculate the fOpen offset and put it in the right location
u32 *pos_fopen = (u32 *)memsearch((u32*)rebootOffset, "OPEN", size, 4); u32 *pos_fopen = (u32 *)memsearch((void *)rebootOffset, "OPEN", size, 4);
getfOpen(firmLocation, firmSize, &fOpenOffset); getfOpen(firmLocation, firmSize, &fOpenOffset);
*pos_fopen = fOpenOffset; *pos_fopen = fOpenOffset;
//Patch path for emuNAND-patched FIRM //Patch path for emuNAND-patched FIRM
if(emuNAND){ if(emuNAND){
void *pos_path = memsearch((u32*)rebootOffset, L"sy", size, 4); void *pos_path = memsearch((void *)rebootOffset, L"sy", size, 4);
memcpy(pos_path, L"emu", 5); memcpy(pos_path, L"emu", 5);
} }
} }
@ -236,12 +236,12 @@ u8 patchFirm(void){
void launchFirm(void){ void launchFirm(void){
if(console && mode) setKeyXs((u8*)firmLocation + section[2].offset); if(console && mode) setKeyXs((void *)firmLocation + section[2].offset);
//Copy firm partitions to respective memory locations //Copy firm partitions to respective memory locations
memcpy(section[0].address, (u8*)firmLocation + section[0].offset, section[0].size); memcpy(section[0].address, (void *)firmLocation + section[0].offset, section[0].size);
memcpy(section[1].address, (u8*)firmLocation + section[1].offset, section[1].size); memcpy(section[1].address, (void *)firmLocation + section[1].offset, section[1].size);
memcpy(section[2].address, (u8*)firmLocation + section[2].offset, section[2].size); memcpy(section[2].address, (void *)firmLocation + section[2].offset, section[2].size);
//Run ARM11 screen stuff //Run ARM11 screen stuff
vu32 *arm11 = (vu32 *)0x1FFFFFF8; vu32 *arm11 = (vu32 *)0x1FFFFFF8;

View File

@ -17,8 +17,8 @@
#define SAFEMODE (BUTTON_L1 | BUTTON_R1 | BUTTON_A | (1 << 6)) #define SAFEMODE (BUTTON_L1 | BUTTON_R1 | BUTTON_A | (1 << 6))
void setupCFW(void); void setupCFW(void);
u8 loadFirm(void); u32 loadFirm(void);
u8 patchFirm(void); u32 patchFirm(void);
void launchFirm(void); void launchFirm(void);
#endif #endif

View File

@ -7,12 +7,12 @@
static FATFS fs; static FATFS fs;
u8 mountSD(void){ u32 mountSD(void){
if(f_mount(&fs, "0:", 1) != FR_OK) return 0; if(f_mount(&fs, "0:", 1) != FR_OK) return 0;
return 1; return 1;
} }
u8 fileRead(u8 *dest, const char *path, u32 size){ u32 fileRead(u8 *dest, const char *path, u32 size){
FRESULT fr; FRESULT fr;
FIL fp; FIL fp;
unsigned int br = 0; unsigned int br = 0;
@ -27,7 +27,7 @@ u8 fileRead(u8 *dest, const char *path, u32 size){
return fr ? 0 : 1; return fr ? 0 : 1;
} }
u8 fileWrite(const u8 *buffer, const char *path, u32 size){ u32 fileWrite(const u8 *buffer, const char *path, u32 size){
FRESULT fr; FRESULT fr;
FIL fp; FIL fp;
unsigned int br = 0; unsigned int br = 0;
@ -50,7 +50,7 @@ u32 fileSize(const char* path){
return size; return size;
} }
u8 fileExists(const char* path){ u32 fileExists(const char *path){
FIL fp; FIL fp;
u8 exists = 0; u8 exists = 0;

View File

@ -7,10 +7,10 @@
#include "types.h" #include "types.h"
u8 mountSD(void); u32 mountSD(void);
u8 fileRead(u8 *dest, const char *path, u32 size); u32 fileRead(u8 *dest, const char *path, u32 size);
u8 fileWrite(const u8 *buffer, const char *path, u32 size); u32 fileWrite(const u8 *buffer, const char *path, u32 size);
u32 fileSize(const char *path); u32 fileSize(const char *path);
u8 fileExists(const char* path); u32 fileExists(const char *path);
#endif #endif

View File

@ -10,7 +10,7 @@
#include "firm.h" #include "firm.h"
#include "draw.h" #include "draw.h"
u8 main(){ u32 main(){
mountSD(); mountSD();
loadSplash(); loadSplash();
setupCFW(); setupCFW();