a.out (Assembler Output Format)
a.out is one of the earliest binary file formats used on Unix systems for executables, object code, and core dumps. While largely obsolete today, it provides a historical foundation for understanding binary file formats. Here's a breakdown of what the a.out header contains and how you can find where the code begins:
Structure of the a.out Header
The a.out header typically contains the following fields:
Magic Number:
Identifies the file as an a.out executable.
Common values:
0x0107: Normal executable.0x0108: Read-only text segment.0x010B: Demand-paged executable.
Header Fields:
a_text(4 bytes):Size of the text (code) segment.
a_data(4 bytes):Size of the initialized data segment.
a_bss(4 bytes):Size of the uninitialized data segment (BSS).
a_syms(4 bytes):Size of the symbol table.
a_entry(4 bytes):Entry point address where execution begins.
a_trsize(4 bytes):Size of the text relocation table.
a_drsize(4 bytes):Size of the data relocation table.
Sections in an a.out File
An a.out file is divided into several segments:
Text Segment:
Contains the executable code.
Data Segment:
Contains initialized variables and constants.
BSS Segment:
Contains uninitialized variables.
Symbol Table:
Stores symbols for debugging and linking.
Relocation Tables:
Used to adjust addresses in the text and data segments during linking or loading.
Finding Where the Code Begins
To determine where the code starts in an a.out file:
Check the Entry Point (
a_entry):The
a_entryfield in the header specifies the address where execution begins.
Locate the Text Segment:
The text segment starts immediately after the header.
Offset of the text segment in the file can be calculated as:
text_offset = sizeof(a.out header)
Disassemble the Code:
Use tools like
objdumporgdbto disassemble the binary and verify the code.
Commands to Analyze a.out Files
objdump -f <file>: Displays the file header, including entry point and segment sizes.objdump -d <file>: Disassembles the text (code) segment.nm <file>: Lists symbols in the file.gdb <file>: Debugs the a.out binary, allowing inspection of the header and code.
Example
These tools can help you analyze the a.out structure and understand how the binary is organized and executed.