Some more tidying up
This commit is contained in:
parent
3475cfe1e6
commit
24186a7148
2
Makefile
2
Makefile
@ -20,7 +20,6 @@ dir_out := out
|
||||
|
||||
ASFLAGS := -mlittle-endian -mcpu=arm946e-s -march=armv5te
|
||||
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2 -ffast-math
|
||||
CFLAGS += -DCONFIG_TITLE="\"$(name) $(version) configuration\""
|
||||
FLAGS := name=$(name).dat dir_out=$(abspath $(dir_out)) ICON=$(abspath icon.png) APP_DESCRIPTION="Noob-friendly 3DS CFW." APP_AUTHOR="Reisyukaku/Aurora Wright" --no-print-directory
|
||||
|
||||
objects_cfw = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
|
||||
@ -97,6 +96,7 @@ $(dir_build)/main.elf: $(objects_cfw)
|
||||
$(CC) -nostartfiles $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^
|
||||
|
||||
$(dir_build)/memory.o : CFLAGS+=-O3
|
||||
$(dir_build)/utils.o : CFLAGS += -DCONFIG_TITLE="\"$(name) $(version) configuration\""
|
||||
|
||||
$(dir_build)/%.o: $(dir_source)/%.c $(dir_build)/patches.h $(dir_build)/loader.h $(dir_build)/screeninit.h
|
||||
@mkdir -p "$(@D)"
|
||||
|
@ -158,7 +158,7 @@ static Result load_code(u64 progid, prog_addrs_t *shared, u64 prog_handle, int i
|
||||
}
|
||||
|
||||
// patch
|
||||
patch_code(progid, (u8 *)shared->text_addr, shared->total_size << 12);
|
||||
patchCode(progid, (u8 *)shared->text_addr, shared->total_size << 12);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -36,31 +36,31 @@ static u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSiz
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static u32 patch_memory(u8 *start, u32 size, const void *pattern, u32 patsize, int offset, const void *replace, u32 repsize, u32 count)
|
||||
static u32 patchMemory(u8 *start, u32 size, const void *pattern, u32 patSize, int offset, const void *replace, u32 repSize, u32 count)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for(i = 0; i < count; i++)
|
||||
{
|
||||
u8 *found = memsearch(start, pattern, size, patsize);
|
||||
u8 *found = memsearch(start, pattern, size, patSize);
|
||||
|
||||
if(found == NULL)
|
||||
break;
|
||||
|
||||
memcpy(found + offset, replace, repsize);
|
||||
memcpy(found + offset, replace, repSize);
|
||||
|
||||
u32 at = (u32)(found - start);
|
||||
|
||||
if(at + patsize > size) size = 0;
|
||||
else size = size - (at + patsize);
|
||||
if(at + patSize > size) size = 0;
|
||||
else size = size - (at + patSize);
|
||||
|
||||
start = found + patsize;
|
||||
start = found + patSize;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int file_open(IFile *file, FS_ArchiveID id, const char *path, int flags)
|
||||
static int fileOpen(IFile *file, FS_ArchiveID id, const char *path, int flags)
|
||||
{
|
||||
FS_Archive archive;
|
||||
FS_Path ppath;
|
||||
@ -76,7 +76,7 @@ static int file_open(IFile *file, FS_ArchiveID id, const char *path, int flags)
|
||||
return IFile_Open(file, archive, ppath, flags);
|
||||
}
|
||||
|
||||
static int load_secureinfo()
|
||||
static int loadSecureinfo()
|
||||
{
|
||||
IFile file;
|
||||
Result ret;
|
||||
@ -85,7 +85,7 @@ static int load_secureinfo()
|
||||
if(secureinfo[0] == 0xFF)
|
||||
return 0;
|
||||
|
||||
ret = file_open(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ);
|
||||
ret = fileOpen(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ);
|
||||
if(R_SUCCEEDED(ret))
|
||||
{
|
||||
ret = IFile_Read(&file, &total, secureinfo, sizeof(secureinfo));
|
||||
@ -97,7 +97,7 @@ static int load_secureinfo()
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int load_config()
|
||||
static int loadConfig()
|
||||
{
|
||||
IFile file;
|
||||
Result ret;
|
||||
@ -106,7 +106,7 @@ static int load_config()
|
||||
if(config)
|
||||
return 0;
|
||||
|
||||
ret = file_open(&file, ARCHIVE_SDMC, "/aurei/config.bin", FS_OPEN_READ);
|
||||
ret = fileOpen(&file, ARCHIVE_SDMC, "/aurei/config.bin", FS_OPEN_READ);
|
||||
if(R_SUCCEEDED(ret))
|
||||
{
|
||||
ret = IFile_Read(&file, &total, (void *)&config, 3);
|
||||
@ -116,7 +116,7 @@ static int load_config()
|
||||
return ret;
|
||||
}
|
||||
|
||||
u32 patch_code(u64 progid, u8 *code, u32 size)
|
||||
void patchCode(u64 progid, u8 *code, u32 size)
|
||||
{
|
||||
switch(progid)
|
||||
{
|
||||
@ -134,7 +134,8 @@ u32 patch_code(u64 progid, u8 *code, u32 size)
|
||||
0x01, 0x00, 0xA0, 0xE3, 0x1E, 0xFF, 0x2F, 0xE1
|
||||
};
|
||||
|
||||
patch_memory(code, size,
|
||||
//Patch SMDH region checks
|
||||
patchMemory(code, size,
|
||||
regionFreePattern,
|
||||
sizeof(regionFreePattern), -16,
|
||||
regionFreePatch,
|
||||
@ -152,27 +153,30 @@ u32 patch_code(u64 progid, u8 *code, u32 size)
|
||||
static const u8 blockAutoUpdatesPatch[] = {
|
||||
0xE3, 0xA0
|
||||
};
|
||||
static const u8 blockEShopUpdateCheckPattern[] = {
|
||||
static const u8 skipEshopUpdateCheckPattern[] = {
|
||||
0x30, 0xB5, 0xF1, 0xB0
|
||||
};
|
||||
static const u8 blockEShopUpdateCheckPatch[] = {
|
||||
static const u8 skipEshopUpdateCheckPatch[] = {
|
||||
0x00, 0x20, 0x08, 0x60, 0x70, 0x47
|
||||
};
|
||||
|
||||
patch_memory(code, size,
|
||||
//Block silent auto-updates
|
||||
patchMemory(code, size,
|
||||
blockAutoUpdatesPattern,
|
||||
sizeof(blockAutoUpdatesPattern), 0,
|
||||
blockAutoUpdatesPatch,
|
||||
sizeof(blockAutoUpdatesPatch), 1
|
||||
);
|
||||
patch_memory(code, size,
|
||||
blockEShopUpdateCheckPattern,
|
||||
sizeof(blockEShopUpdateCheckPattern), 0,
|
||||
blockEShopUpdateCheckPatch,
|
||||
sizeof(blockEShopUpdateCheckPatch), 1
|
||||
|
||||
//Skip update checks to access the EShop
|
||||
patchMemory(code, size,
|
||||
skipEshopUpdateCheckPattern,
|
||||
sizeof(skipEshopUpdateCheckPattern), 0,
|
||||
skipEshopUpdateCheckPatch,
|
||||
sizeof(skipEshopUpdateCheckPatch), 1
|
||||
);
|
||||
|
||||
if(R_SUCCEEDED(load_secureinfo()))
|
||||
if(R_SUCCEEDED(loadSecureinfo()))
|
||||
{
|
||||
static const char countryRespPattern[] = {
|
||||
0x01, 0x20, 0x01, 0x90, 0x22, 0x46, 0x06, 0x9B
|
||||
@ -194,14 +198,14 @@ u32 patch_code(u64 progid, u8 *code, u32 size)
|
||||
case 6: country = "TW"; break;
|
||||
default: case 0: country = "JP"; break;
|
||||
}
|
||||
// patch XML response Country
|
||||
//Patch XML response Country
|
||||
memcpy(countryRespPatch,
|
||||
countryRespPatchModel,
|
||||
sizeof(countryRespPatchModel)
|
||||
);
|
||||
countryRespPatch[6] = country[0];
|
||||
countryRespPatch[10] = country[1];
|
||||
patch_memory(code, size,
|
||||
patchMemory(code, size,
|
||||
countryRespPattern,
|
||||
sizeof(countryRespPattern), 0,
|
||||
countryRespPatch,
|
||||
@ -219,13 +223,14 @@ u32 patch_code(u64 progid, u8 *code, u32 size)
|
||||
case 0x0004001000027000LL: // KOR MSET
|
||||
case 0x0004001000028000LL: // TWN MSET
|
||||
{
|
||||
if(R_SUCCEEDED(load_config()) && ((config >> 5) & 1))
|
||||
if(R_SUCCEEDED(loadConfig()) && ((config >> 5) & 1))
|
||||
{
|
||||
static const u16 verPattern[] = u"Ver.";
|
||||
const u32 currentFirm = ((config >> 12) & 1);
|
||||
const u32 currentNand = ((config >> 13) & 3);
|
||||
|
||||
patch_memory(code, size,
|
||||
//Patch Ver. string
|
||||
patchMemory(code, size,
|
||||
verPattern,
|
||||
sizeof(verPattern) - sizeof(u16), 0,
|
||||
currentNand ? ((currentNand == 1) ? ((currentFirm == 1) ? u" Emu" : u"Emu9") : u"Emu2") :
|
||||
@ -246,7 +251,8 @@ u32 patch_code(u64 progid, u8 *code, u32 size)
|
||||
0x0B, 0x18, 0x21, 0xC8
|
||||
};
|
||||
|
||||
patch_memory(code, size,
|
||||
//Disable updates from foreign carts (makes carts region-free)
|
||||
patchMemory(code, size,
|
||||
stopCartUpdatesPattern,
|
||||
sizeof(stopCartUpdatesPattern), 0,
|
||||
stopCartUpdatesPatch,
|
||||
@ -265,21 +271,21 @@ u32 patch_code(u64 progid, u8 *code, u32 size)
|
||||
0x00, 0x26
|
||||
};
|
||||
|
||||
// disable SecureInfo signature check
|
||||
patch_memory(code, size,
|
||||
//Disable SecureInfo signature check
|
||||
patchMemory(code, size,
|
||||
secureinfoSigCheckPattern,
|
||||
sizeof(secureinfoSigCheckPattern), 0,
|
||||
secureinfoSigCheckPatch,
|
||||
sizeof(secureinfoSigCheckPatch), 1
|
||||
);
|
||||
|
||||
if(R_SUCCEEDED(load_secureinfo()))
|
||||
if(R_SUCCEEDED(loadSecureinfo()))
|
||||
{
|
||||
static const u16 secureinfoFilenamePattern[] = u"SecureInfo_";
|
||||
static const u16 secureinfoFilenamePatch[] = u"C";
|
||||
|
||||
// use SecureInfo_C
|
||||
patch_memory(code, size,
|
||||
//Use SecureInfo_C
|
||||
patchMemory(code, size,
|
||||
secureinfoFilenamePattern,
|
||||
sizeof(secureinfoFilenamePattern) - sizeof(u16),
|
||||
sizeof(secureinfoFilenamePattern) - sizeof(u16),
|
||||
@ -291,6 +297,4 @@ u32 patch_code(u64 progid, u8 *code, u32 size)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -2,4 +2,4 @@
|
||||
|
||||
#include <3ds/types.h>
|
||||
|
||||
u32 patch_code(u64 progid, u8 *code, u32 size);
|
||||
void patchCode(u64 progid, u8 *code, u32 size);
|
@ -80,7 +80,8 @@ int drawString(const char *string, int posX, int posY, u32 color)
|
||||
posY += SPACING_Y;
|
||||
line_i = 0;
|
||||
i++;
|
||||
} else if(line_i >= (SCREEN_TOP_WIDTH - posX) / SPACING_X)
|
||||
}
|
||||
else if(line_i >= (SCREEN_TOP_WIDTH - posX) / SPACING_X)
|
||||
{
|
||||
// Make sure we never get out of the screen.
|
||||
posY += SPACING_Y;
|
||||
|
@ -128,7 +128,8 @@ void setupCFW(void)
|
||||
{
|
||||
//If not 9.0 FIRM and B is pressed, attempt booting the second emuNAND
|
||||
emuNAND = (mode && ((!(pressed & BUTTON_B)) == ((config >> 4) & 1))) ? 2 : 1;
|
||||
} else emuNAND = 0;
|
||||
}
|
||||
else emuNAND = 0;
|
||||
|
||||
/* If tha FIRM patches version is different or user switched to/from A9LH,
|
||||
delete all patched FIRMs */
|
||||
|
@ -12,6 +12,7 @@ void memcpy(void *dest, const void *src, u32 size)
|
||||
{
|
||||
u8 *destc = (u8 *)dest;
|
||||
const u8 *srcc = (const u8 *)src;
|
||||
|
||||
for(u32 i = 0; i < size; i++)
|
||||
destc[i] = srcc[i];
|
||||
}
|
||||
@ -19,6 +20,7 @@ void memcpy(void *dest, const void *src, u32 size)
|
||||
void memset(void *dest, int filler, u32 size)
|
||||
{
|
||||
u8 *destc = (u8 *)dest;
|
||||
|
||||
for(u32 i = 0; i < size; i++)
|
||||
destc[i] = (u8)filler;
|
||||
}
|
||||
@ -26,6 +28,7 @@ void memset(void *dest, int filler, u32 size)
|
||||
void memset32(void *dest, u32 filler, u32 size)
|
||||
{
|
||||
u32 *dest32 = (u32 *)dest;
|
||||
|
||||
for (u32 i = 0; i < size / 4; i++)
|
||||
dest32[i] = filler;
|
||||
}
|
||||
@ -34,6 +37,7 @@ int memcmp(const void *buf1, const void *buf2, u32 size)
|
||||
{
|
||||
const u8 *buf1c = (const u8 *)buf1;
|
||||
const u8 *buf2c = (const u8 *)buf2;
|
||||
|
||||
for(u32 i = 0; i < size; i++)
|
||||
{
|
||||
int cmp = buf1c[i] - buf2c[i];
|
||||
|
@ -40,7 +40,8 @@ static u16 waitInput(void)
|
||||
if(key != HID_PAD) break;
|
||||
if(i == 1) pressedKey = 1;
|
||||
}
|
||||
} while(!pressedKey);
|
||||
}
|
||||
while(!pressedKey);
|
||||
|
||||
return key;
|
||||
}
|
||||
@ -85,7 +86,8 @@ void configureCFW(const char *configPath, const char *firm90Path)
|
||||
}
|
||||
|
||||
pressed = waitInput();
|
||||
} while(!(pressed & MENU_BUTTONS));
|
||||
}
|
||||
while(!(pressed & MENU_BUTTONS));
|
||||
|
||||
switch(pressed)
|
||||
{
|
||||
|
Reference in New Issue
Block a user