简体   繁体   English

您可以从C可执行文件中提取有关编译源文件的信息吗?

[英]Can you extract information from a C executable about which source files it was compiled from?

I have a C executable and would like to know if the executable has any information stored in it about which file(s) it was compiled from and, if so, how to access that information? 我有一个C可执行文件,并想知道可执行文件中是否存有关于编译它的文件的任何信息,如果是,如何访问该信息? I am using RedHat Linux 6. 我正在使用RedHat Linux 6。

If your program has been compiled with debugging information, then yes, it's possible. 如果您的程序已经编译了调试信息,那么是的,这是可能的。

For example, I compiled test.c with gcc -ggdb3 test.c -o test 例如,我编译test.cgcc -ggdb3 test.c -o test

Then, with gdb ./test : 然后,使用gdb ./test

(gdb) info functions
All defined functions:

File main.c:
int main(int, char **);

Non-debugging symbols:
0x0000000000400370  _init
0x00000000004003a0  __libc_start_main@plt
0x00000000004003b0  __gmon_start__@plt
0x00000000004003c0  _start
0x00000000004003f0  deregister_tm_clones
0x0000000000400420  register_tm_clones
0x0000000000400460  __do_global_dtors_aux
0x0000000000400480  frame_dummy
0x00000000004004d0  __libc_csu_init
0x0000000000400540  __libc_csu_fini
0x0000000000400544  _fini

(gdb) info sources
Source files for which symbols have been read in:

/home/john/Projects/test/main.c, /usr/include/bits/sys_errlist.h, ...

Source files for which symbols will be read in on demand:

It entirely depends on the architecture, and whether the executable was compiled in debug mode (or similar). 它完全取决于体系结构,以及可执行文件是否以调试模式(或类似)编译。

For example, UNIX systems embed debug information (including file names) in the executable itself, whereas Windows stores the info in a separate file (ie myprog.exe has a corresponding myprog.pdb with all the debug info). 例如,UNIX系统在可执行文件本身中嵌入调试信息(包括文件名),而Windows将信息存储在单独的文件中(即myprog.exe具有相应的myprog.pdb以及所有调试信息)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从c编写的源文件构建可执行文件? - How to build executable from c written source files? 我们可以从(可调试的)编译代码中提取 C 结构布局吗? - Can we extract the C structures layout from the (debuggable) compiled code? bash脚本可以从作为参数的C可执行文件访问信息吗? - Can a bash script access information from a C executable it takes as parameter? 如何使用 C 从 Linux 上的 /proc 文件的内容中提取信息? - How to extract information from the content of /proc files on Linux using C? 从编译的搜索程序C中提取记录 - Extract records from compiled search program, C 如何为从中获取可执行文件的.c查找? - How To find .c for the executable from which it is obtained? 当隐式规则对可执行文件一无所知时,make如何从C源文件构建可执行文件? - How does make build an executable file from a C source file when the implicit rule says nothing about executables? 通过查看c中与源代码相对的二进制文件,您可以获得什么? - What can you gain from looking at the binary opposed to source in c? 使用C从HTML文档中提取信息 - Extract information from HTML document with C 如何从编译的 C 程序中提取全局变量的值? - How to extract the value of a global variable from a compiled C program?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM