changing the registers without an event is fundamentally not possible rethink and reformulate your query
if you do not want to do it in break-point handler of any debugger you must suspend the process , Get the Thread's context and Set the thread's context and Resume the process
pydbg can do all this iirc in the script body out of break-point handler
EDIT Added a Sample Script
from pydbg import *
from pydbg.defines import *
def handler_breakpoint (pydbg):
if pydbg.first_breakpoint:
return DBG_CONTINUE
def handler_access_violation (pydbg):
if pydbg.dbg.u.Exception.dwFirstChance:
print "crashed and land here on FirstChance"
else:
print "crashed and land here on SecondChancee"
return DBG_EXCEPTION_NOT_HANDLED
dbg = pydbg()
dbg.set_callback(EXCEPTION_BREAKPOINT, handler_breakpoint)
dbg.set_callback(EXCEPTION_ACCESS_VIOLATION, handler_access_violation)
dbg.load("c:\windows\system32\calc.exe")
print "pid of calc.exe is = %d" % dbg.pid
dbg.suspend_all_threads()
for thread_id in dbg.enumerate_threads():
thread_handle = dbg.open_thread(thread_id)
thread_context = dbg.get_thread_context(thread_handle)
print "eax = 0x%08x" % thread_context.Eax
thread_context.Eax=0xdeadbeef
dbg.set_thread_context(thread_context,0,thread_id)
thread_context = dbg.get_thread_context(thread_handle)
print "new eax = 0x%08x" % thread_context.Eax
print "yay we are going to crash now accessing random crap in eax"
dbg.resume_all_threads()
pydbg.debug_event_loop(dbg)
executed
:\>python changereg.py
pid of calc.exe is = 1940
eax = 0x00b52d6c
new eax = 0xdeadbeef
yay we are going to crash now accessing random crap in eax
crashed and land here on FirstChance
crashed and land here on SecondChancee