(Hopefully last) clean-up

This commit is contained in:
Aurora 2016-03-06 03:41:07 +01:00
parent d4a3ce2d0d
commit 99829b3cf7
14 changed files with 47 additions and 41 deletions

View File

@ -1,8 +1,6 @@
// From http://github.com/b1l1s/ctr
#include "crypto.h"
#include <stddef.h>
#include "memory.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){
//Firm keys
u8 keyX[0x10];
u8 keyY[0x10];
u8 CTR[0x10];
u8 slot = mode ? 0x16 : 0x15;
@ -264,9 +261,14 @@ void decArm9Bin(void *armHdr, u8 mode){
//Setup keys needed for arm9bin decryption
memcpy(keyY, armHdr+0x10, 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){
u8 keyX[0x10];
//Set 0x11 to key2 for the arm9bin and misc keys
aes_setkey(0x11, key2, AES_KEYNORMAL, AES_INPUT_BE | AES_INPUT_NORMAL);
aes_use_keyslot(0x11);
@ -286,11 +288,11 @@ void decArm9Bin(void *armHdr, u8 mode){
void setKeyXs(void *armHdr){
//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_use_keyslot(0x11);
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_setkey(slot, decKey, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
*(u8*)(keyData+0xF) += 1;

View File

@ -1,9 +1,8 @@
// From http://github.com/b1l1s/ctr
#ifndef __CRYPTO_H
#define __CRYPTO_H
#ifndef CRYPTO_INC
#define CRYPTO_INC
#include <stdint.h>
#include "types.h"
/**************************AES****************************/
@ -54,4 +53,4 @@ void nandFirm0(u8 *outbuf, const u32 size, u8 console);
void decArm9Bin(void *armHdr, u8 mode);
void setKeyXs(void *armHdr);
#endif /*__CRYPTO_H*/
#endif

View File

@ -7,7 +7,6 @@
#include "draw.h"
#include "fs.h"
#include "memory.h"
#include "types.h"
static struct fb *fb = (struct fb *)0x23FFFE00;

View File

@ -4,6 +4,9 @@
* Copyright (c) 2015 All Rights Reserved
*/
#ifndef DRAW_INC
#define DRAW_INC
#include "types.h"
struct fb {
@ -13,4 +16,6 @@ struct fb {
};
void loadSplash(void);
void shutdownLCD(void);
void shutdownLCD(void);
#endif

View File

@ -6,7 +6,6 @@
#include "emunand.h"
#include "memory.h"
#include "fatfs/ff.h"
#include "fatfs/sdmmc/sdmmc.h"
static u8 *temp = (u8*)0x24300000;

View File

@ -4,8 +4,8 @@
* Copyright (c) 2015 All Rights Reserved
*/
#ifndef EMU_INC
#define EMU_INC
#ifndef EMUNAND_INC
#define EMUNAND_INC
#include "types.h"

View File

@ -181,7 +181,7 @@ u8 patchFirm(void){
//Apply emuNAND patches
if(emuNAND){
if(loadEmu()) return 0;
if(!loadEmu()) return 0;
}
else if(a9lhSetup){
//Patch FIRM partitions writes on SysNAND to protect A9LH

View File

@ -3,6 +3,7 @@
* by Reisyukaku
* Copyright (c) 2015 All Rights Reserved
*/
#ifndef FIRM_INC
#define FIRM_INC

View File

@ -2,18 +2,17 @@
* fs.c
*/
#include <stddef.h>
#include "fs.h"
#include "fatfs/ff.h"
static FATFS fs;
int mountSD(void){
u8 mountSD(void){
if(f_mount(&fs, "0:", 1) != FR_OK) return 0;
return 1;
}
int fileRead(u8 *dest, const char *path, u32 size){
u8 fileRead(u8 *dest, const char *path, u32 size){
FRESULT fr;
FIL fp;
unsigned int br = 0;
@ -28,13 +27,11 @@ int fileRead(u8 *dest, const char *path, u32 size){
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;
FIL fp;
unsigned int br = 0;
f_unlink(path);
fr = f_open(&fp, path, FA_WRITE | FA_OPEN_ALWAYS);
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;
}
int fileSize(const char* path){
u32 fileSize(const char* path){
FIL fp;
int size = 0;
u32 size = 0;
if(f_open(&fp, path, FA_READ) == FR_OK)
size = f_size(&fp);
@ -53,9 +50,9 @@ int fileSize(const char* path){
return size;
}
int fileExists(const char* path){
u8 fileExists(const char* path){
FIL fp;
int exists = 0;
u8 exists = 0;
if(f_open(&fp, path, FA_READ) == FR_OK) exists = 1;

View File

@ -2,15 +2,15 @@
* fs.h
*/
#ifndef __fs_h__
#define __fs_h__
#ifndef FS_INC
#define FS_INC
#include "types.h"
int mountSD(void);
int fileRead(u8 *dest, const char *path, u32 size);
int fileWrite(const u8 *buffer, const char *path, u32 size);
int fileSize(const char* path);
int fileExists(const char* path);
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);
#endif
#endif

View File

@ -3,27 +3,28 @@
* by Reisyukaku
* Copyright (c) 2015 All Rights Reserved
*/
#include "memory.h"
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++) {
char *destc = (char *)dest;
const char *srcc = (const char *)src;
destc[i] = srcc[i];
}
}
void memset(void *dest, int filler, u32 size){
char *destc = (char *)dest;
u32 i; for (i = 0; i < size; i++) {
char *destc = (char *)dest;
destc[i] = filler;
}
}
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++) {
const char *buf1c = (const char *)buf1;
const char *buf2c = (const char *)buf2;
int cmp = buf1c[i] - buf2c[i];
if (cmp) return cmp;
}

View File

@ -3,8 +3,9 @@
* by Reisyukaku
* Copyright (c) 2015 All Rights Reserved
*/
#ifndef MEM_INC
#define MEM_INC
#ifndef MEMORY_INC
#define MEMORY_INC
#include "types.h"

View File

@ -3,6 +3,7 @@
* by Reisyukaku
* Copyright (c) 2015 All Rights Reserved
*/
#ifndef PATCHES_INC
#define PATCHES_INC

View File

@ -3,6 +3,7 @@
* by Reisyukaku
* Copyright (c) 2015 All Rights Reserved
*/
#ifndef TYPES_INC
#define TYPES_INC