简体   繁体   English

.exe程序使用此.dll文件时,如何知道在.dll文件中调用了哪些函数?

[英]How can I know which functions are invoked in a .dll file when this .dll file is used by a .exe program?

I have a question related to invoking functions in a dll file. 我有一个与调用dll文件中的函数有关的问题。 If I understand well, in a dll file we can define a lot of different functions that may be invoked by a .exe file. 如果我很了解,在dll文件中,我们可以定义许多可能由.exe文件调用的功能。 For example, the functions that can be invoked from a.dll file includes the following functions: 例如,可以从a.dll文件调用的功能包括以下功能:

void fun1(int k);
int  fun2(float value);
float fun3(double sig);

For a specific program, for example, a.exe , it may only invoke fun1 function in a.dll without using other functions. 对于特定程序,例如a.exe ,它只能在a.dll调用fun1函数,而不使用其他函数。 Then my question is, how can I know which functions are invoked when runing the .exe program. 然后我的问题是,如何知道运行.exe程序时调用了哪些函数。

You can check the symbol table of the executable for imported symbols. 您可以检查可执行文件的符号表中是否有导入的符号。 For windows ( .exe files) you can use the DUMPBIN utility with /IMPORTS as described here . 对于Windows( .exe文件),您可以将DUMPBIN实用程序与/IMPORTS ,如此处所述

Update : As mentioned in the comments, an executable could load DLLs and access them dynamically in a way that does not create symbols at compile time. 更新 :如注释中所述,可执行文件可以加载DLL并以在编译时不创建符号的方式动态访问它们。 For example, by calling GetProcAddress after loading the DLL using LoadLibrary . 例如,通过使用LoadLibrary加载DLL之后调用GetProcAddress In this case, there will not be a symbol present and DUMPBIN will not list it, but the funciton may or may not be called. 在这种情况下,将不存在符号,并且DUMPBIN不会列出该符号,但是可以调用或可以不调用该函数。

If you know more or less how the exe works and it doesn't seem to be doing stuff dynamically (such as loading code from plugin DLLs) then it might be safe to assume no dynamic loading is occurring. 如果您或多或少知道exe的工作方式,并且它似乎并没有动态地进行处理(例如从插件DLL加载代码),则可以假定没有动态加载发生。 Furthermore, if the exe's symbol table shows some functions from a given DLL, it's unlikely that the exe is dynamically accessing functions from that same DLL. 此外,如果exe的符号表显示了给定DLL中的某些功能,则exe不太可能从同一DLL中动态访问功能。

Also, the fact that a function appears in the symbol table does not guarantee that it will be called by the exe, but in any normal, static case it makes it quite likely. 同样,函数出现在符号表中的事实并不能保证该函数将被exe调用,但是在任何正常的静态情况下,它都很有可能。

You can use Dependency Walker 您可以使用Dependency Walker

"Dependency Walker is a free utility that scans any 32-bit or 64-bit Windows module (exe, dll, ocx, sys, etc.) and builds a hierarchical tree diagram of all dependent modules. For each module found, it lists all the functions that are exported by that module, and which of those functions are actually being called by other modules. Another view displays the minimum set of required files, along with detailed information about each file including a full path to the file, base address, version numbers, machine type, debug information, and more." “ Dependency Walker是一个免费的实用程序,它可以扫描任何32位或64位Windows模块(exe,dll,ocx,sys等),并为所有从属模块构建层次结构树图。对于找到的每个模块,它将列出所有该模块导出的功能以及其他模块实际上正在调用的功能。另一个视图显示所需文件的最小集,以及有关每个文件的详细信息,包括文件的完整路径,基址,版本号,计算机类型,调试信息等。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM