From e299571f94efa02b503c83bfecff43b5e11fe1ca Mon Sep 17 00:00:00 2001 From: OpenSourcereR-dev <45182707+OpenSourcereR-dev@users.noreply.github.com> Date: Sat, 16 May 2026 00:40:27 +0700 Subject: [PATCH] v1.2.3: reduce ucred elevation churn around debug events - dispatch_debug_events: drop the function-wide elev_save_and_set wrapping; macro DDE_RETURN simplified to return (v). - debug_attach_handle: release elevation before wait4 + resume_app, re-acquire only for PT_CONTINUE. - debug_full_teardown / debug_set_watchpoint_handle: use new resume_app_unelev helper so the libk LNC notification fires outside the elevated cred window. - common/include/version.h: single source of truth for the brand/version strings used in meta.c (handle_branding) and main.c (loaded_msg). --- PROTOCOL.md | 4 ++-- README.md | 2 +- common/include/version.h | 6 ++++++ debugger/source/debug.c | 33 ++++++++++++++++++++------------- debugger/source/main.c | 3 ++- debugger/source/meta.c | 3 ++- 6 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 common/include/version.h diff --git a/PROTOCOL.md b/PROTOCOL.md index 3ee38a1..369b680 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -14,7 +14,7 @@ file:line citations. Nothing is summarized from external documentation. | Symbol | Value | Source | |---------------------|--------------------------------------|----------------------------| | `PACKET_VERSION` | `"1.3"` | protocol.h:11 | -| `PACKET_BRANDING` | `"ps5debug-NG by OSR v1.2.2"` | meta.c (`handle_branding`) | +| `PACKET_BRANDING` | `"ps5debug-NG by OSR v1.2.3"` | meta.c (`handle_branding`) | | `PACKET_MAGIC` | `0xFFAABBCC` | protocol.h:13 | | `BROADCAST_MAGIC` | `0xFFFFAAAA` | server.h:19 | @@ -830,7 +830,7 @@ Documented here so a developer doesn't mistake them for bugs: --- -*This document reflects the `ps5debug-NG v1.2.2` payload (see +*This document reflects the `ps5debug-NG v1.2.3` payload (see `debugger/source/meta.c:27`). Citations elsewhere may point at line numbers that drift as the source evolves - when in doubt, the source under `common/include/protocol.h`, `debugger/source/`, and `installer/source/` is diff --git a/README.md b/README.md index e886819..8ad6b85 100644 --- a/README.md +++ b/README.md @@ -266,7 +266,7 @@ elfldr from etaHEN-class loaders). You should see a system notification confirming the payload is alive: ``` -ps5debug-NG by OSR v1.2.2 loaded! +ps5debug-NG by OSR v1.2.3 loaded! Coded by OpenSourcereR Special thanks to golden, Ctn & SiSTRo! ♥ diff --git a/common/include/version.h b/common/include/version.h new file mode 100644 index 0000000..120aeaf --- /dev/null +++ b/common/include/version.h @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0-only + +#pragma once + +#define PS5DEBUG_NG_VERSION_STR "1.2.3" +#define PS5DEBUG_NG_BRAND_STR "ps5debug-NG by OSR v" PS5DEBUG_NG_VERSION_STR diff --git a/debugger/source/debug.c b/debugger/source/debug.c index dd1ccb6..8186d7b 100644 --- a/debugger/source/debug.c +++ b/debugger/source/debug.c @@ -51,6 +51,13 @@ static int resume_app_via_self_id(int pid) { return sceApplicationContinue(app_id); } +static inline void resume_app_unelev(struct elev_state *es, int pid) { + int was_valid = es->valid; + if (was_valid) elev_restore(es); + resume_app_via_self_id(pid); + if (was_valid) (void)elev_save_and_set(es); +} + extern bool fw_uses_kernel_dbreg_path(void); extern bool is_process_stopped(int pid); extern bool kern_thread_step_walker(int pid); @@ -289,12 +296,12 @@ void debug_full_teardown(void *svc) { count = rc; lwpids = (int *)net_alloc_buffer((unsigned long)(count * 4)); if (!lwpids) { - resume_app_via_self_id(pid); + resume_app_unelev(&es, pid); ptrace_raw(PT_CONTINUE, pid, (void *)1, 0); goto close_socket_and_unlock; } if (ptrace_raw(PT_GETLWPLIST, pid, lwpids, count) == -1) { - resume_app_via_self_id(pid); + resume_app_unelev(&es, pid); ptrace_raw(PT_CONTINUE, pid, (void *)1, 0); goto close_socket_and_unlock; } @@ -329,7 +336,7 @@ void debug_full_teardown(void *svc) { free_and_detach: if (lwpids) free(lwpids); if (we_stopped) { - resume_app_via_self_id(pid); + resume_app_unelev(&es, pid); } ptrace_raw(PT_DETACH, pid, NULL, 0); @@ -428,6 +435,8 @@ int debug_attach_handle(int fd, struct cmd_packet *packet) { return 1; } + elev_restore(&es); + int wait_status = 0; *__error() = 0; long wait_rc = __crt_syscall(7 , ap->pid, &wait_status, 0, 0); @@ -436,6 +445,11 @@ int debug_attach_handle(int fd, struct cmd_packet *packet) { } resume_app_via_self_id(ap->pid); + + if (elev_save_and_set(&es) != 0) { + net_send_int32(fd, CMD_ERROR); + return 1; + } if (ptrace_raw(PT_CONTINUE, ap->pid, (void *)1, 0) != 0) { elev_restore(&es); net_send_int32(fd, CMD_ERROR); @@ -597,7 +611,7 @@ int debug_set_watchpoint_handle(int fd, struct cmd_packet *packet) { } if (we_stopped) { - resume_app_via_self_id(pid); + resume_app_unelev(&es, pid); ptrace_raw(PT_CONTINUE, pid, (void *)1, 0); } net_send_int32(fd, CMD_SUCCESS); @@ -606,7 +620,7 @@ int debug_set_watchpoint_handle(int fd, struct cmd_packet *packet) { goto wp_done; wp_resume_and_err: - resume_app_via_self_id(pid); + resume_app_unelev(&es, pid); ptrace_raw(PT_CONTINUE, pid, (void *)1, 0); wp_err_no_resume: net_send_int32(fd, CMD_ERROR); @@ -970,11 +984,7 @@ static void debug_handle_breakpoint_resume(void) { static uint32_t g_last_alive_check = 0; int dispatch_debug_events(void) { - - struct elev_state es; - if (elev_save_and_set(&es) != 0) return 1; - int rc = 0; - #define DDE_RETURN(v) do { rc = (v); goto dde_done; } while (0) + #define DDE_RETURN(v) return (v) debug_handle_breakpoint_resume(); @@ -1221,10 +1231,7 @@ int dispatch_debug_events(void) { resume_app_via_self_id((int)DBGCTX()->pid); DDE_RETURN(0); -dde_done: - elev_restore(&es); #undef DDE_RETURN - return rc; } int debug_handle(int fd, struct cmd_packet *packet) { diff --git a/debugger/source/main.c b/debugger/source/main.c index a660661..275ac9e 100644 --- a/debugger/source/main.c +++ b/debugger/source/main.c @@ -3,6 +3,7 @@ #include "protocol.h" #include "sdk_shim.h" #include "net.h" +#include "version.h" extern int cmd_handler(int fd, struct cmd_packet *packet, unsigned char client_idx); extern void print_ascii_banner(void); @@ -300,7 +301,7 @@ teardown: static void debugger_server_loop(void) { static const char disconnect_msg[] = "ps5debug-NG disconnected."; - static const char loaded_msg[] = "ps5debug-NG by OSR v1.2.2 loaded!\n" + static const char loaded_msg[] = PS5DEBUG_NG_BRAND_STR " loaded!\n" "Coded by OpenSourcereR\n" "Special thanks to\n" "golden, Ctn & SiSTRo! \xE2\x9D\xA4\n"; diff --git a/debugger/source/meta.c b/debugger/source/meta.c index 54f3ca7..a7850e4 100644 --- a/debugger/source/meta.c +++ b/debugger/source/meta.c @@ -5,6 +5,7 @@ #include "net.h" #include "proc.h" #include "debug_state.h" +#include "version.h" extern int kern_handle(int fd, struct cmd_packet *packet); extern int console_handle(int fd, struct cmd_packet *packet); @@ -24,7 +25,7 @@ int handle_version(int fd, struct cmd_packet *packet) { int handle_branding(int fd, struct cmd_packet *packet) { (void)packet; - char brand[] = "ps5debug-NG by OSR v1.2.2"; + char brand[] = PS5DEBUG_NG_BRAND_STR; uint32_t len = (uint32_t)(sizeof(brand) - 1); net_send_all(fd, &len, sizeof(uint32_t)); net_send_all(fd, brand, (int)len);