在c++中编译一个exe文件
Compile an exe file inside c++
我想创建一个c++程序,其中
我可以读取外部文件(可以是exe,dll,apk…等…等)。也就是读取文件将它们转换成字节并存储在数组
接下来,我要编译数组内的字节现在这是比较棘手的部分我想把字节编译成一个数组来检查字节是否工作正常
- 您可能会说我正在将文件转换为字节,然后将这些字节转换回相同的文件....(是的,我确实是这样做的)
这可能吗?
测试可执行文件是否可以加载(与执行不完全相同):
- 它将成功,除非
- 缺少权限
- 文件不可访问
- 其中一个依赖项不可访问(例如依赖库)
请注意,在UNIX上,同样可以使用dlopen
.
// A simple program that uses LoadLibrary
#include <windows.h>
#include <stdio.h>
int main( void )
{
HINSTANCE hinstLib;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(TEXT("input.exe")); // or dll
fFreeResult = FreeLibrary(hinstLib);
if (hinstLib != NULL)
printf("Message printed from executablen");
return 0;
}
参见
- <
- LoadLibrary函数/gh><
- LoadLibraryEx函数/gh>
使用流复制
#include <sstream>
#include <fstream>
int main()
{
std::stringstream in_memory(
std::ios_base::out |
std::ios_base::in |
std::ios::binary);
{
// reading whole file into memory
std::ifstream ifs("input.exe", std::ios::in | std::ios::binary);
in_memory << ifs.rdbuf();
}
{
// optionally write it out
std::ofstream ofs("input.exe.copy", std::ios::out | std::ios::binary);
ofs << in_memory.rdbuf();
}
return 0;
}
如果你不使用内存阶段,它会更有效率(非常大的文件不会引起问题):
#include <sstream>
#include <fstream>
int main()
{
std::ofstream("input.exe.copy2", std::ios::out | std::ios::binary)
<< std::ifstream("input.exe", std::ios::in | std::ios::binary).rdbuf();
return 0;
}
相关文章:
- 调试控制台 ChessEngine.exe "used"在另一个应用程序(国际象棋 GUI)中
- C++ |DLL / EXE - 如何从导出的类调用另一个类方法?
- 是否可以将 EXE 文件作为 lib 文件链接到另一个项目?
- 如何将一个 exe 项目链接到另一个 exe 项目中的类
- 将32位和64位应用程序(具有相同代码)编译为一个EXE
- 运行EXE形成另一个EXE并传递参数
- 将数据从一个.exe传递到另一个
- 是否可以使用 C++ 在我的程序中嵌入另一个 exe
- 调用外部函数(从一个exe到另一个exe)
- 从另一个 exe 运行 Exe
- 将一个exe嵌入到另一个exe中,以便生成单个exe
- 如何使用visual studio 2015创建一个.exe,我可以在桌面上运行
- 在 Visual Studio 2012 中将 C 和 C++ 代码编译为一个.exe文件
- 如何在C++中将一个.exe链接到另一个.exe
- Pantheios 不使用 MFC 应用程序写入一个文件(一个 exe + 两个 DLL)
- 调用另一个exe并获取值
- 在c++中编译一个exe文件
- VS2010构建了一个exe,但不能调试它,抱怨它找不到它
- 调用 CreateProcessAsUser 时,我是否需要在 lpCommandLine 中指定一个 exe 路径作为
- 我怎么能运行一个.exe与dll在单独的目录