diff --git a/injector/Makefile b/injector/Makefile index f7194b2..6fa5844 100755 --- a/injector/Makefile +++ b/injector/Makefile @@ -25,7 +25,7 @@ INCLUDE := $(foreach dir,$(LIBDIRS),-I$(dir)/include) ASFLAGS := -mcpu=mpcore -mfloat-abi=hard -mtp=soft CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -std=c11 -O2 -flto -ffast-math -mword-relocations \ -ffunction-sections -fdata-sections $(INCLUDE) -DARM11 -D_3DS -LDFLAGS := -Xlinker --defsym="__start__=0x14000000" -specs=3dsx.specs $(ASFLAGS) -L$(DEVKITPRO)/libctru/lib +LDFLAGS := -Xlinker --defsym="__start__=0x14000000" -specs=3dsx.specs $(ASFLAGS) objects = $(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \ $(call rwildcard, $(dir_source), *.s *.c)) diff --git a/source/config.c b/source/config.c index ef10f18..8d19352 100644 --- a/source/config.c +++ b/source/config.c @@ -57,11 +57,7 @@ void writeConfig(const char *configPath, u32 configTemp) configData.formatVersionMinor = CONFIG_VERSIONMINOR; if(!fileWrite(&configData, configPath, sizeof(cfgData))) - { - createDirectory("luma"); - if(!fileWrite(&configData, configPath, sizeof(cfgData))) - error("Error writing the configuration file"); - } + error("Error writing the configuration file"); } } diff --git a/source/exceptions.c b/source/exceptions.c index b850139..70e8be8 100644 --- a/source/exceptions.c +++ b/source/exceptions.c @@ -121,13 +121,7 @@ void detectAndProcessExceptionDumps(void) path[fileNameSpot] = '/'; memcpy(&path[fileNameSpot + 1], fileName, sizeof(fileName)); - if(!fileWrite((void *)dumpHeader, path, size)) - { - createDirectory("/luma"); - createDirectory("/luma/dumps"); - createDirectory(pathFolder); - fileWrite((void *)dumpHeader, path, size); - } + fileWrite((void *)dumpHeader, path, size); vu32 *regs = (vu32 *)((vu8 *)dumpHeader + sizeof(ExceptionDumpHeader)); vu8 *additionalData = (vu8 *)dumpHeader + dumpHeader->totalSize - dumpHeader->additionalDataSize; diff --git a/source/fs.c b/source/fs.c index ea9d406..97bebd6 100644 --- a/source/fs.c +++ b/source/fs.c @@ -64,7 +64,9 @@ bool fileWrite(const void *buffer, const char *path, u32 size) { FIL file; - if(f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS) == FR_OK) + FRESULT result = f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS); + + if(result == FR_OK) { unsigned int written; f_write(&file, buffer, size, &written); @@ -72,8 +74,21 @@ bool fileWrite(const void *buffer, const char *path, u32 size) return true; } + else if(result == FR_NO_PATH) + { + char folder[256]; - return false; + for(u32 i = 1; path[i] != 0; i++) + if(path[i] == '/') + { + memcpy(folder, path, i); + folder[i] = 0; + f_mkdir(folder); + } + + return fileWrite(buffer, path, size); + } + else return false; } void fileDelete(const char *path) @@ -81,11 +96,6 @@ void fileDelete(const char *path) f_unlink(path); } -void createDirectory(const char *path) -{ - f_mkdir(path); -} - void loadPayload(u32 pressed) { const char *pattern; @@ -132,27 +142,6 @@ void loadPayload(u32 pressed) } } -void findDumpFile(const char *path, char *fileName) -{ - DIR dir; - FILINFO info; - u32 n = 0; - - while(f_findfirst(&dir, &info, path, fileName) == FR_OK && info.fname[0]) - { - u32 i = 18, - tmp = ++n; - - while(tmp) - { - fileName[i--] = '0' + (tmp % 10); - tmp /= 10; - } - } - - f_closedir(&dir); -} - u32 firmRead(void *dest, u32 firmType) { const char *firmFolders[4][2] = {{ "00000002", "20000002" }, @@ -208,4 +197,25 @@ u32 firmRead(void *dest, u32 firmType) fileRead(dest, path); return firmVersion; +} + +void findDumpFile(const char *path, char *fileName) +{ + DIR dir; + FILINFO info; + u32 n = 0; + + while(f_findfirst(&dir, &info, path, fileName) == FR_OK && info.fname[0]) + { + u32 i = 18, + tmp = ++n; + + while(tmp) + { + fileName[i--] = '0' + (tmp % 10); + tmp /= 10; + } + } + + f_closedir(&dir); } \ No newline at end of file diff --git a/source/fs.h b/source/fs.h index 23244fe..feba3ab 100644 --- a/source/fs.h +++ b/source/fs.h @@ -33,6 +33,7 @@ u32 fileRead(void *dest, const char *path); u32 getFileSize(const char *path); bool fileWrite(const void *buffer, const char *path, u32 size); void fileDelete(const char *path); -void createDirectory(const char *path); +void loadPayload(u32 pressed); +u32 firmRead(void *dest, u32 firmType); + void findDumpFile(const char *path, char *fileName); -void loadPayload(u32 pressed);u32 firmRead(void *dest, u32 firmType); diff --git a/source/memory.c b/source/memory.c index e7a05c9..03a36ae 100644 --- a/source/memory.c +++ b/source/memory.c @@ -41,7 +41,7 @@ void memset32(void *dest, u32 filler, u32 size) { u32 *dest32 = (u32 *)dest; - for (u32 i = 0; i < size / 4; i++) + for(u32 i = 0; i < size / 4; i++) dest32[i] = filler; } diff --git a/source/pin.c b/source/pin.c index 0f52200..e46a1d3 100644 --- a/source/pin.c +++ b/source/pin.c @@ -96,11 +96,7 @@ void newPin(bool allowSkipping) memcpy(pin.hash, tmp, 32); if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData))) - { - createDirectory("luma"); - if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData))) - error("Error writing the PIN file"); - } + error("Error writing the PIN file"); } bool verifyPin(void)