Skip to content

Commit

Permalink
Hack to fix Cheats in Atmosphere
Browse files Browse the repository at this point in the history
  • Loading branch information
masagrator committed Mar 14, 2020
1 parent 2131f40 commit 9e267bc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libnx_min/nx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include $(DEVKITPRO)/devkitA64/base_rules

export LIBNX_MAJOR := 2
export LIBNX_MINOR := 2
export LIBNX_PATCH := 0
export LIBNX_PATCH := 1


VERSION := $(LIBNX_MAJOR).$(LIBNX_MINOR).$(LIBNX_PATCH)
Expand Down
3 changes: 1 addition & 2 deletions libnx_min/nx/include/switch_min/services/pm.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ Result pmdmntEnableDebugForTitleId(Handle* handle_out, u64 title_id);
Result pmdmntGetApplicationPid(u64* pid_out);
Result pmdmntEnableDebugForApplication(Handle* handle_out);
Result pmdmntDisableDebug(void);

Result pminfoGetTitleId(u64* title_id_out, u64 pid);
Result pmdmntGetApplicationProcessId(u64* pid_out);

Result pmshellLaunchProcess(u32 launch_flags, u64 titleID, u64 storageID, u64 *pid);
Result pmshellTerminateProcessByProcessId(u64 processID);
Expand Down
39 changes: 37 additions & 2 deletions saltysd_proc/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Handle saltyport, sdcard, injectserv;
static char g_heap[0x100000];
bool should_terminate = false;
bool already_hijacking = false;
DebugEventInfo eventinfo;
bool check = false;

void __libnx_initheap(void)
{
Expand All @@ -37,6 +39,35 @@ void __appInit(void)

}

u64 TIDnow;

void renametocheatstemp() {
char cheatspath[64];
char cheatspathtemp[64];
TIDnow = eventinfo.tid;
snprintf(cheatspath, sizeof cheatspath, "sdmc:/Atmosphere/titles/%016llx/cheats", TIDnow);
snprintf(cheatspathtemp, sizeof cheatspathtemp, "%stemp", cheatspath);
rename(cheatspath, cheatspathtemp);
snprintf(cheatspath, sizeof cheatspath, "sdmc:/Atmosphere/contents/%016llx/cheats", TIDnow);
snprintf(cheatspathtemp, sizeof cheatspathtemp, "%stemp", cheatspath);
rename(cheatspath, cheatspathtemp);
check = true;
return;
}

void renametocheats() {
char cheatspath[64];
char cheatspathtemp[64];
snprintf(cheatspath, sizeof cheatspath, "sdmc:/Atmosphere/titles/%016llx/cheats", TIDnow);
snprintf(cheatspathtemp, sizeof cheatspathtemp, "%stemp", cheatspath);
rename(cheatspathtemp, cheatspath);
snprintf(cheatspath, sizeof cheatspath, "sdmc:/Atmosphere/contents/%016llx/cheats", TIDnow);
snprintf(cheatspathtemp, sizeof cheatspathtemp, "%stemp", cheatspath);
rename(cheatspathtemp, cheatspath);
check = false;
return;
}

void hijack_bootstrap(Handle* debug, u64 pid, u64 tid)
{
ThreadContext context;
Expand Down Expand Up @@ -76,6 +107,7 @@ void hijack_pid(u64 pid)
Result ret;
u32 threads;
Handle debug;

FILE* disabled = fopen("sdmc:/SaltySD/flags/disable.flag", "r");
u8 disable = 1;

Expand Down Expand Up @@ -112,11 +144,11 @@ void hijack_pid(u64 pid)
char titleidnum[16];
char titleidnumn[17];
char titleidnumrn[18];

DebugEventInfo eventinfo;

while (1)
{
ret = svcGetDebugEventInfo(&eventinfo, debug);
if (check == false) renametocheatstemp();
if (ret)
{
SaltySD_printf("SaltySD: svcGetDebugEventInfo returned %x, breaking\n", ret);
Expand Down Expand Up @@ -188,12 +220,14 @@ void hijack_pid(u64 pid)
}
}
// Poll for new threads (svcStartProcess) while stuck in debug

do
{
ret = svcGetThreadList(&threads, tids, 0x200, debug);
svcSleepThread(-1);
}
while (!threads);
renametocheats();
hijack_bootstrap(&debug, pid, tids[0]);

free(tids);
Expand All @@ -202,6 +236,7 @@ void hijack_pid(u64 pid)
abort_bootstrap:
disable = 0;
free(tids);
renametocheats();

already_hijacking = false;
svcCloseHandle(debug);
Expand Down

0 comments on commit 9e267bc

Please sign in to comment.