From afece371fb046cf9c540512663c02fa77242d12c Mon Sep 17 00:00:00 2001 From: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> Date: Thu, 16 Jul 2026 10:37:49 +0000 Subject: [PATCH] Make inject return the injected program's exit code (#8) This adds that if a process has ran successfully with inject, the exit code from the child process is returned, instead of always success. Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/capnhook/pulls/8 Co-authored-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> Co-committed-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> --- inject/main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/inject/main.c b/inject/main.c index a5295ad..af102b2 100644 --- a/inject/main.c +++ b/inject/main.c @@ -21,6 +21,7 @@ int main(int argc, char **argv) STARTUPINFO si; HRESULT hr; BOOL ok; + DWORD exitCode; hr = options_init(&opt, argc, argv); @@ -102,11 +103,16 @@ int main(int argc, char **argv) } end: + + exitCode = ERROR_SUCCESS; + if (pi.hProcess != NULL) { if (FAILED(hr)) { TerminateProcess(pi.hProcess, EXIT_FAILURE); } + GetExitCodeProcess(pi.hProcess, &exitCode); + CloseHandle(pi.hProcess); } @@ -116,7 +122,7 @@ end: free(cmdline); - return FAILED(hr) ? EXIT_FAILURE : EXIT_SUCCESS; + return FAILED(hr) ? EXIT_FAILURE : exitCode; } static HRESULT inject_dll(HANDLE process, const char *dll_name)