gpt4 book ai didi

c - raw bin 到 coff 的转换

转载 作者:行者123 更新时间:2023-11-30 15:31:38 27 4
gpt4 key购买 nike

我想知道在这种情况下我是否会得到一个包含原始内容的 .bin 文件某些程序(x86-32)是否可以使用某些工具进行转换(或者如果可能的话)到一些可链接的目标文件(如 coff)我可以链接和使用(例如使用 GCC)

具体来说,在我看来,在转换时我应该加一些导出符号名称,不知道导入符号名称是什么,也不知道是否需要一些重新分配表将其与此类 bonary 一起使用,或者不需要并且可以构建在转换的过程中,我无法理解什么是继续处理此重新分配数据

可以这样转换数据吗?有人可以解释一下吗?

最佳答案

您最好的选择是编写一个普通的 C 程序,将 .bin 文件的内容读取到您分配为可执行文件的内存中,然后调用它。

这个(完全未经测试的)程序使用VirtualAlloc分配读/写/执行内存。不返回任何内容且不带任何参数的函数指针 (func) 指向缓冲区的开头,然后进行调用(就像普通的 C 函数一样)。

这假设您的 .bin 以一个可以调用的“正常”函数开始(在偏移量 0 处)。

#include <stdio.h>
#include <Windows.h>

int main(int argc, char** argv)
{
FILE* f;
int size;

// A function pointer to your binary blob.
// Change this prototype, depending on the function you're calling
void (*func)(void);


if (argc < 2) exit(1);

f = fopen(argv[1], "rb");
if (!f) exit(1);

// Get file size
fseek(f, 0, SEEK_END);
size = ftell(f);
fseek(f, 0, SEEK_SET);

// Allocate executable buffer
buf = VirtualAlloc(NULL,
size,
MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE);

// Read the file into the buffer
if (fread(buf, 1, size, f) != size)
exit(1);

// Point your function pointer to the buffer
func = (void*)buf;

// ...and call it
func();

return 0;
}

关于c - raw bin 到 coff 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24620124/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com