Skip to content

Commit

Permalink
Get ready for new Atmosphere release (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
masagrator committed May 14, 2023
1 parent ab4a2d9 commit a3c5d1c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ Remember to restart Switch
| World of Goo | all | 32-bit game, not supported |
| YouTube | plugins | Unknown |

Titles other than 32-bit are added to exceptions.txt which is treated as Black list, you can find it in root of repo. SaltyNX reads it from SaltySD folder. `X` at the beginning of titleid means that this game will not load any patches and plugins.
Titles other than 32-bit are added to exceptions.txt which is treated as Black list, you can find it in root of repo. SaltyNX reads it from SaltySD folder. `X` at the beginning of titleid means that this game will not load any patches and plugins. `R` at the beginning of titleid means that this game will not load any patches and plugins if romfs mod for this game is installed.

32-bit games are ignored by default for patches and plugins.
2 changes: 1 addition & 1 deletion libnx_min/nx/source/services/applet.c
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,7 @@ bool appletHolderCheckFinished(AppletHolder *h) {
return R_SUCCEEDED(eventWait(&h->StateChangedEvent, 0));
}

u32 appletHolderGetExitReason(AppletHolder *h) {
LibAppletExitReason appletHolderGetExitReason(AppletHolder *h) {
return h->exitreason;
}

Expand Down
5 changes: 2 additions & 3 deletions saltysd_core/source/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <switch_min.h>

#include <inttypes.h>
#include <dirent.h>
#include <switch_min/kernel/ipc.h>
#include <switch_min/runtime/threadvars.h>
Expand Down Expand Up @@ -147,7 +146,7 @@ void SaltySDCore_LoadPatches (bool Aarch64) {

SaltySDCore_printf("SaltySD Patcher: Searching patches in dir '/%016llx'...\n", tid);

snprintf(tmp4, 0x100, "sdmc:/SaltySD/patches/%016" PRIx64 "/", tid);
snprintf(tmp4, 0x100, "sdmc:/SaltySD/patches/%016lx/", tid);

d = opendir(tmp4);
if (d)
Expand Down Expand Up @@ -415,7 +414,7 @@ void SaltySDCore_LoadPlugins()
size_t num_elfs = 0;

entries = SaltySDCore_LoadPluginsInDir("", entries, &num_elfs);
snprintf(tmp3, 0x20, "%016" PRIx64 "/", tid);
snprintf(tmp3, 0x20, "%016lx/", tid);
entries = SaltySDCore_LoadPluginsInDir(tmp3, entries, &num_elfs);

for (int i = 0; i < num_elfs; i++)
Expand Down
101 changes: 63 additions & 38 deletions saltysd_proc/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <inttypes.h>
#include <dirent.h>
#include <switch_min/kernel/svc_extra.h>
#include <switch_min/kernel/ipc.h>
#include "saltysd_bootstrap_elf.h"
Expand All @@ -20,7 +20,7 @@ u32 __nx_applet_type = AppletType_None;
void serviceThread(void* buf);

Handle saltyport, sdcard, injectserv;
static char g_heap[0xB0000];
static char g_heap[0x80000];
bool should_terminate = false;
bool already_hijacking = false;
DebugEventInfo eventinfo;
Expand Down Expand Up @@ -54,31 +54,40 @@ void __appExit(void)
u64 TIDnow;
u64 PIDnow;

void renametocheatstemp() {
char cheatspath[60];
char cheatspathtemp[64];
TIDnow = eventinfo.tid;
snprintf(cheatspath, sizeof cheatspath, "sdmc:/Atmosphere/titles/%016"PRIx64"/cheats", TIDnow);
snprintf(cheatspathtemp, sizeof cheatspathtemp, "%stemp", cheatspath);
rename(cheatspath, cheatspathtemp);
snprintf(cheatspath, sizeof cheatspath, "sdmc:/Atmosphere/contents/%016"PRIx64"/cheats", TIDnow);
snprintf(cheatspathtemp, sizeof cheatspathtemp, "%stemp", cheatspath);
rename(cheatspath, cheatspathtemp);
check = true;
void renameCheatsFolder() {
char* cheatspath = (char*)malloc(0x40);
char* cheatspathtemp = (char*)malloc(0x40);

snprintf(cheatspath, 0x40, "sdmc:/atmosphere/contents/%016lx/cheats", TIDnow);
snprintf(cheatspathtemp, 0x40, "%stemp", cheatspath);
if (!check) {
rename(cheatspath, cheatspathtemp);
check = true;
}
else {
rename(cheatspathtemp, cheatspath);
check = false;
}
free(cheatspath);
free(cheatspathtemp);
return;
}

void renametocheats() {
char cheatspath[60];
char cheatspathtemp[64];
snprintf(cheatspath, sizeof cheatspath, "sdmc:/Atmosphere/titles/%016"PRIx64"/cheats", TIDnow);
snprintf(cheatspathtemp, sizeof cheatspathtemp, "%stemp", cheatspath);
rename(cheatspathtemp, cheatspath);
snprintf(cheatspath, sizeof cheatspath, "sdmc:/Atmosphere/contents/%016"PRIx64"/cheats", TIDnow);
snprintf(cheatspathtemp, sizeof cheatspathtemp, "%stemp", cheatspath);
rename(cheatspathtemp, cheatspath);
check = false;
return;
bool isModInstalled() {
char* romfspath = (char*)malloc(0x40);
bool flag = false;

snprintf(romfspath, 0x40, "sdmc:/atmosphere/contents/%016lx/romfs", eventinfo.tid);

DIR* dir = opendir(romfspath);
if (dir) {
if (readdir(dir))
flag = true;
closedir(dir);
}

free(romfspath);
return flag;
}

void hijack_bootstrap(Handle* debug, u64 pid, u64 tid)
Expand Down Expand Up @@ -157,15 +166,19 @@ void hijack_pid(u64 pid)
char exceptions[20];
char line[20];
char titleidnum[20];
char titleidnumF[20];
char titleidnumX[20];
char titleidnumR[20];

while (1)
{
ret = svcGetDebugEventInfo(&eventinfo, debug);

if (check == false) {
TIDnow = eventinfo.tid;
exception = 0;
renametocheatstemp();
renameCheatsFolder();
}

if (ret)
{
SaltySD_printf("SaltySD: svcGetDebugEventInfo returned %x, breaking\n", ret);
Expand All @@ -184,12 +197,12 @@ void hijack_pid(u64 pid)

if (eventinfo.tid <= 0x010000000000FFFF)
{
SaltySD_printf("SaltySD: TID %016llx is a system application, aborting bootstrap...\n", eventinfo.tid);
SaltySD_printf("SaltySD: TID %016lx is a system application, aborting bootstrap...\n", eventinfo.tid);
goto abort_bootstrap;
}
if (eventinfo.tid > 0x01FFFFFFFFFFFFFF || (eventinfo.tid & 0x1F00) != 0)
{
SaltySD_printf("SaltySD: TID %016llx is a homebrew application, aborting bootstrap...\n", eventinfo.tid);
SaltySD_printf("SaltySD: TID %016lx is a homebrew application, aborting bootstrap...\n", eventinfo.tid);
goto abort_bootstrap;
}
if (!eventinfo.isA64)
Expand All @@ -209,24 +222,36 @@ void hijack_pid(u64 pid)
goto abort_bootstrap;
}

snprintf(titleidnum, sizeof titleidnum, "%016"PRIx64, eventinfo.tid);
snprintf(titleidnumF, sizeof titleidnumF, "X%016"PRIx64, eventinfo.tid);

FILE* except = fopen("sdmc:/SaltySD/exceptions.txt", "r");
if (except) {
snprintf(titleidnum, sizeof titleidnum, "%016lx", eventinfo.tid);
snprintf(titleidnumX, sizeof titleidnumX, "X%016lx", eventinfo.tid);
snprintf(titleidnumR, sizeof titleidnumR, "R%016lx", eventinfo.tid);
while (fgets(line, sizeof(line), except)) {
snprintf(exceptions, sizeof exceptions, "%s", line);
if (!strncasecmp(exceptions, titleidnumF, 17)) {
SaltySD_printf("SaltySD: TID %016llx is forced in exceptions.txt, aborting bootstrap...\n", eventinfo.tid);
if (!strncasecmp(exceptions, titleidnumX, 17)) {
SaltySD_printf("SaltySD: TID %016lx is forced in exceptions.txt, aborting bootstrap...\n", eventinfo.tid);
if (!shmemMap(&_sharedMemory)) {
memset(shmemGetAddr(&_sharedMemory), 0, 0x1000);
shmemUnmap(&_sharedMemory);
}
fclose(except);
goto abort_bootstrap;
}
else if (!strncasecmp(exceptions, titleidnumR, 17)) {
if (isModInstalled()) {
SaltySD_printf("SaltySD: TID %016lx is in exceptions.txt as romfs excluded, aborting bootstrap...\n", eventinfo.tid);
if (!shmemMap(&_sharedMemory)) {
memset(shmemGetAddr(&_sharedMemory), 0, 0x1000);
shmemUnmap(&_sharedMemory);
}
fclose(except);
goto abort_bootstrap;
}
else SaltySD_printf("SaltySD: TID %016lx is in exceptions.txt as romfs excluded, but no romfs mod was detected...\n", eventinfo.tid);
}
else if (!strncasecmp(exceptions, titleidnum, 16)) {
SaltySD_printf("SaltySD: TID %016llx is in exceptions.txt, aborting loading plugins...\n", eventinfo.tid);
SaltySD_printf("SaltySD: TID %016lx is in exceptions.txt, aborting loading plugins...\n", eventinfo.tid);
if (!shmemMap(&_sharedMemory)) {
memset(shmemGetAddr(&_sharedMemory), 0, 0x1000);
shmemUnmap(&_sharedMemory);
Expand All @@ -237,11 +262,11 @@ void hijack_pid(u64 pid)
fclose(except);
}
SaltySD_printf("SaltySD: found valid AttachProcess event:\n");
SaltySD_printf(" tid %016llx pid %016llx\n", eventinfo.tid, eventinfo.pid);
SaltySD_printf(" tid %016lx pid %016lx\n", eventinfo.tid, eventinfo.pid);
SaltySD_printf(" name %s\n", eventinfo.name);
SaltySD_printf(" isA64 %01x addrSpace %01x enableDebug %01x\n", eventinfo.isA64, eventinfo.addrSpace, eventinfo.enableDebug);
SaltySD_printf(" enableAslr %01x useSysMemBlocks %01x poolPartition %01x\n", eventinfo.enableAslr, eventinfo.useSysMemBlocks, eventinfo.poolPartition);
SaltySD_printf(" exception %016llx\n", eventinfo.userExceptionContextAddr);
SaltySD_printf(" exception %016lx\n", eventinfo.userExceptionContextAddr);
}
else
{
Expand All @@ -257,7 +282,7 @@ void hijack_pid(u64 pid)
svcSleepThread(-1);
}
while (!threads);
renametocheats();
renameCheatsFolder();

hijack_bootstrap(&debug, pid, tids[0]);

Expand All @@ -267,7 +292,7 @@ void hijack_pid(u64 pid)
abort_bootstrap:
disable = 0;
free(tids);
renametocheats();
renameCheatsFolder();

already_hijacking = false;
svcCloseHandle(debug);
Expand Down

0 comments on commit a3c5d1c

Please sign in to comment.