Search code examples
c++ccoff

Best way to find code and data sections in COFF object files?


I want to find the CODE and Initialized DATA sections in COFF Object files.

The sections that I want to find are called .text$mn and .data in output generated from two versions of Microsoft "c" compilers.

I have no idea how consistent this is across different compiler vendors, compiler versions from one vendor or different compiled languages from the same compiler vendor.


Solution

  • Table 7. Section Header Flags
    STYP_TEXT 00000020h Section contains executable code
    STYP_DATA 00000040h Section contains initialized data
    Common Object File Format
    Does narrow down the options, yet derived two different data sections.

    On the Microsoft platform searching for these section names in the Symbol_Table seems to work reliably: .text$mn and .data. I may have to adapt this for the gcc compiler.