Cleanup of the injector
This commit is contained in:
parent
d0d6baaa85
commit
67e229e5a9
@ -7,7 +7,6 @@ $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>dev
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
TOPDIR ?= $(CURDIR)
|
TOPDIR ?= $(CURDIR)
|
||||||
MAKEROM ?= makerom
|
|
||||||
include $(DEVKITARM)/3ds_rules
|
include $(DEVKITARM)/3ds_rules
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
@ -20,8 +19,6 @@ include $(DEVKITARM)/3ds_rules
|
|||||||
TARGET := $(notdir $(CURDIR))
|
TARGET := $(notdir $(CURDIR))
|
||||||
BUILD := build
|
BUILD := build
|
||||||
SOURCES := source
|
SOURCES := source
|
||||||
DATA := data
|
|
||||||
INCLUDES := include
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# options for code generation
|
# options for code generation
|
||||||
@ -29,14 +26,9 @@ INCLUDES := include
|
|||||||
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
|
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
|
||||||
|
|
||||||
CFLAGS := -flto -Wall -O2 -mword-relocations \
|
CFLAGS := -flto -Wall -O2 -mword-relocations \
|
||||||
-ffast-math -ffunction-sections -fdata-sections \
|
-ffast-math -fno-builtin -ffunction-sections -fdata-sections \
|
||||||
$(ARCH)
|
$(ARCH) $(INCLUDE) -DARM11 -D_3DS
|
||||||
|
|
||||||
CFLAGS += $(INCLUDE) -DARM11 -D_3DS
|
|
||||||
|
|
||||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu99
|
|
||||||
|
|
||||||
ASFLAGS := $(ARCH)
|
|
||||||
LDFLAGS = -flto -Xlinker --defsym="__start__=0x14000000" -specs=3dsx.specs $(ARCH) -Wl,-Map,$(notdir $*.map)
|
LDFLAGS = -flto -Xlinker --defsym="__start__=0x14000000" -specs=3dsx.specs $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||||
|
|
||||||
LIBS := -lctru
|
LIBS := -lctru
|
||||||
@ -58,38 +50,17 @@ ifneq ($(BUILD),$(notdir $(CURDIR)))
|
|||||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||||
export TOPDIR := $(CURDIR)
|
export TOPDIR := $(CURDIR)
|
||||||
|
|
||||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
|
||||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
|
||||||
|
|
||||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
|
||||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
|
||||||
PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
|
|
||||||
SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
|
|
||||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
export LD := $(CC)
|
||||||
# use CXX for linking C++ projects, CC for standard C
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
ifeq ($(strip $(CPPFILES)),)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export LD := $(CC)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
else
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export LD := $(CXX)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
endif
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
export OFILES := $(CFILES:.c=.o)
|
||||||
$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
|
|
||||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
|
||||||
|
|
||||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
export INCLUDE := $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
|
||||||
-I$(CURDIR)/$(BUILD)
|
-I$(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||||
@ -106,7 +77,7 @@ $(BUILD):
|
|||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
clean:
|
clean:
|
||||||
@echo clean ...
|
@echo clean ...
|
||||||
@rm -fr $(BUILD) $(OUTPUT).cxi $(TARGET).elf
|
@rm -fr $(BUILD) $(TARGET).elf
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
@ -118,42 +89,12 @@ DEPENDS := $(OFILES:.o=.d)
|
|||||||
# main targets
|
# main targets
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
$(OUTPUT).cxi : $(OUTPUT).elf
|
$(OUTPUT).cxi : $(OUTPUT).elf
|
||||||
$(MAKEROM) -f ncch -rsf ../loader.rsf -nocodepadding -o $@ -elf $<
|
@makerom -f ncch -rsf ../loader.rsf -nocodepadding -o $@ -elf $<
|
||||||
|
|
||||||
|
memory.o : CFLAGS += -O3
|
||||||
|
|
||||||
$(OUTPUT).elf : $(OFILES)
|
$(OUTPUT).elf : $(OFILES)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# you need a rule like this for each extension you use as binary data
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
%.bin.o : %.bin
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
@echo $(notdir $<)
|
|
||||||
@$(bin2o)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# rules for assembling GPU shaders
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
define shader-as
|
|
||||||
$(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@)))
|
|
||||||
picasso -o $(CURBIN) $1
|
|
||||||
bin2s $(CURBIN) | $(AS) -o $@
|
|
||||||
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
|
|
||||||
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
|
|
||||||
echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
|
|
||||||
endef
|
|
||||||
|
|
||||||
%.shbin.o : %.v.pica %.g.pica
|
|
||||||
@echo $(notdir $^)
|
|
||||||
@$(call shader-as,$^)
|
|
||||||
|
|
||||||
%.shbin.o : %.v.pica
|
|
||||||
@echo $(notdir $<)
|
|
||||||
@$(call shader-as,$<)
|
|
||||||
|
|
||||||
%.shbin.o : %.shlist
|
|
||||||
@echo $(notdir $<)
|
|
||||||
@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file)))
|
|
||||||
|
|
||||||
-include $(DEPENDS)
|
-include $(DEPENDS)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------------
|
||||||
|
@ -64,42 +64,3 @@ Result IFile_Read(IFile *file, u64 *total, void *buffer, u32 len)
|
|||||||
*total = cur;
|
*total = cur;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result IFile_Write(IFile *file, u64 *total, void *buffer, u32 len, u32 flags)
|
|
||||||
{
|
|
||||||
u32 written;
|
|
||||||
u32 left;
|
|
||||||
char *buf;
|
|
||||||
u64 cur;
|
|
||||||
Result res;
|
|
||||||
|
|
||||||
if (len == 0)
|
|
||||||
{
|
|
||||||
*total = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = (char *)buffer;
|
|
||||||
cur = 0;
|
|
||||||
left = len;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
res = FSFILE_Write(file->handle, &written, file->pos, buf, left, flags);
|
|
||||||
if (R_FAILED(res))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
cur += written;
|
|
||||||
file->pos += written;
|
|
||||||
if (written == left)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
buf += written;
|
|
||||||
left -= written;
|
|
||||||
}
|
|
||||||
|
|
||||||
*total = cur;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
@ -13,4 +13,3 @@ Result IFile_Open(IFile *file, FS_Archive archive, FS_Path path, u32 flags);
|
|||||||
Result IFile_Close(IFile *file);
|
Result IFile_Close(IFile *file);
|
||||||
Result IFile_GetSize(IFile *file, u64 *size);
|
Result IFile_GetSize(IFile *file, u64 *size);
|
||||||
Result IFile_Read(IFile *file, u64 *total, void *buffer, u32 len);
|
Result IFile_Read(IFile *file, u64 *total, void *buffer, u32 len);
|
||||||
Result IFile_Write(IFile *file, u64 *total, void *buffer, u32 len, u32 flags);
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include <3ds.h>
|
#include <3ds.h>
|
||||||
#include <string.h>
|
#include "memory.h"
|
||||||
#include <sys/iosupport.h>
|
|
||||||
#include "patcher.h"
|
#include "patcher.h"
|
||||||
#include "exheader.h"
|
#include "exheader.h"
|
||||||
#include "ifile.h"
|
#include "ifile.h"
|
||||||
|
10
injector/source/memory.c
Normal file
10
injector/source/memory.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "memory.h"
|
||||||
|
|
||||||
|
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];
|
||||||
|
}
|
5
injector/source/memory.h
Normal file
5
injector/source/memory.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <3ds/types.h>
|
||||||
|
|
||||||
|
void memcpy(void *dest, const void *src, u32 size);
|
@ -1,17 +1,28 @@
|
|||||||
#include <3ds.h>
|
#include <3ds.h>
|
||||||
#include <string.h>
|
#include "memory.h"
|
||||||
#include "patcher.h"
|
#include "patcher.h"
|
||||||
#include "ifile.h"
|
#include "ifile.h"
|
||||||
|
|
||||||
#ifndef PATH_MAX
|
#ifndef PATH_MAX
|
||||||
#define PATH_MAX 255
|
#define PATH_MAX 255
|
||||||
#define CONFIG(a) ((config >> (a + 16)) & 1)
|
#define CONFIG(a) ((loadConfig() >> (a + 16)) & 1)
|
||||||
#define MULTICONFIG(a) ((config >> (a * 2 + 6)) & 3)
|
#define MULTICONFIG(a) ((loadConfig() >> (a * 2 + 6)) & 3)
|
||||||
#define BOOTCONFIG(a, b) ((config >> a) & b)
|
#define BOOTCONFIG(a, b) ((loadConfig() >> a) & b)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static u32 config = 0;
|
static int memcmp(const void *buf1, const void *buf2, u32 size)
|
||||||
static u8 secureInfo[0x111] = {0};
|
{
|
||||||
|
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
|
//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)
|
static u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize)
|
||||||
@ -62,6 +73,15 @@ static u32 patchMemory(u8 *start, u32 size, const void *pattern, u32 patSize, in
|
|||||||
return i;
|
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 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;
|
||||||
@ -79,43 +99,39 @@ static int fileOpen(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 loadSecureInfo(void)
|
static u32 secureInfoExists(void)
|
||||||
{
|
{
|
||||||
if(secureInfo[0] == 0xFF)
|
static u32 secureInfoExists = 0;
|
||||||
return 0;
|
|
||||||
|
|
||||||
IFile file;
|
if(!secureInfoExists)
|
||||||
Result ret = fileOpen(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ);
|
|
||||||
if(R_SUCCEEDED(ret))
|
|
||||||
{
|
{
|
||||||
u64 total;
|
IFile file;
|
||||||
|
if(R_SUCCEEDED(fileOpen(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ)))
|
||||||
ret = IFile_Read(&file, &total, secureInfo, 0x111);
|
{
|
||||||
|
secureInfoExists = 1;
|
||||||
IFile_Close(&file);
|
IFile_Close(&file);
|
||||||
if(R_SUCCEEDED(ret) && total == 0x111)
|
}
|
||||||
secureInfo[0] = 0xFF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return secureInfoExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int loadConfig(void)
|
static u32 loadConfig(void)
|
||||||
{
|
{
|
||||||
if(config)
|
static u32 config = 0;
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
if(!config)
|
||||||
|
{
|
||||||
IFile file;
|
IFile file;
|
||||||
Result ret = fileOpen(&file, ARCHIVE_SDMC, "/aurei/config.bin", FS_OPEN_READ);
|
if(R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, "/aurei/config.bin", FS_OPEN_READ)))
|
||||||
if(R_SUCCEEDED(ret))
|
|
||||||
{
|
{
|
||||||
u64 total;
|
u64 total;
|
||||||
|
if(R_SUCCEEDED(IFile_Read(&file, &total, &config, 4))) config |= 1 << 4;
|
||||||
ret = IFile_Read(&file, &total, &config, 4);
|
|
||||||
IFile_Close(&file);
|
IFile_Close(&file);
|
||||||
if(R_SUCCEEDED(ret)) config |= 1 << 4;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId)
|
static int loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId)
|
||||||
@ -372,7 +388,7 @@ void patchCode(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(loadConfig()) && CONFIG(6))
|
if(CONFIG(6))
|
||||||
{
|
{
|
||||||
static const u16 verPattern[] = u"Ver.";
|
static const u16 verPattern[] = u"Ver.";
|
||||||
const u32 currentNand = BOOTCONFIG(0, 3);
|
const u32 currentNand = BOOTCONFIG(0, 3);
|
||||||
@ -408,7 +424,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
|
|||||||
sizeof(stopCartUpdatesPatch), 2
|
sizeof(stopCartUpdatesPatch), 2
|
||||||
);
|
);
|
||||||
|
|
||||||
if(R_SUCCEEDED(loadConfig()) && MULTICONFIG(1))
|
if(MULTICONFIG(1))
|
||||||
{
|
{
|
||||||
static const u8 cfgN3dsCpuPattern[] = {
|
static const u8 cfgN3dsCpuPattern[] = {
|
||||||
0x40, 0xA0, 0xE1, 0x07, 0x00
|
0x40, 0xA0, 0xE1, 0x07, 0x00
|
||||||
@ -444,7 +460,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
|
|||||||
sizeof(secureinfoSigCheckPatch), 1
|
sizeof(secureinfoSigCheckPatch), 1
|
||||||
);
|
);
|
||||||
|
|
||||||
if(R_SUCCEEDED(loadSecureInfo()))
|
if(secureInfoExists())
|
||||||
{
|
{
|
||||||
static const u16 secureinfoFilenamePattern[] = u"SecureInfo_";
|
static const u16 secureinfoFilenamePattern[] = u"SecureInfo_";
|
||||||
static const u16 secureinfoFilenamePatch[] = u"C";
|
static const u16 secureinfoFilenamePatch[] = u"C";
|
||||||
@ -463,7 +479,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if(R_SUCCEEDED(loadConfig()) && CONFIG(4))
|
if(CONFIG(4))
|
||||||
{
|
{
|
||||||
u32 tidHigh = (progId & 0xFFFFFFF000000000LL) >> 0x24;
|
u32 tidHigh = (progId & 0xFFFFFFF000000000LL) >> 0x24;
|
||||||
|
|
||||||
@ -473,9 +489,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
|
|||||||
u8 regionId = 0xFF,
|
u8 regionId = 0xFF,
|
||||||
languageId = 0xFF;
|
languageId = 0xFF;
|
||||||
|
|
||||||
int ret = loadTitleLocaleConfig(progId, ®ionId, &languageId);
|
if(R_SUCCEEDED(loadTitleLocaleConfig(progId, ®ionId, &languageId)))
|
||||||
|
|
||||||
if(R_SUCCEEDED(ret))
|
|
||||||
{
|
{
|
||||||
u32 CFGUHandleOffset;
|
u32 CFGUHandleOffset;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user