0

有一段 C 代码用于从二进制文件中提取信息:

bincode_t *initialize_bincode(const char *file)
{
    bfd *abfd;
    bincode_t *bin;
    //char *target = "x86_64-unknown-linux-gnu";
    char *target = "i686-pc-linux-gnu";

    bfd_init();

    if (!bfd_set_default_target(target)) {
        bs_dbgmsg("  (!) bfd_set_default_target()\n");
        return NULL;
    }

    if ((abfd = bfd_openr(file, target)) == NULL) {
        bs_dbgmsg("  (!) bfd_openr(): %s\n", file);
        return NULL;
    }

    if (!bfd_check_format(abfd, bfd_object)) {
        //isolated the error to be here (through simple print debugging)
        bs_dbgmsg("  (!) bfd_check_format()\n");
        printf("Error: %s", bfd_errmsg(bfd_get_error()));
        bfd_close(abfd);
        return NULL;
    }

    if((bin = malloc(sizeof(bincode_t))) == NULL) {
        bs_errmsg("  (!) malloc(): bin\n");
        exit(EXIT_FAILURE);
    }

我在 Linux 上针对 2 个 Windows 二进制样本运行了这段代码。但是,其中一个样本导致错误

错误:无法识别文件格式...忽略节标志 STYP_DSECT (0x1)

两个样本上的file命令都会产生以下输出:

fc671a044d48bffe519a89b06d289d83f52958cb:PE32 可执行文件 (GUI) Intel 80386,适用于 MS Windows

fe0c189a5067a2dfe46bad1c2cedaa5b7bbc6a20:PE32 可执行文件 (DLL) (GUI) Intel 80386,适用于 MS Windows

第二个二进制文件 (DLL) 导致错误。我的问题是,为什么会发生这种情况?我能做些什么来解决这个问题?我希望代码也能“看到”DLL 二进制文件。

我将 DLL 二进制文件插入 gdb,实际上 gdb 无法识别该文件。GDB 输出:

...不是可执行格式:文件格式无法识别

编辑 1:添加代码并完成错误消息输出。请注意,我是 C 初学者。

编辑 2:正如评论中所建议的,我已经使用bfd_errmsg(bfd_get_error())并包含了上面的输出。

4

0 回答 0