高手关照:关于如何得到DLL文件中的重要信息问题。(100分)(100分)

  • 主题发起人 主题发起人 uranium235
  • 开始时间 开始时间
U

uranium235

Unregistered / Unconfirmed
GUEST, unregistred user!
有些程序调用了DLL链接库,其中有一些很有用处的函数<br>和过程,所以问题来了。<br>有以下几个:<br>1.如何得到DLL库中的函数、过程名;<br>2.如何得到它们的参数(包括函数、过程的参数及类型、函数的返回值类型等信息);<br>3.暂时想不出来。。。。。。<br><br>期待大虾及与我一样的菜鸟能热烈的讨论!<br><br>还望高手予以详解,最好附上使用的例程。
 
???? &nbsp;&gt;&gt;是什么意思????<br>请大家看看。
 
只能显示DLL可导出函数<br><br>uses DLLTools; <br><br>function TForm1.ListExport( const name: String; ordinal: Integer; address:Pointer ): Boolean; <br>var <br>listentry: TLIstItem; <br>begin <br>Result := true; <br>listentry:= listview.Items.Add; <br>listentry.Caption := Format('%p',[address] ); <br>listentry.Subitems.Add( format('%d',[ordinal] )); <br>listentry.Subitems.Add( name ); <br>end; <br><br>procedure TForm1.Button1Click(Sender: TObject); <br>begin <br>if opendialog.execute then <br>begin <br>listview.items.clear; <br>ListDLLExports( opendialog.filename, listexport ); <br>end; <br>end; <br><br><br>***** <br>DLLTOOLS 单元 <br>***** <br><br><br>unit dlltools; <br><br>interface <br><br>Uses Windows, Classes, Sysutils, imagehlp ; <br><br>type <br>TDLLExportCallback = function (const name: String; ordinal: Integer; <br>address: Pointer): Boolean of Object; <br>{ Note: address is a RVA here, not a usable virtual address! } <br>DLLToolsError = Class( Exception ); <br><br>Procedure ListDLLExports( const filename: String; callback: <br>TDLLExportCallback ); <br>Procedure DumpExportDirectory( Const ExportDirectory: TImageExportDirectory; <br>lines: TStrings; const Image: LoadedImage ); <br>Function RVAToPchar( rva: DWORD; const Image: LoadedImage ): PChar; <br>Function RVAToPointer( rva: DWORD; const Image: LoadedImage ): Pointer; <br><br>implementation <br><br>resourcestring <br>eDLLNotFound = <br>'ListDLLExports: DLL %s does not exist!'; <br><br>{+---------------------------------------------------------------------- <br>Procedure EnumExports <br><br>Parameters : <br>ExportDirectory: IMAGE_EXPORT_DIRECTORY record to enumerate <br>image : LOADED_IMAGE record for the DLL the export directory belongs <br>to. <br>callback : callback function to hand the found exports to, must not be <br>Nil <br>Description: <br>The export directory of a PE image contains three RVAs that point at <br>tables <br>which describe the exported functions. The first is an array of RVAs <br>that <br>refer to the exported function names, these we translate to PChars to <br>get the exported name. The second array is an array of Word that <br>contains <br>the export ordinal for the matching entry in the names array. The <br>ordinal <br>is biased, that is we have to add the ExportDirectory.Base value to it <br>to <br>get the actual export ordinal. The biased ordinal serves as index for <br>the <br>third array, which is an array of RVAs that give the position of the <br>function code in the image. We don't translate these RVAs since the DLL <br>is not relocated since we load it via MapAndLoad. The function array is <br>usually much larger than the names array, since the ordinals for the <br>exported functions do not have to be in sequence, there can be (and <br>frequently are) gaps in the sequence, for which the matching entries in <br>the <br>function RVA array are garbage. <br>Error Conditions: none <br>Created: 9.1.2000 by P. Below <br>+----------------------------------------------------------------------} <br>Procedure EnumExports( const ExportDirectory : TImageExportDirectory ; <br>const image : LoadedImage ; <br>callback : TDLLExportCallback ) ; <br>Type <br>TDWordArray = Array [0..$FFFFF] of DWORD; <br>Var <br>i: Cardinal; <br>pNameRVAs, pFunctionRVas: ^TDWordArray; <br>pOrdinals: ^TWordArray; <br>name: String; <br>address: Pointer; <br>ordinal: Word; <br>Begin { EnumExports } <br>pNameRVAs := <br>RVAToPointer( DWORD(ExportDirectory.AddressOfNames), image ); <br>pFunctionRVAs := <br>RVAToPointer( DWORD(ExportDirectory.AddressOfFunctions), image ); <br>pOrdinals := <br>RVAToPointer( DWORD(ExportDirectory.AddressOfNameOrdinals), image ); <br>For i:= 0 to Pred( ExportDirectory.NumberOfNames ) Do Begin <br>name := RVAToPChar( pNameRVAs^, image ); <br>ordinal := pOrdinals^; <br>address := Pointer( pFunctionRVAs^[ ordinal ] ); <br>If not callback( name, ordinal+ExportDirectory.Base, address ) Then <br>Exit; <br>End; { For } <br>End; { EnumExports } <br><br>{+---------------------------------------------------------------------- <br>Procedure ListDLLExports <br><br>Parameters : <br>filename : full pathname of DLL to examine <br>callback : callback to hand the found exports to, must not be Nil <br>Description: <br>Loads the passed DLL using the LoadImage function, finds the exported <br>names table and reads it. Each found entry is handed to the callback <br>for further processing, until no more entries remain or the callback <br>returns false. Note that the address passed to the callback for a <br>exported <br>function is an RVA, so not identical to the address the function would <br>have in a properly loaded and relocated DLL! <br>Error Conditions: <br>Exceptions are raised if <br>- the passed DLL does not exist or could not be loaded <br>- no callback was passed (only if assertions are on) <br>- an API function failed <br>Created: 9.1.2000 by P. Below <br>+----------------------------------------------------------------------} <br>Procedure ListDLLExports( const filename : String ; callback : <br>TDLLExportCallback ) ; <br>Var <br>imageinfo: LoadedImage; <br>pExportDirectory: PImageExportDirectory; <br>dirsize: Cardinal; <br>Begin { ListDLLExports } <br>Assert( Assigned( callback )); <br>If not FileExists( filename ) Then <br>raise DLLToolsError.CreateFmt( eDLLnotFound, [filename] ); <br><br>If MapAndLoad( PChar( filename ), nil, @imageinfo, true, true ) Then <br>try <br>pExportDirectory := <br>ImageDirectoryEntryToData( <br>imageinfo.MappedAddress, false, <br>IMAGE_DIRECTORY_ENTRY_EXPORT, dirsize ); <br><br>If pExportDirectory = Nil Then <br>RaiseLastWin32Error <br>Else <br>EnumExports( pExportDirectory^, imageinfo, callback ); <br>finally <br>UnMapAndLoad( @imageinfo ); <br>end <br>Else <br>RaiseLastWin32Error; <br>End; { ListDLLExports } <br><br>{+---------------------------------------------------------------------- <br>Procedure DumpExportDirectory <br><br>Parameters : <br>ExportDirectory: a IMAGE_EXPORT_DIRECTORY record <br>lines : a TStrings descendend to put the info into, must not be Nil <br>Description: <br>Dumps the fields of the passed structure to the passed strings <br>descendent <br>as strings. <br>Error Conditions: <br>will raise an exception if lines is Nil and assertions are enabled. <br>Created: 9.1.2000 by P. Below <br>+----------------------------------------------------------------------} <br>Procedure DumpExportDirectory( Const ExportDirectory : TImageExportDirectory; <br>lines : TStrings; const Image: LoadedImage ) ; <br>Begin { DumpExportDirectory } <br>Assert( Assigned( lines )); <br><br>lines.add( 'Dump of IMAGE_EXPORT_DIRECTORY' ); <br>lines.add( format('Characteristics: %d', <br>[ExportDirectory.Characteristics])); <br>lines.add( format('TimeDateStamp: %d', <br>[ExportDirectory.TimeDateStamp])); <br>lines.add( format('Version: %d.%d', <br>[ExportDirectory.MajorVersion, <br>ExportDirectory.MinorVersion])); <br>lines.add( format('Name (RVA): %x', <br>[ExportDirectory.Name])); <br>lines.add( format('Name (translated): %s', <br>[RVAToPchar( ExportDirectory.name, Image )])); <br>lines.add( format('Base: %d', <br>[ExportDirectory.Base])); <br>lines.add( format('NumberOfFunctions: %d', <br>[ExportDirectory.NumberOfFunctions])); <br>lines.add( format('NumberOfNames: %d', <br>[ExportDirectory.NumberOfNames])); <br>lines.add( format('AddressOfFunctions (RVA): %p', <br>[Pointer(ExportDirectory.AddressOfFunctions)])); <br>lines.add( format('AddressOfNames (RVA): %p', <br>[Pointer(ExportDirectory.AddressOfNames)])); <br>lines.add( format('AddressOfNameOrdinals (RVA): %p', <br>[Pointer(ExportDirectory.AddressOfNameOrdinals)])); <br>End; { DumpExportDirectory } <br><br>{+---------------------------------------------------------------------- <br>Function RVAToPointer <br><br>Parameters : <br>rva : a relative virtual address to translate <br>Image : LOADED_IMAGE structure for the image the RVA relates to <br>Returns : translated address <br>Description: <br>Uses the ImageRVAToVA function to translate the RVA to a virtual <br>address. <br>Error Conditions: <br>Will raise an exception if the translation failed <br>Created: 9.1.2000 by P. Below <br>+----------------------------------------------------------------------} <br>Function RVAToPointer( rva : DWORD ; const Image : LoadedImage ) : Pointer; <br>var <br>pDummy: PImageSectionHeader; <br>Begin { RVAToPchar } <br>pDummy := nil; <br>Result := <br>ImageRvaToVa( Image.FileHeader, Image.MappedAddress, rva, <br>pDummy ); <br>If Result = Nil Then <br>RaiseLastWin32Error; <br>End; { RVAToPointer } <br><br>{+---------------------------------------------------------------------- <br>Function RVAToPchar <br><br>Parameters : <br>rva : a relative virtual address to translate <br>Image : LOADED_IMAGE structure for the image the RVA relates to <br>Returns : translated address <br>Description: <br>Uses the RVAToPointer function to translate the RVA to a virtual <br>address. Note that we do not check that the address does indeed point <br>to a zero-terminated string! <br>Error Conditions: <br>Will raise an exception if the translation failed <br>Created: 9.1.2000 by P. Below <br>+----------------------------------------------------------------------} <br>Function RVAToPchar( rva : DWORD ; const Image : LoadedImage ) : PChar ; <br>Begin { RVAToPchar } <br>Result := RVAToPointer( rva, image ); <br>End; { RVAToPchar } <br><br>end. <br> <br>
 
普通DLL的输出函数可以用Windows的Quickvew查看,或用<br>delphi/bin/tdump.exe工具<br>但无法获得参数说明,这是普通dll的特性,微软的dll都有相应的帮助。<br>第三方写的dll,如果要共享,也必须提供帮助。<br><br>另外一种类型的dll属于Com/Com+组件,可以使用<br>delphi菜单中的Import libaruay命令,导出***_tlb.pas<br>文件,这个文件包含函数声明和参数,信息齐全,往往可以<br>不用帮助就调用,当然,要看这个写组件的人是否语无伦次,<br>还有,你对这个技术的理解程度
 
我知道可以用exescope查看函数或过程名,十分简单,不过,参数是没有的。。。呵呵。
 
Turbo Dump &nbsp;Version 5.0.16.12 Copyright (c) 1988, 2000 Inprise Corporation<br>Syntax: &nbsp; TDUMP [options] [InputFile] [ListFile] [options]<br>&nbsp; -a &nbsp; &nbsp; &nbsp;Display file in 8-bit ASCII &nbsp;-a7 &nbsp; &nbsp; Display file in 7-Bit ASCII<br>&nbsp; -b# &nbsp; &nbsp; Start at offset # &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-C &nbsp; &nbsp; &nbsp;Dump OBJ, LIB COFF info<br>&nbsp; -d &nbsp; &nbsp; &nbsp;Dump OBJ, LIB debug info &nbsp; &nbsp; -e &nbsp; &nbsp; &nbsp;Dump as EXE<br>&nbsp; -ed &nbsp; &nbsp; No EXE debug info &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-ee[=x] PE exports only (x=srch)<br>&nbsp; -eiID &nbsp; EXE tbls:HDR,OBJ,FIX,NAM,ENT -el &nbsp; &nbsp; No EXE line numbers<br>&nbsp; -em[=x] PE imports only (x=srch) &nbsp; &nbsp; -em.[x] PE imp. modules (x=srch)<br>&nbsp; -ep &nbsp; &nbsp; No EXE PE header display &nbsp; &nbsp; -er &nbsp; &nbsp; No EXE relocation records<br>&nbsp; -ea[:v] Dump Exports(:v sort on RVA) -ex &nbsp; &nbsp; No New Executable dump<br>&nbsp; -h &nbsp; &nbsp; &nbsp;Output in hex &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-iID &nbsp; &nbsp;Incl dbg tbl:[?/abc...rst]<br>&nbsp; -l &nbsp; &nbsp; &nbsp;Dump as LIB (OMF) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-le[=x] Dump EXPDEF recs (x=srch)<br>&nbsp; -li[=x] Dump IMPDEF recs (x=srch) &nbsp; &nbsp;-m &nbsp; &nbsp; &nbsp;No C++ de-mangling<br>&nbsp; -o &nbsp; &nbsp; &nbsp;Dump as OBJ (OMF) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-oc &nbsp; &nbsp; Do OMF CRC check<br>&nbsp; -oiID &nbsp; Include OMF rec (? for list) -oxID &nbsp; Exclude OMF rec (? for list)<br>&nbsp; -q &nbsp; &nbsp; &nbsp;Suppress copyright message &nbsp; -r &nbsp; &nbsp; &nbsp;Raw dump of records<br>&nbsp; -R &nbsp; &nbsp; &nbsp;Dump PE relocation table &nbsp; &nbsp; -s[=x] &nbsp;Dump strings (x=srch)<br>&nbsp; -su[=x] Dump unix style strings &nbsp; &nbsp; &nbsp;-um &nbsp; &nbsp; Unmangle file list of names<br>&nbsp; -v &nbsp; &nbsp; &nbsp;Verbose dump of records &nbsp; &nbsp; &nbsp;-xID &nbsp; &nbsp;Excl dbg tbl:[?/abc...rst]<br>&nbsp; -? &nbsp; &nbsp; &nbsp;Display a better help screen
 
//显示DLL可导出函数<br>&nbsp; // 为了测试,你需要在Form上放置一个TButton、TOpenDialog和TListView构件<br><br><br>&nbsp; // 完整的DLLTools单元的代码在示例代码之后<br><br><br>&nbsp; uses DLLTools; <br><br><br>&nbsp; function TForm1.ListExport( const name: String; ordinal: Integer; address:Pointer ): Boolean; <br><br>&nbsp; var <br><br>&nbsp; listentry: TLIstItem; <br><br>&nbsp; begin <br><br>&nbsp; Result := true; <br><br>&nbsp; listentry:= listview.Items.Add; <br><br>&nbsp; listentry.Caption := Format('%p',[address] ); <br><br>&nbsp; listentry.Subitems.Add( format('%d',[ordinal] )); <br><br>&nbsp; listentry.Subitems.Add( name ); <br><br>&nbsp; end; <br><br><br>&nbsp; procedure TForm1.Button1Click(Sender: TObject); <br><br>&nbsp; begin <br><br>&nbsp; if opendialog.execute then <br><br>&nbsp; begin <br><br>&nbsp; listview.items.clear; <br><br>&nbsp; ListDLLExports( opendialog.filename, listexport ); <br><br>&nbsp; end; <br><br>&nbsp; end; <br><br><br><br>&nbsp; ***** <br><br>&nbsp; DLLTOOLS 单元<br><br>&nbsp; ***** <br><br><br><br>&nbsp; unit dlltools; <br><br><br>&nbsp; interface <br><br><br>&nbsp; Uses Windows, Classes, Sysutils, imagehlp ; <br><br><br>&nbsp; type <br><br>&nbsp; TDLLExportCallback = function (const name: String; ordinal: Integer; <br><br>&nbsp; address: Pointer): Boolean of Object; <br><br>&nbsp; { Note: address is a RVA here, not a usable virtual address! } <br><br>&nbsp; DLLToolsError = Class( Exception ); <br><br><br>&nbsp; Procedure ListDLLExports( const filename: String; callback: <br><br>&nbsp; TDLLExportCallback ); <br><br>&nbsp; Procedure DumpExportDirectory( Const ExportDirectory: TImageExportDirectory; <br><br>&nbsp; lines: TStrings; const Image: LoadedImage ); <br><br>&nbsp; Function RVAToPchar( rva: DWORD; const Image: LoadedImage ): PChar; <br><br>&nbsp; Function RVAToPointer( rva: DWORD; const Image: LoadedImage ): Pointer; <br><br><br>&nbsp; implementation <br><br><br>&nbsp; resourcestring <br><br>&nbsp; eDLLNotFound = <br><br>&nbsp; 'ListDLLExports: DLL %s does not exist!'; <br><br><br>&nbsp; {+---------------------------------------------------------------------- <br><br>&nbsp; | Procedure EnumExports <br><br>&nbsp; | <br><br>&nbsp; | Parameters : <br><br>&nbsp; | ExportDirectory: IMAGE_EXPORT_DIRECTORY record to enumerate <br><br>&nbsp; | image : LOADED_IMAGE record for the DLL the export directory belongs <br><br>&nbsp; | to. <br><br>&nbsp; | callback : callback function to hand the found exports to, must not be <br><br>&nbsp; Nil <br><br>&nbsp; | Description: <br><br>&nbsp; | The export directory of a PE image contains three RVAs that point at <br><br>&nbsp; tables <br><br>&nbsp; | which describe the exported functions. The first is an array of RVAs <br><br>&nbsp; that <br><br>&nbsp; | refer to the exported function names, these we translate to PChars to <br><br>&nbsp; | get the exported name. The second array is an array of Word that <br><br>&nbsp; contains <br><br>&nbsp; | the export ordinal for the matching entry in the names array. The <br><br>&nbsp; ordinal <br><br>&nbsp; | is biased, that is we have to add the ExportDirectory.Base value to it <br><br>&nbsp; to <br><br>&nbsp; | get the actual export ordinal. The biased ordinal serves as index for <br><br>&nbsp; the <br><br>&nbsp; | third array, which is an array of RVAs that give the position of the <br><br>&nbsp; | function code in the image. We don't translate these RVAs since the DLL <br><br>&nbsp; | is not relocated since we load it via MapAndLoad. The function array is <br><br>&nbsp; | usually much larger than the names array, since the ordinals for the <br><br>&nbsp; | exported functions do not have to be in sequence, there can be (and <br><br>&nbsp; | frequently are) gaps in the sequence, for which the matching entries in <br><br>&nbsp; the <br><br>&nbsp; | function RVA array are garbage. <br><br>&nbsp; | Error Conditions: none <br><br>&nbsp; | Created: 9.1.2000 by P. Below <br><br>&nbsp; +----------------------------------------------------------------------} <br><br>&nbsp; Procedure EnumExports( const ExportDirectory : TImageExportDirectory ; <br><br>&nbsp; const image : LoadedImage ; <br><br>&nbsp; callback : TDLLExportCallback ) ; <br><br>&nbsp; Type <br><br>&nbsp; TDWordArray = Array [0..$FFFFF] of DWORD; <br><br>&nbsp; Var <br><br>&nbsp; i: Cardinal; <br><br>&nbsp; pNameRVAs, pFunctionRVas: ^TDWordArray; <br><br>&nbsp; pOrdinals: ^TWordArray; <br><br>&nbsp; name: String; <br><br>&nbsp; address: Pointer; <br><br>&nbsp; ordinal: Word; <br><br>&nbsp; Begin { EnumExports } <br><br>&nbsp; pNameRVAs := <br><br>&nbsp; RVAToPointer( DWORD(ExportDirectory.AddressOfNames), image ); <br><br>&nbsp; pFunctionRVAs := <br><br>&nbsp; RVAToPointer( DWORD(ExportDirectory.AddressOfFunctions), image ); <br><br>&nbsp; pOrdinals := <br><br>&nbsp; RVAToPointer( DWORD(ExportDirectory.AddressOfNameOrdinals), image ); <br><br>&nbsp; For i:= 0 to Pred( ExportDirectory.NumberOfNames ) Do Begin <br><br>&nbsp; name := RVAToPChar( pNameRVAs^, image ); <br><br>&nbsp; ordinal := pOrdinals^; <br><br>&nbsp; address := Pointer( pFunctionRVAs^[ ordinal ] ); <br><br>&nbsp; If not callback( name, ordinal+ExportDirectory.Base, address ) Then <br><br>&nbsp; Exit; <br><br>&nbsp; End; { For } <br><br>&nbsp; End; { EnumExports } <br><br><br>&nbsp; {+---------------------------------------------------------------------- <br><br>&nbsp; | Procedure ListDLLExports <br><br>&nbsp; | <br><br>&nbsp; | Parameters : <br><br>&nbsp; | filename : full pathname of DLL to examine <br><br>&nbsp; | callback : callback to hand the found exports to, must not be Nil <br><br>&nbsp; | Description: <br><br>&nbsp; | Loads the passed DLL using the LoadImage function, finds the exported <br><br>&nbsp; | names table and reads it. Each found entry is handed to the callback <br><br>&nbsp; | for further processing, until no more entries remain or the callback <br><br>&nbsp; | returns false. Note that the address passed to the callback for a <br><br>&nbsp; exported <br><br>&nbsp; | function is an RVA, so not identical to the address the function would <br><br>&nbsp; | have in a properly loaded and relocated DLL! <br><br>&nbsp; | Error Conditions: <br><br>&nbsp; | Exceptions are raised if <br><br>&nbsp; | - the passed DLL does not exist or could not be loaded <br><br>&nbsp; | - no callback was passed (only if assertions are on) <br><br>&nbsp; | - an API function failed <br><br>&nbsp; | Created: 9.1.2000 by P. Below <br><br>&nbsp; +----------------------------------------------------------------------} <br><br>&nbsp; Procedure ListDLLExports( const filename : String ; callback : <br><br>&nbsp; TDLLExportCallback ) ; <br><br>&nbsp; Var <br><br>&nbsp; imageinfo: LoadedImage; <br><br>&nbsp; pExportDirectory: PImageExportDirectory; <br><br>&nbsp; dirsize: Cardinal; <br><br>&nbsp; Begin { ListDLLExports } <br><br>&nbsp; Assert( Assigned( callback )); <br><br>&nbsp; If not FileExists( filename ) Then <br><br>&nbsp; raise DLLToolsError.CreateFmt( eDLLnotFound, [filename] ); <br><br><br>&nbsp; If MapAndLoad( PChar( filename ), nil, @imageinfo, true, true ) Then <br><br>&nbsp; try <br><br>&nbsp; pExportDirectory := <br><br>&nbsp; ImageDirectoryEntryToData( <br><br>&nbsp; imageinfo.MappedAddress, false, <br><br>&nbsp; IMAGE_DIRECTORY_ENTRY_EXPORT, dirsize ); <br><br><br>&nbsp; If pExportDirectory = Nil Then <br><br>&nbsp; RaiseLastWin32Error <br><br>&nbsp; Else <br><br>&nbsp; EnumExports( pExportDirectory^, imageinfo, callback ); <br><br>&nbsp; finally <br><br>&nbsp; UnMapAndLoad( @imageinfo ); <br><br>&nbsp; end <br><br>&nbsp; Else <br><br>&nbsp; RaiseLastWin32Error; <br><br>&nbsp; End; { ListDLLExports } <br><br><br>&nbsp; {+---------------------------------------------------------------------- <br><br>&nbsp; | Procedure DumpExportDirectory <br><br>&nbsp; | <br><br>&nbsp; | Parameters : <br><br>&nbsp; | ExportDirectory: a IMAGE_EXPORT_DIRECTORY record <br><br>&nbsp; | lines : a TStrings descendend to put the info into, must not be Nil <br><br>&nbsp; | Description: <br><br>&nbsp; | Dumps the fields of the passed structure to the passed strings <br><br>&nbsp; descendent <br><br>&nbsp; | as strings. <br><br>&nbsp; | Error Conditions: <br><br>&nbsp; | will raise an exception if lines is Nil and assertions are enabled. <br><br>&nbsp; | Created: 9.1.2000 by P. Below <br><br>&nbsp; +----------------------------------------------------------------------} <br><br>&nbsp; Procedure DumpExportDirectory( Const ExportDirectory : TImageExportDirectory; <br><br>&nbsp; lines : TStrings; const Image: LoadedImage ) ; <br><br>&nbsp; Begin { DumpExportDirectory } <br><br>&nbsp; Assert( Assigned( lines )); <br><br><br>&nbsp; lines.add( 'Dump of IMAGE_EXPORT_DIRECTORY' ); <br><br>&nbsp; lines.add( format('Characteristics: %d', <br><br>&nbsp; [ExportDirectory.Characteristics])); <br><br>&nbsp; lines.add( format('TimeDateStamp: %d', <br><br>&nbsp; [ExportDirectory.TimeDateStamp])); <br><br>&nbsp; lines.add( format('Version: %d.%d', <br><br>&nbsp; [ExportDirectory.MajorVersion, <br><br>&nbsp; ExportDirectory.MinorVersion])); <br><br>&nbsp; lines.add( format('Name (RVA): %x', <br><br>&nbsp; [ExportDirectory.Name])); <br><br>&nbsp; lines.add( format('Name (translated): %s', <br><br>&nbsp; [RVAToPchar( ExportDirectory.name, Image )])); <br><br>&nbsp; lines.add( format('Base: %d', <br><br>&nbsp; [ExportDirectory.Base])); <br><br>&nbsp; lines.add( format('NumberOfFunctions: %d', <br><br>&nbsp; [ExportDirectory.NumberOfFunctions])); <br><br>&nbsp; lines.add( format('NumberOfNames: %d', <br><br>&nbsp; [ExportDirectory.NumberOfNames])); <br><br>&nbsp; lines.add( format('AddressOfFunctions (RVA): %p', <br><br>&nbsp; [Pointer(ExportDirectory.AddressOfFunctions)])); <br><br>&nbsp; lines.add( format('AddressOfNames (RVA): %p', <br><br>&nbsp; [Pointer(ExportDirectory.AddressOfNames)])); <br><br>&nbsp; lines.add( format('AddressOfNameOrdinals (RVA): %p', <br><br>&nbsp; [Pointer(ExportDirectory.AddressOfNameOrdinals)])); <br><br>&nbsp; End; { DumpExportDirectory } <br><br><br>&nbsp; {+---------------------------------------------------------------------- <br><br>&nbsp; | Function RVAToPointer <br><br>&nbsp; | <br><br>&nbsp; | Parameters : <br><br>&nbsp; | rva : a relative virtual address to translate <br><br>&nbsp; | Image : LOADED_IMAGE structure for the image the RVA relates to <br><br>&nbsp; | Returns : translated address <br><br>&nbsp; | Description: <br><br>&nbsp; | Uses the ImageRVAToVA function to translate the RVA to a virtual <br><br>&nbsp; | address. <br><br>&nbsp; | Error Conditions: <br><br>&nbsp; | Will raise an exception if the translation failed <br><br>&nbsp; | Created: 9.1.2000 by P. Below <br><br>&nbsp; +----------------------------------------------------------------------} <br><br>&nbsp; Function RVAToPointer( rva : DWORD ; const Image : LoadedImage ) : Pointer; <br><br>&nbsp; var <br><br>&nbsp; pDummy: PImageSectionHeader; <br><br>&nbsp; Begin { RVAToPchar } <br><br>&nbsp; pDummy := nil; <br><br>&nbsp; Result := <br><br>&nbsp; ImageRvaToVa( Image.FileHeader, Image.MappedAddress, rva, <br><br>&nbsp; pDummy ); <br><br>&nbsp; If Result = Nil Then <br><br>&nbsp; RaiseLastWin32Error; <br><br>&nbsp; End; { RVAToPointer } <br><br><br>&nbsp; {+---------------------------------------------------------------------- <br><br>&nbsp; | Function RVAToPchar <br><br>&nbsp; | <br><br>&nbsp; | Parameters : <br><br>&nbsp; | rva : a relative virtual address to translate <br><br>&nbsp; | Image : LOADED_IMAGE structure for the image the RVA relates to <br><br>&nbsp; | Returns : translated address <br><br>&nbsp; | Description: <br><br>&nbsp; | Uses the RVAToPointer function to translate the RVA to a virtual <br><br>&nbsp; | address. Note that we do not check that the address does indeed point <br><br>&nbsp; | to a zero-terminated string! <br><br>&nbsp; | Error Conditions: <br><br>&nbsp; | Will raise an exception if the translation failed <br><br>&nbsp; | Created: 9.1.2000 by P. Below <br><br>&nbsp; +----------------------------------------------------------------------} <br><br>&nbsp; Function RVAToPchar( rva : DWORD ; const Image : LoadedImage ) : PChar ; <br><br>&nbsp; Begin { RVAToPchar } <br><br>&nbsp; Result := RVAToPointer( rva, image ); <br><br>&nbsp; End; { RVAToPchar } <br><br><br>&nbsp; end. <br><br>&nbsp;----------------------------------------- <br><br>取得某一dll所有输出函数名 &nbsp; &nbsp; <br><br>取得某一dll所有输出函数名<br>在uses里加上ImageHlp<br><br>procedure ListDLLFunctions(DLLName: String; List: TStrings);<br>type<br>&nbsp; chararr = array [0..$FFFFFF] of Char;<br>&nbsp; var<br>&nbsp; H: THandle;<br>&nbsp; I,<br>&nbsp; fc: integer;<br>&nbsp; st: string;<br>&nbsp; arr: Pointer;<br>&nbsp; ImageDebugInformation: PImageDebugInformation;<br>begin<br>&nbsp; List.Clear;<br>&nbsp; DLLName := ExpandFileName(DLLName);<br>&nbsp; if FileExists(DLLName) then<br>&nbsp; begin<br>&nbsp; &nbsp; H := CreateFile(PChar(DLLName), GENERIC_READ, FILE_SHARE_READ or<br>&nbsp; &nbsp; &nbsp; FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);<br>&nbsp; &nbsp; if H&lt;&gt;INVALID_HANDLE_VALUE then<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; ImageDebugInformation := MapDebugInformation(H, PChar(DLLName), nil, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; if ImageDebugInformation&lt;&gt;nil then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arr := ImageDebugInformation^.ExportedNames;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fc := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for I := 0 to ImageDebugInformation^.ExportedNamesSize - 1 do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if chararr(arr^)=#0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; st := PChar(@chararr(arr^)[fc]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Length(st)&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List.Add(st);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (I&gt;0) and (chararr(arr^)[I-1]=#0) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fc := I + 1<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UnmapDebugInformation(ImageDebugInformation)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(H)<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; end<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; List: TStrings;<br>&nbsp; I: integer;<br>&nbsp; S: String;<br><br>begin<br>&nbsp; List := TStringList.Create;<br><br>&nbsp; ListDLLFunctions('c:/windows/system/Abcsda.dll', List);<br>&nbsp; showmessage(inttostr(list.count));<br>&nbsp; S := 'List of functions';<br>&nbsp; for I := 0 to List.Count - 1 do<br>&nbsp; &nbsp; S := S + #13#10 + List;<br>&nbsp; ShowMessage(S);<br><br>&nbsp; List.Free<br>end;<br><br><br>&nbsp;<br>
 
好大一段英文程序……<br>KOKS的是什么东东?<br>突然发现上面两位引用的是同一个程序~!◎#¥%……<br>
 
&gt;&gt;&gt;&gt; [:D]
 
问题搁了好久,该结了!
 
后退
顶部