Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In an attempt to inject a DLL into a process before it calls a specific method, I am trying to suspend a process while it is being created.

Alternatively I am trying to do a system wide hook of CreateFile, located in kernel32.dll. If that is possible it would be even better since that was the end result intended.


Old Questioin: I am looking to suspend a process as soon as it is created but before it is started. But I don't want to have to launch the process suspended manually.

I want to be able to double click any .exe, and if it has a specific process name(Or if it's metadata matches), I want to be able to suspend it before it starts.

I looked at "Hooking the native API and controlling process creation on a system-wide basis", but it doesn't seem to work on my system, Windows 7 x64... I am terrible at C and I was hoping for a C# alternative? I don't even know if that is possible...

And a side question. If I self sign my program, will an antivirus be set off by a driver and DLL injection? (This is not for malicious intent, see here for more information.) I am only worried about self signing and AV because most users freak out about that type of thing.
Posted
Updated 13-Nov-11 9:38am
v5

Pretty sure as described that is impossible.

"Suspend" only applies to a process that is running. If it hasn't started then it can't be running.
 
Share this answer
 
Comments
KairuByte 9-Nov-11 17:44pm    
You can create a process in suspended state. Hooking specific methods could potentially force any file to start in a suspended state, I just have no clue what methods.

Not impossible, just difficult.
You can create a process in suspended using the api CreateProcess with CREATE_SUSPENDED flag in dwCreationFlags parameter. This is the link of the CreateProcess documentation link http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx and after your injection is done you can resume the thread for the application to load properly with the function hooked. However, when you create a process this way, not all the dlls are loaded except the ntdll.dll and your hooking engine might fail. In that case you have to monitor the process and when the required dlls are loaded you can suspend it, hook the methods and resume the threads.To monitor the process, you have two options, periodically theck the loaded modules or use a driver to get notification of modules loaded for a process.
 
Share this answer
 
Comments
KairuByte 7-Sep-13 12:00pm    
While this isn't exactly what I was trying to do, driver did turn out to be one of the only real solutions at the time.

I wasn't trying to create the process suspended however, I was trying to hook into the systems creation processes themselves so if a user creates a process with a specific name I can start it suspended, hook it, and then let it continue.
Ashraf Hussain Chowdhury 15-Oct-13 2:03am    
In that case, driver is the only solution for getting process creation callback. You can use PsSetCreateProcessNotifyRoutine inside the driver to get a callback on process creation and send it to usermode application which listens to this event. There is a sample on CP by the name procObsrv or something, you can have a look, PsSetCreateProcessNotifyRoutine gives you the thread id, so you can suspend the thread, do your injection and then resume the thread in the usermode. I hope i could help you out a little bit on this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900