对二进制文件的GNU BFD结果为"没有这样的文件或目录" (二进制未执行)

时间:2016-09-30 03:57:13

标签: c portable-executable bfd

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

core

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

  

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

两个样本上的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); } 命令产生以下输出:

  

fc671a044d48bffe519a89b06d289d83f52958cb:PE32可执行文件(GUI)英特尔   80386,用于MS Windows

  

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

第二个二进制文件(DLL)导致错误。我的问题是,为什么会发生这种情况?我该怎么做才能解决这个问题?我希望代码也可以"看" DLL二进制文件。

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

  

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

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

编辑2: 正如评论中所建议的那样,我使用了file并包含了上面的输出。

0 个答案:

没有答案