Object format

Compiled code is stored in a different format then the usual ELF format. A new format is used, coined ‘oj’. It is valid json and contains all the information that is also in ELF, but then in more plain text format. You can open and even edit an oj-object file with a text editor.

Object files are used to store assembled code.

Information contained is code, symbol table and relocation information.

The hierarchy is as follows:

  • an object file contains zero or more sections.
  • an object file may contains memory definitions, which contain a sequence of contained sections.
  • a section contains a name and data.
  • relocations are offset into a section, refer a symbol and have a type
  • symbols are offset into a section and have a name
  • debug data have an offset into a section and contain data.
  • sections cannot overlap
class ppci.binutils.objectfile.Image(name: str, address: int)

Memory image.

A memory image is a piece that can be loaded into memory.

add_section(section)

Add a section to this memory image

data

Get the data of this memory

size

Determine the size of this memory

class ppci.binutils.objectfile.ObjectFile(arch)

Container for sections with compiled code or data. Also contains symbols and relocation entries. Also contains debug information.

add_image(image)

Add an image

add_relocation(reloc)

Add a relocation entry

add_section(section)

Add a section

add_symbol(name, value, section)

Define a new symbol

byte_size

Get the size in bytes of this object file

del_symbol(name)

Remove a symbol with a given name

gen_relocation(typ, sym_name, offset=0, section=None, addend=0)

Create a relocation given by name

get_image(name)

Get a memory image

get_section(name, create=False)

Get or create a section with the given name

get_symbol(name)

Get a symbol

get_symbol_value(name)

Lookup a symbol and determine its value

has_section(name)

Check if the object file has a section with the given name

has_symbol(name)

Check if this object file has a symbol with name ‘name’

static load()

Load object file from file

polish()

Cleanup an object file

save(output_file)

Save object file to a file like object

class ppci.binutils.objectfile.Section(name)

A defined region of data in the object file

add_data(data)

Append data to the end of this section

class ppci.binutils.objectfile.Symbol(name, value, section)

A symbol definition in an object file

ppci.binutils.objectfile.asc2bin(data)

Decode ascii into binary

ppci.binutils.objectfile.bin2asc(data)

Encode binary data as ascii. If it is a large data set, then use a list of hex characters.

ppci.binutils.objectfile.chunks(data, size=30)

Split iterable thing into n-sized chunks

ppci.binutils.objectfile.deserialize(data)

Create an object file from dict-like data

ppci.binutils.objectfile.get_object(obj)

Try hard to load an object

ppci.binutils.objectfile.merge_memories(mem1, mem2, name)

Merge two memories into a new one

ppci.binutils.objectfile.print_object(obj)

Display an object in a user friendly manner

ppci.binutils.objectfile.serialize(x)

Serialize an object so it can be json-ified, or serialized