1. variante
Delphi-Quellcode:
function GetProcAddressX(module: integer; procname: pchar): pointer; stdcall;
var
DataDirectory: TImageDataDirectory;
P1: ^integer;
P2: ^Word;
Base, NumberOfNames, AddressOfFunctions, AddressOfNames,
AddressOfNameOrdinals, i, Ordinal: integer;
TempStr1, TempStr2: string;
begin
Result := nil;
DataDirectory := PImageNtHeaders(Cardinal(module) +
Cardinal(PImageDosHeader(module)^._lfanew))^.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT];
P1 := Pointer(module + integer(DataDirectory.VirtualAddress) + 16);
Base := P1^;
P1 := Pointer(module + integer(DataDirectory.VirtualAddress) + 24);
NumberOfNames := P1^;
P1 := Pointer(module + integer(DataDirectory.VirtualAddress) + 28);
AddressOfFunctions := P1^;
P1 := Pointer(module + integer(DataDirectory.VirtualAddress) + 32);
AddressOfNames := P1^;
P1 := Pointer(module + integer(DataDirectory.VirtualAddress) + 36);
AddressOfNameOrdinals := P1^;
Ordinal := 0;
if Cardinal(procname) > $0000FFFF then
begin
TempStr1 := PChar(procname);
for i := 1 to NumberOfNames do
begin
P1 := Pointer(module + AddressOfNames + (i - 1) * 4);
TempStr2 := PChar(module + P1^);
if TempStr1 = TempStr2 then
begin
P2 := Pointer(module + AddressOfNameOrdinals + (i - 1) * 2);
Ordinal := P2^;
Break;
end;
end;
end else
Ordinal := integer(procname) - Base;
if Ordinal <> 0 then
begin
P1 := Pointer(module + AddressOfFunctions + Ordinal * 4);
if (P1^ >= integer(DataDirectory.VirtualAddress)) and
(P1^ <= integer(DataDirectory.VirtualAddress + DataDirectory.Size)) then
begin
TempStr1 := PChar(module + P1^);
TempStr2 := TempStr1;
while Pos('.', TempStr2) > 0 do
TempStr2 := Copy(TempStr2, Pos('.', TempStr2) + 1, Length(TempStr2) - Pos('.', TempStr2));
TempStr1 := Copy(TempStr1, 1, Length(TempStr1) - Length(TempStr2) - 1);
Base := GetModuleHandleA(PChar(TempStr1));
if Base = 0 then
Base := LoadLibrary(PChar(TempStr1));
if Base > 0 then
Result := GetProcAddressX(Base, PChar(TempStr2));
end else Result := Pointer(module + P1^);
end;
end;
es wird GetModuleHandleA und Loadlibrary, falls es eine
API ist die weitergeleitet wird (forwarded) das kannst du getrost bei normalen APIs wie CreateFileA etc. rausnehmen dann ist der teil auch ohne andere delphi funktionen (copy etc) ausführbar