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
|
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 := -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
|
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, \
|
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) $^
|
$(CC) -nostartfiles $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^
|
||||||
|
|
||||||
$(dir_build)/memory.o : CFLAGS+=-O3
|
$(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
|
$(dir_build)/%.o: $(dir_source)/%.c $(dir_build)/patches.h $(dir_build)/loader.h $(dir_build)/screeninit.h
|
||||||
@mkdir -p "$(@D)"
|
@mkdir -p "$(@D)"
|
||||||
|
@ -158,7 +158,7 @@ static Result load_code(u64 progid, prog_addrs_t *shared, u64 prog_handle, int i
|
|||||||
}
|
}
|
||||||
|
|
||||||
// patch
|
// patch
|
||||||
patch_code(progid, (u8 *)shared->text_addr, shared->total_size << 12);
|
patchCode(progid, (u8 *)shared->text_addr, shared->total_size << 12);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -36,31 +36,31 @@ static u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSiz
|
|||||||
return NULL;
|
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;
|
u32 i;
|
||||||
|
|
||||||
for(i = 0; i < count; i++)
|
for(i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
u8 *found = memsearch(start, pattern, size, patsize);
|
u8 *found = memsearch(start, pattern, size, patSize);
|
||||||
|
|
||||||
if(found == NULL)
|
if(found == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
memcpy(found + offset, replace, repsize);
|
memcpy(found + offset, replace, repSize);
|
||||||
|
|
||||||
u32 at = (u32)(found - start);
|
u32 at = (u32)(found - start);
|
||||||
|
|
||||||
if(at + patsize > size) size = 0;
|
if(at + patSize > size) size = 0;
|
||||||
else size = size - (at + patsize);
|
else size = size - (at + patSize);
|
||||||
|
|
||||||
start = found + patsize;
|
start = found + patSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
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_Archive archive;
|
||||||
FS_Path ppath;
|
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);
|
return IFile_Open(file, archive, ppath, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int load_secureinfo()
|
static int loadSecureinfo()
|
||||||
{
|
{
|
||||||
IFile file;
|
IFile file;
|
||||||
Result ret;
|
Result ret;
|
||||||
@ -85,7 +85,7 @@ static int load_secureinfo()
|
|||||||
if(secureinfo[0] == 0xFF)
|
if(secureinfo[0] == 0xFF)
|
||||||
return 0;
|
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))
|
if(R_SUCCEEDED(ret))
|
||||||
{
|
{
|
||||||
ret = IFile_Read(&file, &total, secureinfo, sizeof(secureinfo));
|
ret = IFile_Read(&file, &total, secureinfo, sizeof(secureinfo));
|
||||||
@ -97,7 +97,7 @@ static int load_secureinfo()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int load_config()
|
static int loadConfig()
|
||||||
{
|
{
|
||||||
IFile file;
|
IFile file;
|
||||||
Result ret;
|
Result ret;
|
||||||
@ -106,7 +106,7 @@ static int load_config()
|
|||||||
if(config)
|
if(config)
|
||||||
return 0;
|
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))
|
if(R_SUCCEEDED(ret))
|
||||||
{
|
{
|
||||||
ret = IFile_Read(&file, &total, (void *)&config, 3);
|
ret = IFile_Read(&file, &total, (void *)&config, 3);
|
||||||
@ -116,7 +116,7 @@ static int load_config()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 patch_code(u64 progid, u8 *code, u32 size)
|
void patchCode(u64 progid, u8 *code, u32 size)
|
||||||
{
|
{
|
||||||
switch(progid)
|
switch(progid)
|
||||||
{
|
{
|
||||||
@ -134,7 +134,8 @@ u32 patch_code(u64 progid, u8 *code, u32 size)
|
|||||||
0x01, 0x00, 0xA0, 0xE3, 0x1E, 0xFF, 0x2F, 0xE1
|
0x01, 0x00, 0xA0, 0xE3, 0x1E, 0xFF, 0x2F, 0xE1
|
||||||
};
|
};
|
||||||
|
|
||||||
patch_memory(code, size,
|
//Patch SMDH region checks
|
||||||
|
patchMemory(code, size,
|
||||||
regionFreePattern,
|
regionFreePattern,
|
||||||
sizeof(regionFreePattern), -16,
|
sizeof(regionFreePattern), -16,
|
||||||
regionFreePatch,
|
regionFreePatch,
|
||||||
@ -152,27 +153,30 @@ u32 patch_code(u64 progid, u8 *code, u32 size)
|
|||||||
static const u8 blockAutoUpdatesPatch[] = {
|
static const u8 blockAutoUpdatesPatch[] = {
|
||||||
0xE3, 0xA0
|
0xE3, 0xA0
|
||||||
};
|
};
|
||||||
static const u8 blockEShopUpdateCheckPattern[] = {
|
static const u8 skipEshopUpdateCheckPattern[] = {
|
||||||
0x30, 0xB5, 0xF1, 0xB0
|
0x30, 0xB5, 0xF1, 0xB0
|
||||||
};
|
};
|
||||||
static const u8 blockEShopUpdateCheckPatch[] = {
|
static const u8 skipEshopUpdateCheckPatch[] = {
|
||||||
0x00, 0x20, 0x08, 0x60, 0x70, 0x47
|
0x00, 0x20, 0x08, 0x60, 0x70, 0x47
|
||||||
};
|
};
|
||||||
|
|
||||||
patch_memory(code, size,
|
//Block silent auto-updates
|
||||||
|
patchMemory(code, size,
|
||||||
blockAutoUpdatesPattern,
|
blockAutoUpdatesPattern,
|
||||||
sizeof(blockAutoUpdatesPattern), 0,
|
sizeof(blockAutoUpdatesPattern), 0,
|
||||||
blockAutoUpdatesPatch,
|
blockAutoUpdatesPatch,
|
||||||
sizeof(blockAutoUpdatesPatch), 1
|
sizeof(blockAutoUpdatesPatch), 1
|
||||||
);
|
);
|
||||||
patch_memory(code, size,
|
|
||||||
blockEShopUpdateCheckPattern,
|
//Skip update checks to access the EShop
|
||||||
sizeof(blockEShopUpdateCheckPattern), 0,
|
patchMemory(code, size,
|
||||||
blockEShopUpdateCheckPatch,
|
skipEshopUpdateCheckPattern,
|
||||||
sizeof(blockEShopUpdateCheckPatch), 1
|
sizeof(skipEshopUpdateCheckPattern), 0,
|
||||||
|
skipEshopUpdateCheckPatch,
|
||||||
|
sizeof(skipEshopUpdateCheckPatch), 1
|
||||||
);
|
);
|
||||||
|
|
||||||
if(R_SUCCEEDED(load_secureinfo()))
|
if(R_SUCCEEDED(loadSecureinfo()))
|
||||||
{
|
{
|
||||||
static const char countryRespPattern[] = {
|
static const char countryRespPattern[] = {
|
||||||
0x01, 0x20, 0x01, 0x90, 0x22, 0x46, 0x06, 0x9B
|
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;
|
case 6: country = "TW"; break;
|
||||||
default: case 0: country = "JP"; break;
|
default: case 0: country = "JP"; break;
|
||||||
}
|
}
|
||||||
// patch XML response Country
|
//Patch XML response Country
|
||||||
memcpy(countryRespPatch,
|
memcpy(countryRespPatch,
|
||||||
countryRespPatchModel,
|
countryRespPatchModel,
|
||||||
sizeof(countryRespPatchModel)
|
sizeof(countryRespPatchModel)
|
||||||
);
|
);
|
||||||
countryRespPatch[6] = country[0];
|
countryRespPatch[6] = country[0];
|
||||||
countryRespPatch[10] = country[1];
|
countryRespPatch[10] = country[1];
|
||||||
patch_memory(code, size,
|
patchMemory(code, size,
|
||||||
countryRespPattern,
|
countryRespPattern,
|
||||||
sizeof(countryRespPattern), 0,
|
sizeof(countryRespPattern), 0,
|
||||||
countryRespPatch,
|
countryRespPatch,
|
||||||
@ -219,13 +223,14 @@ u32 patch_code(u64 progid, u8 *code, u32 size)
|
|||||||
case 0x0004001000027000LL: // KOR MSET
|
case 0x0004001000027000LL: // KOR MSET
|
||||||
case 0x0004001000028000LL: // TWN 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.";
|
static const u16 verPattern[] = u"Ver.";
|
||||||
const u32 currentFirm = ((config >> 12) & 1);
|
const u32 currentFirm = ((config >> 12) & 1);
|
||||||
const u32 currentNand = ((config >> 13) & 3);
|
const u32 currentNand = ((config >> 13) & 3);
|
||||||
|
|
||||||
patch_memory(code, size,
|
//Patch Ver. string
|
||||||
|
patchMemory(code, size,
|
||||||
verPattern,
|
verPattern,
|
||||||
sizeof(verPattern) - sizeof(u16), 0,
|
sizeof(verPattern) - sizeof(u16), 0,
|
||||||
currentNand ? ((currentNand == 1) ? ((currentFirm == 1) ? u" Emu" : u"Emu9") : u"Emu2") :
|
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
|
0x0B, 0x18, 0x21, 0xC8
|
||||||
};
|
};
|
||||||
|
|
||||||
patch_memory(code, size,
|
//Disable updates from foreign carts (makes carts region-free)
|
||||||
|
patchMemory(code, size,
|
||||||
stopCartUpdatesPattern,
|
stopCartUpdatesPattern,
|
||||||
sizeof(stopCartUpdatesPattern), 0,
|
sizeof(stopCartUpdatesPattern), 0,
|
||||||
stopCartUpdatesPatch,
|
stopCartUpdatesPatch,
|
||||||
@ -265,21 +271,21 @@ u32 patch_code(u64 progid, u8 *code, u32 size)
|
|||||||
0x00, 0x26
|
0x00, 0x26
|
||||||
};
|
};
|
||||||
|
|
||||||
// disable SecureInfo signature check
|
//Disable SecureInfo signature check
|
||||||
patch_memory(code, size,
|
patchMemory(code, size,
|
||||||
secureinfoSigCheckPattern,
|
secureinfoSigCheckPattern,
|
||||||
sizeof(secureinfoSigCheckPattern), 0,
|
sizeof(secureinfoSigCheckPattern), 0,
|
||||||
secureinfoSigCheckPatch,
|
secureinfoSigCheckPatch,
|
||||||
sizeof(secureinfoSigCheckPatch), 1
|
sizeof(secureinfoSigCheckPatch), 1
|
||||||
);
|
);
|
||||||
|
|
||||||
if(R_SUCCEEDED(load_secureinfo()))
|
if(R_SUCCEEDED(loadSecureinfo()))
|
||||||
{
|
{
|
||||||
static const u16 secureinfoFilenamePattern[] = u"SecureInfo_";
|
static const u16 secureinfoFilenamePattern[] = u"SecureInfo_";
|
||||||
static const u16 secureinfoFilenamePatch[] = u"C";
|
static const u16 secureinfoFilenamePatch[] = u"C";
|
||||||
|
|
||||||
// use SecureInfo_C
|
//Use SecureInfo_C
|
||||||
patch_memory(code, size,
|
patchMemory(code, size,
|
||||||
secureinfoFilenamePattern,
|
secureinfoFilenamePattern,
|
||||||
sizeof(secureinfoFilenamePattern) - sizeof(u16),
|
sizeof(secureinfoFilenamePattern) - sizeof(u16),
|
||||||
sizeof(secureinfoFilenamePattern) - sizeof(u16),
|
sizeof(secureinfoFilenamePattern) - sizeof(u16),
|
||||||
@ -291,6 +297,4 @@ u32 patch_code(u64 progid, u8 *code, u32 size)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
#include <3ds/types.h>
|
#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;
|
posY += SPACING_Y;
|
||||||
line_i = 0;
|
line_i = 0;
|
||||||
i++;
|
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.
|
// Make sure we never get out of the screen.
|
||||||
posY += SPACING_Y;
|
posY += SPACING_Y;
|
||||||
|
@ -128,7 +128,8 @@ void setupCFW(void)
|
|||||||
{
|
{
|
||||||
//If not 9.0 FIRM and B is pressed, attempt booting the second emuNAND
|
//If not 9.0 FIRM and B is pressed, attempt booting the second emuNAND
|
||||||
emuNAND = (mode && ((!(pressed & BUTTON_B)) == ((config >> 4) & 1))) ? 2 : 1;
|
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,
|
/* If tha FIRM patches version is different or user switched to/from A9LH,
|
||||||
delete all patched FIRMs */
|
delete all patched FIRMs */
|
||||||
|
@ -12,6 +12,7 @@ void memcpy(void *dest, const void *src, u32 size)
|
|||||||
{
|
{
|
||||||
u8 *destc = (u8 *)dest;
|
u8 *destc = (u8 *)dest;
|
||||||
const u8 *srcc = (const u8 *)src;
|
const u8 *srcc = (const u8 *)src;
|
||||||
|
|
||||||
for(u32 i = 0; i < size; i++)
|
for(u32 i = 0; i < size; i++)
|
||||||
destc[i] = srcc[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)
|
void memset(void *dest, int filler, u32 size)
|
||||||
{
|
{
|
||||||
u8 *destc = (u8 *)dest;
|
u8 *destc = (u8 *)dest;
|
||||||
|
|
||||||
for(u32 i = 0; i < size; i++)
|
for(u32 i = 0; i < size; i++)
|
||||||
destc[i] = (u8)filler;
|
destc[i] = (u8)filler;
|
||||||
}
|
}
|
||||||
@ -26,6 +28,7 @@ void memset(void *dest, int filler, u32 size)
|
|||||||
void memset32(void *dest, u32 filler, u32 size)
|
void memset32(void *dest, u32 filler, u32 size)
|
||||||
{
|
{
|
||||||
u32 *dest32 = (u32 *)dest;
|
u32 *dest32 = (u32 *)dest;
|
||||||
|
|
||||||
for (u32 i = 0; i < size / 4; i++)
|
for (u32 i = 0; i < size / 4; i++)
|
||||||
dest32[i] = filler;
|
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 *buf1c = (const u8 *)buf1;
|
||||||
const u8 *buf2c = (const u8 *)buf2;
|
const u8 *buf2c = (const u8 *)buf2;
|
||||||
|
|
||||||
for(u32 i = 0; i < size; i++)
|
for(u32 i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
int cmp = buf1c[i] - buf2c[i];
|
int cmp = buf1c[i] - buf2c[i];
|
||||||
|
@ -40,7 +40,8 @@ static u16 waitInput(void)
|
|||||||
if(key != HID_PAD) break;
|
if(key != HID_PAD) break;
|
||||||
if(i == 1) pressedKey = 1;
|
if(i == 1) pressedKey = 1;
|
||||||
}
|
}
|
||||||
} while(!pressedKey);
|
}
|
||||||
|
while(!pressedKey);
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
@ -85,7 +86,8 @@ void configureCFW(const char *configPath, const char *firm90Path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pressed = waitInput();
|
pressed = waitInput();
|
||||||
} while(!(pressed & MENU_BUTTONS));
|
}
|
||||||
|
while(!(pressed & MENU_BUTTONS));
|
||||||
|
|
||||||
switch(pressed)
|
switch(pressed)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user