3.1.6. structure – Structure module¶
This module exposes a number of tools and defines some classes that can be used to interacting with the structures defined in the database. The classes defined by this module wrap IDAPython’s structure API and expose a simpler interface that can be used to perform various operations against a structure such as renaming or enumerating the structure’s members.
The base argument type for getting a structure_t can be either a name,
an identifier, or an index. Typically one will call structure.by
with either identifier type which will then return an instance of their
structure_t.
To list the different structures available in the database, one can use
structure.list with their chosen method of filtering. This will
list all of the available structures at which point the user can then
request it by passing an identifer to structure.by. The chosen
methods of filtering are:
name- Match the structures to a structure namelike- Filter the structure names according to a globregex- Filter the structure names according to a regular-expressionindex- Match the structures by its indexidentifierorid- Match the structure by its id which is aidaapi.uval_tsize- Filter the structures for any matching the specified sizegreaterorge- Match structures that are larger (inclusive) than the specified sizegt- Match structures that are larger (exclusive) than the specified sizelessorle- Match structures that are smaller (inclusive) than the specified sizelt- Match structures that are smaller (exclusive) than the specified sizepredicate- Filter the structures by passing the id (idaapi.uval_t) to a callable
Some examples of using these keywords are as follows:
> structure.list('my*')
> iterable = structure.iterate(regex='__.*')
> result = structure.search(index=42)
3.1.6.1. Function list¶
The functions that are available in this module use multicased functions and aliases. For more information on this, please see Aliases and Multicased functions.
-
structure.by(name, *suffix, **options)¶ Return the structure with the given
name.Parameters: - name (str) – the name of the structure to return
- *suffix – any other numbers or strings that should be appended to the name
- **options – if
offsetis specified, then use it as the base offset of the structure
-
structure.by(id, **options) Return the structure with the specified
idor index.Parameters: - id (int or long) – the identifier or the index of the structure to return
- **options – if
offsetis specified, then use it as the base offset of the structure
-
structure.by(sptr, **options) Return the structure for the specified
sptr.Parameters: - sptr (idaapi.struc_t or structure_t) – the
idaapi.struc_tto return - **options – if
offsetis specified, then use it as the base offset of the structure
- sptr (idaapi.struc_t or structure_t) – the
-
structure.by(tinfo, **options) Return the structure for the specified
tinfo.Parameters: - tinfo (idaapi.tinfo_t) – the
idaapi.tinfo_tto return the structure for - **options –
- tinfo (idaapi.tinfo_t) – the
-
structure.by(**type) Return the structure matching the keyword specified by
type.Parameters: **type – any keyword that can be used to match the structure with
-
structure.by_identifier(identifier, **options)¶ Return the structure identified by
identifier.Aliases:
structure.byid,structure.by_id,structure.byidentifierParameters: - identifier – the identifier of the structure to return
- **options – if
offsetis specified, then use it as the base offset of the structure
-
structure.by_index(index, **options)¶ Return a structure by its index.
Aliases:
structure.byindexParameters: - index – the index of the structure to return
- **options – if
offsetis specified, then use it as the base offset of the structure
-
structure.by_name(name, *suffix, **options)¶ Return a structure by its name.
Aliases:
structure.bynameParameters: - name – the name of the structure to return
- *suffix – any other numbers or strings that should be appended to the name
- **options – if
offsetis specified, then use it as the base offset of the structure
-
structure.comment(id, **repeatable)¶ Return the comment of the structure identified by
id.If the bool
repeatableis specified, return the repeatable comment.Parameters: - id (int or long) – the identifier of the structure
- **repeatable – whether the comment should be repeatable or not
-
structure.comment(structure, **repeatable) Return the comment for the specified
structure.Parameters: - structure (structure_t) – the
structure_tto return the comment for - **repeatable – whether the comment should be repeatable or not
- structure (structure_t) – the
-
structure.comment(structure, cmt, **repeatable) Set the comment to
cmtfor the specifiedstructure.Parameters: - structure (structure_t) – the
structure_tto apply the comment to - cmt (str) – the comment to apply
- **repeatable – whether the comment should be repeatable or not
- structure (structure_t) – the
-
structure.comment(structure, none, **repeatable) Remove the comment from the specified
structure.Parameters: - structure (structure_t) – the
structure_tto remove the comment from - none (None) – the python value
None - **repeatable – whether the removed comment should be the repeatable one
- structure (structure_t) – the
-
structure.comment(id, cmt, **repeatable) Set the comment of the structure identified by
idtocmt.If the bool
repeatableis specified, set the repeatable comment.Parameters: - id (int or long) – the identifier of the structure
- cmt (str) – the comment to apply
- **repeatable – whether the comment should be repeatable or not
-
structure.comment(id, none, **repeatable) Remove the comment from the structure identified by
id.Parameters: - id (int or long) – the identifier of the structure
- none (None) – the python value
None - **repeatable – whether the removed comment should be the repeatable one
-
structure.fragment(structure, offset, **base)¶ Yield each member of the given
structurefrom the specifiedoffsetas a tuple containing its attributes.Parameters: - structure – the structure to yield the members from
- offset (int or long) – the starting offset of the fragment
- **base –
-
structure.fragment(structure, offset, size, **base) Yield each member of the given
structurefrom the specifiedoffsetup tosizeas a tuple containing its attributes.Parameters: - structure – the structure to yield the members from
- offset (int or long) – the starting offset of the fragment
- size (int or long) – the size of the members to yield
- **base –
-
structure.fragment(id, offset, size, **base) Yield each member of the structure with the specified
idfrom the givenoffsetup tosizeas a tuple containing its(offset, size, tags).If the integer
baseis defined, then the offset of each member will be translated by the given value.Parameters: - id (int or long) – the identifer of the structure to yield the members from
- offset (int or long) – the starting offset of the fragment
- size (int or long) – the size of the members to yield
- **base –
-
structure.has(id)¶ Return whether a structure with the specified
idexists within the database.Parameters: id (int or long) – the identifier or the index of the structure to check
-
structure.has(name, *suffix) Return if a structure with the specified
nameexists within the database.Parameters: - name (str) – the name of the structure to check
- *suffix – any other numbers or strings that should be appended to the name
-
structure.has(structure) Return whether the database includes the provided
structure.Parameters: structure (idaapi.struc_t or structure_t) – the idaapi.struc_tor thestructure_tto check
-
structure.index(id)¶ Return the index of the structure identified by
id.Parameters: id (int or long) – the identifier of the structure to return the index for
-
structure.index(structure) Return the index of the specified
structure.Parameters: structure (structure_t) – the structure_tto return the index for
-
structure.index(id, index) Move the structure identified by
idto the specifiedindexin the structure list.Parameters: - id (int or long) – the identifier of the structure
- index (int or long) – the index to move the structure to
-
structure.index(structure, index) Move the specified
structureto the specifiedindexin the structure list.Parameters: - structure (structure_t) – the
structure_tto move - index (int or long) – the index to move the structure to
- structure (structure_t) – the
-
structure.is_frame(id)¶ Return whether the structure identified by
idis a frame or not.Aliases:
structure.isframe,structure.frameQParameters: id (int or long) – the identifier of the structure to check
-
structure.is_frame(structure) Return whether the provided
structureis a frame or not.Aliases:
structure.isframe,structure.frameQParameters: structure (idaapi.struc_t or structure_t) – the idaapi.struc_torstructure_tto check
-
structure.is_union(id)¶ Return whether the structure identified by
idis a union or not.Aliases:
structure.unionQ,structure.isunionParameters: id (int or long) – the identifier of the structure to check
-
structure.is_union(structure) Return whether the provided
structureis defined as a union.Aliases:
structure.unionQ,structure.isunionParameters: structure (idaapi.struc_t or structure_t) – the idaapi.struc_torstructure_tto check
-
structure.iterate(string, *suffix)¶ Iterate through all of the structures in the database with a glob that matches
string.Parameters: - string (str) – the glob to filter the structure names with
- *suffix – any other numbers or strings that should be appended to the name
-
structure.iterate(**type) Iterate through all of the structures that match the keyword specified by
type.Parameters: **type – any keyword that can be used to filter structures with
-
structure.list(string, *suffix)¶ List any structures that match the glob in
string.Parameters: - string (str) – the glob to filter the structure names with
- *suffix – any other numbers or strings that should be appended to the name
-
structure.list(**type) List all the structures within the database that match the keyword specified by
type.Parameters: **type – any keyword that can be used to filter structures with
-
structure.members(structure, **base)¶ Yield each member of the given
structureas a tuple containing its attributes.Parameters: - structure – the structure to yield the members from
- **base – a base address to translate the offset of each yielded member with
-
structure.members(id, **base) Yield each member of the structure with the specified
idas a tuple of containing its(offset, size, tags).If the integer
baseis defined, then the offset of each member will be translated by the given value.Parameters: - id (int or long) – the identifier of the structure to yield the members from
- **base – a base address to translate the offset of each yielded member with
-
structure.name(id)¶ Return the name of the structure identified by
id.Parameters: id – the identifier of the structure to return the name of
-
structure.name(structure) Parameters: structure (structure_t) – the structure_tto return the name of
-
structure.name(id, string, *suffix) Set the name of the structure identified by
idtostring.Parameters: - id – the identifier of the structure to return the name for
- string (str) – the name to rename the structure to
- *suffix – any other numbers or strings to append to the base name
-
structure.name(structure, string, *suffix) Set the name of the specified
structuretostring.Parameters: - structure (structure_t) – the
structure_tto rename - string (str) – the name to rename the structure to
- *suffix – any other numbers or strings to append to the base name
- structure (structure_t) – the
-
structure.new(string, *suffix, **offset)¶ Return a new structure using the name specified by
string.If the integer
offsetis provided, then use it as the base offset for the newly created structure.Parameters: - string (str or tuple) – a string to use as the name
- *suffix – any other numbers or strings to append to the name
- **offset – the base offset of the structure that is being created
-
structure.remove(structure)¶ Remove the specified
structurefrom the database.Aliases:
structure.deleteParameters: structure (structure_t) – the structure_tto remove from the database
-
structure.remove(name, *suffix) Remove the structure with the specified
name.Aliases:
structure.deleteParameters: - name (str) – the name of the structure to remove from the database
- *suffix – any other numbers or strings that should be appended to the name
-
structure.remove(id) Remove a structure by its index or
id.Aliases:
structure.deleteParameters: id (int or long) – the identifier of the structure to remove from the database
-
structure.remove(**type) Remove the first structure that matches the result described by
type.Aliases:
structure.deleteParameters: **type – any keyword that can be used to match the structure with
-
structure.search(string, *suffix)¶ Search through all the structure names matching the glob
string.Parameters: - string (str) – the glob to match the structure name with
- *suffix – any other numbers or strings that should be appended to the name
-
structure.search(**type) Search through all of the structures and return the first result matching the keyword specified by
type.Parameters: **type – any keyword that can be used to filter the structures with
-
structure.select(tag, *And, **boolean)¶ Query all of the structure tags for the specified
tagand any others specified asAnd.Parameters: - tag (str) – a required tag name to search for
- *And – any other required tag names
- **boolean – either
AndorOrwhich specifies required or optional tags (respectively)
-
structure.select(**boolean) Query all the structures (linearly) for any tags specified by
boolean. Yields each address found along with the matching tags as a dictionary.If
Andcontains an iterable then require the returned structure contains them. IfOrcontains an iterable then include any other tags that are specified.Parameters: **boolean – either AndorOrwhich specifies required or optional tags (respectively)
-
structure.size(structure)¶ Return the size of the specified
structure.Parameters: structure (structure_t) – the structure_tto return the size for
-
structure.size(id) Return the size of the structure identified by
id.Parameters: id (int or long) – the identifier of the structure to return the size for
3.1.6.2. Class list¶
Classes provide the definition necessary to instantiate an object. In most cases, a class is returned when calling one of the prior listed functions and thus have no need to be manually instantiated. Classes may also have aliases defined for them. Please refer to the documentation for the class to see what is available. For more information on aliases, please see Aliases.
3.1.6.2.1. member_t¶
-
class
structure.member_t¶ This object is an abstraction around a single member belonging to a structure. A member within a structue contains a number of properties which this object will expose. Some of these properties allow for a user to modify the member’s
typeorname. Thetagmethod is also provided to allow for a user to annotate the member similar to the database or a function’s contents. Another method,refswill allow one to enumerate everything in the database that references said member.-
bounds¶ Parameters: getter – Return the boundaries of the member.
-
comment¶
- The comment of this
member_t. param getter: Return the repeatable comment of the member. param repeatable: whether the comment should be repeatable or not param setter: Set the repeatable comment of the member to value.param value: the comment to apply to the member param repeatable: whether the comment should be repeatable or not
-
dt_type¶
- The "dt_type" attribute of the
idaapi.member_tthat is wrapped by thismember_t. param getter: Return the dt_typeattribute of the member.
-
flag¶
- The flags for this specific
member_t. param getter: Return the “flag” attribute of the member.
-
fullname¶
- The full name for this
member_tincluding its structure’s name. param getter: Return the fullname of the member.
-
id¶
- The member identifier for this
member_t. param getter: Return the identifier of the member.
-
index¶
- The index of this
member_tinto its structure. param getter: Return the index of the member.
-
left¶
- The starting offset of the
member_t. param getter: Return the beginning offset of the member.
-
name¶
- The name of this
member_t. param getter: Return the name of the member. param setter: Set the name of the member to string.param string: the new name to rename the member to
-
offset¶ Parameters: getter – Return the offset of the member.
-
parent¶ Parameters: getter – Return the structure_t that owns the member.
-
properties¶
- The "props" field of the
idaapi.member_tthat thismember_twraps. param getter: Return the properties for the current member.
-
ptr¶
- The
idaapi.member_tthat thismember_twraps. param getter: Return the pointer of the idaapi.member_t.
-
realbounds¶
- The
structure_tthat owns thismember_t. param getter: Return the real boundaries of the member.
-
realoffset¶
- The offset of this
member_trelative to the structure’s base offset. param getter: Return the real offset of the member.
-
right¶
- The ending offset of the
member_t(starting offset plus its size). param getter: Return the ending offset of the member.
-
size¶
- The size of this
member_t. param getter: Return the size of the member.
-
type¶
- The pythonic type that is associated with this
member_t. param getter: Return the type of the member in its pythonic form. param setter: Set the type of the member to the provided type.param type: the pythonic type to set the member type to
-
typeid¶
- The type identifier for this
member_t. param getter: Return the identifier of the type of the member.
-
typeinfo¶ Parameters: - getter – Return the type information of the current member.
- setter – Set the type information of the current member to
info. - info – the type information to apply to the member
-
refs(self)¶ Return the
(address, opnum, type)of all the code and data references to this member within the database.If
opnumisNone, then the returnedaddresshas the structure applied to it. Ifopnumis defined, then the instruction at the returnedaddressreferences a field that contains the specified structure.
-
tag(self)¶ Return the tags associated with the member.
-
tag(self, key) Return the tag identified by
keybelonging to the member.Parameters: key (str) – a string representing the tag name
-
tag(self, key, value) Set the tag identified by
keytovaluefor the member.Parameters: - key (str) – a string representing the tag name
- value – a python object to store at the tag
-
tag(self, key, none) Removes the tag specified by
keyfrom the member.Parameters: - key (str) – a string representing the tag name
- none (None) – the python value
None
-
3.1.6.2.2. members_t¶
-
class
structure.members_t¶ This object is an abstraction around all the members belonging to a specific IDA structure. This object is implicitly part of a
structure_tand allows one to access each member of the structure by its index as well as create new members and remove existing ones from the structure.To list the different members available in the structure, one can use
structure.listwith a chosen method of filtering. This will list all of the available members that match the keyword that they specified. The keywords that are available to filter members are:name- Match the structure member by a nameoffset- Match the structure member by its offsetlike- Filter the structure members according to a globregex- Filter the structure members according to a regular-expressionindex- Match the structure member by its indexfullname- Filter the structure members by matching its full name according to a globcommentorcomments- Filter the structure members by applying a glob to its commentidentifierorid- Match the structure member by its identifiergreaterorge- Filter the structure members for any after the specified offset (inclusive)gt- Filter the structure members for any after the specified offset (exclusive)lessorle- Filter the structure members for any before the specified offset (inclusive)lt- Filter the structure members for any before the specified offset (exclusive)predicate- Filter the structure members by passing themember_tto a callable
Some examples of using these keywords are as follows:
> st.members.list('field_4*') > iterable = st.members.iterate(like='p_*') > result = st.members.by(offset=0x2a)
-
owner¶
- The
structure_tthat owns thismembers_t. param getter: Return the owner structure_tfor thismembers_t.
-
ptr¶
- The
idaapi.member_tthat thismembers_twraps. param getter: Return the pointer to the idaapi.member_tthat contains all the members.
-
add(self, name)¶ Append the specified member
namewith the default type at the end of the structure.Parameters: name (str or tuple) – the name of the member to add
-
add(self, name, type) Append the specified member
namewith the giventypeat the end of the structure.Parameters: - name (str or tuple) – the name of the member to add
- type – the pythonic type of the new member to add
-
add(self, name, type, offset) Add a member at
offsetwith the givennameandtype.To specify a particular size,
typecan be a tuple with the second element referring to the size.Parameters: - name (str or tuple) – the name of the member to add
- type – the pythonic type of the new member to add
- offset (int or long) – the offset to add the member at
-
by(self, **type)¶ Return the member that matches the keyword specified by
type.Parameters: **type – any keyword that can be used to match the structure member with
-
by(self, name, *suffix) Return the member with the specified
name.Parameters: - name (str) – the name of the member to return
- *suffix – any other numbers or strings that should be appended to the name
-
by(self, offset) Return the member at the specified
offset.Parameters: offset (int or long) – the offset of the member to return
-
by(self, location) Return the member at the specified
location.Parameters: location (tuple) – a tuple containing the offset and exact size to use when locating the member
-
by_fullname(self, fullname, *suffix)¶ Return the member with the specified
fullname.Aliases:
structure.members_t.byfullnameParameters: - fullname – the full name of the member to return
- *suffix – any other numbers or strings that should be appended to the name
-
by_identifier(self, id)¶ Return the member in the structure that has the specified
id.Aliases:
structure.members_t.byid,structure.members_t.by_idParameters: id – the identifier of the member to return
-
by_name(self, name, *suffix)¶ Return the member with the specified
name.Aliases:
structure.members_t.bynameParameters: - name – the name of the member to return
- *suffix – any other numbers or strings that should be appended to the name
-
by_offset(self, offset)¶ Return the member at the specified
offsetfrom the base offset of the structure.Aliases:
structure.members_t.byoffsetParameters: offset – the offset of the member to return
-
by_realoffset(self, offset)¶ Return the member at the specified
offsetof the structure.Aliases:
structure.members_t.byrealoffsetParameters: offset – the real offset of the member to return
-
index(self, member)¶ Return the index of the specified
member.Parameters: member – the member_tto return the index for
-
iterate(self, **type)¶ Iterate through all of the members in the structure that match the keyword specified by
type.Parameters: **type – any keyword that can be used to filter the structure members with
-
iterate(self, string, *suffix) Iterate through all of the members in the structure with a name that matches the glob in
string.Parameters: - string (str) – the glob to filter the structure member names with
- *suffix – any other numbers or strings that should be appended to the name
-
list(self, string, *suffix)¶ List any members that match the glob in
string.Parameters: - string (str) – the glob to filter the structure member names with
- *suffix – any other numbers or strings that should be appended to the name
-
list(self, **type) List all the members within the structure that match the keyword specified by
type.Parameters: **type – any keyword that can be used to filter the structure members with
-
near_offset(self, offset)¶ Return the member nearest to the specified
offsetfrom the base offset of the structure.Aliases:
structure.members_t.nearoffset,structure.members_t.nearParameters: offset – the offset nearest to the member to return
-
near_realoffset(self, offset)¶ Return the member nearest to the specified
offset.Parameters: offset – the real offset nearest to the member to return
-
pop(self, index)¶ Remove the member at the specified
index.Parameters: index – the index of the member to remove
-
remove(self, offset)¶ Remove the member at
offsetfrom the structure.Parameters: offset – the offset of the member to remove
-
remove(self, offset, size) Remove all the members from the structure from the specified
offsetup tosizebytes.Parameters: - offset – the offset of the starting member to remove
- size – the size of the members that follow to remove
-
select(self, tag, *And, **boolean)¶ Query all of the members for the specified
tagand any others specified asAnd.Parameters: - tag (str) – a required tag name to search for
- *And – any other required tag names
- **boolean – either
AndorOrwhich specifies required or optional tags (respectively)
-
select(self, **boolean) Query all of the members (linearly) for any tags specified by
boolean. Yields each member found along with the matching tags as a dictionary.If
Andcontains an iterable then require the returned members contains them. IfOrcontains an iterable then include any other tags that are specified.Parameters: **boolean – either AndorOrwhich specifies required or optional tags (respectively)
3.1.6.2.3. structure_t¶
-
class
structure.structure_t¶ This object is an abstraction around an IDA structure type. This allows for one to treat an IDA structure as a regular python object. A number of methods and properties are provided in order to access certain attributes of the structure.
To access the members belonging to the structure, one can use the
membersproperty. This property is intended to be treated as an array in order to access the different elements available. This property also allows a user to create a new member or remove an already existing one.-
bounds¶
- The
interface.bounds_tdescribing the boundaries of this structure relative to its base offset. param getter:
-
comment¶
- The comment belonging to the
structure_t. param getter: Return the repeatable comment for the structure. param repeatable: param setter: Set the repeatable comment for the structure to value.param value: a string repesenting the comment to apply param repeatable: whether the comment should be repeatable or not
-
id¶
- The identifier for this
structure_t. param getter: Return the identifier of the structure.
-
index¶
- The index of this
structure_twithin the IDA’s structure list. param getter: Return the index of the structure. param setter: Set the index of the structure to idx.param index: the new index to move the structure to
-
members¶
- The
members_tfor accessing the structure members. param getter: Return the members belonging to the structure.
-
name¶
- The name of the
structure_t. param getter: Return the name of the structure. param setter: Set the name of the structure to string.param string: a string representing the new name of the structure
-
offset¶
- The base offset of the
structure_t. param getter: Return the base offset of the structure. param setter: Set the base offset of the structure to offset.param offset: the new base offset to assign to the structure
-
ordinal¶ Parameters: getter – Return the ordinal number of the structure within the current type library.
-
properties¶
- The "props" field of the
idaapi.struc_tthat thisstructure_twraps. param getter: Return the properties for the current structure.
-
ptr¶
- The
idaapi.struc_tthat thisstructure_twraps. param getter: Return the pointer of the idaapi.struc_t.
-
realbounds¶
- The
interface.bounds_tdescribing the boundaries of this structure. param getter:
-
size¶
- The total size of the
structure_t. param getter: Return the size of the structure. param setter: Expand the structure to the new sizethat is specified.param size: an integer representing the new size to expand the structure to
-
typeinfo¶ Parameters: - getter – Return the type information of the current structure.
- setter – Sets the type information of the current structure to
info. - info –
-
contains(self, offset)¶ Return whether the specified
offsetis contained by the structure.Parameters: offset – the offset to check
-
destroy(self)¶ Remove the structure from the database.
-
field(self, offset)¶ Return the member at the specified offset.
Parameters: offset – the offset of the member to return
-
refs(self)¶ Return all the structure members and operand references which reference this specific structure.
-
tag(self)¶ Return the tags associated with the structure.
-
tag(self, key) Return the tag identified by
keybelonging to the structure.Parameters: key (str) – a string representing the tag name
-
tag(self, key, value) Set the tag identified by
keytovaluefor the structure.Parameters: - key (str) – a string representing the tag name
- value – a python object to store at the tag
-
tag(self, key, none) Removes the tag specified by
keyfrom the structure.Parameters: - key (str) – a string representing the tag name
- none (None) – the python value
None
-
up(self)¶ Return all structure or frame members within the database that reference this particular structure.
-