Switched to 32-bit variables when possible, removed unneeded casts
Thanks @Fix94 for the tip
This commit is contained in:
parent
4bdba9f8e9
commit
13fd33a61d
@ -233,14 +233,14 @@ u8 key2[0x10] = {
|
||||
};
|
||||
|
||||
//Get Nand CTR key
|
||||
void getNandCTR(u8 *buf, u8 console){
|
||||
void getNandCTR(u8 *buf, u32 console){
|
||||
u8 *addr = (console ? (u8 *)0x080D8BBC : (u8 *)0x080D797C) + 0x0F;
|
||||
for(u8 keyLen = 0x10; keyLen; keyLen--)
|
||||
*(buf++) = *(addr--);
|
||||
}
|
||||
|
||||
//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];
|
||||
getNandCTR(CTR, console);
|
||||
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
|
||||
void decArm9Bin(void *armHdr, u8 mode){
|
||||
void decArm9Bin(void *armHdr, u32 mode){
|
||||
|
||||
//Firm keys
|
||||
u8 keyY[0x10];
|
||||
|
@ -49,8 +49,8 @@
|
||||
#define AES_KEYY 2
|
||||
|
||||
//NAND/FIRM stuff
|
||||
void nandFirm0(u8 *outbuf, u32 size, u8 console);
|
||||
void decArm9Bin(void *armHdr, u8 mode);
|
||||
void nandFirm0(u8 *outbuf, u32 size, u32 console);
|
||||
void decArm9Bin(void *armHdr, u32 mode);
|
||||
void setKeyXs(void *armHdr);
|
||||
|
||||
#endif
|
@ -26,10 +26,10 @@ void getSDMMC(void *pos, u32 *off, u32 size){
|
||||
*off = (u32)memsearch(pos, pattern, size, 4) - 1;
|
||||
|
||||
//Get DCD values
|
||||
u8 buf[4],
|
||||
p;
|
||||
u8 buf[4];
|
||||
u32 addr = 0,
|
||||
additive = 0;
|
||||
additive = 0,
|
||||
p;
|
||||
memcpy(buf, (void *)(*off+0x0A), 4);
|
||||
for (p = 0; p < 4; p++) addr |= ((u32) buf[p]) << (8 * p);
|
||||
memcpy(buf, (void *)(*off+0x0E), 4);
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
firmHeader *firmLocation = (firmHeader *)0x24000000;
|
||||
firmSectionHeader *section;
|
||||
u32 firmSize = 0;
|
||||
u8 mode = 1,
|
||||
u32 firmSize = 0,
|
||||
mode = 1,
|
||||
console = 1,
|
||||
emuNAND = 0,
|
||||
a9lhSetup = 0,
|
||||
@ -30,7 +30,7 @@ void setupCFW(void){
|
||||
u8 a9lhBoot = (*(u8 *)0x101401C0 == 0x0) ? 1 : 0;
|
||||
//Retrieve the last booted FIRM via CFG_BOOTENV
|
||||
u8 previousFirm = *(u8 *)0x10010000;
|
||||
u8 overrideConfig = 0;
|
||||
u32 overrideConfig = 0;
|
||||
const char lastConfigPath[] = "rei/lastbootcfg";
|
||||
|
||||
//Detect the console being used
|
||||
@ -93,7 +93,7 @@ void setupCFW(void){
|
||||
}
|
||||
|
||||
//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(!usePatchedFirm && !a9lhSetup && !mode){
|
||||
@ -101,7 +101,7 @@ u8 loadFirm(void){
|
||||
firmSize = console ? 0xF2000 : 0xE9000;
|
||||
nandFirm0((u8 *)firmLocation, firmSize, console);
|
||||
//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
|
||||
else{
|
||||
@ -118,13 +118,13 @@ u8 loadFirm(void){
|
||||
if((((u32)section[2].address >> 8) & 0xFF) != (console ? 0x60 : 0x68)) return 0;
|
||||
|
||||
if(console && !usePatchedFirm)
|
||||
decArm9Bin((u8*)firmLocation + section[2].offset, mode);
|
||||
decArm9Bin((void *)firmLocation + section[2].offset, mode);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Nand redirection
|
||||
u8 loadEmu(void){
|
||||
u32 loadEmu(void){
|
||||
|
||||
u32 emuOffset = 0,
|
||||
emuHeader = 0,
|
||||
@ -145,9 +145,9 @@ u8 loadEmu(void){
|
||||
fileRead((u8 *)emuCodeOffset, path, size);
|
||||
|
||||
//Find and patch emunand related offsets
|
||||
u32 *pos_sdmmc = (u32 *)memsearch((u32*)emuCodeOffset, "SDMC", size, 4);
|
||||
u32 *pos_offset = (u32 *)memsearch((u32*)emuCodeOffset, "NAND", size, 4);
|
||||
u32 *pos_header = (u32 *)memsearch((u32*)emuCodeOffset, "NCSD", size, 4);
|
||||
u32 *pos_sdmmc = (u32 *)memsearch((void *)emuCodeOffset, "SDMC", size, 4);
|
||||
u32 *pos_offset = (u32 *)memsearch((void *)emuCodeOffset, "NAND", size, 4);
|
||||
u32 *pos_header = (u32 *)memsearch((void *)emuCodeOffset, "NCSD", size, 4);
|
||||
getSDMMC(firmLocation, &sdmmcOffset, firmSize);
|
||||
getEmunandSect(&emuOffset, &emuHeader);
|
||||
getEmuRW(firmLocation, firmSize, &emuRead, &emuWrite);
|
||||
@ -158,7 +158,7 @@ u8 loadEmu(void){
|
||||
|
||||
//Patch emuNAND code in memory for O3DS and 9.0 N3DS
|
||||
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));
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ u8 loadEmu(void){
|
||||
}
|
||||
|
||||
//Patches
|
||||
u8 patchFirm(void){
|
||||
u32 patchFirm(void){
|
||||
|
||||
//Skip patching
|
||||
if(usePatchedFirm) return 1;
|
||||
@ -216,13 +216,13 @@ u8 patchFirm(void){
|
||||
fileRead((u8 *)rebootOffset, path, size);
|
||||
|
||||
//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);
|
||||
*pos_fopen = fOpenOffset;
|
||||
|
||||
//Patch path for emuNAND-patched FIRM
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -236,12 +236,12 @@ u8 patchFirm(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
|
||||
memcpy(section[0].address, (u8*)firmLocation + section[0].offset, section[0].size);
|
||||
memcpy(section[1].address, (u8*)firmLocation + section[1].offset, section[1].size);
|
||||
memcpy(section[2].address, (u8*)firmLocation + section[2].offset, section[2].size);
|
||||
memcpy(section[0].address, (void *)firmLocation + section[0].offset, section[0].size);
|
||||
memcpy(section[1].address, (void *)firmLocation + section[1].offset, section[1].size);
|
||||
memcpy(section[2].address, (void *)firmLocation + section[2].offset, section[2].size);
|
||||
|
||||
//Run ARM11 screen stuff
|
||||
vu32 *arm11 = (vu32 *)0x1FFFFFF8;
|
||||
|
@ -17,8 +17,8 @@
|
||||
#define SAFEMODE (BUTTON_L1 | BUTTON_R1 | BUTTON_A | (1 << 6))
|
||||
|
||||
void setupCFW(void);
|
||||
u8 loadFirm(void);
|
||||
u8 patchFirm(void);
|
||||
u32 loadFirm(void);
|
||||
u32 patchFirm(void);
|
||||
void launchFirm(void);
|
||||
|
||||
#endif
|
@ -7,12 +7,12 @@
|
||||
|
||||
static FATFS fs;
|
||||
|
||||
u8 mountSD(void){
|
||||
u32 mountSD(void){
|
||||
if(f_mount(&fs, "0:", 1) != FR_OK) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
u8 fileRead(u8 *dest, const char *path, u32 size){
|
||||
u32 fileRead(u8 *dest, const char *path, u32 size){
|
||||
FRESULT fr;
|
||||
FIL fp;
|
||||
unsigned int br = 0;
|
||||
@ -27,7 +27,7 @@ u8 fileRead(u8 *dest, const char *path, u32 size){
|
||||
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;
|
||||
FIL fp;
|
||||
unsigned int br = 0;
|
||||
@ -50,7 +50,7 @@ u32 fileSize(const char* path){
|
||||
return size;
|
||||
}
|
||||
|
||||
u8 fileExists(const char* path){
|
||||
u32 fileExists(const char *path){
|
||||
FIL fp;
|
||||
u8 exists = 0;
|
||||
|
||||
|
@ -7,10 +7,10 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
u8 mountSD(void);
|
||||
u8 fileRead(u8 *dest, const char *path, u32 size);
|
||||
u8 fileWrite(const u8 *buffer, const char *path, u32 size);
|
||||
u32 mountSD(void);
|
||||
u32 fileRead(u8 *dest, const char *path, u32 size);
|
||||
u32 fileWrite(const u8 *buffer, const char *path, u32 size);
|
||||
u32 fileSize(const char *path);
|
||||
u8 fileExists(const char* path);
|
||||
u32 fileExists(const char *path);
|
||||
|
||||
#endif
|
@ -10,7 +10,7 @@
|
||||
#include "firm.h"
|
||||
#include "draw.h"
|
||||
|
||||
u8 main(){
|
||||
u32 main(){
|
||||
mountSD();
|
||||
loadSplash();
|
||||
setupCFW();
|
||||
|
Loading…
x
Reference in New Issue
Block a user