signals - Can I send a ctrl-C (SIGINT) to an application on Windows? -
i have (in past) written cross-platform (windows/unix) applications which, when started command line, handled user-typed ctrl-c combination in same way (i.e. terminate application cleanly).
is possible on windows send ctrl-c/sigint/equivalent process (unrelated) process request terminate cleanly (giving opportunity tidy resources etc.)?
the closest i've come solution sendsignal 3rd party app. author lists source code , executable. i've verified works under 64-bit windows (running 32-bit program, killing 32-bit program), i've not figured out how embed code windows program (either 32-bit or 64-bit).
how works:
after digging around in debugger discovered entry point behavior associated signal ctrl-break kernel32!ctrlroutine. function had same prototype threadproc, can used createremotethread directly, without having inject code. however, that's not exported symbol! it's @ different addresses (and has different names) on different versions of windows. do?
here solution came with. install console ctrl handler app, generate ctrl-break signal app. when handler gets called, @ top of stack find out parameters passed kernel32!basethreadstart. grab first param, desired start address of thread, address of kernel32!ctrlroutine. return handler, indicating have handled signal , app should not terminated. in main thread, wait until address of kernel32!ctrlroutine has been retrieved. once i've got it, create remote thread in target process discovered start address. causes ctrl handlers in target process evaluated if ctrl-break had been pressed!
the nice thing target process affected, , process (even windowed process) can targeted. 1 downside little app can't used in batch file, since kill when sends ctrl-break event in order discover address of kernel32!ctrlroutine.
(precede start
if running in batch file.)
Comments
Post a Comment