fix fs path buffer size

path size has to be at least 0x301 in size or else there be dragons.

replaced the misc changes i made to minIni.c with the upstream master branch version.

fixed misspelling of atmosphere in readme, thanks archbox.
This commit is contained in:
TotalJustice 2023-05-23 13:02:19 +01:00
parent 4b1a4b17bd
commit abb8d28d55
4 changed files with 22 additions and 14 deletions

View File

@ -35,7 +35,7 @@ ldr on the other hand needs new patches after every new atmosphere release. this
it uses a collection of patterns to find the piece of code to patch. alternatively, it could just use offsets, however this would mean this tool would have to be updated after every new fw update, that's not ideal.
the patches are applied at boot, then, the sysmod stops running. the memory footpint of the sysmod is very very small, only using 16kib in total. the size of the binary itself is only 14kib! this doesnt really mean much, but im pretty proud of it :)
the patches are applied at boot, then, the sysmod stops running. the memory footpint of the sysmod is very very small, only using 16kib in total. the size of the binary itself is only ~50kib! this doesnt really mean much, but im pretty proud of it :)
---
@ -49,7 +49,7 @@ No, i would personally recommend continuing to use sigpatches. Reason being is t
Yes, in 2 niche cases.
1. A new ldr patch needs to be created after every atosphere update. Sometimes, a new silent atmosphere update is released. This tool will always patch ldr without having to update patches.
1. A new ldr patch needs to be created after every atmosphere update. Sometimes, a new silent atmosphere update is released. This tool will always patch ldr without having to update patches.
2. Building atmosphere from src will require you to generate a new ldr patch for that custom built atmosphere. This is easy enough due to the public scripts / tools that exist out there, however this will always be able to

View File

@ -339,12 +339,14 @@ auto apply_patch(const PatchEntry& patch) -> bool {
auto create_dir(const char* path) -> bool {
Result rc{};
FsFileSystem fs{};
char path_buf[FS_MAX_PATH]{};
if (R_FAILED(fsOpenSdCardFileSystem(&fs))) {
return false;
}
rc = fsFsCreateDirectory(&fs, path);
strcpy(path_buf, path);
rc = fsFsCreateDirectory(&fs, path_buf);
fsFsClose(&fs);
return R_SUCCEEDED(rc);
}

View File

@ -3,17 +3,21 @@
static bool ini_open(const char* filename, struct NxFile* nxfile, u32 mode) {
Result rc = {0};
char filename_buf[FS_MAX_PATH] = {0};
if (R_FAILED(rc = fsOpenSdCardFileSystem(&nxfile->system))) {
return false;
}
if (R_FAILED(rc = fsFsOpenFile(&nxfile->system, filename, mode, &nxfile->file))) {
strcpy(filename_buf, filename);
if (R_FAILED(rc = fsFsOpenFile(&nxfile->system, filename_buf, mode, &nxfile->file))) {
if (mode & FsOpenMode_Write) {
if (R_FAILED(rc = fsFsCreateFile(&nxfile->system, filename, 0, 0))) {
if (R_FAILED(rc = fsFsCreateFile(&nxfile->system, filename_buf, 0, 0))) {
fsFsClose(&nxfile->system);
return false;
} else {
if (R_FAILED(rc = fsFsOpenFile(&nxfile->system, filename, mode, &nxfile->file))) {
if (R_FAILED(rc = fsFsOpenFile(&nxfile->system, filename_buf, mode, &nxfile->file))) {
fsFsClose(&nxfile->system);
return false;
}
@ -94,12 +98,16 @@ bool ini_seek(struct NxFile* nxfile, s64* pos) {
bool ini_rename(const char* src, const char* dst) {
Result rc = {0};
FsFileSystem fs = {0};
char src_buf[FS_MAX_PATH] = {0};
char dst_buf[FS_MAX_PATH] = {0};
if (R_FAILED(rc = fsOpenSdCardFileSystem(&fs))) {
return false;
}
rc = fsFsRenameFile(&fs, src, dst);
strcpy(src_buf, src);
strcpy(dst_buf, dst);
rc = fsFsRenameFile(&fs, src_buf, dst_buf);
fsFsClose(&fs);
return R_SUCCEEDED(rc);
}
@ -107,12 +115,14 @@ bool ini_rename(const char* src, const char* dst) {
bool ini_remove(const char* filename) {
Result rc = {0};
FsFileSystem fs = {0};
char filename_buf[FS_MAX_PATH] = {0};
if (R_FAILED(rc = fsOpenSdCardFileSystem(&fs))) {
return false;
}
rc = fsFsDeleteFile(&fs, filename);
strcpy(filename_buf, filename);
rc = fsFsDeleteFile(&fs, filename_buf);
fsFsClose(&fs);
return R_SUCCEEDED(rc);
}

View File

@ -570,7 +570,7 @@ static void ini_tempname(TCHAR *dest, const TCHAR *source, int maxlength)
ini_strncpy(dest, source, maxlength, QUOTE_NONE);
p = _tcschr(dest, '\0');
assert(p != NULL);
*(p - 1) = '2';
*(p - 1) = '~';
}
static enum quote_option check_enquote(const TCHAR *Value)
@ -683,10 +683,7 @@ int ini_puts(const TCHAR *Section, const TCHAR *Key, const TCHAR *Value, const T
INI_FILEPOS mark;
INI_FILEPOS head, tail;
TCHAR *sp, *ep;
// TJ: not making this static breaks everything.
// this only happens as sysmod.
// likley some UB stuff is going on here, will investigate soon.
static TCHAR LocalBuffer[INI_BUFFERSIZE];
TCHAR LocalBuffer[INI_BUFFERSIZE];
int len, match, flag, cachelen;
assert(Filename != NULL);
@ -757,7 +754,6 @@ int ini_puts(const TCHAR *Section, const TCHAR *Key, const TCHAR *Value, const T
ini_tempname(LocalBuffer, Filename, INI_BUFFERSIZE);
if (!ini_openwrite(LocalBuffer, &wfp))
return 0;
/* In the case of (advisory) file locks, ini_openwrite() may have been blocked
* on the open, and after the block is lifted, the original file may have been
* renamed, which is why the original file was closed and is now reopened */