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>
This commit is contained in:
kyoubate-haruka
2026-07-16 10:37:49 +00:00
committed by Dniel97
parent a3443a8b5b
commit afece371fb
+7 -1
View File
@@ -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)