将导入添加到导入表中,可能吗?
我正在用 C 进行编码,我想知道是否可以从已导入的库中将导入添加到任何已编译的 EXE,例如 EXE 导入
Kernel32.dll
GetFileSize()、FindNextFileA、FindFirstFileA
是否有任何方法可以向此列表添加另一个函数?比如说CreateMutexA
?
I'm coding in C, and I want to know if it's possible to Add Imports to Any Compiled EXE from an already Imported library, for example, the EXE Imports
Kernel32.dll
GetFileSize(), FindNextFileA, FindFirstFileA
Is there any method I can add another function to this list? Let's say CreateMutexA
for example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当编译器(链接器)检测到正在编译的应用程序由于使用特定函数而静态链接到库时,将项目放入所谓的“导入表”中是编译器(链接器)的工作。在您的示例中,您要编译的应用程序调用 CreateMutexA API,然后静态链接到 Kernel32.lib。当加载程序启动您的应用程序时,它会检测到您的应用程序已静态链接到 Kernel32.lib,因为导入表中存在 FindNextFile 以及导入表中的库名称 (kernel32.dll),然后搜索 Kernel32.dll 是否存在,当然它总是已经加载到内存中)。导入表中存在项目意味着将调用 API(很快或稍后)。导入表中缺少某一项,意味着不会调用 API(除非您使用 LoadLibrary 和 GetProcAdress - 又名使用运行时动态链接库!)
不,没有可以“人工”调用的特定 API将项目添加到导入表中。理论上,如果您说 PE,您可以直接通过修改(欺骗)图像来做到这一点,但这是另一个故事,因为您需要调整包含导入表的修改后的 PE 部分的大小!
Putting Items in the so called "Import Table" is the job of the compiler (the Linker) when it detects that an application being compiled is statically linked to a library because it uses a specific function. In your example, the application you would compile invokes the CreateMutexA API and would be then statically linked to Kernel32.lib. When the loader will start your application, it would detect that your application has been statically linked to Kernel32.lib because of the presence of FindNextFile in the Import Table and the name of the library (kernel32.dll) in the Import Table and would then search for the presence of Kernel32.dll, which of course always present already loaded in memory). The presence of an item in the Import Table, means that the API will be invoked (soon or later). The absence of an item in the Import Table, means that the API won't be invoked (unless, you use LoadLibrary and GetProcAdress - aka using runtime Dynamic Link Library!)
NO, there is no specific API one can invoke to "artificially" add an item into the Import Table. You could, in theory, do this - if you speak PE - directly by modifying (fooling) the image, but this is another story, since you would need to adjust the size of the modified PE section that contains the Import Table!