mirror of
https://github.com/vivisect/vivisect
synced 2026-06-08 18:04:23 +00:00
1e4cf061b6
* emu tests and fixes, and a little bit of cleanup * add tests * fixes per atlas and more tests * btr tests * tweaks per at1as and willi * clean up some test output
53 lines
1.1 KiB
Python
53 lines
1.1 KiB
Python
import sys
|
|
import shlex
|
|
|
|
import vtrace
|
|
|
|
|
|
class ShellcodeLoadNotifier(vtrace.Notifier):
|
|
def __init__(self, db, fname):
|
|
self.db = db
|
|
self.fname = fname
|
|
|
|
def notify(self, event, trace):
|
|
if event != vtrace.NOTIFY_BREAK:
|
|
return
|
|
|
|
bytez = None
|
|
with open(self.fname, 'rb') as f:
|
|
bytez = f.read()
|
|
|
|
va = trace.allocateMemory(len(bytez))
|
|
trace.writeMemory(va, bytez)
|
|
|
|
self.db.vprint('Loaded shellcode at address: 0x%x' % va)
|
|
|
|
trace.setProgramCounter(va)
|
|
trace.addBreakByAddr(va)
|
|
|
|
self.db.deregisterNotifier(vtrace.NOTIFY_BREAK, self)
|
|
|
|
|
|
def execsc(db, line):
|
|
'''
|
|
Load and execute shellcode stub from file
|
|
|
|
Usage: execsc <fname>
|
|
'''
|
|
argv = shlex.split(line)
|
|
if len(argv) != 1:
|
|
return db.do_help('execsc')
|
|
|
|
cmd = sys.executable
|
|
trace = db.newTrace()
|
|
db.vprint('Executing %s' % cmd)
|
|
|
|
sc = ShellcodeLoadNotifier(db, argv[0])
|
|
db.registerNotifier(vtrace.NOTIFY_BREAK, sc)
|
|
|
|
trace.execute(cmd)
|
|
|
|
|
|
def vdbExtension(vdb, trace):
|
|
vdb.registerCmdExtension(execsc)
|