unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; OpenDialog1: TOpenDialog; Button2: TButton; Label1: TLabel; procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses ImageHlp; function GetLastErrorText(): string; var dwSize: DWORD; lpszTemp: PAnsiChar; begin dwSize := 512; lpszTemp := nil; try GetMem(lpszTemp, dwSize); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_ARGUMENT_ARRAY, nil, GetLastError(), LANG_NEUTRAL, lpszTemp, dwSize, nil) finally Result := lpszTemp; FreeMem(lpszTemp) end end; function ListDllExports(FName: string; List: TStringList): boolean; type PDWORDArray = ^TDWORDArray; TDWORDArray = array [0..$FFFFF] of DWORD; var ImageInfo: LoadedImage; pExportDir: PImageExportDirectory; DirSize: Cardinal; pDummy: PImageSectionHeader; I: Cardinal; pNameRVAs: PDWORDArray; Name: string; begin List.Clear; if MapAndLoad(PChar(FName), nil, @ImageInfo, true, true) then begin try pExportDir := ImageDirectoryEntryToData(ImageInfo.MappedAddress, false, IMAGE_DIRECTORY_ENTRY_EXPORT, DirSize); if pEXportDir <> nil then begin pNameRVAs := ImageRvaToVa(ImageInfo.FileHeader, ImageInfo.MappedAddress, DWORD(pExportDir^.AddressOfNames),pDummy); for I := 0 to pExportDir^.NumberOfNames - 1 do begin Name := PChar(ImageRvaToVa(ImageInfo.FileHeader, ImageInfo.MappedAddress, pNameRVAs^[i], pDummy)); List.Add(Name); end; end; finally UnMapAndLoad(@ImageInfo); end; Result := true; end { MapAndLoad } else Result := false; end; procedure TForm1.Button2Click(Sender: TObject); begin OpenDialog1.InitialDir := 'C:/WINDOWS/system32'; OpenDialog1.Filter := 'Dll files (*.dll)|*.Dll'; if OpenDialog1.Execute then begin Caption := OpenDialog1.FileName; if not ListDllExports(OpenDialog1.FileName, TStringList(Memo1.Lines)) then MessageDlg(GetLastErrorText, mtError, [mbOK], 0); end; Label1.Caption := 'Found ' + IntToStr(TStringList(Memo1.Lines).Count) + ' Functions'; end; end.
[Code Collection] 枚举DLL的Export Functions
最新推荐文章于 2021-05-20 06:33:05 发布