如何才能得到dll(没有源码)内的接口及参数(100分)

  • 主题发起人 主题发起人 linuxer
  • 开始时间 开始时间
L

linuxer

Unregistered / Unconfirmed
GUEST, unregistred user!
如何才能得到dll(没有源码)内的接口及参数
 
用dumpbin试试。<br>好像有点难度,我觉得应该首先知道它是语言开发的,因为不同的语言对接口的参数的及<br>调用方式改动不一样,再次充分发挥一下想像力:-(<br><br>另外网上有个dlltolib不知这个对你有没有用?
 
好像只有分析函数的汇编指令了
 
调出dll文件接口的源码<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, ComCtrls;<br><br>type<br>&nbsp; TFrmmain = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; ListBox1: TListBox;<br>&nbsp; &nbsp; OpenDialog1: TOpenDialog;<br>&nbsp; &nbsp; ListView1: TListView;<br>&nbsp; &nbsp; function ListExport( const name: String; ordinal: Integer; address:Pointer ): Boolean;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Frmmain: TFrmmain;<br><br>implementation<br>uses dlltools;<br><br>{$R *.dfm}<br>function TFrmmain.ListExport( const name: String; ordinal: Integer; address:Pointer ): Boolean;<br>var<br>&nbsp; listentry:TLIstItem;<br>&nbsp; begin<br>&nbsp; Result := true; <br><br>&nbsp; listentry:= listview1.Items.Add;<br><br>&nbsp; listbox1.Items.Add(Format('%p',[address] )+','+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; format('%d',[ordinal] )+','+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; listentry.Caption := Format('%p',[address] );<br><br>&nbsp; listentry.Subitems.Add( format('%d',[ordinal] ));<br>&nbsp;// edit1.Text:=format('%d',[ordinal] );<br>&nbsp;// edit2.Text:=name;<br>&nbsp; listentry.Subitems.Add( name );<br><br>&nbsp; end;<br><br>procedure TFrmmain.Button1Click(Sender: TObject);<br>begin<br>if opendialog1.execute then<br><br>&nbsp; begin<br><br>&nbsp; listview1.items.clear;<br>&nbsp; listbox1.Items.Clear;<br>&nbsp; ListDLLExports( opendialog1.filename, listexport );<br><br>&nbsp; end;<br><br><br>end;<br><br>end.<br><br><br><br><br><br><br>unit dlltools; <br><br>&nbsp; <br><br>&nbsp; interface <br><br>&nbsp; <br><br>&nbsp; Uses Windows, Classes, Sysutils, imagehlp ; <br><br>&nbsp; <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>&nbsp; <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>&nbsp; <br><br>&nbsp; implementation <br><br>&nbsp; <br><br>&nbsp; resourcestring <br><br>&nbsp; eDLLNotFound = <br><br>&nbsp; 'ListDLLExports: DLL %s does not exist!'; <br><br>&nbsp; <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>&nbsp; <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 : 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>&nbsp; <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>&nbsp; <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>&nbsp; <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>&nbsp; <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>&nbsp; <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>&nbsp; <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>&nbsp; <br><br>&nbsp; end. <br><br>
 
dumpbin只能列出接口,不能列出参数。<br>dlltolib不知是否OK,下载一个试试看
 
用delphi导入ActiveX 控件,导入这个Dll,生成的PAS文件里就有接口及参数
 
最简单明了的就是使用Delphi的类型库编程器来查看。
 
对不起,上面的老兄,我很菜,不要笑我<br>您说的类型库编程器是什么东东?怎么使用?
 
沒有找到答案﹐但lixx的答案最為接近。
 
后退
顶部