0

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

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

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

4

1 回答 1

1

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

这个(完全未经测试的)程序使用VirtualAlloc. 一个不返回任何参数且不带参数的函数指针 ( func) 指向缓冲区的开头,然后被调用(就像普通的 C 函数一样)。

这假设您的.bin开始(在偏移量 0 处)具有可以call'd 的“​​正常”函数。

#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;
}
于 2014-07-07T22:31:29.257 回答