Merge branch 'master' into developer

This commit is contained in:
Aurora 2016-09-06 14:11:29 +02:00
commit 66ffc78f60
11 changed files with 89 additions and 84 deletions

View File

@ -28,10 +28,10 @@ typedef struct __attribute__((packed))
{ {
u32 magic[2]; u32 magic[2];
u16 versionMinor, versionMajor; u16 versionMinor, versionMajor;
u16 processor, core; u16 processor, core;
u32 type; u32 type;
u32 totalSize; u32 totalSize;
u32 registerDumpSize; u32 registerDumpSize;
u32 codeDumpSize; u32 codeDumpSize;

View File

@ -46,22 +46,22 @@ static u32 __attribute__((noinline)) copyMemory(void *dst, const void *src, u32
void __attribute__((noreturn)) mainHandler(u32 regs[REG_DUMP_SIZE / 4], u32 type, u32 cpuId) void __attribute__((noreturn)) mainHandler(u32 regs[REG_DUMP_SIZE / 4], u32 type, u32 cpuId)
{ {
ExceptionDumpHeader dumpHeader; ExceptionDumpHeader dumpHeader;
u32 registerDump[REG_DUMP_SIZE / 4]; u32 registerDump[REG_DUMP_SIZE / 4];
u8 codeDump[CODE_DUMP_SIZE]; u8 codeDump[CODE_DUMP_SIZE];
u8 *final = (u8 *)FINAL_BUFFER; u8 *final = (u8 *)FINAL_BUFFER;
while(*(vu32 *)final == 0xDEADC0DE && *((vu32 *)final + 1) == 0xDEADCAFE); while(*(vu32 *)final == 0xDEADC0DE && *((vu32 *)final + 1) == 0xDEADCAFE);
dumpHeader.magic[0] = 0xDEADC0DE; dumpHeader.magic[0] = 0xDEADC0DE;
dumpHeader.magic[1] = 0xDEADCAFE; dumpHeader.magic[1] = 0xDEADCAFE;
dumpHeader.versionMajor = 1; dumpHeader.versionMajor = 1;
dumpHeader.versionMinor = 2; dumpHeader.versionMinor = 2;
dumpHeader.processor = 11; dumpHeader.processor = 11;
dumpHeader.core = cpuId & 0xF; dumpHeader.core = cpuId & 0xF;
dumpHeader.type = type; dumpHeader.type = type;
dumpHeader.registerDumpSize = REG_DUMP_SIZE; dumpHeader.registerDumpSize = REG_DUMP_SIZE;
dumpHeader.codeDumpSize = CODE_DUMP_SIZE; dumpHeader.codeDumpSize = CODE_DUMP_SIZE;
dumpHeader.additionalDataSize = 0; dumpHeader.additionalDataSize = 0;
@ -80,24 +80,24 @@ void __attribute__((noreturn)) mainHandler(u32 regs[REG_DUMP_SIZE / 4], u32 type
//Dump code //Dump code
u8 *instr = (u8 *)pc + ((cpsr & 0x20) ? 2 : 4) - dumpHeader.codeDumpSize; //Doesn't work well on 32-bit Thumb instructions, but it isn't much of a problem u8 *instr = (u8 *)pc + ((cpsr & 0x20) ? 2 : 4) - dumpHeader.codeDumpSize; //Doesn't work well on 32-bit Thumb instructions, but it isn't much of a problem
dumpHeader.codeDumpSize = copyMemory(codeDump, instr, dumpHeader.codeDumpSize, ((cpsr & 0x20) != 0) ? 2 : 4); dumpHeader.codeDumpSize = copyMemory(codeDump, instr, dumpHeader.codeDumpSize, ((cpsr & 0x20) != 0) ? 2 : 4);
//Copy register dump and code dump //Copy register dump and code dump
final = (u8 *)(FINAL_BUFFER + sizeof(ExceptionDumpHeader)); final = (u8 *)(FINAL_BUFFER + sizeof(ExceptionDumpHeader));
final += copyMemory(final, registerDump, dumpHeader.registerDumpSize, 1); final += copyMemory(final, registerDump, dumpHeader.registerDumpSize, 1);
final += copyMemory(final, codeDump, dumpHeader.codeDumpSize, 1); final += copyMemory(final, codeDump, dumpHeader.codeDumpSize, 1);
//Dump stack in place //Dump stack in place
dumpHeader.stackDumpSize = copyMemory(final, (const void *)registerDump[13], 0x1000 - (registerDump[13] & 0xFFF), 1); dumpHeader.stackDumpSize = copyMemory(final, (const void *)registerDump[13], 0x1000 - (registerDump[13] & 0xFFF), 1);
final += dumpHeader.stackDumpSize; final += dumpHeader.stackDumpSize;
vu8 *currentKProcess = cannotAccessVA((u8 *)0xFFFF9004) ? NULL : *(vu8 **)0xFFFF9004; vu8 *currentKProcess = cannotAccessVA((u8 *)0xFFFF9004) ? NULL : *(vu8 **)0xFFFF9004;
vu8 *currentKCodeSet = currentKProcess != NULL ? *(vu8 **)(currentKProcess + CODESET_OFFSET) : NULL; vu8 *currentKCodeSet = currentKProcess != NULL ? *(vu8 **)(currentKProcess + CODESET_OFFSET) : NULL;
if(currentKCodeSet != NULL) if(currentKCodeSet != NULL)
{ {
vu64 *additionalData = (vu64 *)final; vu64 *additionalData = (vu64 *)final;
dumpHeader.additionalDataSize = 16; dumpHeader.additionalDataSize = 16;
additionalData[0] = *(vu64 *)(currentKCodeSet + 0x50); //Process name additionalData[0] = *(vu64 *)(currentKCodeSet + 0x50); //Process name
additionalData[1] = *(vu64 *)(currentKCodeSet + 0x5C); //Title ID additionalData[1] = *(vu64 *)(currentKCodeSet + 0x5C); //Title ID
} }

View File

@ -43,7 +43,7 @@ clean:
$(dir_build)/$(name).elf: $(objects) $(dir_build)/$(name).elf: $(objects)
$(LINK.o) $(OUTPUT_OPTION) $^ $(LIBPATHS) $(LIBS) $(LINK.o) $(OUTPUT_OPTION) $^ $(LIBPATHS) $(LIBS)
$(dir_build)/memory.o : CFLAGS += -O3 $(dir_build)/memory.o $(dir_build)/strings.o: CFLAGS += -O3
$(dir_build)/%.o: $(dir_source)/%.c $(dir_build)/%.o: $(dir_source)/%.c
@mkdir -p "$(@D)" @mkdir -p "$(@D)"

View File

@ -7,4 +7,44 @@ void memcpy(void *dest, const void *src, u32 size)
for(u32 i = 0; i < size; i++) for(u32 i = 0; i < size; i++)
destc[i] = srcc[i]; destc[i] = srcc[i];
}
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];
if(cmp) return cmp;
}
return 0;
}
//Quick Search algorithm, adapted from http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190
u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize)
{
const u8 *patternc = (const u8 *)pattern;
//Preprocessing
u32 table[256];
for(u32 i = 0; i < 256; i++)
table[i] = patternSize + 1;
for(u32 i = 0; i < patternSize; i++)
table[patternc[i]] = patternSize - i;
//Searching
u32 j = 0;
while(j <= size - patternSize)
{
if(memcmp(pattern, startPos + j, patternSize) == 0)
return startPos + j;
j += table[startPos[j + patternSize]];
}
return NULL;
} }

View File

@ -2,4 +2,6 @@
#include <3ds/types.h> #include <3ds/types.h>
void memcpy(void *dest, const void *src, u32 size); void memcpy(void *dest, const void *src, u32 size);
int memcmp(const void *buf1, const void *buf2, u32 size);
u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize);

View File

@ -1,56 +1,15 @@
#include <3ds.h> #include <3ds.h>
#include "memory.h"
#include "patcher.h" #include "patcher.h"
#include "memory.h"
#include "strings.h"
#include "ifile.h" #include "ifile.h"
#include "CFWInfo.h" #include "CFWInfo.h"
static CFWInfo info; static CFWInfo info;
static int memcmp(const void *buf1, const void *buf2, u32 size) static void patchMemory(u8 *start, u32 size, const void *pattern, u32 patSize, int offset, const void *replace, u32 repSize, u32 count)
{ {
const u8 *buf1c = (const u8 *)buf1; for(u32 i = 0; i < count; i++)
const u8 *buf2c = (const u8 *)buf2;
for(u32 i = 0; i < size; i++)
{
int cmp = buf1c[i] - buf2c[i];
if(cmp) return cmp;
}
return 0;
}
//Quick Search algorithm, adapted from http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190
static u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize)
{
const u8 *patternc = (const u8 *)pattern;
//Preprocessing
u32 table[256];
for(u32 i = 0; i < 256; ++i)
table[i] = patternSize + 1;
for(u32 i = 0; i < patternSize; ++i)
table[patternc[i]] = patternSize - i;
//Searching
u32 j = 0;
while(j <= size - patternSize)
{
if(memcmp(patternc, startPos + j, patternSize) == 0)
return startPos + j;
j += table[startPos[j + patternSize]];
}
return NULL;
}
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);
@ -65,17 +24,6 @@ static u32 patchMemory(u8 *start, u32 size, const void *pattern, u32 patSize, in
size -= at + patSize; size -= at + patSize;
start = found + patSize; start = found + patSize;
} }
return i;
}
static inline size_t strnlen(const char *string, size_t maxlen)
{
size_t size;
for(size = 0; *string && size < maxlen; string++, size++);
return size;
} }
static int fileOpen(IFile *file, FS_ArchiveID archiveId, const char *path, int flags) static int fileOpen(IFile *file, FS_ArchiveID archiveId, const char *path, int flags)
@ -119,16 +67,6 @@ static bool secureInfoExists(void)
return exists; return exists;
} }
static void progIdToStr(char *strEnd, u64 progId)
{
while(progId)
{
static const char hexDigits[] = "0123456789ABCDEF";
*strEnd-- = hexDigits[(u32)(progId & 0xF)];
progId >>= 4;
}
}
static void loadTitleCodeSection(u64 progId, u8 *code, u32 size) static void loadTitleCodeSection(u64 progId, u8 *code, u32 size)
{ {
/* Here we look for "/luma/code_sections/[u64 titleID in hex, uppercase].bin" /* Here we look for "/luma/code_sections/[u64 titleID in hex, uppercase].bin"

20
injector/source/strings.c Normal file
View File

@ -0,0 +1,20 @@
#include "strings.h"
size_t strnlen(const char *string, size_t maxlen)
{
size_t size;
for(size = 0; *string && size < maxlen; string++, size++);
return size;
}
void progIdToStr(char *strEnd, u64 progId)
{
while(progId)
{
static const char hexDigits[] = "0123456789ABCDEF";
*strEnd-- = hexDigits[(u32)(progId & 0xF)];
progId >>= 4;
}
}

View File

@ -0,0 +1,6 @@
#pragma once
#include <3ds/types.h>
size_t strnlen(const char *string, size_t maxlen);
void progIdToStr(char *strEnd, u64 progId);

View File

@ -23,7 +23,6 @@
.arm.little .arm.little
.create "build/svcGetCFWInfo.bin", 0 .create "build/svcGetCFWInfo.bin", 0
.arm .arm
adr r1, infoStart adr r1, infoStart

View File

@ -31,10 +31,10 @@ typedef struct __attribute__((packed))
{ {
u32 magic[2]; u32 magic[2];
u16 versionMinor, versionMajor; u16 versionMinor, versionMajor;
u16 processor, core; u16 processor, core;
u32 type; u32 type;
u32 totalSize; u32 totalSize;
u32 registerDumpSize; u32 registerDumpSize;
u32 codeDumpSize; u32 codeDumpSize;

View File

@ -66,9 +66,9 @@ u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize)
//Preprocessing //Preprocessing
u32 table[256]; u32 table[256];
for(u32 i = 0; i < 256; ++i) for(u32 i = 0; i < 256; i++)
table[i] = patternSize + 1; table[i] = patternSize + 1;
for(u32 i = 0; i < patternSize; ++i) for(u32 i = 0; i < patternSize; i++)
table[patternc[i]] = patternSize - i; table[patternc[i]] = patternSize - i;
//Searching //Searching
@ -76,7 +76,7 @@ u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize)
while(j <= size - patternSize) while(j <= size - patternSize)
{ {
if(memcmp(patternc, startPos + j, patternSize) == 0) if(memcmp(pattern, startPos + j, patternSize) == 0)
return startPos + j; return startPos + j;
j += table[startPos[j + patternSize]]; j += table[startPos[j + patternSize]];
} }