C++/CLI: Use LoadLibrary + GetProcAddress with an exe

江枫思渺然 提交于 2019-12-01 07:33:06

It is possible.

http://www.codeproject.com/Articles/1045674/Load-EXE-as-DLL-Mission-Possible

The idea is to patch the IAT, then call the CRT. Of course, the EXE must be relocatable, and by default (ASLR) it is.

You can use LoadLibrary and GetProcAddress on the main executable for your process, this allows dynamic exports in the reverse direction (.exe to .dll).

You cannot load a second .exe into your process memory space, except for access to resources/data, because .exe code is not relocatable. (Pure MSIL .exe files are an exception, because there is no code in the file, it's all generated by the JIT.)

Basically, LoadLibrary on a .exe is useful only when

  • The .exe is the main process exe, in which case you might as well use GetModuleHandle

    or

  • The LOAD_LIBRARY_AS_DATAFILE flag is used

Whilst Ben's answer covers most cases this article http://sandsprite.com/CodeStuff/Using_an_exe_as_a_dll.html may be useful in some circumstances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!