function GetRealAddress(addr: Pointer): Pointer;
var
si : SYSTEM_INFO;
begin
result := addr;
GetSystemInfo(si);
if DWORD(addr) > DWORD(si.lpMaximumApplicationAddress) then
begin
if PBYTE(addr)^ = $68 then
begin
result := PDWORD(DWORD(PBYTE(addr)) + 1);
result := PDWORD(result^);
end;
end;
end;
if RVA = 0 then exit;
ImportDesc := pointer(integer(Dos) + RVA);
while (ImportDesc^.Name <> 0) do
begin
DLL := PChar(Integer(Dos) + ImportDesc^.Name);
RepointAddrInModule(GetModuleHandle(PChar(DLL)), OldFunc, NewFunc);
Func := Pointer(Integer(DOS) + ImportDesc.LookupTable);
while Func^ <> nil do
begin
f := LocateFunctionAddress(Func^);
if f = OldFunc then
begin
WriteProcessMemory(GetCurrentProcess, Func, @NewFunc, 4, written);
if Written > 0 then Inc(Result);
end;
Inc(Func);
end;
Inc(ImportDesc);
end;
end;
begin
IsDone := TList.Create;
try
Result := RepointAddrInModule(GetModuleHandle(nil), OldFunc, NewFunc);
finally
IsDone.Free;
end;
end;