(Hopefully last) clean-up
This commit is contained in:
parent
d4a3ce2d0d
commit
99829b3cf7
@ -1,8 +1,6 @@
|
|||||||
// From http://github.com/b1l1s/ctr
|
// From http://github.com/b1l1s/ctr
|
||||||
|
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "fatfs/sdmmc/sdmmc.h"
|
#include "fatfs/sdmmc/sdmmc.h"
|
||||||
|
|
||||||
@ -256,7 +254,6 @@ void nandFirm0(u8 *outbuf, const u32 size, u8 console){
|
|||||||
void decArm9Bin(void *armHdr, u8 mode){
|
void decArm9Bin(void *armHdr, u8 mode){
|
||||||
|
|
||||||
//Firm keys
|
//Firm keys
|
||||||
u8 keyX[0x10];
|
|
||||||
u8 keyY[0x10];
|
u8 keyY[0x10];
|
||||||
u8 CTR[0x10];
|
u8 CTR[0x10];
|
||||||
u8 slot = mode ? 0x16 : 0x15;
|
u8 slot = mode ? 0x16 : 0x15;
|
||||||
@ -264,9 +261,14 @@ void decArm9Bin(void *armHdr, u8 mode){
|
|||||||
//Setup keys needed for arm9bin decryption
|
//Setup keys needed for arm9bin decryption
|
||||||
memcpy(keyY, armHdr+0x10, 0x10);
|
memcpy(keyY, armHdr+0x10, 0x10);
|
||||||
memcpy(CTR, armHdr+0x20, 0x10);
|
memcpy(CTR, armHdr+0x20, 0x10);
|
||||||
u32 size = atoi(armHdr+0x30);
|
u32 size = 0;
|
||||||
|
//http://stackoverflow.com/questions/12791077/atoi-implementation-in-c
|
||||||
|
for(u8 *tmp = armHdr+0x30; *tmp; tmp++)
|
||||||
|
size = (size<<3)+(size<<1)+(*tmp)-'0';
|
||||||
|
|
||||||
if(mode){
|
if(mode){
|
||||||
|
u8 keyX[0x10];
|
||||||
|
|
||||||
//Set 0x11 to key2 for the arm9bin and misc keys
|
//Set 0x11 to key2 for the arm9bin and misc keys
|
||||||
aes_setkey(0x11, key2, AES_KEYNORMAL, AES_INPUT_BE | AES_INPUT_NORMAL);
|
aes_setkey(0x11, key2, AES_KEYNORMAL, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||||
aes_use_keyslot(0x11);
|
aes_use_keyslot(0x11);
|
||||||
@ -286,11 +288,11 @@ void decArm9Bin(void *armHdr, u8 mode){
|
|||||||
void setKeyXs(void *armHdr){
|
void setKeyXs(void *armHdr){
|
||||||
|
|
||||||
//Set keys 0x19..0x1F keyXs
|
//Set keys 0x19..0x1F keyXs
|
||||||
void *keyData = armHdr+0x89814;
|
|
||||||
void *decKey = keyData+0x10;
|
|
||||||
aes_setkey(0x11, key2, AES_KEYNORMAL, AES_INPUT_BE | AES_INPUT_NORMAL);
|
aes_setkey(0x11, key2, AES_KEYNORMAL, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||||
aes_use_keyslot(0x11);
|
aes_use_keyslot(0x11);
|
||||||
for(u8 slot = 0x19; slot < 0x20; slot++){
|
for(u8 slot = 0x19; slot < 0x20; slot++){
|
||||||
|
void *keyData = armHdr+0x89814;
|
||||||
|
void *decKey = keyData+0x10;
|
||||||
aes(decKey, keyData, 1, NULL, AES_ECB_DECRYPT_MODE, 0);
|
aes(decKey, keyData, 1, NULL, AES_ECB_DECRYPT_MODE, 0);
|
||||||
aes_setkey(slot, decKey, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
|
aes_setkey(slot, decKey, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||||
*(u8*)(keyData+0xF) += 1;
|
*(u8*)(keyData+0xF) += 1;
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
// From http://github.com/b1l1s/ctr
|
// From http://github.com/b1l1s/ctr
|
||||||
|
|
||||||
#ifndef __CRYPTO_H
|
#ifndef CRYPTO_INC
|
||||||
#define __CRYPTO_H
|
#define CRYPTO_INC
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
/**************************AES****************************/
|
/**************************AES****************************/
|
||||||
@ -54,4 +53,4 @@ void nandFirm0(u8 *outbuf, const u32 size, u8 console);
|
|||||||
void decArm9Bin(void *armHdr, u8 mode);
|
void decArm9Bin(void *armHdr, u8 mode);
|
||||||
void setKeyXs(void *armHdr);
|
void setKeyXs(void *armHdr);
|
||||||
|
|
||||||
#endif /*__CRYPTO_H*/
|
#endif
|
@ -7,7 +7,6 @@
|
|||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
static struct fb *fb = (struct fb *)0x23FFFE00;
|
static struct fb *fb = (struct fb *)0x23FFFE00;
|
||||||
|
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
* Copyright (c) 2015 All Rights Reserved
|
* Copyright (c) 2015 All Rights Reserved
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef DRAW_INC
|
||||||
|
#define DRAW_INC
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
struct fb {
|
struct fb {
|
||||||
@ -13,4 +16,6 @@ struct fb {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void loadSplash(void);
|
void loadSplash(void);
|
||||||
void shutdownLCD(void);
|
void shutdownLCD(void);
|
||||||
|
|
||||||
|
#endif
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include "emunand.h"
|
#include "emunand.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "fatfs/ff.h"
|
|
||||||
#include "fatfs/sdmmc/sdmmc.h"
|
#include "fatfs/sdmmc/sdmmc.h"
|
||||||
|
|
||||||
static u8 *temp = (u8*)0x24300000;
|
static u8 *temp = (u8*)0x24300000;
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
* Copyright (c) 2015 All Rights Reserved
|
* Copyright (c) 2015 All Rights Reserved
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef EMU_INC
|
#ifndef EMUNAND_INC
|
||||||
#define EMU_INC
|
#define EMUNAND_INC
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ u8 patchFirm(void){
|
|||||||
|
|
||||||
//Apply emuNAND patches
|
//Apply emuNAND patches
|
||||||
if(emuNAND){
|
if(emuNAND){
|
||||||
if(loadEmu()) return 0;
|
if(!loadEmu()) return 0;
|
||||||
}
|
}
|
||||||
else if(a9lhSetup){
|
else if(a9lhSetup){
|
||||||
//Patch FIRM partitions writes on SysNAND to protect A9LH
|
//Patch FIRM partitions writes on SysNAND to protect A9LH
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
* by Reisyukaku
|
* by Reisyukaku
|
||||||
* Copyright (c) 2015 All Rights Reserved
|
* Copyright (c) 2015 All Rights Reserved
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef FIRM_INC
|
#ifndef FIRM_INC
|
||||||
#define FIRM_INC
|
#define FIRM_INC
|
||||||
|
|
||||||
|
17
source/fs.c
17
source/fs.c
@ -2,18 +2,17 @@
|
|||||||
* fs.c
|
* fs.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "fatfs/ff.h"
|
#include "fatfs/ff.h"
|
||||||
|
|
||||||
static FATFS fs;
|
static FATFS fs;
|
||||||
|
|
||||||
int mountSD(void){
|
u8 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fileRead(u8 *dest, const char *path, u32 size){
|
u8 fileRead(u8 *dest, const char *path, u32 size){
|
||||||
FRESULT fr;
|
FRESULT fr;
|
||||||
FIL fp;
|
FIL fp;
|
||||||
unsigned int br = 0;
|
unsigned int br = 0;
|
||||||
@ -28,13 +27,11 @@ int fileRead(u8 *dest, const char *path, u32 size){
|
|||||||
return fr ? 0 : 1;
|
return fr ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fileWrite(const u8 *buffer, const char *path, u32 size){
|
u8 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;
|
||||||
|
|
||||||
f_unlink(path);
|
|
||||||
|
|
||||||
fr = f_open(&fp, path, FA_WRITE | FA_OPEN_ALWAYS);
|
fr = f_open(&fp, path, FA_WRITE | FA_OPEN_ALWAYS);
|
||||||
if(fr == FR_OK) fr = f_write(&fp, buffer, size, &br);
|
if(fr == FR_OK) fr = f_write(&fp, buffer, size, &br);
|
||||||
|
|
||||||
@ -42,9 +39,9 @@ int fileWrite(const u8 *buffer, const char *path, u32 size){
|
|||||||
return fr ? 0 : 1;
|
return fr ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fileSize(const char* path){
|
u32 fileSize(const char* path){
|
||||||
FIL fp;
|
FIL fp;
|
||||||
int size = 0;
|
u32 size = 0;
|
||||||
|
|
||||||
if(f_open(&fp, path, FA_READ) == FR_OK)
|
if(f_open(&fp, path, FA_READ) == FR_OK)
|
||||||
size = f_size(&fp);
|
size = f_size(&fp);
|
||||||
@ -53,9 +50,9 @@ int fileSize(const char* path){
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fileExists(const char* path){
|
u8 fileExists(const char* path){
|
||||||
FIL fp;
|
FIL fp;
|
||||||
int exists = 0;
|
u8 exists = 0;
|
||||||
|
|
||||||
if(f_open(&fp, path, FA_READ) == FR_OK) exists = 1;
|
if(f_open(&fp, path, FA_READ) == FR_OK) exists = 1;
|
||||||
|
|
||||||
|
16
source/fs.h
16
source/fs.h
@ -2,15 +2,15 @@
|
|||||||
* fs.h
|
* fs.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __fs_h__
|
#ifndef FS_INC
|
||||||
#define __fs_h__
|
#define FS_INC
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
int mountSD(void);
|
u8 mountSD(void);
|
||||||
int fileRead(u8 *dest, const char *path, u32 size);
|
u8 fileRead(u8 *dest, const char *path, u32 size);
|
||||||
int fileWrite(const u8 *buffer, const char *path, u32 size);
|
u8 fileWrite(const u8 *buffer, const char *path, u32 size);
|
||||||
int fileSize(const char* path);
|
u32 fileSize(const char* path);
|
||||||
int fileExists(const char* path);
|
u8 fileExists(const char* path);
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -3,27 +3,28 @@
|
|||||||
* by Reisyukaku
|
* by Reisyukaku
|
||||||
* Copyright (c) 2015 All Rights Reserved
|
* Copyright (c) 2015 All Rights Reserved
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
void memcpy(void *dest, const void *src, u32 size){
|
void memcpy(void *dest, const void *src, u32 size){
|
||||||
char *destc = (char *)dest;
|
|
||||||
const char *srcc = (const char *)src;
|
|
||||||
u32 i; for (i = 0; i < size; i++) {
|
u32 i; for (i = 0; i < size; i++) {
|
||||||
|
char *destc = (char *)dest;
|
||||||
|
const char *srcc = (const char *)src;
|
||||||
destc[i] = srcc[i];
|
destc[i] = srcc[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void memset(void *dest, int filler, u32 size){
|
void memset(void *dest, int filler, u32 size){
|
||||||
char *destc = (char *)dest;
|
|
||||||
u32 i; for (i = 0; i < size; i++) {
|
u32 i; for (i = 0; i < size; i++) {
|
||||||
|
char *destc = (char *)dest;
|
||||||
destc[i] = filler;
|
destc[i] = filler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int memcmp(const void *buf1, const void *buf2, u32 size){
|
int memcmp(const void *buf1, const void *buf2, u32 size){
|
||||||
const char *buf1c = (const char *)buf1;
|
|
||||||
const char *buf2c = (const char *)buf2;
|
|
||||||
u32 i; for (i = 0; i < size; i++) {
|
u32 i; for (i = 0; i < size; i++) {
|
||||||
|
const char *buf1c = (const char *)buf1;
|
||||||
|
const char *buf2c = (const char *)buf2;
|
||||||
int cmp = buf1c[i] - buf2c[i];
|
int cmp = buf1c[i] - buf2c[i];
|
||||||
if (cmp) return cmp;
|
if (cmp) return cmp;
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
* by Reisyukaku
|
* by Reisyukaku
|
||||||
* Copyright (c) 2015 All Rights Reserved
|
* Copyright (c) 2015 All Rights Reserved
|
||||||
*/
|
*/
|
||||||
#ifndef MEM_INC
|
|
||||||
#define MEM_INC
|
#ifndef MEMORY_INC
|
||||||
|
#define MEMORY_INC
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
* by Reisyukaku
|
* by Reisyukaku
|
||||||
* Copyright (c) 2015 All Rights Reserved
|
* Copyright (c) 2015 All Rights Reserved
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PATCHES_INC
|
#ifndef PATCHES_INC
|
||||||
#define PATCHES_INC
|
#define PATCHES_INC
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
* by Reisyukaku
|
* by Reisyukaku
|
||||||
* Copyright (c) 2015 All Rights Reserved
|
* Copyright (c) 2015 All Rights Reserved
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TYPES_INC
|
#ifndef TYPES_INC
|
||||||
#define TYPES_INC
|
#define TYPES_INC
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user