From 04978ebb01101dad87a5f0e26d85329099877aa3 Mon Sep 17 00:00:00 2001 From: Aurora Date: Sun, 6 Mar 2016 23:52:14 +0100 Subject: [PATCH] Const for all Probably useless, but for the sake of readability --- source/crypto.c | 2 +- source/emunand.c | 6 +++--- source/memory.c | 2 +- source/memory.h | 2 +- source/patches.c | 20 ++++++++++---------- source/patches.h | 10 +++++----- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/source/crypto.c b/source/crypto.c index 64902f5..53735e8 100755 --- a/source/crypto.c +++ b/source/crypto.c @@ -228,7 +228,7 @@ void aes(void *dst, const void *src, u32 blockCount, void *iv, u32 mode, u32 ivM ****************************************************************/ //Nand key#2 (0x12C10) -u8 key2[0x10] = { +const u8 key2[0x10] = { 0x42, 0x3F, 0x81, 0x7A, 0x23, 0x52, 0x58, 0x31, 0x6E, 0x75, 0x8E, 0x3A, 0x39, 0x43, 0x2E, 0xD0 }; diff --git a/source/emunand.c b/source/emunand.c index 33ede4b..fed0a1b 100644 --- a/source/emunand.c +++ b/source/emunand.c @@ -22,7 +22,7 @@ void getEmunandSect(u32 *off, u32 *head){ void getSDMMC(void *pos, u32 *off, u32 size){ //Look for struct code - unsigned char pattern[] = {0x21, 0x20, 0x18, 0x20}; + const unsigned char pattern[] = {0x21, 0x20, 0x18, 0x20}; *off = (u32)memsearch(pos, pattern, size, 4) - 1; //Get DCD values @@ -41,7 +41,7 @@ void getSDMMC(void *pos, u32 *off, u32 size){ void getEmuRW(void *pos, u32 size, u32 *readOff, u32 *writeOff){ //Look for read/write code - unsigned char pattern[] = {0x1E, 0x00, 0xC8, 0x05}; + const unsigned char pattern[] = {0x1E, 0x00, 0xC8, 0x05}; *writeOff = (u32)memsearch(pos, pattern, size, 4) - 6; *readOff = (u32)memsearch((void *)(*writeOff - 0x1000), pattern, 0x1000, 4) - 6; @@ -49,7 +49,7 @@ void getEmuRW(void *pos, u32 size, u32 *readOff, u32 *writeOff){ void getMPU(void *pos, u32 *off, u32 size){ //Look for MPU pattern - unsigned char pattern[] = {0x03, 0x00, 0x24, 0x00}; + const unsigned char pattern[] = {0x03, 0x00, 0x24, 0x00}; *off = (u32)memsearch(pos, pattern, size, 4); } \ No newline at end of file diff --git a/source/memory.c b/source/memory.c index 4769dfe..a66f88d 100644 --- a/source/memory.c +++ b/source/memory.c @@ -29,7 +29,7 @@ int memcmp(const void *buf1, const void *buf2, u32 size){ return 0; } -void *memsearch(void *start_pos, void *search, u32 size, u32 size_search){ +void *memsearch(void *start_pos, const void *search, u32 size, u32 size_search){ for(void *pos = start_pos + size - size_search; pos >= start_pos; pos--){ if(memcmp(pos, search, size_search) == 0) return pos; } diff --git a/source/memory.h b/source/memory.h index c5436dc..63686a6 100644 --- a/source/memory.h +++ b/source/memory.h @@ -12,6 +12,6 @@ void memcpy(void *dest, const void *src, u32 size); void memset(void *dest, int filler, u32 size); int memcmp(const void *buf1, const void *buf2, u32 size); -void *memsearch(void *start_pos, void *search, u32 size, u32 size_search); +void *memsearch(void *start_pos, const void *search, u32 size, u32 size_search); #endif \ No newline at end of file diff --git a/source/patches.c b/source/patches.c index 9e472a4..00ec5ab 100644 --- a/source/patches.c +++ b/source/patches.c @@ -11,7 +11,7 @@ * Patches **************************************************/ -u8 mpu[0x2C] = { //MPU shit +const u8 mpu[0x2C] = { //MPU shit 0x03, 0x00, 0x36, 0x00, 0x00, 0x00, 0x10, 0x10, 0x01, 0x00, 0x00, 0x01, 0x03, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x01, 0x01, 0x01, 0x03, 0x06, 0x20, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01, 0x01, 0x01, 0x01, 0x03, 0x06, 0x1C, 0x00, 0x00, 0x00, 0x02, 0x08 @@ -19,12 +19,12 @@ u8 mpu[0x2C] = { //MPU shit u8 nandRedir[0x08] = {0x00, 0x4C, 0xA0, 0x47, 0xC0, 0xA5, 0x01, 0x08}; //Branch to emunand function -u8 sigPat1[2] = {0x00, 0x20}; -u8 sigPat2[4] = {0x00, 0x20, 0x70, 0x47}; +const u8 sigPat1[2] = {0x00, 0x20}; +const u8 sigPat2[4] = {0x00, 0x20, 0x70, 0x47}; -u8 FIRMblock[4] = {0x00, 0x20, 0xC0, 0x46}; +const u8 FIRMblock[4] = {0x00, 0x20, 0xC0, 0x46}; -u8 emuInstr[5] = {0xA5, 0x01, 0x08, 0x30, 0xA5}; +const u8 emuInstr[5] = {0xA5, 0x01, 0x08, 0x30, 0xA5}; /************************************************** * Functions @@ -32,8 +32,8 @@ u8 emuInstr[5] = {0xA5, 0x01, 0x08, 0x30, 0xA5}; void getSignatures(void *pos, u32 size, u32 *off, u32 *off2){ //Look for signature checks - unsigned char pattern[] = {0xC0, 0x1C, 0x76, 0xE7}; - unsigned char pattern2[] = {0xB5, 0x22, 0x4D, 0x0C}; + const unsigned char pattern[] = {0xC0, 0x1C, 0x76, 0xE7}; + const unsigned char pattern2[] = {0xB5, 0x22, 0x4D, 0x0C}; *off = (u32)memsearch(pos, pattern, size, 4); *off2 = (u32)memsearch(pos, pattern2, size, 4) - 1; @@ -41,7 +41,7 @@ void getSignatures(void *pos, u32 size, u32 *off, u32 *off2){ void getReboot(void *pos, u32 size, u32 *off){ //Look for FIRM reboot code - unsigned char pattern[] = {0xDE, 0x1F, 0x8D, 0xE2}; + const unsigned char pattern[] = {0xDE, 0x1F, 0x8D, 0xE2}; *off = (u32)memsearch(pos, pattern, size, 4) - 0x10; } @@ -50,7 +50,7 @@ void getfOpen(void *pos, u32 size, u32 *off){ //Calculate fOpen u32 p9addr = *(u32 *)((u8 *)memsearch(pos, "ess9", size, 4) + 0xC); u32 p9off = (u32)memsearch(pos, "code", size, 4) + 0x1FF; - unsigned char pattern[] = {0xB0, 0x04, 0x98, 0x0D}; + const unsigned char pattern[] = {0xB0, 0x04, 0x98, 0x0D}; *off = (u32)memsearch(pos, pattern, size, 4) - 2 - p9off + p9addr; } @@ -58,7 +58,7 @@ void getfOpen(void *pos, u32 size, u32 *off){ void getFIRMWrite(void *pos, u32 size, u32 *off){ //Look for FIRM writing code u8 *firmwrite = (u8 *)memsearch(pos, "exe:", size, 4); - unsigned char pattern[] = {0x00, 0x28, 0x01, 0xDA}; + const unsigned char pattern[] = {0x00, 0x28, 0x01, 0xDA}; *off = (u32)memsearch(firmwrite - 0x100, pattern, 0x100, 4); } \ No newline at end of file diff --git a/source/patches.h b/source/patches.h index e5f574b..879a3bf 100644 --- a/source/patches.h +++ b/source/patches.h @@ -12,12 +12,12 @@ /************************************************** * Patches **************************************************/ -u8 mpu[0x2C]; +const u8 mpu[0x2C]; u8 nandRedir[0x08]; -u8 sigPat1[2]; -u8 sigPat2[4]; -u8 FIRMblock[4]; -u8 emuInstr[5]; +const u8 sigPat1[2]; +const u8 sigPat2[4]; +const u8 FIRMblock[4]; +const u8 emuInstr[5]; /************************************************** * Functions