Hooking process creation/destruction not capturing all processes #21
Open
Description
I have downloaded and compiled Deviare from source.
Windows 7 x64 SP1
Python 2.7.9 Stackless 32bit
pywin32 220
when running the following code not all process creation/destruction notifications show. There are specific process that i am looking for that happen very quickly and some of them are getting passed by. I have tested this in many different ways. but in this example I am using threading.Event() to stall the process creation. but it seems to be the "sweet spot" 0.728 seconds. with 4 creation and 4 destruction notifications out of 10 processes created and destroyed.
please excuse the code this is for testing purposes and wasn't meant to be pretty
import os
import win32com.client
import ctypes
import sys
import threading
dllPath = os.path.join(os.path.split(__file__)[0], 'DeviareCOM.dll')
dll = ctypes.windll[dllPath]
dll.DllRegisterServer()
class ProcessEvents:
def OnProcessStarted(self, pyPID):
process = win32com.client.Dispatch(pyPID)
name = process.Name.split('.')[0]
pid = process.Id
user = process.UserName
print 'OnProcessStarted:', name, pid, user
def OnProcessTerminated(self, pyPID):
process = win32com.client.Dispatch(pyPID)
name = process.Name.split('.')[0]
pid = process.Id
user = process.UserName
print 'OnProcessTerminated:', name, pid, user
win32com.client.pythoncom.CoInitialize()
processManager = win32com.client.DispatchWithEvents("DeviareCOM.NktSpyMgr", ProcessEvents)
processManager.Initialize()
hook = processManager.CreateHook("kernel32.dll!CreateProcess", 0)
hook.Hook(True)
event = threading.Event()
event.set()
def run():
while event.isSet():
pass
for i in range(10):
os.system("cmd /c echo Test")
event.wait(0.0728)
threading.Thread(target=run).start()
MessageBox = ctypes.windll.user32.MessageBoxW
event.clear()
MessageBox(None, "", "", 0)
I am not sure if this is normal behavior please advise
Metadata
Assignees
Labels
No labels