Page 1 of 1

Determine own file from being closed

PostPosted: Thu Aug 26, 2010 3:09 pm
by ira
I am trying to prevent my program from being closed. So, I hooks TerminateProcess etc.

DLL:
if myprogram then
dontkill
else
goahead

What is the best way to check "myprogram" is really my program?
File name? :(
Hash?? It can make system slower if the file size is big..
Any idea?

Re: Determine own file from being closed

PostPosted: Mon Nov 22, 2010 3:09 pm
by madshi
Why is this in "fun talk"?

Anyway, this is a difficult question to answer because there's a lot of information missing. My first suggestion would be this:

(1) In your application, before injecting the hook dll, create a global file mapping (see "CreateGlobalFileMapping") and write your process ID into it.
(2) In your hook dll's initialization, open the global file mapping.
(3) In your TerminateProcess etc callback, check if the target process has the same process ID as your own process.