diff --git a/server/source/noexs/.vscode/settings.json b/server/source/noexs/.vscode/settings.json index 1507357..9be9b27 100644 --- a/server/source/noexs/.vscode/settings.json +++ b/server/source/noexs/.vscode/settings.json @@ -1,5 +1,12 @@ { "files.associations": { - "functional": "cpp" + "functional": "cpp", + "*.tcc": "cpp", + "deque": "cpp", + "list": "cpp", + "string": "cpp", + "vector": "cpp", + "system_error": "cpp", + "array": "cpp" } } \ No newline at end of file diff --git a/server/source/noexs/054e4f4558454000.zip b/server/source/noexs/054e4f4558454000.zip index 5c50043..22432cc 100644 Binary files a/server/source/noexs/054e4f4558454000.zip and b/server/source/noexs/054e4f4558454000.zip differ diff --git a/server/source/noexs/054e4f4558454000/exefs.nsp b/server/source/noexs/054e4f4558454000/exefs.nsp index dc1b58d..824ca2f 100644 Binary files a/server/source/noexs/054e4f4558454000/exefs.nsp and b/server/source/noexs/054e4f4558454000/exefs.nsp differ diff --git a/server/source/noexs/exefs.nsp b/server/source/noexs/exefs.nsp index f4d8b78..824ca2f 100644 Binary files a/server/source/noexs/exefs.nsp and b/server/source/noexs/exefs.nsp differ diff --git a/server/source/noexs/go.bat b/server/source/noexs/go.bat new file mode 100644 index 0000000..8df3409 --- /dev/null +++ b/server/source/noexs/go.bat @@ -0,0 +1 @@ +copy noexs.nsp exefs.nsp diff --git a/server/source/noexs/include/debug.h b/server/source/noexs/include/debug.h index f98d6a4..6c87abb 100644 --- a/server/source/noexs/include/debug.h +++ b/server/source/noexs/include/debug.h @@ -64,6 +64,7 @@ namespace Gecko{ void addEventCallback(std::function callback); u64 attachedPid(); Result attach(u64 pid); + Result assign(u64 pid); Result attached(); Result detatch(); diff --git a/server/source/noexs/include/dmntcht.c b/server/source/noexs/include/dmntcht.c index 4318343..434a8ae 100644 --- a/server/source/noexs/include/dmntcht.c +++ b/server/source/noexs/include/dmntcht.c @@ -14,7 +14,7 @@ * along with this program. If not, see . */ #define NX_SERVICE_ASSUME_NON_DOMAIN -#include "../service_guard.h" +#include "service_guard.h" #include "dmntcht.h" static Service g_dmntchtSrv; diff --git a/server/source/noexs/noexs.nso b/server/source/noexs/noexs.nso index 3e4c229..3080910 100644 Binary files a/server/source/noexs/noexs.nso and b/server/source/noexs/noexs.nso differ diff --git a/server/source/noexs/noexs.nsp b/server/source/noexs/noexs.nsp new file mode 100644 index 0000000..ff14556 Binary files /dev/null and b/server/source/noexs/noexs.nsp differ diff --git a/server/source/noexs/source/commands.cpp b/server/source/noexs/source/commands.cpp index 549eab9..15bf30a 100644 --- a/server/source/noexs/source/commands.cpp +++ b/server/source/noexs/source/commands.cpp @@ -1,3 +1,4 @@ +#include #include "gecko.h" #include "errors.h" #include "dmntcht.h" @@ -189,19 +190,34 @@ static Result _attach(Gecko::Context& ctx){ READ_CHECKED(ctx, pid); Result rc = ctx.dbg.attach(pid); if(R_SUCCEEDED(rc)){ + dmnt = false; ctx.status = Gecko::Status::Paused; } else { - dmnt = true; - dmntchtInitialize(); - rc = dmntchtPauseCheatProcess(); - ctx.status = Gecko::Status::Paused; + if (ctx.dbg.attached()) { + dmntchtInitialize(); + DmntCheatProcessMetadata cht; + dmntchtGetCheatProcessMetadata(&cht); + if (cht.process_id == pid) { + rc = dmntchtPauseCheatProcess(); + if(R_SUCCEEDED(rc)){ + ctx.dbg.assign(pid); + dmnt = true; + ctx.status = Gecko::Status::Paused; + } + } + else { + dmntchtExit(); + } + } } return rc; } //0x0B static Result _detatch(Gecko::Context& ctx){ - Result rc = ctx.dbg.detatch(); + Result rc; + if (dmnt) {rc = dmntchtResumeCheatProcess(); dmntchtExit(); dmnt = false; ctx.dbg.assign(0);} + else rc = ctx.dbg.detatch(); if(R_SUCCEEDED(rc)){ ctx.status = Gecko::Status::Running; } @@ -388,11 +404,80 @@ static Result _detach_dmnt(Gecko::Context& ctx){ return ctx.dbg.setBreakpoint(id, flags, addr); } +static u64 m_heap_start, m_heap_end, m_main_start, m_main_end; +static Result getmeminfo(Gecko::Context& ctx) { + Result rc = 0; + u64 addr; + u32 requestCount; + u32 count = 0; + MemoryInfo info = {}; + addr = 0; + requestCount = 10000; + m_heap_start = 0; + m_main_start = 0; + u32 mod = 0; + for(count = 0; count < requestCount; count++){ + if (dmnt) rc = dmntchtQueryCheatProcessMemory(&info, addr); + else rc =ctx.dbg.query(&info, addr); + if (info.type == MemType_Heap){ + if (m_heap_start == 0) m_heap_start = info.addr; + m_heap_end = info.addr + info.size; + } + if (info.type == MemType_CodeStatic){ + if (mod == 1) m_main_start = info.addr; + mod += 1; + } + if (info.type == MemType_CodeMutable){ + if (mod ==1 ) m_main_end = info.addr + info.size; + } + if(info.type == 0x10 || R_FAILED(rc)){ + break; + } + addr += info.size; + } + return rc; +} + +//0x19 +static Result _dump_ptr(Gecko::Context& ctx){ + getmeminfo(ctx); + Result rc = 0; + u64 addr; + u32 requestCount; + u32 count = 0; + MemoryInfo info = {}; + addr = 0; + requestCount = 10000; + m_heap_start = 0; + m_main_start = 0; + u32 mod = 0; + for(count = 0; count < requestCount; count++){ + if (dmnt) rc = dmntchtQueryCheatProcessMemory(&info, addr); + else rc =ctx.dbg.query(&info, addr); + if (info.type == MemType_Heap){ + if (m_heap_start == 0) m_heap_start = info.addr; + m_heap_end = info.addr + info.size; + } + if (info.type == MemType_CodeStatic){ + if (mod == 1) m_main_start = info.addr; + mod += 1; + } + if (info.type == MemType_CodeMutable){ + if (mod ==1 ) m_main_end = info.addr + info.size; + } + if(info.type == 0x10 || R_FAILED(rc)){ + break; + } + addr += info.size; + } + return rc; +} + Result cmd_decode(Gecko::Context& ctx, int cmd){ static Result (*cmds[255])(Gecko::Context&) = {NULL, _status, _poke8, _poke16, _poke32, _poke64, _readmem, _writemem, _resume, _pause, _attach, _detatch, _querymem_single, _querymem_multi, _current_pid, _attached_pid, _list_pids, - _get_titleid, _disconnect, _readmem_multi, _set_breakpoint, _freeze_address, _search_local, _fetch_result, _detach_dmnt}; + _get_titleid, _disconnect, _readmem_multi, _set_breakpoint, _freeze_address, _search_local, _fetch_result, _detach_dmnt, _dump_ptr}; Result rc = 0; if(cmds[cmd]){ rc = cmds[cmd](ctx); diff --git a/server/source/noexs/source/debug.cpp b/server/source/noexs/source/debug.cpp index 734fe0a..8225b51 100644 --- a/server/source/noexs/source/debug.cpp +++ b/server/source/noexs/source/debug.cpp @@ -51,6 +51,13 @@ Result Gecko::Debugger::attach(u64 pid){ {handle = 0; pid =0;} return rc; } +//fake attached and detatch +Result Gecko::Debugger::assign(u64 pid){ + Result rc = 0; + handle = pid; + this->pid = pid; + return rc; +} Result Gecko::Debugger::attached(){ if(!handle){ diff --git a/server/source/noexs/source/main.cpp b/server/source/noexs/source/main.cpp index 9f729de..fc29548 100644 --- a/server/source/noexs/source/main.cpp +++ b/server/source/noexs/source/main.cpp @@ -132,8 +132,7 @@ static Result _eventCallback(Gecko::DebugEvent event){ int main(int argc, char **argv) { - g_debugFile = fopen("/switch/EdiZon/Log.txt", "w"); - printf("testing\n"); + // g_debugFile = fopen("/atmosphere/contents/054e4f4558454000/Log.txt", "w"); g_Context.dbg.addEventCallback(_eventCallback); while(appletMainLoop() && !g_Context.exit){