gtirb package¶
Subpackages¶
- gtirb.proto package
- Submodules
- gtirb.proto.AuxData_pb2 module
- gtirb.proto.ByteInterval_pb2 module
- gtirb.proto.CFG_pb2 module
- gtirb.proto.CodeBlock_pb2 module
- gtirb.proto.DataBlock_pb2 module
- gtirb.proto.IR_pb2 module
- gtirb.proto.Module_pb2 module
- gtirb.proto.Offset_pb2 module
- gtirb.proto.ProxyBlock_pb2 module
- gtirb.proto.Section_pb2 module
- gtirb.proto.Symbol_pb2 module
- gtirb.proto.SymbolicExpression_pb2 module
- Module contents
- Submodules
Submodules¶
- gtirb.auxdata module
- gtirb.block module
- gtirb.byteinterval module
ByteInterval
ByteInterval.__init__()
ByteInterval.address
ByteInterval.blocks
ByteInterval.byte_blocks_at()
ByteInterval.byte_blocks_at_offset()
ByteInterval.byte_blocks_on()
ByteInterval.byte_blocks_on_offset()
ByteInterval.code_blocks_at()
ByteInterval.code_blocks_at_offset()
ByteInterval.code_blocks_on()
ByteInterval.code_blocks_on_offset()
ByteInterval.data_blocks_at()
ByteInterval.data_blocks_at_offset()
ByteInterval.data_blocks_on()
ByteInterval.data_blocks_on_offset()
ByteInterval.deep_eq()
ByteInterval.initialized_size
ByteInterval.ir
ByteInterval.module
ByteInterval.section
ByteInterval.size
ByteInterval.symbolic_expressions
ByteInterval.symbolic_expressions_at()
ByteInterval.symbolic_expressions_at_offset()
- gtirb.cfg module
- gtirb.ir module
IR
IR.__init__()
IR.byte_blocks
IR.byte_blocks_at()
IR.byte_blocks_on()
IR.byte_intervals
IR.byte_intervals_at()
IR.byte_intervals_on()
IR.cfg_nodes
IR.code_blocks
IR.code_blocks_at()
IR.code_blocks_on()
IR.data_blocks
IR.data_blocks_at()
IR.data_blocks_on()
IR.deep_eq()
IR.get_by_uuid()
IR.load_protobuf()
IR.load_protobuf_file()
IR.modules_named()
IR.proxy_blocks
IR.save_protobuf()
IR.save_protobuf_file()
IR.sections
IR.sections_at()
IR.sections_on()
IR.symbolic_expressions_at()
IR.symbols
- gtirb.lazyintervaltree module
- gtirb.module module
Module
Module.ByteOrder
Module.FileFormat
Module.ISA
Module.__init__()
Module.byte_blocks
Module.byte_blocks_at()
Module.byte_blocks_on()
Module.byte_intervals
Module.byte_intervals_at()
Module.byte_intervals_on()
Module.cfg_nodes
Module.code_blocks
Module.code_blocks_at()
Module.code_blocks_on()
Module.data_blocks
Module.data_blocks_at()
Module.data_blocks_on()
Module.deep_eq()
Module.ir
Module.sections_at()
Module.sections_on()
Module.symbolic_expressions_at()
Module.symbols_named()
- gtirb.node module
- gtirb.offset module
- gtirb.section module
Section
Section.Flag
Section.__init__()
Section.address
Section.byte_blocks
Section.byte_blocks_at()
Section.byte_blocks_on()
Section.byte_intervals_at()
Section.byte_intervals_on()
Section.code_blocks
Section.code_blocks_at()
Section.code_blocks_on()
Section.data_blocks
Section.data_blocks_at()
Section.data_blocks_on()
Section.deep_eq()
Section.ir
Section.module
Section.size
Section.symbolic_expressions_at()
- gtirb.serialization module
BoolCodec
Codec
CodecError
DecodeError
EncodeError
Float32Codec
Float64Codec
FloatCodec
Int16Codec
Int32Codec
Int64Codec
Int8Codec
IntegerCodec
MappingCodec
OffsetCodec
SequenceCodec
Serialization
SetCodec
StringCodec
SubtypeTree
TupleCodec
TypeNameError
UUIDCodec
Uint16Codec
Uint32Codec
Uint64Codec
Uint8Codec
UnknownCodecError
UnknownData
Variant
VariantCodec
- gtirb.symbol module
- gtirb.symbolicexpression module
SymAddrAddr
SymAddrConst
SymbolicExpression
SymbolicExpression.Attribute
SymbolicExpression.Attribute.ABS
SymbolicExpression.Attribute.CALL
SymbolicExpression.Attribute.DISP
SymbolicExpression.Attribute.DTPMOD
SymbolicExpression.Attribute.DTPOFF
SymbolicExpression.Attribute.DTPREL
SymbolicExpression.Attribute.G0
SymbolicExpression.Attribute.G1
SymbolicExpression.Attribute.G2
SymbolicExpression.Attribute.G3
SymbolicExpression.Attribute.GOT
SymbolicExpression.Attribute.GOTNTPOFF
SymbolicExpression.Attribute.GOTOFF
SymbolicExpression.Attribute.GOTPC
SymbolicExpression.Attribute.GOTREL
SymbolicExpression.Attribute.GPREL
SymbolicExpression.Attribute.H
SymbolicExpression.Attribute.HA
SymbolicExpression.Attribute.HI
SymbolicExpression.Attribute.HI12
SymbolicExpression.Attribute.HI16
SymbolicExpression.Attribute.HI21
SymbolicExpression.Attribute.HIGH
SymbolicExpression.Attribute.HIGHA
SymbolicExpression.Attribute.HIGHER
SymbolicExpression.Attribute.HIGHERA
SymbolicExpression.Attribute.HIGHEST
SymbolicExpression.Attribute.HIGHESTA
SymbolicExpression.Attribute.INDNTPOFF
SymbolicExpression.Attribute.L
SymbolicExpression.Attribute.LO
SymbolicExpression.Attribute.LO12
SymbolicExpression.Attribute.LO14
SymbolicExpression.Attribute.LO15
SymbolicExpression.Attribute.LO16
SymbolicExpression.Attribute.LOWER16
SymbolicExpression.Attribute.NC
SymbolicExpression.Attribute.NOTOC
SymbolicExpression.Attribute.NTPOFF
SymbolicExpression.Attribute.OFST
SymbolicExpression.Attribute.PAGE
SymbolicExpression.Attribute.PAGEOFF
SymbolicExpression.Attribute.PCREL
SymbolicExpression.Attribute.PG
SymbolicExpression.Attribute.PLT
SymbolicExpression.Attribute.PLTOFF
SymbolicExpression.Attribute.PREL
SymbolicExpression.Attribute.PREL31
SymbolicExpression.Attribute.S
SymbolicExpression.Attribute.SBREL
SymbolicExpression.Attribute.SECREL
SymbolicExpression.Attribute.TARGET1
SymbolicExpression.Attribute.TARGET2
SymbolicExpression.Attribute.TLS
SymbolicExpression.Attribute.TLSCALL
SymbolicExpression.Attribute.TLSDESC
SymbolicExpression.Attribute.TLSGD
SymbolicExpression.Attribute.TLSLD
SymbolicExpression.Attribute.TLSLDM
SymbolicExpression.Attribute.TLSLDO
SymbolicExpression.Attribute.TOC
SymbolicExpression.Attribute.TOCBASE
SymbolicExpression.Attribute.TPOFF
SymbolicExpression.Attribute.TPREL
SymbolicExpression.Attribute.UPPER16
SymbolicExpression.Attribute.__int__()
SymbolicExpression.__init__()
SymbolicExpression.deep_eq()
SymbolicExpression.symbols
- gtirb.util module
- gtirb.version module
Module contents¶
- class gtirb.AuxData(data, type_name, lazy_container=None)[source]¶
Bases:
object
AuxData objects can be attached to the
gtirb.IR
or individualgtirb.Module
s to store additional client-specific data in a portable way.AuxData represents a portable, language-independent manner of encoding rich data. To do this, all data is stored on disk as a series of bytes with a string describing the format of the data, called a type name. See
gtirb.serialization
for the list of all default types. Types may also be parameterized; for example,mapping<string,UUID>
is adict
fromstr
objects toUUID
objects. AllAuxData
requires a valid type name in order to be serialized.- Variables:
~.data – The value stored in this AuxData.
~.type_name – A string describing the type of
data
. Used to determine the proper codec for serializing this AuxData.
- __init__(data, type_name, lazy_container=None)[source]¶
- Parameters:
data (
object
) – The value stored in this AuxData.type_name (
str
) – A string describing the type ofdata
. Used to determine the proper codec for serializing this AuxData.lazy_container (
typing.Optional
[gtirb.auxdata._LazyDataContainer
]) – An object that will lazily deserialize the auxdata table backing this object, or None.
- property data: Any¶
-
serializer:
typing.ClassVar
[gtirb.serialization.Serialization
] = <gtirb.serialization.Serialization object>¶ This is a
gtirb.Serialization
instance, used to encode and decodedata
fields of allAuxData
. Seegtirb.serialization
for details.
- class gtirb.AuxDataContainer(aux_data={}, uuid=None)[source]¶
Bases:
Node
The base class for anything that holds AuxData tables; that is,
gtirb.IR
andgtirb.Module
.- Variables:
~.aux_data – The auxiliary data associated with the object, as a mapping from names to
gtirb.AuxData
.
- __init__(aux_data={}, uuid=None)[source]¶
- Parameters:
aux_data (
typing.Union
[typing.Mapping
[str
,gtirb.auxdata.AuxData
],typing.Iterable
[typing.Tuple
[str
,gtirb.auxdata.AuxData
]]]) – The initial auxiliary data to be associated with the object, as a mapping from names togtirb.AuxData
. Defaults to an emptydict
.uuid (
typing.Optional
[uuid.UUID
]) – the UUID of thisAuxDataContainer
, or None if a new UUID needs generated viauuid.uuid4()
. Defaults to None.
- deep_eq(other)[source]¶
This overrides
gtirb.Node.deep_eq()
to check for AuxData equality.Because the values stored by AuxData are not necessarily amenable to deep checking, the auxiliary data dictionaries stored for
self
andother
are not deeply checked. Instead, they are considered to be equal if their sets of keys are equal.- Return type:
bool
- class gtirb.Block(uuid=None)[source]¶
Bases:
Node
The base class for blocks. Symbols may have references to any subclass of Block.
- class gtirb.ByteBlock(*, size=0, offset=0, uuid=None, byte_interval=None)[source]¶
Bases:
Block
The base class for blocks that belong to a
ByteInterval
and store their bytes there.- Variables:
~.size – The size of the block in bytes.
~.offset – The offset from the beginning of the byte interval to which this block belongs. Multiple blocks in the same interval may have the same offset.
- __init__(*, size=0, offset=0, uuid=None, byte_interval=None)[source]¶
- Parameters:
size (
int
) – The size of the data object in bytes.offset (
int
) – The offset from the beginning of the byte interval to which this block belongs.uuid (
typing.Optional
[uuid.UUID
]) – The UUID of thisByteBlock
, or None if a new UUID needs generated viauuid.uuid4()
. Defaults to None.byte_interval (
typing.Optional
[gtirb.byteinterval.ByteInterval
]) – TheByteInterval
this block belongs to.
- property address: int | None¶
Get the address of this block, or None if not present.
- property byte_interval: ByteInterval | None¶
The
ByteInterval
this block belongs to.
- contains_address(address)[source]¶
Indicate if the provided address is within this block. Returns False if the block has no address.
- Return type:
bool
- contains_offset(offset)[source]¶
Indicate if the provided offset is within this block.
- Return type:
bool
- property contents: bytes¶
Get the bytes in this block.
- deep_eq(other)[source]¶
Check: is
self
structurally equal toother
?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
- offset¶
A descriptor that will notify a parent when the value is set and can be otherwise used like a normal attribute.
- size¶
A descriptor that will notify a parent when the value is set and can be otherwise used like a normal attribute.
- class gtirb.ByteInterval(*, address=None, size=None, initialized_size=None, contents=b'', blocks=(), symbolic_expressions={}, uuid=None, section=None)[source]¶
Bases:
Node
A contiguous region of bytes in a binary.
A ByteInterval defines a relative ordering for a group of
ByteBlock
s, optionally at a fixed address in memory. It also stores the bytes associated with these blocks.If two blocks are in two different ByteIntervals, then it should be considered safe (that is, preserving of program semantics) to move one block relative to the other in memory. If two blocks are in the same ByteInterval, then it should be considered unknown if moving the two blocks relative to one another in memory is a safe operation.
- Variables:
~.address – The fixed address of this interval, if present. If this field is present, it may indicate the original address at which this interval was located at in memory, or it may indicate that this block’s address is fixed and must not be changed. If this field is not present, it indicates that the interval is free to be moved around in memory while preserving program semantics.
~.size – The size of this interval in bytes. If this number is greater than
initialized_size
, this indicates that the high addresses taken up by this interval consist of uninitialized bytes. This often occurs in BSS sections, where data is zero-initialized rather than stored as zeroes in the binary.~.contents – The bytes stored in this interval.
~.blocks – A set of all
ByteBlock
s in this interval.~.symbolic_expressions – A mapping, from offset in the interval, to a
SymbolicExpression
in the interval.
- __init__(*, address=None, size=None, initialized_size=None, contents=b'', blocks=(), symbolic_expressions={}, uuid=None, section=None)[source]¶
- Parameters:
address (
typing.Optional
[int
]) – The fixed address of this interval, if present.size (
typing.Optional
[int
]) – The size of this interval in bytes.initialized_size (
typing.Optional
[int
]) – The number of initialized bytes in this interval.contents (
typing.ByteString
) – The bytes stored in this interval.blocks (
typing.Iterable
[gtirb.block.ByteBlock
]) – A set of allByteBlock
s in this interval.symbolic_expressions (
typing.Union
[typing.Mapping
[int
,gtirb.symbolicexpression.SymbolicExpression
],typing.Iterable
[typing.Tuple
[int
,gtirb.symbolicexpression.SymbolicExpression
]]]) – A mapping, from offset in the interval, to aSymbolicExpression
in the interval.uuid (
typing.Optional
[uuid.UUID
]) – The UUID of thisByteInterval
, or None if a new UUID needs generated viauuid.uuid4()
. Defaults to None.section (
typing.Optional
[gtirb.section.Section
]) – TheSection
this interval belongs to.
- address¶
A descriptor that will notify a parent when the value is set and can be otherwise used like a normal attribute.
- 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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.ByteBlock
]
- byte_blocks_at_offset(offsets)[source]¶
Finds all the byte blocks that begin at an offset or range of offsets.
- Parameters:
offsets (
typing.Union
[int
,range
]) – Either arange
object or a single offset.- 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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.ByteBlock
]
- byte_blocks_on_offset(offsets)[source]¶
Finds all the byte blocks that overlap an offset or range of offsets.
- Parameters:
offsets (
typing.Union
[int
,range
]) – Either arange
object or a single offset.- Return type:
typing.Iterable
[gtirb.block.ByteBlock
]
- 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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.CodeBlock
]
- code_blocks_at_offset(offsets)[source]¶
Finds all the code blocks that begin at an offset or range of offsets.
- Parameters:
offsets (
typing.Union
[int
,range
]) – Either arange
object or a single offset.- 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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.CodeBlock
]
- code_blocks_on_offset(offsets)[source]¶
Finds all the code blocks that overlap an offset or range of offsets.
- Parameters:
offsets (
typing.Union
[int
,range
]) – Either arange
object or a single offset.- Return type:
typing.Iterable
[gtirb.block.CodeBlock
]
- 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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.DataBlock
]
- data_blocks_at_offset(offsets)[source]¶
Finds all the data blocks that begin at an offset or range of offsets.
- Parameters:
offsets (
typing.Union
[int
,range
]) – Either arange
object or a single offset.- 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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.DataBlock
]
- data_blocks_on_offset(offsets)[source]¶
Finds all the data blocks that overlap an offset or range of offsets.
- Parameters:
offsets (
typing.Union
[int
,range
]) – Either arange
object or a single offset.- Return type:
typing.Iterable
[gtirb.block.DataBlock
]
- deep_eq(other)[source]¶
Check: is
self
structurally equal toother
?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 initialized_size: int¶
The number of initialized bytes in this interval.
Not all bytes in this interval may correspond to bytes physically stored in the underlying file format. This can occur, for example, in BSS sections, which are zero-initialized at loadtime, but these zeroes are not stored in the file itself. If this number is smaller than
size
, this indicates that any bytes past this number are unitialized bytes with values determined at loadtime. As such, all bytes past this number in this interval’s byte vector are truncated when saving to file.
- size¶
A descriptor that will notify a parent when the value is set and can be otherwise used like a normal attribute.
- property symbolic_expressions: MutableMapping[int, SymbolicExpression]¶
- 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 arange
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.
- symbolic_expressions_at_offset(offsets)[source]¶
Finds all the symbolic expressions that begin at an offset or range of offsets.
- Parameters:
addrs – Either a
range
object or a single offset.- 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.
- class gtirb.CFG(edges=None)[source]¶
Bases:
MutableSet
[Edge
]A control-flow graph for an
IR
. Vertices areCfgNode
s, and edges may optionally containEdge.Label
s.The graph may be viewed simply as a set of
Edge
s. For convenience, theout_edges()
andin_edges()
methods provide access to the outgoing or incoming edges of individual nodes.For efficency, only vertices with edges are guaranteed to be stored in this graph. If you want to find all vertices possible (that is, all
CfgNode
s), useIR.cfg_nodes()
instead.Internally, the graph is stored as a NetworkX instance, which can be accessed using
nx()
. This allows NetworkX’s large library of graph algorithms to be used on CFGs, if desired.- __iter__()[source]¶
- Return type:
typing.Iterator
[gtirb.cfg.Edge
]
- in_edges(node)[source]¶
- Return type:
typing.Iterator
[gtirb.cfg.Edge
]
- out_edges(node)[source]¶
- Return type:
typing.Iterator
[gtirb.cfg.Edge
]
- class gtirb.CfgNode(uuid=None)[source]¶
Bases:
Block
The base class for blocks that may appear as vertices in the CFG.
- class gtirb.CodeBlock(*, decode_mode=DecodeMode.Default, size=0, offset=0, uuid=None, byte_interval=None)[source]¶
-
A basic block in the binary.
Does not directly store data bytes, which are kept in a
ByteInterval
.- Variables:
~.decode_mode – The decode mode of the block, used in some ISAs to differentiate between sub-ISAs (e.g. differentiating blocks written in ARM and Thumb).
- class DecodeMode(value)[source]¶
Bases:
Enum
Variations on decoding a particular ISA
- Default = 0¶
Default decode mode for all ISAs
- Thumb = 1¶
Thumb decode mode for ARM32
- __init__(*, decode_mode=DecodeMode.Default, size=0, offset=0, uuid=None, byte_interval=None)[source]¶
- Parameters:
size (
int
) – The length of the block in bytes.decode_mode (
gtirb.block.CodeBlock.DecodeMode
) – The decode mode of the block, used in some ISAs to differentiate between sub-ISAs (e.g. differentiating blocks written in ARM and Thumb). Defaults to DecodeMode.Default.offset (
int
) – The offset from the beginning of the byte interval to which this block belongs.uuid (
typing.Optional
[uuid.UUID
]) – The UUID of thisCodeBlock
, or None if a new UUID needs generated viauuid.uuid4()
. Defaults to None.byte_interval (
typing.Optional
[gtirb.byteinterval.ByteInterval
]) – TheByteInterval
this block belongs to.
- deep_eq(other)[source]¶
Check: is
self
structurally equal toother
?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
- class gtirb.DataBlock(*, size=0, offset=0, uuid=None, byte_interval=None)[source]¶
Bases:
ByteBlock
Represents a data object, possibly symbolic.
- __init__(*, size=0, offset=0, uuid=None, byte_interval=None)[source]¶
- Parameters:
size (
int
) – The size of the data object in bytes.offset (
int
) – The offset from the beginning of the byte interval to which this block belongs.uuid (
typing.Optional
[uuid.UUID
]) – The UUID of thisDataBlock
, or None if a new UUID needs generated viauuid.uuid4()
. Defaults to None.byte_interval (
typing.Optional
[gtirb.byteinterval.ByteInterval
]) – TheByteInterval
this block belongs to.
- class gtirb.Edge(source: CfgNode, target: CfgNode, label: EdgeLabel | None = None)[source]¶
Bases:
NamedTuple
An edge in the CFG from
source
totarget
, with optional control-flow details inlabel
.- Variables:
~.source – The source CFG node.
~.target – The target CFG node.
~.label – An optional label containing more control flow information.
- static __new__(cls, source, target, label=None)[source]¶
Create new instance of NamedTuple(source, target, label)
- Return type:
- __slots__ = ()¶
- class gtirb.EdgeLabel(type: EdgeType, conditional: bool = False, direct: bool = True)[source]¶
Bases:
tuple
Contains a more detailed description of a
gtirb.Edge
in the CFG.- Variables:
~.conditional – When this edge is part of a conditional branch,
conditional
isTrue
when the edge represents the control flow taken when the branch’s condition is met, andFalse
when it represents the control flow taken when the branch’s condition is not met. Otherwise, it is alwaysFalse
.~.direct –
True
if the branch or call is direct, andFalse
if it is indirect. If an edge is indirect, then all outgoing indirect edges represent the set of possible locations the edge may branch to. If there exists an indirect outgoing edge to agtirb.ProxyBlock
without anygtirb.Symbol
objects referring to it, then the set of all possible branch locations is unknown.~.type – The type of control flow the
gtirb.Edge
represents.
- __getnewargs__()¶
Return self as a plain tuple. Used by copy and pickle.
- __slots__ = ()¶
-
conditional:
bool
¶ Alias for field number 1
-
direct:
bool
¶ Alias for field number 2
-
type:
gtirb.cfg.EdgeType
¶ Alias for field number 0
- class gtirb.EdgeType(value)[source]¶
Bases:
Enum
The type of control flow transfer indicated by a
gtirb.Edge
.- Branch = 0¶
This edge is the explicit target of a jump instruction. May be conditional or unconditional. If conditional, there will be a corresponding edge of type
gtirb.Edge.Type.Fallthrough
.
- Call = 1¶
This edge is the explicit target of a call instruction. Unless the function does not return, there will also be a corresponding edge of type
gtirb.Edge.Type.Fallthrough
.
- Fallthrough = 2¶
This edge represents two blocks executing in sequence. This occurs on the non-branching paths of conditional branch instructions, after call instructons have returned, and when two blocks have no control flow between them, but another
gtirb.Edge
targets the target block. If there exists a fallthrough edge from blockA
to blockB
, thenA
must immediately precedeB
in memory.
- Return = 3¶
This edge represents a return from a function, generally via a return instruction. Return edges may either go to a symbolless
gtirb.ProxyBlock
, which indicates that the set of possible return targets is unknown, or there may be one return edge per return target, which indicates that the set of possible return targets if fully known.
- Syscall = 4¶
This edge is the explicit target of a system call instruction. Unless the function does not return, there will also be a corresponding edge of type
gtirb.Edge.Type.Fallthrough
. This is the system call equivalent togtirb.Edge.Type.Call
.
- Sysret = 5¶
This edge represents a return from a system call, generally via a return instruction. Return edges may either go to a symbolless
gtirb.ProxyBlock
, which indicates that the set of possible return targets is unknown, or there may be one return edge per return target, which indicates that the set of possible return targets if fully known. This is the system call equivalent togtirb.Edge.Type.Return
.
- class gtirb.IR(*, modules=[], aux_data={}, cfg={}, version=4, uuid=None)[source]¶
Bases:
AuxDataContainer
A complete internal representation consisting of multiple Modules.
- Variables:
~.modules – A list of
Module
s contained in the IR.~.cfg – The IR’s control flow graph.
~.version – The Protobuf version of this IR.
- __init__(*, modules=[], aux_data={}, cfg={}, version=4, uuid=None)[source]¶
- Parameters:
modules (
typing.Iterable
[gtirb.module.Module
]) – A list of Modules contained in the IR.cfg (
typing.Iterable
[gtirb.cfg.Edge
]) – A set ofEdge
s representing the IR’s control flow graph. Defaults to being empty.aux_data (
typing.Union
[typing.Mapping
[str
,gtirb.auxdata.AuxData
],typing.Iterable
[typing.Tuple
[str
,gtirb.auxdata.AuxData
]]]) – The initial auxiliary data to be associated with the object, as a mapping from names togtirb.AuxData
. Defaults to being empty.version (
int
) – The Protobuf version of this IR.uuid (
typing.Optional
[uuid.UUID
]) – The UUID of thisIR
, or None if a new UUID needs generated viauuid.uuid4()
. Defaults to None.
- 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 arange
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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.ByteBlock
]
- property byte_intervals: Iterator[ByteInterval]¶
The
ByteInterval
s in this IR.
- 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 arange
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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.byteinterval.ByteInterval
]
- 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 arange
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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.CodeBlock
]
- 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 arange
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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.DataBlock
]
- deep_eq(other)[source]¶
This overrides
gtirb.Node.deep_eq()
to check for AuxData equality.Because the values stored by AuxData are not necessarily amenable to deep checking, the auxiliary data dictionaries stored for
self
andother
are not deeply checked. Instead, they are considered to be equal if their sets of keys are equal.- Return type:
bool
- get_by_uuid(uuid)[source]¶
Look up a node by its UUID.
This method will find any node currently attached to this IR. It will not find any nodes attached to other IRs, or not attached to any IR.
- Parameters:
uuid (
uuid.UUID
) – The UUID to look up.- Return type:
typing.Optional
[gtirb.node.Node
]- Returns:
The Node this UUID corresponds to, or None if no node exists with that UUID.
- static load_protobuf(file_name)[source]¶
Load IR from a Protobuf file at the specified path.
- Parameters:
file_name – The path to the Protobuf file.
- Returns:
A Python GTIRB IR object.
- static load_protobuf_file(protobuf_file)[source]¶
Load IR from a Protobuf object.
Use this function when you have a Protobuf object already loaded, and you want to parse it as a GTIRB IR. If the Protobuf object is stored in a file, use
gtirb.IR.load_protobuf()
instead.- Parameters:
protobuf_file (
typing.BinaryIO
) – A byte stream encoding a GTIRB Protobuf message.- Return type:
- Returns:
An IR object representing the same information that is contained in
protobuf_file
.
- modules_named(name)[source]¶
Find all modules with a given name
- Return type:
typing.Iterator
[gtirb.module.Module
]
- property proxy_blocks: Iterator[ProxyBlock]¶
The
ProxyBlock
s in this IR.
- save_protobuf(file_name)[source]¶
Save
self
to a Protobuf file at the specified path.- Parameters:
file_name – The file path at which to save the Protobuf representation of
self
.
- save_protobuf_file(protobuf_file)[source]¶
Save
self
to a Protobuf object.- Parameters:
protobuf_file (
typing.BinaryIO
) – The byte stream to write the GTIRB Protobuf message to.- Return type:
None
- sections_at(addrs)[source]¶
Finds all the sections that begin at an address or range of addresses.
- Parameters:
addrs (
typing.Union
[int
,range
]) – Either arange
object or a single address.- Return type:
typing.Iterable
[gtirb.section.Section
]
- sections_on(addrs)[source]¶
Finds all the sections that overlap an address or range of addresses.
- Parameters:
addrs (
typing.Union
[int
,range
]) – Either arange
object or a single address.- Return type:
typing.Iterable
[gtirb.section.Section
]
- 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 arange
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.
- class gtirb.Module(*, name, aux_data={}, binary_path='', file_format=FileFormat.Undefined, isa=ISA.Undefined, byte_order=ByteOrder.Undefined, preferred_addr=0, proxies={}, rebase_delta=0, sections={}, symbols={}, entry_point=None, uuid=None, ir=None)[source]¶
Bases:
AuxDataContainer
Represents a loadable object, such as an executable or library.
- Variables:
~.binary_path – The path to the loadable binary object represented by this module. An empty string if not specified. The file represented by this path is indicitave of what file this
Module
was initially created from; it is not guaranteed to currently exist or have the same contents.~.isa – The ISA of the binary.
~.file_format – The file format of the binary.
~.byte_order – The endianness of the binary.
~.name – The name given to the binary. Some file formats use this for linking and/or symbol resolution purposes. The file name (without directory components) if not specified by the format.
~.preferred_addr – The preferred loading address of the binary.
~.proxies – A set containing all the
gtirb.ProxyBlock
s in the binary.~.rebase_delta – The rebase delta of the binary.
~.sections – A set containing all the
gtirb.Section
s in the binary.~.symbols – A set containing all the
gtirb.Symbol
s in the binary.~.entry_point – A
CodeBlock
representing where control flow of this module begins at, or None if not present.
- class ByteOrder(value)[source]¶
Bases:
Enum
Identifies the endianness of a
gtirb.Module
.- Big = 1¶
Big endian.
- Little = 2¶
Little endian.
- Undefined = 0¶
An unknown or uninitialized endianness.
- class FileFormat(value)[source]¶
Bases:
Enum
Identifies the executable file format of the binary represented by a
gtirb.Module
.- COFF = 1¶
The Common Object File Format.
- ELF = 2¶
The Executable and Linkable Format, formerly the Extensible Linking Format.
- IdaProDb32 = 4¶
A 32-bit IDA Pro database file.
- IdaProDb64 = 5¶
A 64-bit IDA Pro database file.
- MACHO = 7¶
A Mach object file.
- PE = 3¶
Microsoft’s Portable Executable format.
- RAW = 8¶
A raw binary file, with no file format.
- Undefined = 0¶
A file format that has not yet been specified. This is for unitialized modules; do not use to refer to file formats without
FileFormat
values.
- XCOFF = 6¶
The Extended Common Object File Format.
- class ISA(value)[source]¶
Bases:
Enum
Identifies the instruction set architecture (ISA) targeted by a
gtirb.Module
.- ARM = 4¶
The Acorn RISC Machine, 32-bit.
- ARM64 = 7¶
The Acorn RISC Machine, 64-bit.
- IA32 = 1¶
The 32-bit Intel Architecture. Also known as i386, x86, or x32.
- MIPS32 = 8¶
Microprocessor without Interlocked Pipelined Stages, 32-bit.
- MIPS64 = 9¶
Microprocessor without Interlocked Pipelined Stages, 64-bit.
- PPC32 = 2¶
IBM’s 32-bit PowerPC (Performance Optimization with Enhanced RISC / Performance Computing) architecture.
- PPC64 = 6¶
IBM’s 64-bit PowerPC (Performance Optimization with Enhanced RISC / Performance Computing) architecture.
- Undefined = 0¶
An ISA that has not yet been specified. This is for unitialized modules; use
gtirb.Module.ISA.ValidButUnsupported
instead for specifying undefined ISAs.
- ValidButUnsupported = 5¶
An unknown or undefined ISA.
- X64 = 3¶
The 64-bit Intel Architecture. Also known as x86_64.
- __init__(*, name, aux_data={}, binary_path='', file_format=FileFormat.Undefined, isa=ISA.Undefined, byte_order=ByteOrder.Undefined, preferred_addr=0, proxies={}, rebase_delta=0, sections={}, symbols={}, entry_point=None, uuid=None, ir=None)[source]¶
- Parameters:
aux_data (
typing.Union
[typing.Mapping
[str
,gtirb.auxdata.AuxData
],typing.Iterable
[typing.Tuple
[str
,gtirb.auxdata.AuxData
]]]) – The initial auxiliary data to be associated with the object, as a mapping from names togtirb.AuxData
, defaults to an emptydict
.binary_path (
str
) – The path to the loadable binary object represented by this module.isa (
gtirb.module.Module.ISA
) – The ISA of the binary.byte_order (
gtirb.module.Module.ByteOrder
) – The endianness of the binary.file_format (
gtirb.module.Module.FileFormat
) – The file format of the binary.name (
str
) – The name given to the binary.preferred_addr (
int
) – The preferred loading address of the binary.proxies (
typing.Iterable
[gtirb.block.ProxyBlock
]) – A set containing all thegtirb.ProxyBlock
s in the binary.rebase_delta (
int
) – The rebase delta of the binary.sections (
typing.Iterable
[gtirb.section.Section
]) – A set containing all thegtirb.Section
s in the binary.symbols (
typing.Iterable
[gtirb.symbol.Symbol
]) – A set containing all thegtirb.Symbol
s in the binary.entry_point (
typing.Optional
[gtirb.block.CodeBlock
]) – ACodeBlock
representing where control flow of this module begins at, or None if not present.uuid (
typing.Optional
[uuid.UUID
]) – The UUID of thisModule
, or None if a new UUID needs generated viauuid.uuid4()
. Defaults to None.ir (
typing.Optional
[gtirb.ir.IR
]) – TheIR
this module belongs to.
- 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 arange
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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.ByteBlock
]
- property byte_intervals: Iterator[ByteInterval]¶
The
ByteInterval
s in this module.
- 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 arange
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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.byteinterval.ByteInterval
]
- 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 arange
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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.CodeBlock
]
- 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 arange
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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.DataBlock
]
- deep_eq(other)[source]¶
This overrides
gtirb.Node.deep_eq()
to check for AuxData equality.Because the values stored by AuxData are not necessarily amenable to deep checking, the auxiliary data dictionaries stored for
self
andother
are not deeply checked. Instead, they are considered to be equal if their sets of keys are equal.- Return type:
bool
- sections_at(addrs)[source]¶
Finds all the sections that begin at an address or range of addresses.
- Parameters:
addrs (
typing.Union
[int
,range
]) – Either arange
object or a single address.- Return type:
typing.Iterable
[gtirb.section.Section
]
- sections_on(addrs)[source]¶
Finds all the sections that overlap an address or range of addresses.
- Parameters:
addrs (
typing.Union
[int
,range
]) – Either arange
object or a single address.- Return type:
typing.Iterable
[gtirb.section.Section
]
- 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 arange
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.
- symbols_named(name)[source]¶
Finds all symbols with a given name.
- Return type:
typing.Iterator
[gtirb.symbol.Symbol
]
- class gtirb.Node(uuid=None)[source]¶
Bases:
object
A Node is any GTIRB object which can be referenced by UUID.
- Variables:
~.uuid – The UUID of this Node.
- __init__(uuid=None)[source]¶
- Parameters:
uuid (
typing.Optional
[uuid.UUID
]) – The UUID of thisNode
, or None if a new UUID needs generated viauuid.uuid4()
. Defaults to None.
- deep_eq(other)[source]¶
Check: is
self
structurally equal toother
?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
- class gtirb.Offset(element_id, displacement)[source]¶
Bases:
NamedTuple
An Offset describes a location inside a
gtirb.Node
, such as agtirb.DataBlock
orgtirb.ByteInterval
.- Variables:
~.element_id – The
gtirb.Node
containing the location of interest.~.displacement – The offset inside the Node to point to.
- class gtirb.ProxyBlock(*, uuid=None, module=None)[source]¶
Bases:
CfgNode
A placeholder that serves as the endpoint (source or target) of a
gtirb.Edge
.ProxyBlock objects allow the construction of CFG edges to or from another node. For example, a call to a function in another module may be represented by a
gtirb.Edge
that originates at the callinggtirb.CodeBlock
and targets a ProxyBlock. Another example would be agtirb.Edge
that represents an indirect jump whose target is not known.A ProxyBlock does not represent any instructions and so has neither an address nor a size.
- __init__(*, uuid=None, module=None)[source]¶
- Parameters:
uuid (
typing.Optional
[uuid.UUID
]) – The UUID of thisNode
, or None if a new UUID needs generated viauuid.uuid4()
. Defaults to None.
- deep_eq(other)[source]¶
Check: is
self
structurally equal toother
?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
- class gtirb.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
ByteInterval
s in this section.~.flags – The
Section.Flag
s 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
]) – TheByteInterval
s in this section.flags (
typing.Iterable
[gtirb.section.Section.Flag
]) – TheSection.Flag
s this section has.uuid (
typing.Optional
[uuid.UUID
]) – The UUID of thisSection
, or None if a new UUID needs generated viauuid.uuid4()
. Defaults to None.module (
typing.Optional
[gtirb.module.Module
]) – TheModule
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 beNone
, 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 beNone
in that case.
- 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 arange
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 arange
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 arange
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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.byteinterval.ByteInterval
]
- 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 arange
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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.CodeBlock
]
- 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 arange
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 arange
object or a single address.- Return type:
typing.Iterable
[gtirb.block.DataBlock
]
- deep_eq(other)[source]¶
Check: is
self
structurally equal toother
?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 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 beNone
, 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 beNone
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 arange
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.
- class gtirb.Serialization[source]¶
Bases:
object
Manages codecs used to serialize and deserialize GTIRB objects.
The
gtirb.Serialization.decode()
method ofgtirb.AuxData.serializer
is called when GTIRB AuxData is loaded viagtirb.IR.load_protobuf()
, and thegtirb.Serialization.encode()
method ofgtirb.AuxData.serializer
is called when GTIRB AuxData is saved to file viagtirb.IR.save_protobuf()
. You can alter the encoding and decoding of AuxData values viagtirb.Serialization.codecs
. To do this, create a new subclass ofgtirb.serialization.Codec
and add it togtirb.Serialization.codecs
:>>> gtirb.AuxData.serializer.codecs['my_custom_type'] = MyCustomCodec
This example registers a new type name,
my_custom_type
, and associate it with a new codec,MyCustomCodec
.- Variables:
~.codecs – A mapping of type names to codecs. Codecs can be added or overridden using this dictionary.
- decode(raw_bytes, type_name, get_by_uuid=None)[source]¶
Decode a
gtirb.AuxData
of the specified type from the specified byte stream.- Parameters:
raw_bytes (
typing.Union
[bytes
,bytearray
,memoryview
,typing.BinaryIO
]) – The byte stream from which to read the encoded value.type_name (
str
) – The type name of the object encoded byraw_bytes
.get_by_uuid (
typing.Optional
[typing.Callable
[[uuid.UUID
],typing.Optional
[gtirb.node.Node
]]]) – A function to look up nodes by UUID.
- Return type:
object
- Returns:
The object encoded by
raw_bytes
.
- encode(out, val, type_name)[source]¶
Encodes the value of an AuxData value to bytes.
- Parameters:
out (
typing.BinaryIO
) – A binary stream to write bytes to.val (
object
) – Thegtirb.AuxData
to encode.type_name (
str
) – The type name of the value encapsulated by thegtirb.AuxData
.
- Return type:
None
- class gtirb.SymAddrAddr(scale, offset, symbol1, symbol2, attributes={})[source]¶
Bases:
SymbolicExpression
Represents a symbolic expression of the form “(Sym1 - Sym2) / Scale + Offset”.
- Variables:
~.scale – Constant scale factor.
~.offset – Constant offset.
~.symbol1 – Symbol representing the base address.
~.symbol2 – Symbol to subtract from
symbol1
.
- __init__(scale, offset, symbol1, symbol2, attributes={})[source]¶
- Parameters:
scale (
int
) – Constant scale factor.offset (
int
) – Constant offset.symbol1 (
gtirb.symbol.Symbol
) – Symbol representing the base address.symbol2 (
gtirb.symbol.Symbol
) – Symbol to subtract fromsymbol1
.attributes (
typing.Iterable
[typing.Union
[int
,gtirb.symbolicexpression.SymbolicExpression.Attribute
]]) –SymobolicExpression.Attribute
s of this expression.
- class gtirb.SymAddrConst(offset, symbol, attributes={})[source]¶
Bases:
SymbolicExpression
Represents a symbolic expression of the form “Sym + Offset”.
- Variables:
~.offset – Constant offset.
~.symbol – Symbol representing an address.
- __init__(offset, symbol, attributes={})[source]¶
- Parameters:
offset (
int
) – Constant offset.symbol (
gtirb.symbol.Symbol
) – Symbol representing an address.attributes (
typing.Iterable
[typing.Union
[int
,gtirb.symbolicexpression.SymbolicExpression.Attribute
]]) –SymbolicExpression.Attribute
s of this expression.
- class gtirb.Symbol(name, uuid=None, payload=None, at_end=False, module=None)[source]¶
Bases:
Node
Represents a symbol, which maps a name to an object in the IR.
- Variables:
~.name – The name of this symbol.
~.at_end – True if this symbol is at the end of its referent, rather than at the beginning. Has no meaning for integral symbols.
- __init__(name, uuid=None, payload=None, at_end=False, module=None)[source]¶
- Parameters:
name (
str
) – The name of this symbol.uuid (
typing.Optional
[uuid.UUID
]) – The UUID of thisSymbol
, or None if a new UUID needs generated viauuid.uuid4()
. Defaults to None.payload (
typing.Union
[gtirb.block.Block
,int
,None
]) – The value this symbol points to. May be an address, a Node, or None.at_end (
bool
) – True if this symbol is at the end of its referent, rather than at the beginning.module (
typing.Optional
[gtirb.module.Module
]) – TheModule
this symbol belongs to.
- deep_eq(other)[source]¶
Check: is
self
structurally equal toother
?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
- name¶
A descriptor that will notify a parent when the value is set and can be otherwise used like a normal attribute.
- property referent: Block | None¶
The object referred to by a Symbol, which is
Block
or None.value
andreferent
are mutually exclusive.
- property value: int | None¶
The value of a Symbol, which is an integer or None.
value
andreferent
are mutually exclusive.
- class gtirb.SymbolicExpression(attributes={})[source]¶
Bases:
object
Base class of symbolic expression types.
- class Attribute(value)[source]¶
Bases:
Enum
Attributes representing a known property of a symbolic expression. See https://grammatech.github.io/gtirb/md__symbolic_expression.html
- ABS = 2015¶
- CALL = 22¶
- DISP = 3003¶
- DTPMOD = 19¶
- DTPOFF = 17¶
- DTPREL = 16¶
- G0 = 2001¶
- G1 = 2002¶
- G2 = 2003¶
- G3 = 2004¶
- GOT = 0¶
- GOTNTPOFF = 1000¶
- GOTOFF = 2¶
- GOTPC = 1¶
- GOTREL = 3¶
- GPREL = 3002¶
- H = 4000¶
- HA = 4002¶
- HI = 24¶
- HI12 = 2010¶
- HI16 = 3000¶
- HI21 = 2011¶
- HIGH = 4003¶
- HIGHA = 4004¶
- HIGHER = 25¶
- HIGHERA = 4005¶
- HIGHEST = 26¶
- HIGHESTA = 4006¶
- INDNTPOFF = 1001¶
- L = 4001¶
- LO = 23¶
- LO12 = 2007¶
- LO14 = 2009¶
- LO15 = 2008¶
- LO16 = 3001¶
- LOWER16 = 2006¶
- NC = 2014¶
- NOTOC = 4009¶
- NTPOFF = 18¶
- OFST = 3004¶
- PAGE = 20¶
- PAGEOFF = 21¶
- PCREL = 6¶
- PG = 2013¶
- PLT = 4¶
- PLTOFF = 5¶
- PREL = 2016¶
- PREL31 = 2017¶
- S = 2012¶
- SBREL = 2020¶
- SECREL = 7¶
- TARGET1 = 2018¶
- TARGET2 = 2019¶
- TLS = 8¶
- TLSCALL = 12¶
- TLSDESC = 13¶
- TLSGD = 9¶
- TLSLD = 10¶
- TLSLDM = 11¶
- TLSLDO = 2021¶
- TOC = 4008¶
- TOCBASE = 4007¶
- TPOFF = 15¶
- TPREL = 14¶
- UPPER16 = 2005¶