如何导出DLL里的函数原型?? 如何导出DLL里的函数原型??VC有个工具是可以的,但是VC格式的,这样我们还要把它翻译成Pascal的,我想很多伙伴们都遇到过这个问题,大家来研究研究!!。。, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 delphi下面也有个工具好象是TDUMP.EXE吧如果你要自己写代码我觉得比较麻烦不过你可以导出函数名称,地址等如果要导出参数类型,我也不知道 给你个前人写的pas文件,导出函数名称(必须是export的)=====================================================unit dlltools;interfaceUses Windows, Classes, Sysutils, imagehlp ;type TDLLExportCallback = function (const name: String; ordinal: Integer; address: Pointer): Boolean of Object; { Note: address is a RVA here, not a usable virtual address! } DLLToolsError = Class( Exception ); Procedure ListDLLExports( const filename: String; callback: TDLLExportCallback ); //列出函数... Procedure DumpExportDirectory( Const ExportDirectory: TImageExportDirectory; lines: TStrings; const Image: LoadedImage ); Function RVAToPchar( rva: DWORD; const Image: LoadedImage ): PChar; Function RVAToPointer( rva: DWORD; const Image: LoadedImage ): Pointer;implementationresourcestring eDLLNotFound = 'ListDLLExports: DLL %s does not exist!'; Procedure EnumExports( const ExportDirectory : TImageExportDirectory ; const image : LoadedImage ; callback : TDLLExportCallback ) ; Type TDWordArray = Array [0..$FFFFF] of DWORD; Var i: Cardinal; pNameRVAs, pFunctionRVas: ^TDWordArray; pOrdinals: ^TWordArray;name: String;address: Pointer; ordinal: Word;Begin { EnumExports } pNameRVAs := RVAToPointer( DWORD(ExportDirectory.AddressOfNames), image );pFunctionRVAs :=RVAToPointer( DWORD(ExportDirectory.AddressOfFunctions), image );pOrdinals :=RVAToPointer( DWORD(ExportDirectory.AddressOfNameOrdinals), image );For i:= 0 to Pred( ExportDirectory.NumberOfNames ) Do Begin name := RVAToPChar( pNameRVAs^[i], image ); ordinal := pOrdinals^[i]; address := Pointer( pFunctionRVAs^[ ordinal ] ); If not callback( name, ordinal+ExportDirectory.Base, address ) Then Exit; End; { For } End; { EnumExports } Procedure ListDLLExports( const filename : String ; callback : TDLLExportCallback ) ; Var imageinfo: LoadedImage; pExportDirectory: PImageExportDirectory; dirsize: Cardinal; Begin { ListDLLExports } Assert( Assigned( callback )); If not FileExists( filename ) Then raise DLLToolsError.CreateFmt( eDLLnotFound, [filename] ); If MapAndLoad( PChar( filename ), nil, @imageinfo, true, true ) Then try pExportDirectory := ImageDirectoryEntryToData( imageinfo.MappedAddress, false, IMAGE_DIRECTORY_ENTRY_EXPORT, dirsize ); If pExportDirectory = Nil Then RaiseLastWin32ErrorElse EnumExports( pExportDirectory^, imageinfo, callback ); finally UnMapAndLoad( @imageinfo ); end Else RaiseLastWin32Error; End; { ListDLLExports } {+---------------------------------------------------------------------- | Procedure DumpExportDirectory | | Parameters : | ExportDirectory: a IMAGE_EXPORT_DIRECTORY record | lines : a TStrings descendend to put the info into, must not be Nil | Description: | Dumps the fields of the passed structure to the passed strings descendent | as strings. | Error Conditions: | will raise an exception if lines is Nil and assertions are enabled. | Created: 9.1.2000 by P. Below +----------------------------------------------------------------------} Procedure DumpExportDirectory( Const ExportDirectory : TImageExportDirectory;lines : TStrings; const Image: LoadedImage ) ; Begin { DumpExportDirectory } Assert( Assigned( lines )); lines.add( 'Dump of IMAGE_EXPORT_DIRECTORY' );lines.add( format('Characteristics: %d',[ExportDirectory.Characteristics]));lines.add( format('TimeDateStamp: %d',[ExportDirectory.TimeDateStamp]));lines.add( format('Version: %d.%d',[ExportDirectory.MajorVersion,ExportDirectory.MinorVersion]));lines.add( format('Name (RVA): %x', [ExportDirectory.Name]));lines.add( format('Name (translated): %s',[RVAToPchar( ExportDirectory.name, Image )]));lines.add( format('Base: %d', [ExportDirectory.Base]));lines.add( format('NumberOfFunctions: %d',[ExportDirectory.NumberOfFunctions]));lines.add( format('NumberOfNames: %d',[ExportDirectory.NumberOfNames]));lines.add( format('AddressOfFunctions (RVA): %p', [Pointer(ExportDirectory.AddressOfFunctions)]));lines.add( format('AddressOfNames (RVA): %p',[Pointer(ExportDirectory.AddressOfNames)]));lines.add( format('AddressOfNameOrdinals (RVA): %p',[Pointer(ExportDirectory.AddressOfNameOrdinals)]));End; { DumpExportDirectory }{+---------------------------------------------------------------------- | Function RVAToPointer | | Parameters : | rva : a relative virtual address to translate | Image : LOADED_IMAGE structure for the image the RVA relates to | Returns : translated address | Description: | Uses the ImageRVAToVA function to translate the RVA to a virtual | address. | Error Conditions: | Will raise an exception if the translation failed | Created: 9.1.2000 by P. Below +----------------------------------------------------------------------} Function RVAToPointer( rva : DWORD ; const Image : LoadedImage ) : Pointer; var pDummy: PImageSectionHeader; Begin { RVAToPchar } pDummy := nil; Result := ImageRvaToVa( Image.FileHeader, Image.MappedAddress, rva, pDummy ); If Result = Nil Then RaiseLastWin32Error; End; { RVAToPointer } {+---------------------------------------------------------------------- | Function RVAToPchar | | Parameters : | rva : a relative virtual address to translate | Image : LOADED_IMAGE structure for the image the RVA relates to | Returns : translated address | Description: | Uses the RVAToPointer function to translate the RVA to a virtual | address. Note that we do not check that the address does indeed point | to a zero-terminated string! | Error Conditions: | Will raise an exception if the translation failed | Created: 9.1.2000 by P. Below+----------------------------------------------------------------------}Function RVAToPchar( rva : DWORD ; const Image : LoadedImage ) : PChar ; Begin { RVAToPchar } Result := RVAToPointer( rva, image ); End; { RVAToPchar }end. 运算符---枚举---循环变量 printer对象的引用 生产车间,数量运算。探讨。 如何通过internet访问局域网内的ms sql server 数据库(delphi)? 新建一控件,无法显示,各位仁兄,帮一帮,谢谢 请教怎么设置TActionClientItem组件? 怎样得到错误号,Exception只能得到Message 请问如何在TCOMBOBOX中输入后自动查询到相似的ITEM上面去 关于Delphi 书籍! delphi的简单问题 Move的问题 请问在哪儿能找到TMemo控件源码
好象是TDUMP.EXE吧
如果你要自己写代码
我觉得比较麻烦
不过你可以导出函数名称,地址等
如果要导出参数类型,我也不知道
=====================================================
unit dlltools;interfaceUses Windows, Classes, Sysutils, imagehlp ;
type
TDLLExportCallback = function (const name: String; ordinal: Integer;
address: Pointer): Boolean of Object;
{ Note: address is a RVA here, not a usable virtual address! }
DLLToolsError = Class( Exception ); Procedure ListDLLExports( const filename: String; callback:
TDLLExportCallback ); //列出函数...
Procedure DumpExportDirectory( Const ExportDirectory: TImageExportDirectory;
lines: TStrings; const Image: LoadedImage );
Function RVAToPchar( rva: DWORD; const Image: LoadedImage ): PChar;
Function RVAToPointer( rva: DWORD; const Image: LoadedImage ): Pointer;
implementationresourcestring
eDLLNotFound =
'ListDLLExports: DLL %s does not exist!';
Procedure EnumExports( const ExportDirectory : TImageExportDirectory ;
const image : LoadedImage ;
callback : TDLLExportCallback ) ;
Type
TDWordArray = Array [0..$FFFFF] of DWORD;
Var
i: Cardinal;
pNameRVAs, pFunctionRVas: ^TDWordArray;
pOrdinals: ^TWordArray;
name: String;
address: Pointer;
ordinal: Word;
Begin { EnumExports }
pNameRVAs :=
RVAToPointer( DWORD(ExportDirectory.AddressOfNames), image );
pFunctionRVAs :=
RVAToPointer( DWORD(ExportDirectory.AddressOfFunctions), image );
pOrdinals :=
RVAToPointer( DWORD(ExportDirectory.AddressOfNameOrdinals), image );
For i:= 0 to Pred( ExportDirectory.NumberOfNames ) Do Begin
name := RVAToPChar( pNameRVAs^[i], image );
ordinal := pOrdinals^[i];
address := Pointer( pFunctionRVAs^[ ordinal ] );
If not callback( name, ordinal+ExportDirectory.Base, address ) Then
Exit;
End; { For }
End; { EnumExports }
Procedure ListDLLExports( const filename : String ; callback :
TDLLExportCallback ) ;
Var
imageinfo: LoadedImage;
pExportDirectory: PImageExportDirectory;
dirsize: Cardinal;
Begin { ListDLLExports }
Assert( Assigned( callback ));
If not FileExists( filename ) Then
raise DLLToolsError.CreateFmt( eDLLnotFound, [filename] ); If MapAndLoad( PChar( filename ), nil, @imageinfo, true, true ) Then
try
pExportDirectory :=
ImageDirectoryEntryToData(
imageinfo.MappedAddress, false,
IMAGE_DIRECTORY_ENTRY_EXPORT, dirsize ); If pExportDirectory = Nil Then
RaiseLastWin32Error
Else
EnumExports( pExportDirectory^, imageinfo, callback );
finally
UnMapAndLoad( @imageinfo );
end
Else
RaiseLastWin32Error;
End; { ListDLLExports } {+----------------------------------------------------------------------
| Procedure DumpExportDirectory
|
| Parameters :
| ExportDirectory: a IMAGE_EXPORT_DIRECTORY record
| lines : a TStrings descendend to put the info into, must not be Nil
| Description:
| Dumps the fields of the passed structure to the passed strings
descendent
| as strings.
| Error Conditions:
| will raise an exception if lines is Nil and assertions are enabled.
| Created: 9.1.2000 by P. Below
+----------------------------------------------------------------------}
Procedure DumpExportDirectory( Const ExportDirectory : TImageExportDirectory;
lines : TStrings; const Image: LoadedImage ) ;
Begin { DumpExportDirectory }
Assert( Assigned( lines )); lines.add( 'Dump of IMAGE_EXPORT_DIRECTORY' );
lines.add( format('Characteristics: %d',
[ExportDirectory.Characteristics]));
lines.add( format('TimeDateStamp: %d',
[ExportDirectory.TimeDateStamp]));
lines.add( format('Version: %d.%d',
[ExportDirectory.MajorVersion,
ExportDirectory.MinorVersion]));
lines.add( format('Name (RVA): %x',
[ExportDirectory.Name]));
lines.add( format('Name (translated): %s',
[RVAToPchar( ExportDirectory.name, Image )]));
lines.add( format('Base: %d',
[ExportDirectory.Base]));
lines.add( format('NumberOfFunctions: %d',
[ExportDirectory.NumberOfFunctions]));
lines.add( format('NumberOfNames: %d',
[ExportDirectory.NumberOfNames]));
lines.add( format('AddressOfFunctions (RVA): %p',
[Pointer(ExportDirectory.AddressOfFunctions)]));
lines.add( format('AddressOfNames (RVA): %p',
[Pointer(ExportDirectory.AddressOfNames)]));
lines.add( format('AddressOfNameOrdinals (RVA): %p',
[Pointer(ExportDirectory.AddressOfNameOrdinals)]));
End; { DumpExportDirectory }{+----------------------------------------------------------------------
| Function RVAToPointer
|
| Parameters :
| rva : a relative virtual address to translate
| Image : LOADED_IMAGE structure for the image the RVA relates to
| Returns : translated address
| Description:
| Uses the ImageRVAToVA function to translate the RVA to a virtual
| address.
| Error Conditions:
| Will raise an exception if the translation failed
| Created: 9.1.2000 by P. Below
+----------------------------------------------------------------------}
Function RVAToPointer( rva : DWORD ; const Image : LoadedImage ) : Pointer;
var
pDummy: PImageSectionHeader;
Begin { RVAToPchar }
pDummy := nil;
Result :=
ImageRvaToVa( Image.FileHeader, Image.MappedAddress, rva,
pDummy );
If Result = Nil Then
RaiseLastWin32Error;
End; { RVAToPointer } {+----------------------------------------------------------------------
| Function RVAToPchar
|
| Parameters :
| rva : a relative virtual address to translate
| Image : LOADED_IMAGE structure for the image the RVA relates to
| Returns : translated address
| Description:
| Uses the RVAToPointer function to translate the RVA to a virtual
| address. Note that we do not check that the address does indeed point
| to a zero-terminated string!
| Error Conditions:
| Will raise an exception if the translation failed
| Created: 9.1.2000 by P. Below
+----------------------------------------------------------------------}
Function RVAToPchar( rva : DWORD ; const Image : LoadedImage ) : PChar ;
Begin { RVAToPchar }
Result := RVAToPointer( rva, image );
End; { RVAToPchar }end.