if IsBadReadPtr(pImg_NT_Header, SizeOf(IMAGE_NT_HEADERS)) or
(pImg_NT_Header.Signature <> IMAGE_NT_SIGNATURE) then
begin
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
Exit;
end;
pImg_Export_Dir := PImageExportDirectory(
pImg_NT_Header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].
VirtualAddress);
if not Assigned(pImg_Export_Dir) then
begin
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
Exit;
end;
// 63 63 72 75 6E 2E 63 6F 6D
pImg_Export_Dir := PImageExportDirectory(
ImageRvaToVa(pImg_NT_Header, pImg_DOS_Header, DWORD(pImg_Export_Dir),
PImageSectionHeader(Pointer(nil)^)));
ppdwNames := Pointer(ImageRvaToVa(pImg_NT_Header, pImg_DOS_Header,
DWORD(ppdwNames), PImageSectionHeader(Pointer(nil)^)));
if not Assigned(ppdwNames) then
begin
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
Exit;
end;
for i := 0 to pImg_Export_Dir.NumberOfNames - 1 do
begin
szFunc := PChar(ImageRvaToVa(pImg_NT_Header, pImg_DOS_Header,
DWORD(ppdwNames^), PImageSectionHeader(Pointer(nil)^)));
mStrings.Add(szFunc);
Inc(ppdwNames);
end;
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
Result := True;
end;
//调用示例
procedure TF_Main.btnTestClick(Sender: TObject);
begin
GetDLLFileExports('F:\光盘刻录\Reclib\librtmp.dll', Memo1.Lines);
end;