From 1ae01c2406cf195181d5dff5545be9657a091328 Mon Sep 17 00:00:00 2001 From: Nanquitas Date: Thu, 15 Nov 2018 13:44:45 +0100 Subject: [PATCH] GDB: add 'catchsvc' command to catch svc with IDA Usage: - 'catchsvc 0' : Don't catch svcs - 'catchsvc 1' : Catch all svcs - 'catchsvc 1;19;24;32;' : Only catch svc 0x19, svc 0x24 and svc 0x32 --- .../rosalina/include/gdb/remote_command.h | 1 + .../rosalina/source/gdb/remote_command.c | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/sysmodules/rosalina/include/gdb/remote_command.h b/sysmodules/rosalina/include/gdb/remote_command.h index 7eb2cf7..f7f01c3 100644 --- a/sysmodules/rosalina/include/gdb/remote_command.h +++ b/sysmodules/rosalina/include/gdb/remote_command.h @@ -39,5 +39,6 @@ GDB_DECLARE_REMOTE_COMMAND_HANDLER(GetMmuConfig); GDB_DECLARE_REMOTE_COMMAND_HANDLER(GetMemRegions); GDB_DECLARE_REMOTE_COMMAND_HANDLER(FlushCaches); GDB_DECLARE_REMOTE_COMMAND_HANDLER(ToggleExternalMemoryAccess); +GDB_DECLARE_REMOTE_COMMAND_HANDLER(CatchSvc); GDB_DECLARE_QUERY_HANDLER(Rcmd); diff --git a/sysmodules/rosalina/source/gdb/remote_command.c b/sysmodules/rosalina/source/gdb/remote_command.c index 64adc1b..621941e 100644 --- a/sysmodules/rosalina/source/gdb/remote_command.c +++ b/sysmodules/rosalina/source/gdb/remote_command.c @@ -45,6 +45,7 @@ struct { "getmemregions" , GDB_REMOTE_COMMAND_HANDLER(GetMemRegions) }, { "flushcaches" , GDB_REMOTE_COMMAND_HANDLER(FlushCaches) }, { "toggleextmemaccess", GDB_REMOTE_COMMAND_HANDLER(ToggleExternalMemoryAccess) }, + { "catchsvc" , GDB_REMOTE_COMMAND_HANDLER(CatchSvc) }, }; static const char *GDB_SkipSpaces(const char *pos) @@ -478,6 +479,41 @@ GDB_DECLARE_REMOTE_COMMAND_HANDLER(ToggleExternalMemoryAccess) return GDB_SendHexPacket(ctx, outbuf, n); } +GDB_DECLARE_REMOTE_COMMAND_HANDLER(CatchSvc) +{ + if(ctx->commandData[0] == '0') + { + memset(ctx->svcMask, 0, 32); + return R_SUCCEEDED(svcKernelSetState(0x10002, ctx->pid, false)) ? GDB_ReplyOk(ctx) : GDB_ReplyErrno(ctx, EPERM); + } + else if(ctx->commandData[0] == '1') + { + if(ctx->commandData[1] == ';') + { + u32 id; + const char *pos = ctx->commandData + 1; + memset(ctx->svcMask, 0, 32); + + do + { + pos = GDB_ParseHexIntegerList(&id, pos + 1, 1, ';'); + if(pos == NULL) + return GDB_ReplyErrno(ctx, EILSEQ); + + if(id < 0xFE) + ctx->svcMask[id / 32] |= 1 << (31 - (id % 32)); + } + while(*pos != 0); + } + else + memset(ctx->svcMask, 0xFF, 32); + + return R_SUCCEEDED(svcKernelSetState(0x10002, ctx->pid, true, ctx->svcMask)) ? GDB_ReplyOk(ctx) : GDB_ReplyErrno(ctx, EPERM); + } + else + return GDB_ReplyErrno(ctx, EILSEQ); +} + GDB_DECLARE_QUERY_HANDLER(Rcmd) { char commandData[GDB_BUF_LEN / 2 + 1];