Switched to 32-bit variables when possible, removed unneeded casts
Thanks @Fix94 for the tip
This commit is contained in:
parent
4bdba9f8e9
commit
13fd33a61d
@ -57,7 +57,7 @@ __asm__\
|
||||
void aes_setkey(u8 keyslot, const void* key, u32 keyType, u32 mode)
|
||||
{
|
||||
if(keyslot <= 0x03) return; // Ignore TWL keys for now
|
||||
u32* key32 = (u32*)key;
|
||||
u32 * key32 = (u32 *)key;
|
||||
*REG_AESCNT = (*REG_AESCNT & ~(AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER)) | mode;
|
||||
*REG_AESKEYCNT = (*REG_AESKEYCNT >> 6 << 6) | keyslot | AES_KEYCNT_WRITE;
|
||||
|
||||
@ -78,7 +78,7 @@ void aes_use_keyslot(u8 keyslot)
|
||||
|
||||
void aes_setiv(const void* iv, u32 mode)
|
||||
{
|
||||
const u32* iv32 = (const u32*)iv;
|
||||
const u32 *iv32 = (const u32 *)iv;
|
||||
*REG_AESCNT = (*REG_AESCNT & ~(AES_CNT_INPUT_ENDIAN | AES_CNT_INPUT_ORDER)) | mode;
|
||||
|
||||
// Word order for IV can't be changed in REG_AESCNT and always default to reversed
|
||||
@ -98,9 +98,9 @@ void aes_setiv(const void* iv, u32 mode)
|
||||
}
|
||||
}
|
||||
|
||||
void aes_advctr(void* ctr, u32 val, u32 mode)
|
||||
void aes_advctr(void *ctr, u32 val, u32 mode)
|
||||
{
|
||||
u32* ctr32 = (u32*)ctr;
|
||||
u32 *ctr32 = (u32*)ctr;
|
||||
|
||||
int i;
|
||||
if(mode & AES_INPUT_BE)
|
||||
@ -125,9 +125,9 @@ void aes_advctr(void* ctr, u32 val, u32 mode)
|
||||
}
|
||||
}
|
||||
|
||||
void aes_change_ctrmode(void* ctr, u32 fromMode, u32 toMode)
|
||||
void aes_change_ctrmode(void *ctr, u32 fromMode, u32 toMode)
|
||||
{
|
||||
u32* ctr32 = (u32*)ctr;
|
||||
u32 *ctr32 = (u32 *)ctr;
|
||||
int i;
|
||||
if((fromMode ^ toMode) & AES_CNT_INPUT_ENDIAN)
|
||||
{
|
||||
@ -147,13 +147,13 @@ void aes_change_ctrmode(void* ctr, u32 fromMode, u32 toMode)
|
||||
}
|
||||
}
|
||||
|
||||
void aes_batch(void* dst, const void* src, u32 blockCount)
|
||||
void aes_batch(void *dst, const void *src, u32 blockCount)
|
||||
{
|
||||
*REG_AESBLKCNT = blockCount << 16;
|
||||
*REG_AESCNT |= AES_CNT_START;
|
||||
|
||||
const u32* src32 = (const u32*)src;
|
||||
u32* dst32 = (u32*)dst;
|
||||
const u32 *src32 = (const u32 *)src;
|
||||
u32 *dst32 = (u32 *)dst;
|
||||
|
||||
u32 wbc = blockCount;
|
||||
u32 rbc = blockCount;
|
||||
@ -180,7 +180,7 @@ void aes_batch(void* dst, const void* src, u32 blockCount)
|
||||
}
|
||||
}
|
||||
|
||||
void aes(void* dst, const void* src, u32 blockCount, void* iv, u32 mode, u32 ivMode)
|
||||
void aes(void *dst, const void *src, u32 blockCount, void *iv, u32 mode, u32 ivMode)
|
||||
{
|
||||
*REG_AESCNT = mode |
|
||||
AES_CNT_INPUT_ORDER | AES_CNT_OUTPUT_ORDER |
|
||||
@ -233,14 +233,14 @@ u8 key2[0x10] = {
|
||||
};
|
||||
|
||||
//Get Nand CTR key
|
||||
void getNandCTR(u8 *buf, u8 console){
|
||||
u8 *addr = (console ? (u8*)0x080D8BBC : (u8*)0x080D797C) + 0x0F;
|
||||
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];
|
||||
@ -295,6 +295,6 @@ void setKeyXs(void *armHdr){
|
||||
for(u8 slot = 0x19; slot < 0x20; slot++){
|
||||
aes(decKey, keyData, 1, NULL, AES_ECB_DECRYPT_MODE, 0);
|
||||
aes_setkey(slot, decKey, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||
*(u8*)(keyData+0xF) += 1;
|
||||
*(u8 *)(keyData+0xF) += 1;
|
||||
}
|
||||
}
|
@ -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
|
@ -12,7 +12,7 @@ static struct fb *fb = (struct fb *)0x23FFFE00;
|
||||
|
||||
void shutdownLCD(void){
|
||||
|
||||
vu32 *arm11 = (vu32*)0x1FFFFFF8;
|
||||
vu32 *arm11 = (vu32 *)0x1FFFFFF8;
|
||||
|
||||
//Clear ARM11 entry offset
|
||||
*arm11 = 0;
|
||||
@ -36,7 +36,7 @@ void clearScreen(void){
|
||||
|
||||
void loadSplash(void){
|
||||
//Check if it's a no-screen-init A9LH boot via PDN_GPU_CNT
|
||||
if(*(u8*)0x10141200 == 0x1) return;
|
||||
if(*(u8 *)0x10141200 == 0x1) return;
|
||||
clearScreen();
|
||||
if(!fileRead(fb->top_left, "/rei/splash.bin", 0x46500)) return;
|
||||
u64 i = 0xFFFFFF; while(--i) __asm("mov r0, r0"); //Less Ghetto sleep func
|
||||
|
@ -8,12 +8,12 @@
|
||||
#include "memory.h"
|
||||
#include "fatfs/sdmmc/sdmmc.h"
|
||||
|
||||
static u8 *temp = (u8*)0x24300000;
|
||||
static u8 *temp = (u8 *)0x24300000;
|
||||
|
||||
void getEmunandSect(u32 *off, u32 *head){
|
||||
u32 nandSize = getMMCDevice(0)->total_size;
|
||||
if(sdmmc_sdcard_readsectors(nandSize, 1, temp) == 0){
|
||||
if(*(u32*)(temp + 0x100) == NCSD_MAGIC){
|
||||
if(*(u32 *)(temp + 0x100) == NCSD_MAGIC){
|
||||
*off = 0;
|
||||
*head = nandSize;
|
||||
}
|
||||
@ -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,
|
||||
@ -27,10 +27,10 @@ char *firmPathPatched = NULL;
|
||||
void setupCFW(void){
|
||||
|
||||
//Determine if booting with A9LH via PDN_SPI_CNT
|
||||
u8 a9lhBoot = (*(u8*)0x101401C0 == 0x0) ? 1 : 0;
|
||||
u8 a9lhBoot = (*(u8 *)0x101401C0 == 0x0) ? 1 : 0;
|
||||
//Retrieve the last booted FIRM via CFG_BOOTENV
|
||||
u8 previousFirm = *(u8*)0x10010000;
|
||||
u8 overrideConfig = 0;
|
||||
u8 previousFirm = *(u8 *)0x10010000;
|
||||
u32 overrideConfig = 0;
|
||||
const char lastConfigPath[] = "rei/lastbootcfg";
|
||||
|
||||
//Detect the console being used
|
||||
@ -93,15 +93,15 @@ 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){
|
||||
//Read FIRM from NAND and write to FCRAM
|
||||
firmSize = console ? 0xF2000 : 0xE9000;
|
||||
nandFirm0((u8*)firmLocation, firmSize, console);
|
||||
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{
|
||||
@ -109,7 +109,7 @@ u8 loadFirm(void){
|
||||
(mode ? "/rei/firmware.bin" : "/rei/firmware90.bin");
|
||||
firmSize = fileSize(path);
|
||||
if(!firmSize) return 0;
|
||||
fileRead((u8*)firmLocation, path, firmSize);
|
||||
fileRead((u8 *)firmLocation, path, firmSize);
|
||||
}
|
||||
|
||||
section = firmLocation->section;
|
||||
@ -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,
|
||||
@ -142,12 +142,12 @@ u8 loadEmu(void){
|
||||
//Find offset for emuNAND code from the offset in nandRedir
|
||||
emuCodeOffset = *(u32 *)(nandRedir + 4) - (u32)section[2].address +
|
||||
section[2].offset + (u32)firmLocation;
|
||||
fileRead((u8*)emuCodeOffset, path, size);
|
||||
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;
|
||||
@ -199,7 +199,7 @@ u8 patchFirm(void){
|
||||
|
||||
//Patch ARM9 entrypoint on N3DS to skip arm9loader
|
||||
if(console){
|
||||
u32 *arm9 = (u32*)&firmLocation->arm9Entry;
|
||||
u32 *arm9 = (u32 *)&firmLocation->arm9Entry;
|
||||
*arm9 = 0x801B01C;
|
||||
}
|
||||
|
||||
@ -213,40 +213,40 @@ u8 patchFirm(void){
|
||||
u32 size = fileSize(path);
|
||||
if(!size) return 0;
|
||||
getReboot(firmLocation, firmSize, &rebootOffset);
|
||||
fileRead((u8*)rebootOffset, path, size);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
//Write patched FIRM to SD if needed
|
||||
if(firmPathPatched)
|
||||
if(!fileWrite((u8*)firmLocation, firmPathPatched, firmSize)) return 0;
|
||||
if(!fileWrite((u8 *)firmLocation, firmPathPatched, firmSize)) return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
vu32 *arm11 = (vu32 *)0x1FFFFFF8;
|
||||
*arm11 = (u32)shutdownLCD;
|
||||
while (*arm11);
|
||||
while(*arm11);
|
||||
|
||||
//Set ARM11 kernel
|
||||
*arm11 = (u32)firmLocation->arm11Entry;
|
||||
|
@ -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
|
10
source/fs.c
10
source/fs.c
@ -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;
|
||||
@ -39,7 +39,7 @@ u8 fileWrite(const u8 *buffer, const char *path, u32 size){
|
||||
return fr ? 0 : 1;
|
||||
}
|
||||
|
||||
u32 fileSize(const char* path){
|
||||
u32 fileSize(const char *path){
|
||||
FIL fp;
|
||||
u32 size = 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;
|
||||
|
||||
|
10
source/fs.h
10
source/fs.h
@ -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 fileSize(const char* path);
|
||||
u8 fileExists(const char* path);
|
||||
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);
|
||||
u32 fileExists(const char *path);
|
||||
|
||||
#endif
|
@ -10,7 +10,7 @@
|
||||
#include "firm.h"
|
||||
#include "draw.h"
|
||||
|
||||
u8 main(){
|
||||
u32 main(){
|
||||
mountSD();
|
||||
loadSplash();
|
||||
setupCFW();
|
||||
|
Reference in New Issue
Block a user