type
PExceptionRecord = ^TExceptionRecord;
_EXCEPTION_RECORD = record
ExceptionCode: DWORD;
ExceptionFlags: DWORD;
ExceptionRecord: PExceptionRecord;
ExceptionAddress: Pointer;<-----内存断点触发时访问你VirtualProtect所设置的内存页的汇编指令地址就是EIP
NumberParameters: DWORD;
ExceptionInformation: array[0..EXCEPTION_MAXIMUM_PARAMETERS - 1] of DWORD;<-----ExceptionInformation[1]中是当前在内存页中所被访问到的地址
end;
function ExceptionHandler(const exce: TExceptionPointers): LongInt; stdcall;
const
EXCEPTION_CONTINUE_SEARCH = 0;
EXCEPTION_EXECUTE_HANDLER = 1;
EXCEPTION_CONTINUE_EXECUTION = -1;
var
per: PExceptionRecord;
begin
per := exce.ExceptionRecord;
case per.ExceptionCode of
EXCEPTION_ACCESS_VIOLATION: //内存断点异常
begin
if per.ExceptionInformation[1] = $0050020 then
begin
TTLog.Log(Format('内存断点异常 汇编地址:%.8x 访问地址:%.8x', [Cardinal(per.ExceptionAddress),per.ExceptionInformation[1]]));
//这里就只会断到0400200所在的汇编指令了做你的处理
MemoryBreakPoint.DelMBP($0050020);//删除掉断点
Result:=EXCEPTION_CONTINUE_EXECUTION;//正常运行
Exit;
end;
end;
end;
Result := EXCEPTION_CONTINUE_SEARCH;//下一次搜索
end;