From 1e1d61f15f1c104165bad2848d294d90ee8c2ce6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-SN9KF5O\\Strawberry" Date: Sat, 15 Nov 2025 21:11:53 +0000 Subject: [PATCH 01/13] Bump version --- sys-botbase/source/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys-botbase/source/main.c b/sys-botbase/source/main.c index e4c0e22..2aac48f 100644 --- a/sys-botbase/source/main.c +++ b/sys-botbase/source/main.c @@ -17,7 +17,7 @@ #define TITLE_ID 0x430000000000000B #define HEAP_SIZE 0x00480000 #define THREAD_SIZE 0x1A000 -#define VERSION_S "2.4" +#define VERSION_S "2.41" typedef enum { Active = 0, From 8af8edd152b237b4b3312ee8b8e17217414086da Mon Sep 17 00:00:00 2001 From: Lusamine <30205550+Lusamine@users.noreply.github.com> Date: Sat, 7 Feb 2026 00:06:03 -0600 Subject: [PATCH 02/13] Handle potential errors from readMem --- sys-botbase/source/commands.c | 51 +++++++++++++++++++++++++++-------- sys-botbase/source/commands.h | 2 +- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/sys-botbase/source/commands.c b/sys-botbase/source/commands.c index c4885a6..bf29c47 100644 --- a/sys-botbase/source/commands.c +++ b/sys-botbase/source/commands.c @@ -243,8 +243,13 @@ void peek(u64 offset, u64 size) { u8 *out = malloc(sizeof(u8) * size); attach(); - readMem(out, offset, size); - detach(); + Result rc = readMem(out, offset, size); + if (R_FAILED(rc)) + { + detach(); + free(out); + return; + } u64 i; for (i = 0; i < size; i++) @@ -252,6 +257,7 @@ void peek(u64 offset, u64 size) printf("%02X", out[i]); } printf("\n"); + detach(); free(out); } @@ -267,7 +273,14 @@ void peekInfinite(u64 offset, u64 size) { u64 thisBuffersize = sizeRemainder > MAX_LINE_LENGTH ? MAX_LINE_LENGTH : sizeRemainder; sizeRemainder -= thisBuffersize; - readMem(out, offset + totalFetched, thisBuffersize); + Result rc = readMem(out, offset + totalFetched, thisBuffersize); + if (R_FAILED(rc)) + { + detach(); + free(out); + return; + } + for (i = 0; i < thisBuffersize; i++) { printf("%02X", out[i]); @@ -291,10 +304,15 @@ void peekMulti(u64* offset, u64* size, u64 count) attach(); for (int i = 0; i < count; i++) { - readMem(out + ofs, offset[i], size[i]); + Result rc = readMem(out + ofs, offset[i], size[i]); + if (R_FAILED(rc)) + { + detach(); + free(out); + return; + } ofs += size[i]; } - detach(); u64 i; for (i = 0; i < totalSize; i++) @@ -302,14 +320,16 @@ void peekMulti(u64* offset, u64* size, u64 count) printf("%02X", out[i]); } printf("\n"); + detach(); free(out); } -void readMem(u8* out, u64 offset, u64 size) +Result readMem(u8* out, u64 offset, u64 size) { - Result rc = svcReadDebugProcessMemory(out, debughandle, offset, size); + Result rc = svcReadDebugProcessMemory(out, debughandle, offset, size); if (R_FAILED(rc) && debugResultCodes) printf("svcReadDebugProcessMemory: %d\n", rc); + return rc; } void click(HidNpadButton btn) @@ -375,14 +395,23 @@ u64 followMainPointer(s64* jumps, size_t count) MetaData meta = getMetaData(); attach(); - readMem(out, meta.main_nso_base + jumps[0], size); + Result rc = readMem(out, meta.main_nso_base + jumps[0], size); + if (R_FAILED(rc)) + { + detach(); + free(out); + return 0; + } offset = *(u64*)out; + int i; for (i = 1; i < count; ++i) { - readMem(out, offset + jumps[i], size); - offset = *(u64*)out; - // this traversal resulted in an error + rc = readMem(out, offset + jumps[i], size); + if (R_FAILED(rc)) + break; + offset = *(u64*)out; + // This traversal resulted in an error if (offset == 0) break; } diff --git a/sys-botbase/source/commands.h b/sys-botbase/source/commands.h index a8fbc6d..293b5fa 100644 --- a/sys-botbase/source/commands.h +++ b/sys-botbase/source/commands.h @@ -54,7 +54,7 @@ void writeMem(u64 offset, u64 size, u8* val); void peek(u64 offset, u64 size); void peekInfinite(u64 offset, u64 size); void peekMulti(u64* offset, u64* size, u64 count); -void readMem(u8* out, u64 offset, u64 size); +Result readMem(u8* out, u64 offset, u64 size); void click(HidNpadButton btn); void press(HidNpadButton btn); void release(HidNpadButton btn); From b3b0ebf0f4b5f456a0573d61a89d7a206d8b3c8c Mon Sep 17 00:00:00 2001 From: Lusamine <30205550+Lusamine@users.noreply.github.com> Date: Sat, 7 Feb 2026 00:11:27 -0600 Subject: [PATCH 03/13] Standardize formatting, white space, and pointer declaration --- sys-botbase/source/args.c | 14 +- sys-botbase/source/args.h | 2 +- sys-botbase/source/commands.c | 174 ++++----- sys-botbase/source/freeze.c | 114 +++--- sys-botbase/source/freeze.h | 12 +- sys-botbase/source/main.c | 681 +++++++++++++++++----------------- sys-botbase/source/util.c | 61 +-- sys-botbase/source/util.h | 4 +- sys-botbase/sys-botbase.json | 368 +++++++++--------- 9 files changed, 719 insertions(+), 711 deletions(-) diff --git a/sys-botbase/source/args.c b/sys-botbase/source/args.c index 171fc0f..8f907d9 100644 --- a/sys-botbase/source/args.c +++ b/sys-botbase/source/args.c @@ -2,15 +2,15 @@ #include #include -int parseArgs(char *origargstr, int (*callback)(int, char **)) +int parseArgs(char* origargstr, int (*callback)(int, char**)) { - char *argstr = malloc(strlen(origargstr) + 1); + char* argstr = malloc(strlen(origargstr) + 1); memcpy(argstr, origargstr, strlen(origargstr) + 1); int argc = 0; - char *tmpstr = malloc(strlen(argstr) + 1); + char* tmpstr = malloc(strlen(argstr) + 1); memcpy(tmpstr, argstr, strlen(argstr) + 1); - for (char *p = strtok(tmpstr, " \r\n"); p != NULL; p = strtok(NULL, " \r\n")) { + for (char* p = strtok(tmpstr, " \r\n"); p != NULL; p = strtok(NULL, " \r\n")) { argc++; } free(tmpstr); @@ -20,13 +20,13 @@ int parseArgs(char *origargstr, int (*callback)(int, char **)) return (*callback)(argc, NULL); } - char **argv = malloc(sizeof(char *) * argc); + char** argv = malloc(sizeof(char*) * argc); int i = 0; - for (char *p = strtok(argstr, " \r\n"); p != NULL; p = strtok(NULL, " \r\n")) + for (char* p = strtok(argstr, " \r\n"); p != NULL; p = strtok(NULL, " \r\n")) argv[i++] = p; int ret = (*callback)(argc, argv); free(argv); free(argstr); return ret; -} \ No newline at end of file +} diff --git a/sys-botbase/source/args.h b/sys-botbase/source/args.h index bf46a9b..b86a56e 100644 --- a/sys-botbase/source/args.h +++ b/sys-botbase/source/args.h @@ -1 +1 @@ -int parseArgs(char* argstr, int (*callback)(int, char**)); \ No newline at end of file +int parseArgs(char* argstr, int (*callback)(int, char**)); diff --git a/sys-botbase/source/commands.c b/sys-botbase/source/commands.c index bf29c47..d92112f 100644 --- a/sys-botbase/source/commands.c +++ b/sys-botbase/source/commands.c @@ -11,21 +11,21 @@ //Controller: bool bControllerIsInitialised = false; HidDeviceType controllerInitializedType = HidDeviceType_FullKey3; -HiddbgHdlsHandle controllerHandle = {0}; -HiddbgHdlsDeviceInfo controllerDevice = {0}; -HiddbgHdlsState controllerState = {0}; +HiddbgHdlsHandle controllerHandle = { 0 }; +HiddbgHdlsDeviceInfo controllerDevice = { 0 }; +HiddbgHdlsState controllerState = { 0 }; //Keyboard: -HiddbgKeyboardAutoPilotState dummyKeyboardState = {0}; +HiddbgKeyboardAutoPilotState dummyKeyboardState = { 0 }; Handle debughandle = 0; u64 buttonClickSleepTime = 50; u64 keyPressSleepTime = 25; u64 pollRate = 17; // polling is linked to screen refresh rate (system UI) or game framerate. Most cases this is 1/60 or 1/30 u32 fingerDiameter = 50; -HiddbgHdlsSessionId sessionId = {0}; -bool initflag=0; -u8 *workmem = NULL; +HiddbgHdlsSessionId sessionId = { 0 }; +bool initflag = 0; +u8* workmem = NULL; size_t workmem_size = 0x1000; void attach() @@ -43,28 +43,29 @@ void attach() printf("svcDebugActiveProcess: %d\n", rc); } -void detach(){ +void detach() { if (debughandle != 0) svcCloseHandle(debughandle); } -u64 getMainNsoBase(u64 pid){ +u64 getMainNsoBase(u64 pid) { LoaderModuleInfo proc_modules[2]; s32 numModules = 0; Result rc = ldrDmntGetProcessModuleInfo(pid, proc_modules, 2, &numModules); if (R_FAILED(rc) && debugResultCodes) printf("ldrDmntGetProcessModuleInfo: %d\n", rc); - LoaderModuleInfo *proc_module = 0; - if(numModules == 2){ + LoaderModuleInfo* proc_module = 0; + if (numModules == 2) { proc_module = &proc_modules[1]; - }else{ + } + else { proc_module = &proc_modules[0]; } return proc_module->base_address; } -u64 getHeapBase(Handle handle){ +u64 getHeapBase(Handle handle) { u64 heap_base = 0; Result rc = svcGetInfo(&heap_base, InfoType_HeapRegionAddress, debughandle, 0); if (R_FAILED(rc) && debugResultCodes) @@ -73,7 +74,7 @@ u64 getHeapBase(Handle handle){ return heap_base; } -u64 getTitleId(u64 pid){ +u64 getTitleId(u64 pid) { u64 titleId = 0; Result rc = pminfoGetProgramId(&titleId, pid); if (R_FAILED(rc) && debugResultCodes) @@ -81,15 +82,15 @@ u64 getTitleId(u64 pid){ return titleId; } -u64 GetTitleVersion(u64 pid){ +u64 GetTitleVersion(u64 pid) { u64 titleV = 0; s32 out; Result rc = nsInitialize(); - if (R_FAILED(rc)) + if (R_FAILED(rc)) fatalThrow(rc); - NsApplicationContentMetaStatus *MetaStatus = malloc(sizeof(NsApplicationContentMetaStatus[100U])); + NsApplicationContentMetaStatus* MetaStatus = malloc(sizeof(NsApplicationContentMetaStatus[100U])); rc = nsListApplicationContentMetaStatus(getTitleId(pid), 0, MetaStatus, 100, &out); if (R_FAILED(rc) && debugResultCodes) printf("nsListApplicationContentMetaStatus: %d\n", rc); @@ -103,7 +104,7 @@ u64 GetTitleVersion(u64 pid){ return (titleV / 0x10000); } -u64 getoutsize(NsApplicationControlData* buf){ +u64 getoutsize(NsApplicationControlData* buf) { Result rc = nsInitialize(); if (R_FAILED(rc)) fatalThrow(rc); @@ -117,32 +118,33 @@ u64 getoutsize(NsApplicationControlData* buf){ nsExit(); return outsize; } -void getBuildID(MetaData* meta, u64 pid){ +void getBuildID(MetaData* meta, u64 pid) { LoaderModuleInfo proc_modules[2]; s32 numModules = 0; Result rc = ldrDmntGetProcessModuleInfo(pid, proc_modules, 2, &numModules); if (R_FAILED(rc) && debugResultCodes) printf("ldrDmntGetProcessModuleInfo: %d\n", rc); - LoaderModuleInfo *proc_module = 0; - if(numModules == 2){ + LoaderModuleInfo* proc_module = 0; + if (numModules == 2) { proc_module = &proc_modules[1]; - }else{ + } + else { proc_module = &proc_modules[0]; } memcpy(meta->buildID, proc_module->build_id, 0x20); } -MetaData getMetaData(){ +MetaData getMetaData() { MetaData meta; attach(); - u64 pid = 0; + u64 pid = 0; Result rc = pmdmntGetApplicationProcessId(&pid); if (R_FAILED(rc) && debugResultCodes) printf("pmdmntGetApplicationProcessId: %d\n", rc); - + meta.main_nso_base = getMainNsoBase(pid); - meta.heap_base = getHeapBase(debughandle); + meta.heap_base = getHeapBase(debughandle); meta.titleID = getTitleId(pid); meta.titleVersion = GetTitleVersion(pid); getBuildID(&meta, pid); @@ -153,7 +155,7 @@ MetaData getMetaData(){ bool getIsProgramOpen(u64 id) { - u64 pid = 0; + u64 pid = 0; Result rc = pmdmntGetProcessId(&pid, id); if (pid == 0 || R_FAILED(rc)) return false; @@ -163,32 +165,32 @@ bool getIsProgramOpen(u64 id) void initController() { - if(bControllerIsInitialised) return; + if (bControllerIsInitialised) return; //taken from switchexamples github Result rc = hiddbgInitialize(); - - //old + + //old //if (R_FAILED(rc) && debugResultCodes) //printf("hiddbgInitialize: %d\n", rc); - - //new - if (R_FAILED(rc) && debugResultCodes) { + + //new + if (R_FAILED(rc) && debugResultCodes) { printf("hiddbgInitialize(): 0x%x\n", rc); } else { workmem = aligned_alloc(0x1000, workmem_size); if (workmem) initflag = 1; else printf("workmem alloc failed\n"); - } - - // Set the controller type to Pro-Controller, and set the npadInterfaceType. + } + + // Set the controller type to Pro-Controller, and set the npadInterfaceType. controllerDevice.deviceType = controllerInitializedType; controllerDevice.npadInterfaceType = HidNpadInterfaceType_Bluetooth; // Set the controller colors. The grip colors are for Pro-Controller on [9.0.0+]. - controllerDevice.singleColorBody = RGBA8_MAXALPHA(255,255,255); - controllerDevice.singleColorButtons = RGBA8_MAXALPHA(0,0,0); - controllerDevice.colorLeftGrip = RGBA8_MAXALPHA(230,255,0); - controllerDevice.colorRightGrip = RGBA8_MAXALPHA(0,40,20); + controllerDevice.singleColorBody = RGBA8_MAXALPHA(255, 255, 255); + controllerDevice.singleColorButtons = RGBA8_MAXALPHA(0, 0, 0); + controllerDevice.colorLeftGrip = RGBA8_MAXALPHA(230, 255, 0); + controllerDevice.colorRightGrip = RGBA8_MAXALPHA(0, 40, 20); // Setup example controller state. controllerState.battery_level = 4; // Set battery charge to full. @@ -219,7 +221,7 @@ void detachController() if (R_FAILED(rc) && debugResultCodes) printf("hiddbgReleaseHdlsWorkBuffer: %d\n", rc); hiddbgExit(); - free(workmem); + free(workmem); bControllerIsInitialised = false; sessionId.id = 0; @@ -234,14 +236,14 @@ void poke(u64 offset, u64 size, u8* val) void writeMem(u64 offset, u64 size, u8* val) { - Result rc = svcWriteDebugProcessMemory(debughandle, val, offset, size); + Result rc = svcWriteDebugProcessMemory(debughandle, val, offset, size); if (R_FAILED(rc) && debugResultCodes) printf("svcWriteDebugProcessMemory: %d\n", rc); } void peek(u64 offset, u64 size) { - u8 *out = malloc(sizeof(u8) * size); + u8* out = malloc(sizeof(u8) * size); attach(); Result rc = readMem(out, offset, size); if (R_FAILED(rc)) @@ -266,7 +268,7 @@ void peekInfinite(u64 offset, u64 size) u64 sizeRemainder = size; u64 totalFetched = 0; u64 i; - u8 *out = malloc(sizeof(u8) * MAX_LINE_LENGTH); + u8* out = malloc(sizeof(u8) * MAX_LINE_LENGTH); attach(); while (sizeRemainder > 0) @@ -298,8 +300,8 @@ void peekMulti(u64* offset, u64* size, u64 count) u64 totalSize = 0; for (int i = 0; i < count; i++) totalSize += size[i]; - - u8 *out = malloc(sizeof(u8) * totalSize); + + u8* out = malloc(sizeof(u8) * totalSize); u64 ofs = 0; attach(); for (int i = 0; i < count; i++) @@ -362,15 +364,15 @@ void setStickState(int side, int dxVal, int dyVal) { initController(); if (side == JOYSTICK_LEFT) - { + { controllerState.analog_stick_l.x = dxVal; - controllerState.analog_stick_l.y = dyVal; - } - else - { - controllerState.analog_stick_r.x = dxVal; - controllerState.analog_stick_r.y = dyVal; - } + controllerState.analog_stick_l.y = dyVal; + } + else + { + controllerState.analog_stick_r.x = dxVal; + controllerState.analog_stick_r.y = dyVal; + } hiddbgSetHdlsState(controllerHandle, &controllerState); } @@ -379,22 +381,22 @@ void reverseArray(u8* arr, int start, int end) int temp; while (start < end) { - temp = arr[start]; + temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; - } -} + } +} -u64 followMainPointer(s64* jumps, size_t count) +u64 followMainPointer(s64* jumps, size_t count) { - u64 offset; + u64 offset; u64 size = sizeof offset; - u8 *out = malloc(size); - MetaData meta = getMetaData(); - - attach(); + u8* out = malloc(size); + MetaData meta = getMetaData(); + + attach(); Result rc = readMem(out, meta.main_nso_base + jumps[0], size); if (R_FAILED(rc)) { @@ -402,11 +404,11 @@ u64 followMainPointer(s64* jumps, size_t count) free(out); return 0; } - offset = *(u64*)out; + offset = *(u64*)out; - int i; + int i; for (i = 1; i < count; ++i) - { + { rc = readMem(out, offset + jumps[i], size); if (R_FAILED(rc)) break; @@ -414,10 +416,10 @@ u64 followMainPointer(s64* jumps, size_t count) // This traversal resulted in an error if (offset == 0) break; - } - detach(); - free(out); - + } + detach(); + free(out); + return offset; } @@ -439,19 +441,19 @@ void touch(HidTouchState* state, u64 sequentialCount, u64 holdTime, bool hold, u break; } - if(hold) // send finger release event + if (hold) // send finger release event { hiddbgSetTouchScreenAutoPilotState(NULL, 0); svcSleepThread(pollRate * 1e+6L); } - + hiddbgUnsetTouchScreenAutoPilotState(); } void key(HiddbgKeyboardAutoPilotState* states, u64 sequentialCount) { initController(); - HiddbgKeyboardAutoPilotState tempState = {0}; + HiddbgKeyboardAutoPilotState tempState = { 0 }; u32 i; for (i = 0; i < sequentialCount; i++) { @@ -460,9 +462,9 @@ void key(HiddbgKeyboardAutoPilotState* states, u64 sequentialCount) hiddbgSetKeyboardAutoPilotState(&tempState); svcSleepThread(keyPressSleepTime * 1e+6L); - if (i != (sequentialCount-1)) + if (i != (sequentialCount - 1)) { - if (memcmp(states[i].keys, states[i+1].keys, sizeof(u64) * 4) == 0 && states[i].modifiers == states[i+1].modifiers) + if (memcmp(states[i].keys, states[i + 1].keys, sizeof(u64) * 4) == 0 && states[i].modifiers == states[i + 1].modifiers) { hiddbgSetKeyboardAutoPilotState(&dummyKeyboardState); svcSleepThread(pollRate * 1e+6L); @@ -487,7 +489,7 @@ void clickSequence(char* seq, u8* token) const char startLStick = '%'; const char startRStick = '&'; char* command = strtok(seq, &delim); - HidNpadButton currKey = {0}; + HidNpadButton currKey = { 0 }; u64 currentWait = 0; initController(); @@ -500,28 +502,28 @@ void clickSequence(char* seq, u8* token) { // l stick s64 x = parseStringToSignedLong(&command[1]); - if(x > JOYSTICK_MAX) x = JOYSTICK_MAX; - if(x < JOYSTICK_MIN) x = JOYSTICK_MIN; + if (x > JOYSTICK_MAX) x = JOYSTICK_MAX; + if (x < JOYSTICK_MIN) x = JOYSTICK_MIN; s64 y = 0; command = strtok(NULL, &delim); if (command != NULL) y = parseStringToSignedLong(command); - if(y > JOYSTICK_MAX) y = JOYSTICK_MAX; - if(y < JOYSTICK_MIN) y = JOYSTICK_MIN; + if (y > JOYSTICK_MAX) y = JOYSTICK_MAX; + if (y < JOYSTICK_MIN) y = JOYSTICK_MIN; setStickState(JOYSTICK_LEFT, (s32)x, (s32)y); } else if (!strncmp(command, &startRStick, 1)) { // r stick s64 x = parseStringToSignedLong(&command[1]); - if(x > JOYSTICK_MAX) x = JOYSTICK_MAX; - if(x < JOYSTICK_MIN) x = JOYSTICK_MIN; + if (x > JOYSTICK_MAX) x = JOYSTICK_MAX; + if (x < JOYSTICK_MIN) x = JOYSTICK_MIN; s64 y = 0; command = strtok(NULL, &delim); if (command != NULL) y = parseStringToSignedLong(command); - if(y > JOYSTICK_MAX) y = JOYSTICK_MAX; - if(y < JOYSTICK_MIN) y = JOYSTICK_MIN; + if (y > JOYSTICK_MAX) y = JOYSTICK_MAX; + if (y < JOYSTICK_MIN) y = JOYSTICK_MIN; setStickState(JOYSTICK_RIGHT, (s32)x, (s32)y); } else if (!strncmp(command, &startPress, 1)) @@ -529,13 +531,13 @@ void clickSequence(char* seq, u8* token) // press currKey = parseStringToButton(&command[1]); press(currKey); - } + } else if (!strncmp(command, &startRelease, 1)) { // release currKey = parseStringToButton(&command[1]); release(currKey); - } + } else if (!strncmp(command, &startWait, 1)) { // wait diff --git a/sys-botbase/source/freeze.c b/sys-botbase/source/freeze.c index 994a5e3..15cb95a 100644 --- a/sys-botbase/source/freeze.c +++ b/sys-botbase/source/freeze.c @@ -12,89 +12,89 @@ FreezeBlock* freezes; void initFreezes(void) { - freezes = calloc(FREEZE_DIC_LENGTH, sizeof(FreezeBlock)); + freezes = calloc(FREEZE_DIC_LENGTH, sizeof(FreezeBlock)); } void freeFreezes(void) { - free(freezes); + free(freezes); } int findAddrSlot(u64 addr) { - for (int i = 0; i < FREEZE_DIC_LENGTH; i++) - { - if (freezes[i].address == addr) - return i; - } - - return -1; + for (int i = 0; i < FREEZE_DIC_LENGTH; i++) + { + if (freezes[i].address == addr) + return i; + } + + return -1; } int findNextEmptySlot() { - return findAddrSlot(0); + return findAddrSlot(0); } int addToFreezeMap(u64 addr, u8* v_data, u64 v_size, u64 tid) { - // update slot if already exists - int slot = findAddrSlot(addr); - if (slot == -1) - slot = findNextEmptySlot(); - else - removeFromFreezeMap(addr); - - if (slot == -1) - return 0; - - freezes[slot].address = addr; - freezes[slot].vData = v_data; - freezes[slot].size = v_size; - freezes[slot].state = 1; - freezes[slot].titleId = tid; - - return slot; + // update slot if already exists + int slot = findAddrSlot(addr); + if (slot == -1) + slot = findNextEmptySlot(); + else + removeFromFreezeMap(addr); + + if (slot == -1) + return 0; + + freezes[slot].address = addr; + freezes[slot].vData = v_data; + freezes[slot].size = v_size; + freezes[slot].state = 1; + freezes[slot].titleId = tid; + + return slot; } int removeFromFreezeMap(u64 addr) { - int slot = findAddrSlot(addr); - if (slot == -1) - return 0; - freezes[slot].address = 0; - freezes[slot].state = 0; - free(freezes[slot].vData); - return slot; + int slot = findAddrSlot(addr); + if (slot == -1) + return 0; + freezes[slot].address = 0; + freezes[slot].state = 0; + free(freezes[slot].vData); + return slot; } int getFreezeCount(bool print) { - int count = 0; - for (int i = 0; i < FREEZE_DIC_LENGTH; i++) - { - if (freezes[i].state != 0) - ++count; - } - if (print) - { - printf("%02X", count); - printf("\n"); - } - return count; + int count = 0; + for (int i = 0; i < FREEZE_DIC_LENGTH; i++) + { + if (freezes[i].state != 0) + ++count; + } + if (print) + { + printf("%02X", count); + printf("\n"); + } + return count; } // returns 0 if there was nothing to clear u8 clearFreezes(void) { - u8 clearedOne = 0; - for (int i = 0; i < FREEZE_DIC_LENGTH; i++) - { - if (freezes[i].state != 0) - { - removeFromFreezeMap(freezes[i].address); - clearedOne = 1; - } - } - return clearedOne; -} \ No newline at end of file + u8 clearedOne = 0; + for (int i = 0; i < FREEZE_DIC_LENGTH; i++) + { + if (freezes[i].state != 0) + { + removeFromFreezeMap(freezes[i].address); + clearedOne = 1; + } + } + return clearedOne; +} diff --git a/sys-botbase/source/freeze.h b/sys-botbase/source/freeze.h index 6344b76..b5ce56e 100644 --- a/sys-botbase/source/freeze.h +++ b/sys-botbase/source/freeze.h @@ -2,11 +2,11 @@ #define FREEZE_DIC_LENGTH 255 typedef struct { - char state; - u64 address; - u8* vData; - u64 size; - u64 titleId; + char state; + u64 address; + u8* vData; + u64 size; + u64 titleId; } FreezeBlock; extern FreezeBlock* freezes; @@ -18,4 +18,4 @@ int findNextEmptySlot(); int addToFreezeMap(u64 addr, u8* v_data, u64 v_size, u64 tid); int removeFromFreezeMap(u64 addr); int getFreezeCount(bool print); -u8 clearFreezes(void); \ No newline at end of file +u8 clearFreezes(void); diff --git a/sys-botbase/source/main.c b/sys-botbase/source/main.c index 2aac48f..ed50b80 100644 --- a/sys-botbase/source/main.c +++ b/sys-botbase/source/main.c @@ -29,20 +29,20 @@ typedef enum { Thread freezeThread, touchThread, keyboardThread, clickThread; // prototype thread functions to give the illusion of cleanliness -void sub_freeze(void *arg); -void sub_touch(void *arg); -void sub_key(void *arg); -void sub_click(void *arg); +void sub_freeze(void* arg); +void sub_touch(void* arg); +void sub_key(void* arg); +void sub_click(void* arg); // locks for thread Mutex freezeMutex, touchMutex, keyMutex, clickMutex; // events for releasing or idling threads -FreezeThreadState freeze_thr_state = Active; +FreezeThreadState freeze_thr_state = Active; u8 clickThreadState = 0; // 1 = break thread // key and touch events currently being processed -KeyData currentKeyEvent = {0}; -TouchData currentTouchEvent = {0}; +KeyData currentKeyEvent = { 0 }; +TouchData currentTouchEvent = { 0 }; char* currentClick = NULL; // for cancelling the touch/click thread @@ -59,13 +59,13 @@ u32 __nx_applet_type = AppletType_None; // we override libnx internals to do a minimal init void __libnx_initheap(void) { - static u8 inner_heap[HEAP_SIZE]; + static u8 inner_heap[HEAP_SIZE]; extern void* fake_heap_start; extern void* fake_heap_end; // Configure the newlib heap. fake_heap_start = inner_heap; - fake_heap_end = inner_heap + sizeof(inner_heap); + fake_heap_end = inner_heap + sizeof(inner_heap); } void __appInit(void) @@ -86,14 +86,14 @@ void __appInit(void) } } rc = pmdmntInitialize(); - if (R_FAILED(rc)) + if (R_FAILED(rc)) fatalThrow(rc); rc = ldrDmntInitialize(); - if (R_FAILED(rc)) - fatalThrow(rc); + if (R_FAILED(rc)) + fatalThrow(rc); rc = pminfoInitialize(); - if (R_FAILED(rc)) - fatalThrow(rc); + if (R_FAILED(rc)) + fatalThrow(rc); rc = socketInitializeDefault(); if (R_FAILED(rc)) fatalThrow(rc); @@ -149,7 +149,7 @@ void makeClickSeq(char* seq) mutexUnlock(&clickMutex); } -int argmain(int argc, char **argv) +int argmain(int argc, char** argv) { if (argc == 0) return 0; @@ -158,7 +158,7 @@ int argmain(int argc, char **argv) //peek
if (!strcmp(argv[0], "peek")) { - if(argc != 3) + if (argc != 3) return 0; MetaData meta = getMetaData(); @@ -170,26 +170,26 @@ int argmain(int argc, char **argv) if (!strcmp(argv[0], "peekMulti")) { - if(argc < 3 || argc % 2 == 0) + if (argc < 3 || argc % 2 == 0) return 0; MetaData meta = getMetaData(); - u64 itemCount = (argc - 1)/2; + u64 itemCount = (argc - 1) / 2; u64 offsets[itemCount]; u64 sizes[itemCount]; for (int i = 0; i < itemCount; ++i) { - offsets[i] = meta.heap_base + parseStringToInt(argv[(i*2)+1]); - sizes[i] = parseStringToInt(argv[(i*2)+2]); + offsets[i] = meta.heap_base + parseStringToInt(argv[(i * 2) + 1]); + sizes[i] = parseStringToInt(argv[(i * 2) + 2]); } peekMulti(offsets, sizes, itemCount); } if (!strcmp(argv[0], "peekAbsolute")) { - if(argc != 3) + if (argc != 3) return 0; u64 offset = parseStringToInt(argv[1]); @@ -199,24 +199,24 @@ int argmain(int argc, char **argv) if (!strcmp(argv[0], "peekAbsoluteMulti")) { - if(argc < 3 || argc % 2 == 0) + if (argc < 3 || argc % 2 == 0) return 0; - u64 itemCount = (argc - 1)/2; + u64 itemCount = (argc - 1) / 2; u64 offsets[itemCount]; u64 sizes[itemCount]; for (int i = 0; i < itemCount; ++i) { - offsets[i] = parseStringToInt(argv[(i*2)+1]); - sizes[i] = parseStringToInt(argv[(i*2)+2]); + offsets[i] = parseStringToInt(argv[(i * 2) + 1]); + sizes[i] = parseStringToInt(argv[(i * 2) + 2]); } peekMulti(offsets, sizes, itemCount); } if (!strcmp(argv[0], "peekMain")) { - if(argc != 3) + if (argc != 3) return 0; MetaData meta = getMetaData(); @@ -228,19 +228,19 @@ int argmain(int argc, char **argv) if (!strcmp(argv[0], "peekMainMulti")) { - if(argc < 3 || argc % 2 == 0) + if (argc < 3 || argc % 2 == 0) return 0; MetaData meta = getMetaData(); - u64 itemCount = (argc - 1)/2; + u64 itemCount = (argc - 1) / 2; u64 offsets[itemCount]; u64 sizes[itemCount]; for (int i = 0; i < itemCount; ++i) { - offsets[i] = meta.main_nso_base + parseStringToInt(argv[(i*2)+1]); - sizes[i] = parseStringToInt(argv[(i*2)+2]); + offsets[i] = meta.main_nso_base + parseStringToInt(argv[(i * 2) + 1]); + sizes[i] = parseStringToInt(argv[(i * 2) + 2]); } peekMulti(offsets, sizes, itemCount); } @@ -248,9 +248,9 @@ int argmain(int argc, char **argv) //poke
if (!strcmp(argv[0], "poke")) { - if(argc != 3) + if (argc != 3) return 0; - + MetaData meta = getMetaData(); u64 offset = parseStringToInt(argv[1]); @@ -258,11 +258,11 @@ int argmain(int argc, char **argv) u8* data = parseStringToByteBuffer(argv[2], &size); poke(meta.heap_base + offset, size, data); free(data); - } - + } + if (!strcmp(argv[0], "pokeAbsolute")) { - if(argc != 3) + if (argc != 3) return 0; u64 offset = parseStringToInt(argv[1]); @@ -271,12 +271,12 @@ int argmain(int argc, char **argv) poke(offset, size, data); free(data); } - + if (!strcmp(argv[0], "pokeMain")) { - if(argc != 3) + if (argc != 3) return 0; - + MetaData meta = getMetaData(); u64 offset = parseStringToInt(argv[1]); @@ -284,12 +284,12 @@ int argmain(int argc, char **argv) u8* data = parseStringToByteBuffer(argv[2], &size); poke(meta.main_nso_base + offset, size, data); free(data); - } + } //click if (!strcmp(argv[0], "click")) { - if(argc != 2) + if (argc != 2) return 0; HidNpadButton key = parseStringToButton(argv[1]); click(key); @@ -299,9 +299,9 @@ int argmain(int argc, char **argv) //syntax: