unction InternalHandler(ExceptionInfo: PEXCEPTION_POINTERS; threadid: dword): LONG;
var i: integer;
eventhandles: array [0..1] of THandle;
wr: dword;
contextsize: integer;
begin
HandlerCS.enter; //block any other thread that has an single step exception untill this is handles
//fill in the exception and context structures
{$ifdef cpu64}
VEHSharedMem.Exception64.ExceptionCode:=ExceptionInfo.ExceptionRecord.ExceptionCode;
VEHSharedMem.Exception64.ExceptionFlags:=ExceptionInfo.ExceptionRecord.ExceptionFlags;
VEHSharedMem.Exception64.ExceptionRecord:=DWORD64(ExceptionInfo.ExceptionRecord.ExceptionRecord);
VEHSharedMem.Exception64.NumberParameters:=ExceptionInfo.ExceptionRecord.NumberParameters;
for i:=0 to ExceptionInfo.ExceptionRecord.NumberParameters-1 do
VEHSharedMem.Exception64.ExceptionInformation[i]:=ExceptionInfo.ExceptionRecord.ExceptionInformation[i];
{$else}
VEHSharedMem.Exception32.ExceptionCode:=ExceptionInfo.ExceptionRecord.ExceptionCode;
VEHSharedMem.Exception32.ExceptionFlags:=ExceptionInfo.ExceptionRecord.ExceptionFlags;
VEHSharedMem.Exception32.ExceptionRecord:=DWORD(ExceptionInfo.ExceptionRecord.ExceptionRecord);
VEHSharedMem.Exception32.NumberParameters:=ExceptionInfo.ExceptionRecord.NumberParameters;
for i:=0 to ExceptionInfo.ExceptionRecord.NumberParameters-1 do
VEHSharedMem.Exception32.ExceptionInformation[i]:=ExceptionInfo.ExceptionRecord.ExceptionInformation[i];
{$endif}
//setup the context
if ExceptionInfo.ContextRecord<>nil then
begin
contextsize:=sizeof(TContext);
{$ifdef cpu32}
//32-bit
if (ExceptionInfo.ContextRecord.ContextFlags and CONTEXT_EXTENDED)=CONTEXT_EXTENDED then
contextsize:=sizeof(TEContext);
{$endif}
CopyMemory(@VEHSharedMem.CurrentContext[0],ExceptionInfo.ContextRecord,contextsize);
end
else
zeromemory(@VEHSharedMem.CurrentContext[0], sizeof(TEContext));
i:=wr -WAIT_OBJECT_0;
if i=0 then //hashandleddebugevent has been set. After ce is done with it use the new context
begin
if ExceptionInfo.ContextRecord<>nil then
begin
CopyMemory(ExceptionInfo.ContextRecord,@VEHSharedMem.CurrentContext[0],contextsize);
if VEHSharedMem.ContinueMethod=DBG_CONTINUE then //it got handled, set the debug registers (else don't touch them. DR6 might be needed)
begin
PContext(@VEHSharedMem.CurrentContext[0])^.ContextFlags:=CONTEXT_DEBUG_REGISTERS; //only debug regs
SetThreadContext(GetCurrentThread, PContext(@VEHSharedMem.CurrentContext[0])^);
end;
end;
end
else
begin
//MessageBox(0,'WaitForMultipleObjects failed', 'VEH Debug Error', MB_OK);
result:=EXCEPTION_CONTINUE_EXECUTION; //something went wrong VEHSharedmem might even be broken
HandlerCS.Leave;
exit;
end;
//depending on user options either return EXCEPTION_CONTINUE_SEARCH or EXCEPTION_CONTINUE_EXECUTION
if VEHSharedMem.ContinueMethod=DBG_CONTINUE then
result:=EXCEPTION_CONTINUE_EXECUTION
else
result:=EXCEPTION_CONTINUE_SEARCH;