Can't seem to handle crash when using COM
doria90 opened this issue · 5 comments
Hi all,
I'm building my own fuzzer and I'm using winappdbg alongside COM functionalities to make it all work.
the code works something like that:
`
while not q.empty():
launchWord(wordFile, refFile, q)
def launchWord(wordFile, refFile, queue):
fail_count = 0
word = win32com.client.DispatchEx("word.Application")
cmd = ["WINWORD.EXE", fileArgument]
debug = Debug(AccessViolationHandlerWINAPPDBG, bKillOnExit = True )
proc = debug.execv(cmd)
debug.loop()
while (fail_count < 10 and fail_count >= 0):
try:
if (word.Selection.Fields.Update() == 0): #update document fields
queue.task_done()
except:
fail_count += 1
def AccessViolationHandlerWINAPPDBG(event):
code = event.get_event_code()
print event
if event.get_event_code() == win32.EXCEPTION_DEBUG_EVENT and event.is_last_chance():
print 'Crash detected'
`
Basically it executes Word with a given file and update it's fields via COM Fields.Update() method.
Everything works fine, printing every event that happens, but fails to handle the crash.
I first thought that it had something to do with the COM operations but now I'm not so sure..
I simply want it to detect the Word crash and act accordingly.
Any ideas?
I don't quite understand this code... debug.loop() should never return until the process dies, how does it get to execute the COM stuff that comes later on?
I'm not that sure either, but it does..
As I wrote, I suspect the COM business is messing with it and so I went to seek professional advice.
One thing I did notice is that the COM update will only work if the DispatchEx is called prior to the process launch, so maybe this has something to do with it..
What do you think?
I suspect the debugger and the COM stuff should be run in separate threads, but to be honest I never played with COM stuff in Python.
No worries! Let me know if it worked :)