diff --git a/Makefile b/Makefile
index 5959325..5d2e982 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,8 @@ objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
$(call rwildcard, $(dir_source), *.s *.c)))
bundled = $(dir_build)/rebootpatch.h $(dir_build)/emunandpatch.h $(dir_build)/k11modulespatch.h $(dir_build)/svcGetCFWInfopatch.h $(dir_build)/twl_k11modulespatch.h \
- $(dir_build)/arm9_exceptions.h $(dir_build)/arm11_exceptions.h $(dir_build)/injector.h $(dir_build)/loader.h
+ $(dir_build)/arm9_exceptions.h $(dir_build)/arm11_exceptions.h $(dir_build)/injector.h $(dir_build)/loader.h
+
.PHONY: all
all: launcher a9lh ninjhax
@@ -127,8 +128,8 @@ $(dir_build)/arm9_exceptions.h: $(dir_arm9_exceptions)/Makefile
$(dir_build)/arm11_exceptions.h: $(dir_arm11_exceptions)/Makefile
@$(MAKE) -C $(dir_arm11_exceptions)
@bin2c -o $@ -n arm11_exceptions $(@D)/arm11_exceptions.bin
-
-$(dir_build)/memory.o: CFLAGS += -O3
+
+$(dir_build)/memory.o $(dir_build)/strings.o: CFLAGS += -O3
$(dir_build)/config.o: CFLAGS += -DCONFIG_TITLE="\"$(name) $(revision) (dev) configuration\""
$(dir_build)/patches.o: CFLAGS += -DREVISION=\"$(revision)\" -DCOMMIT_HASH="0x$(commit)"
diff --git a/source/draw.c b/source/draw.c
index a6a99f5..14b8b0e 100644
--- a/source/draw.c
+++ b/source/draw.c
@@ -26,20 +26,12 @@
*/
#include "draw.h"
+#include "strings.h"
#include "screen.h"
#include "utils.h"
#include "fs.h"
#include "font.h"
-static inline int strlen(const char *string)
-{
- char *stringEnd = (char *)string;
-
- while(*stringEnd) stringEnd++;
-
- return stringEnd - string;
-}
-
bool loadSplash(void)
{
//Don't delay boot nor init the screens if no splash image is on the SD
diff --git a/source/exceptions.c b/source/exceptions.c
index 70e8be8..81fad25 100644
--- a/source/exceptions.c
+++ b/source/exceptions.c
@@ -22,6 +22,7 @@
#include "exceptions.h"
#include "fs.h"
+#include "strings.h"
#include "memory.h"
#include "screen.h"
#include "draw.h"
@@ -103,23 +104,12 @@ void detectAndProcessExceptionDumps(void)
char fileName[] = "crash_dump_00000000.dmp";
u32 size = dumpHeader->totalSize;
- char *pathFolder;
- u32 fileNameSpot;
- if(dumpHeader->processor == 9)
- {
- pathFolder = "/luma/dumps/arm9";
- fileNameSpot = 16;
- }
- else
- {
- pathFolder = "/luma/dumps/arm11";
- fileNameSpot = 17;
- }
+ char *pathFolder = dumpHeader->processor == 9 ? "/luma/dumps/arm9" : "/luma/dumps/arm11";
findDumpFile(pathFolder, fileName);
- memcpy(path, pathFolder, 17);
- path[fileNameSpot] = '/';
- memcpy(&path[fileNameSpot + 1], fileName, sizeof(fileName));
+ memcpy(path, pathFolder, strlen(pathFolder));
+ concatenateStrings(path, "/");
+ concatenateStrings(path, fileName);
fileWrite((void *)dumpHeader, path, size);
diff --git a/source/firm.c b/source/firm.c
index 6084b97..a251a48 100755
--- a/source/firm.c
+++ b/source/firm.c
@@ -26,6 +26,7 @@
#include "fs.h"
#include "patches.h"
#include "memory.h"
+#include "strings.h"
#include "cache.h"
#include "emunand.h"
#include "crypto.h"
@@ -436,10 +437,8 @@ static inline void copySection0AndInjectSystemModules(FirmwareType firmType)
const char *ext = ".cxi";
//Read modules from files if they exist
- u32 nameOff;
- for(nameOff = 0; nameOff < 8 && moduleName[nameOff] != 0; nameOff++);
- memcpy(fileName + 17, moduleName, nameOff);
- memcpy(fileName + 17 + nameOff, ext, 5);
+ concatenateStrings(fileName, moduleName);
+ concatenateStrings(fileName, ext);
u32 fileSize = fileRead(dst, fileName);
if(fileSize) dstModuleSize = fileSize;
diff --git a/source/fs.c b/source/fs.c
index 97bebd6..347bf01 100644
--- a/source/fs.c
+++ b/source/fs.c
@@ -22,6 +22,7 @@
#include "fs.h"
#include "memory.h"
+#include "strings.h"
#include "cache.h"
#include "screen.h"
#include "fatfs/ff.h"
@@ -128,8 +129,8 @@ void loadPayload(u32 pressed)
memcpy(loaderAddress, loader, loader_size);
- path[14] = '/';
- memcpy(&path[15], info.altname, 13);
+ concatenateStrings(path, "/");
+ concatenateStrings(path, info.altname);
loaderAddress[1] = fileRead((void *)0x24F00000, path);
@@ -149,8 +150,9 @@ u32 firmRead(void *dest, u32 firmType)
{ "00000202", "20000202" },
{ "00000003", "20000003" }};
- char path[48] = "1:/title/00040138/00000000/content";
- memcpy(&path[18], firmFolders[firmType][isN3DS ? 1 : 0], 8);
+ char path[48] = "1:/title/00040138/";
+ concatenateStrings(path, firmFolders[firmType][isN3DS ? 1 : 0]);
+ concatenateStrings(path, "/content");
DIR dir;
FILINFO info;
@@ -180,7 +182,7 @@ u32 firmRead(void *dest, u32 firmType)
f_closedir(&dir);
//Complete the string with the .app name
- memcpy(&path[34], "/00000000.app", 14);
+ concatenateStrings(path, "/00000000.app");
//Last digit of the .app
u32 i = 42;
diff --git a/source/strings.c b/source/strings.c
new file mode 100644
index 0000000..adaa712
--- /dev/null
+++ b/source/strings.c
@@ -0,0 +1,41 @@
+/*
+* This file is part of Luma3DS
+* Copyright (C) 2016 Aurora Wright, TuxSH
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+* Additional Terms 7.b of GPLv3 applies to this file: Requiring preservation of specified
+* reasonable legal notices or author attributions in that material or in the Appropriate Legal
+* Notices displayed by works containing it.
+*/
+
+#include "strings.h"
+#include "memory.h"
+
+int strlen(const char *string)
+{
+ char *stringEnd = (char *)string;
+
+ while(*stringEnd) stringEnd++;
+
+ return stringEnd - string;
+}
+
+void concatenateStrings(char *destination, const char *source)
+{
+ int i = strlen(source),
+ j = strlen(destination);
+
+ memcpy(&destination[j], source, i + 1);
+}
\ No newline at end of file
diff --git a/source/strings.h b/source/strings.h
new file mode 100644
index 0000000..f6b035f
--- /dev/null
+++ b/source/strings.h
@@ -0,0 +1,28 @@
+/*
+* This file is part of Luma3DS
+* Copyright (C) 2016 Aurora Wright, TuxSH
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+* Additional Terms 7.b of GPLv3 applies to this file: Requiring preservation of specified
+* reasonable legal notices or author attributions in that material or in the Appropriate Legal
+* Notices displayed by works containing it.
+*/
+
+#pragma once
+
+#include "types.h"
+
+int strlen(const char *string);
+void concatenateStrings(char *destination, const char *source);
\ No newline at end of file