gtirb.section module

class gtirb.section.Section(*, name='', byte_intervals=(), flags={}, uuid=None, module=None)[source]

Bases: Node

Represents a named section of the binary.

Does not directly store the contents of the section, which are kept in a gtirb.ImageByteMap.

Variables:
  • ~.name – The section name (E.g. “.text”, “.bss”, etc).

  • ~.byte_intervals – The ByteIntervals in this section.

  • ~.flags – The Section.Flags this section has.

class Flag(value)[source]

Bases: Enum

A flag representing a known property of a section.

Executable = 3

This section contains executable code.

Initialized = 5

This section has bytes allocated to it in the binary file.

Loaded = 4

This section is present in memory at runtime.

Readable = 1

This section can be read from at runtime.

ThreadLocal = 6

This section is created in memory once per thread.

Undefined = 0

This value is defined for Protobuf compatibility. Do not use.

Writable = 2

This section can be written to at runtime.

__init__(*, name='', byte_intervals=(), flags={}, uuid=None, module=None)[source]
Parameters:
  • name (str) – The name of this section.

  • byte_intervals (typing.Iterable[gtirb.byteinterval.ByteInterval]) – The ByteIntervals in this section.

  • flags (typing.Iterable[gtirb.section.Section.Flag]) – The Section.Flags this section has.

  • uuid (typing.Optional[uuid.UUID]) – The UUID of this Section, or None if a new UUID needs generated via uuid.uuid4(). Defaults to None.

  • module (typing.Optional[gtirb.module.Module]) – The Module this section belongs to.

property address: int | None

Get the address of this section, if known.

The address is calculated from the ByteInterval objects in this section. More specifically, if the address of all byte intervals in this section are fixed, then it will return the address of the interval lowest in memory. If any one interval does not have an address then this will be None, as the address is not calculable in that case. Note that a section with no intervals in it has no address or size, so it will be None in that case.

property byte_blocks: Iterator[ByteBlock]

The ByteBlocks in this section.

byte_blocks_at(addrs)[source]

Finds all the byte blocks that begin at an address or range of addresses.

Parameters:

addrs (typing.Union[int, range]) – Either a range object or a single address.

Return type:

typing.Iterable[gtirb.block.ByteBlock]

byte_blocks_on(addrs)[source]

Finds all the byte blocks that overlap an address or range of addresses.

Parameters:

addrs (typing.Union[int, range]) – Either a range object or a single address.

Return type:

typing.Iterable[gtirb.block.ByteBlock]

byte_intervals_at(addrs)[source]

Finds all the byte intervals that begin at an address or range of addresses.

Parameters:

addrs (typing.Union[int, range]) – Either a range object or a single address.

Return type:

typing.Iterable[gtirb.byteinterval.ByteInterval]

byte_intervals_on(addrs)[source]

Finds all the byte intervals that overlap an address or range of addresses.

Parameters:

addrs (typing.Union[int, range]) – Either a range object or a single address.

Return type:

typing.Iterable[gtirb.byteinterval.ByteInterval]

property code_blocks: Iterator[CodeBlock]

The CodeBlocks in this section.

code_blocks_at(addrs)[source]

Finds all the code blocks that begin at an address or range of addresses.

Parameters:

addrs (typing.Union[int, range]) – Either a range object or a single address.

Return type:

typing.Iterable[gtirb.block.CodeBlock]

code_blocks_on(addrs)[source]

Finds all the code blocks that overlap an address or range of addresses.

Parameters:

addrs (typing.Union[int, range]) – Either a range object or a single address.

Return type:

typing.Iterable[gtirb.block.CodeBlock]

property data_blocks: Iterator[DataBlock]

The DataBlocks in this section.

data_blocks_at(addrs)[source]

Finds all the data blocks that begin at an address or range of addresses.

Parameters:

addrs (typing.Union[int, range]) – Either a range object or a single address.

Return type:

typing.Iterable[gtirb.block.DataBlock]

data_blocks_on(addrs)[source]

Finds all the data blocks that overlap an address or range of addresses.

Parameters:

addrs (typing.Union[int, range]) – Either a range object or a single address.

Return type:

typing.Iterable[gtirb.block.DataBlock]

deep_eq(other)[source]

Check: is self structurally equal to other?

This method should be used only when deep structural equality checks are actually needed, and not for all equality checks. Typically the default implmentation of __eq__, which checks pointer equality, is sufficient; Nodes are cached such that references to two Nodes with the same UUID refer to the same exact object. Use this method when you have manually constructed Nodes that may share the same UUID despite being different objects, and you need to check for structural equality.

Return type:

bool

property ir: IR | None

Get the IR this node ultimately belongs to.

property module: Module | None

The Module this section belongs to.

property size: int | None

Get the size of this section, if known.

The address is calculated from the ByteInterval objects in this section. More specifically, if the address of all byte intervals in this section are fixed, then it will return the difference between the lowest and highest address among the intervals. If any one interval does not have an address, then this will be None, as the size is not calculable in that case. Note that a section with no intervals in it has no address or size, so it will be None in that case.

symbolic_expressions_at(addrs)[source]

Finds all the symbolic expressions that begin at an address or range of addresses.

Parameters:

addrs (typing.Union[int, range]) – Either a range object or a single address.

Return type:

typing.Iterable[typing.Tuple[gtirb.byteinterval.ByteInterval, int, gtirb.symbolicexpression.SymbolicExpression]]

Returns:

Yields (interval, offset, symexpr) tuples for every symbolic expression in the range.