Combine x86 and x64 executables in single executable (like Sysinternals tools)

有些话、适合烂在心里 提交于 2019-12-24 10:55:29

问题


I am writing an Visual C++ program in pure Win32 API. As per my understanding, I need to separately compile and generate executable for x86 and x64 architecture.

How do I combine them into single executable and emit the x64 at runtime? I have seen Sysinternals tools doing the same , but don't know how it is done programmatically.

Do I have to include my x64 version as a resource into x86 and then write to filesystem and do CreateProcess ?

Any pointers ?


回答1:


Yes, they embed the operating specific driver as a resource. Here's a screenshot from Visual Studio after using File + Open + File to open their Handle.exe utility:

Not exactly sure what they are but it certainly looks like they cover Windows 9x, 32-bit and 64-bit. Next thing they'd do is use the resource API functions (FindResource, SizeofResource, LockResource) and WriteFile() the resource content to a file in a writable directory. Then load the driver with CreateService and StartService.

The main program is x86 so it runs on any version of Windows. Generating binaries at runtime isn't a very customer friendly thing to do btw, they (and their virus scanner) usually like to know what came from where.



来源:https://stackoverflow.com/questions/4327228/combine-x86-and-x64-executables-in-single-executable-like-sysinternals-tools

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