Type¶
Types are used every where in IDA: data (BipData
),
functions (BipFunction
), local variable
(HxLvar
) … In Bip all types are reprensented as
an object which inherit from BipType
. BipType
objects can
be recursive: a pointer will be represented by the BTypePtr
which
will contain a reference on the pointed type, a BTypeFunc
in the
case of a function pointer for example. All subclasses of BipType
start with the prefix BType*
.
For creating a new BipType
the easiest way is to use the
BipType.from_c()
static method: it will create an object which inherit
from BipType
of the correct class from a string representing the C
declaration of the type.
When recuperating a type from IDA (tinfo_t
) Bip will try to determine the
correct object much the same way it is done for the BipBaseElt
when
using GetElt()
. This is made using the static method
BipType.from_tinfo()
and the class method for determining the correct
class is BipType.is_handling_type()
.
Warning
Modifying types
Modifying types can have unexpected side effects. In particular the object recuperated through the API (Bip or IDAPython) may not be the one currently used. For avoiding those problems types are copied before setting them in most case by the Bip API. However recuperating a type while it is changed by another script or the IDA GUI will still make manipulation invalid.
Here is a quick descriptions of the different types implemented in Bip:
Type name | Description |
---|---|
BTypeEmpty |
An empty type, should never happen but… |
BTypePartial |
A type where the size is known but without any other information. |
BTypeVoid |
The void type (not void* just void ). |
BTypeInt |
An int , can have different size, be signed or unsigned. |
BTypeBool |
A boolean, can have different size. |
BTypeFloat |
A float or double. |
BTypePtr |
A pointer, recursive type, pointed() for getting the subtype. |
BTypeArray |
An array, recursive type (BTypeArray.elt_type() ), have a number of element. |
BTypeFunc |
A function, recursive type for arguments and return value. Also access to the arguments name and their numbers. |
BTypeStruct |
A structure, rescursive type for the members. This is different from BipStruct . |
BTypeUnion |
A union, rescursive type for the members. |
BTypeEnum |
An enum, bugged before IDA 7.3, implementation is not finished. |
BipType API¶
-
class
bip.base.
BipType
(tinfo)¶ Abstract class for representing a
tinfo_t
object from ida in bip. All basic types are subclasses of this one, the class name start with the prefixBType
, see Type for more information.The objects which inherit from
BipType
can contain other childrenBipType
objects. For example a pointer (BTypePtr
) will contain one child object corresponding to the pointed type. Thechildren()
property allow to get a list of the child object.Todo
allow creation of types
Todo
General todo for types:
- SSE
- const
-
__init__
(tinfo)¶ Base constructor for the child classes of
BipType
. This constructor is used for interfacing with IDA and initializing. A bip user should probably used theBipType.from_tinfo()
function which will directly create the object of the correct class.Parameters: tinfo – The tinfo_t
representing the type in IDA.
-
_tinfo
= None¶ Internal object which correspond to the
tinfo_t
object equivalent to this object in IDA.
-
size
¶ Property which return the number of bytes in this type.
In case the number of bytes is unknown None is returned.
-
str
¶ Property which return the C String equivalent to the type of this object. It will take into account the child type. This should never be empty (except for unknown ? TODO test).
Returns: A string which represent the type as in C.
-
is_named
¶ Return true if this type has a name. This can be because of a typedef, a structure declaration, … The name can be recuperated with the
BipType.name()
property.
-
name
¶ Property which return the name of this type if it has one. A type can a name because of a typedef, a structure, … If it does not have one this property will return an empty string. The presence of a named can be tested using the
BipType.is_named()
property.Returns: A string corresponding to the name of this type. Empty if this type does not have a name.
-
__eq__
(other)¶ Compare two BipType. This is only based on the compare of the IDA underlying object.
-
__ne__
(other)¶ x.__ne__(y) <==> x!=y
-
set_at
(ea, flags=1)¶ Function which try to set the type of the current object at a given position, in particular this will work for global data and function. If an error occur when trying to set the type a
RuntimeError
will be raised.This create a copy of the
tinfo_t
in this object.Todo
delete flags and make something better here.
Parameters: - ea (int) – The address at which set the type.
- flags (int) – This are the
TINFO_*
flags from ida_typeinf, by defaultTINFO_DEFINITE
.
-
static
is_set_at
(ea)¶ This function allow to test if a type is defined at a particular address. This function will return False if a type is not set but ida may be able to guess it. This means that this function may return False while
BipType.get_at()
return a type, if this function return TrueBipType.get_at()
should always return a type.Parameters: ea – The address at which to make the test. Returns: True if a type is defined at the address given in argument, False otherwise.
-
static
get_at
(ea=None)¶ Function which will create an object which inherit from
BipType
representing the type at the current address. This function will not set the type at the address given and it may not be set if it was guess by ida.Internally this function will first try to get the type at the address, if no type are defined it will try to guess it. If ida is not able to guess it it will return
None
.Todo
make something better when no type are set ?
Note
Implementation
Ida allow to guess the type but this “guess” ignore the fact that this may have been set. It seems necessary to use ida_nalt.get_tinfo for recuperating the type set, it will fail if no type has been set. If no type were set the guess_tinfo is then used, it will typically fail if the data is undefined, in this case None will be return. This may change in the future as by default a tinfo_t
empty
is true (but not the tinfo_t.is_unknown).Parameters: ea – The address at which to get the type. If None
the screen address will be used.Returns: An object which inherit from BipType
representing the type at the address given in argument.None
will be return if no type is define and ida was not able to guess it .
-
static
del_at
(ea)¶ Function which delete the type set at a particular address.
Parameters: ea – The address at which to delete the type. If None
the screen address will be used.
-
children
¶ Property which return a list of children types. All elements of this list will be object which inherit from
BipType
.Returns: A list of object inheriting from BipType
which are “child” of this type.
-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-
static
from_tinfo
(tinfo)¶ Function which convert a
tinfo_t
object from ida to one of the child object ofBipType
. This should be used for converting the type from IDA into their correct object for bip. This function is used as an interface with the IDA object.If no
BipType
child object supports thetinfo_t
aValueError
exception will be raised. Internally this use the_get_class_bip_type()
function.This create a copy of the underlying
tinfo_t
object, this allow to avoid problems if when using the IdaPython API or the GUI from IDA the type is change. This is a problem because it means bip should dynamically change the class of the object and even if possible this will create an error prone API. Instead types are handle by copy instead of by reference, and interface with other bip object take this into account. For creating an object of the correct class without a copy thefrom_tinfo_no_copy()
can be used by is subject to the above problems.Parameters: tinfo – A tinfo_t
from ida.Returns: The equivalent object to the tinfo_t
for bip. This will be an object which inherit fromBipType
.
-
static
from_tinfo_no_copy
(tinfo)¶ Function which convert a
tinfo_t
object from ida to one of the child object ofBipType
.If no
BipType
child object supports thetinfo_t
aValueError
exception will be raised. Internally this use the_get_class_bip_type()
function.Warning
This function does not create a copy of the underlying
tinfo_t
object which can create several problems when using the GUI or the IdaPython/IDC API. For creating a copy of the object use thefrom_tinfo()
instead.Parameters: tinfo – A tinfo_t
from ida.Returns: The equivalent object to the tinfo_t
for bip. This will be an object which inherit fromBipType
.
-
static
from_c
(cstr, flags=1025)¶ Function which convert a C string declaration into a object which inherit from a
BipType
. If there is no;
at the end of the string provided, one will be added automatically.This is made for parsing one declaration and can create problem if several declarations are in the string.
Parameters: - cstr (str) – A string representing a declaration in C.
- flags (int) –
PT_*
flags from IDA (see typeinf.hpp). The default is0x401
(PT_RAWARGS | PT_SIL
) should be enough in most case.
Returns: An object which inherit from
BipType
equivalent to the C declaration.Raises: RuntimeError – if the function was not able to create the type.
-
static
import_c_header
(path, pack=0, raw_args=True, silent=False, autoimport=True)¶ Import a C header file.
Parameters: - path (str) – The path to the C header file to import.
- pack (int) – The packing for the structure in the header. 0 means default (from compiler/configuration), other values are power of 2 up to 16. No verification is made on that value.
- raw_args (bool) – Should leave the name of the argument unchanged: do not remove the _ in the name. True by default.
- silent (bool) – Should silently fails on error and mask warnings.
- autoimport (bool) – If True (the default), this function will import all new types in the IDB (“Structures”, “Enums”, … Views), instead of only keeping them in the type library (til, the “Local Types” view).
Returns: The number of error which occur during parsing.
-
static
_get_class_bip_type
(tinfo)¶ Internal function which allow to recuperate the correct child class of
BipType
corresponding totinfo_t
object from ida. This is used internally for converting the type from IDA into their correct object for bip. This function is used as an interface with the IDA object.If no
BipType
child object supports thetinfo_t
aValueError
exception will be raised.Parameters: tinfo – A tinfo_t
from ida.Returns: The bip class which should be used as equivalent for the tinfo_t
provided as argument. This will be an object which inherit fromBipType
.
-
_get_tinfo_copy
()¶ Return a copy of the ida type (
tinfo_t
) represented by this object. This is an internal function which is used as an helper for setting the types of an element from aBipType
Returns: A copy of the tinfo_t
represented by this object.
-
__weakref__
¶ list of weak references to the object (if defined)
-
class
bip.base.
BTypeEmpty
(tinfo)¶ Class which represent the
BipType
for a type with no information (empty or unknown). This is really used by IDA including in structures and so on.-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-
classmethod
-
class
bip.base.
BTypePartial
(tinfo)¶ Class which represent the
BipType
for a partial type: when only the size is known but no other information is available.-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-
classmethod
-
class
bip.base.
BTypeVoid
(tinfo)¶ Class which represent the
BipType
for a void.-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-
classmethod
-
class
bip.base.
BTypeInt
(tinfo)¶ Class which represent the
BipType
for an integer, it can be signed or unsigned and may have differentsize()
.-
is_signed
¶ Property which return True if the integer is signed and false if it is unsigned.
-
is_unsigned
¶ Property which return True if the integer is unsigned and false if it is signed.
-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-
-
class
bip.base.
BTypeBool
(tinfo)¶ Class which represent the
BipType
for a boolean (bool
). All boolean do not have the samesize()
.-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-
classmethod
-
class
bip.base.
BTypeFloat
(tinfo)¶ Class which represent the
BipType
for a float or a double.-
is_double
¶ Property which return true if this type represent a double (by opposition to a float).
-
is_float
¶ Property which return true if this type represent a float (by opposition to a double).
-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-
-
class
bip.base.
BTypePtr
(tinfo)¶ Class which represent the
BipType
for a pointer. This is a recursive type, it is possible to have the pointed type with the propertypointed()
.-
pointed
¶ Property which return the type pointed by this type.
Returns: An object which inherit from BipType
class.
-
is_pvoid
¶ Property which return true if this type is a pointer on void (
void *
).
-
is_pfunc
¶ Property which return true if this type is a pointer on a function.
-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-
-
class
bip.base.
BTypeArray
(tinfo)¶ Class which represent the
BipType
for an array (a static array:int[8]
for example). This is a recursive type, it is poissible to have the type of the elements with the propertyelt_type()
.Note
The array (and in particular the
array_type_data_t
from IDA) have abase
property. Not really sure what that is, when or how it is used. It is possible to access it using_array_info()
then accessing the propertybase
if needed.-
_array_info
¶ Property which return
array_type_data_t
object from ida associated with this object. This is only for interfacing with IDA and should probably not be used directly from bip.This is used by the other method/property of
BTypeArray
.
-
elt_type
¶ Property which returns the type of the elements in the type array.
Returns: An object which inherit from BipType
class.
-
nb_elts
¶ Property which returns the number of elements in the type array.
Returns: An int.
-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-
-
class
bip.base.
BTypeFunc
(tinfo)¶ Class which represent the
BipType
for a function. This is a recursive type, it is poissible to have the type of the return value using thereturn_type()
property and the type of the arguments using the methodget_arg_type()
or the propertyargs_type()
.Other methods are available allowing to access the name of the arguments (
get_arg_name()
).Todo
everything about arguments (ida_typeinf.funcarg_t): * location * cmt * flags * compare
Todo
calling convention
Todo
everything in func_type_data_t
Todo
spoiled registers
Todo
stack link (once stack is implemented)
Todo
does function return ?
Todo
flags for function type
Todo
return location
Todo
setter for arg (name, type, cmt, …)
Todo
setter for return value (type)
Todo
the handling of the arguments may have to be change
Todo
helper for if the function return void (and maybe other: a ptr and so on)
-
_ida_func_type_data
¶ Internal property which allow to get the
func_type_data_t
for this type function.Returns: the ida_typeinf.func_type_data_t
for this object.
-
get_arg_name
(pos)¶ Get the name of an argument.
Parameters: pos (int) – The position of the argument (start at 0). Returns: The name of the argument at pos
for this function type. If the argument does not have a name the empty string will be returned.
-
get_arg_type
(pos)¶ Get the
BipType
object corresponding to the type of an argument.Returns: An object which inherit from BipType
class.
-
nb_args
¶ Property which return the number of arguments that this function type posess.
Returns: An int.
-
args_type
¶ Property which return a list of the
BipType
object for the argument of this function.Returns: A list of objects which inherit from BipType
class.
-
return_type
¶ - Property which return the
BipType
object corresponding - to the type of the return of this function.
Returns: An object which inherit from BipType
class.- Property which return the
-
children
¶ Property which return a list of children types. All elements of this list will be object which inherit from
BipType
.First element is the return type followed by the argument types. The length of this property is variable depending of the function type but will always be equal to
nb_args + 1
.Returns: A list of object inheriting from BipType
which are “child” of this type.
-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-
-
class
bip.base.
BTypeStruct
(tinfo)¶ Class which represent the
BipType
for a structure. This is a recursive type, each member of the struct posess its own types.It is possible to get the name of the member using the
get_member_name()
method, it is also possible to get the type using theget_member_type()
method or themembers_type()
property (which return a list), themembers_info()
return a dictionary with the name of the members as key and their type as value.Todo
link to struct in bip
Todo
anonymous udt ?
Todo
everything in ida_typeinf.udt_type_data_t
Todo
everything in udt_member_t for the members. Change the handling of the members ?
Todo
allow to get the offset of a member from its name and/or index.
-
_ida_udt_type_data
¶ Internal property which allow to get the
udt_type_data_t
for this type structure.Warning
Carefull to this! The information contain in this object (such as the types) do not reference the
udt_type_data_t
object. Meaning that as soon as theudt_type_data_t
object is delete by python, all the subobject will be deleted. All of those should be copied before the python object is destroyed or we may trigger use-after-free. For problematic of swig and memory management see http://www.swig.org/Doc1.3/Python.html#Python_nn30.Returns: the ida_typeinf.udt_type_data_t
for this object.
-
get_member_name
(num)¶ Get the name of a member.
Parameters: num (int) – The number corresponding to the member. This is not the offset of the member but its index in the struct, this index start at 0 up to the nb_members()
minus one.Returns: The name of the num
member for this struct type.
-
get_member_type
(num)¶ Get the
BipType
object corresponding to the type of a member.Todo
handle the recuperation of a member by name ?
Parameters: num (int) – The number corresponding to the member. This is not the offset of the member but its index in the struct, this index start at 0 up to the nb_members()
minus one.Returns: An object which inherit from BipType
class.
-
nb_members
¶ Property which return the number of members present in the type structure.
Returns: an int.
-
members_type
¶ Property which return a list of the
BipType
object for the members of this struct.Returns: A list of objects which inherit from BipType
class.
-
members_info
¶ Property which return a dict providing information about the members of this struct. The keys of the dict correspond to their name (str) and the values to their type (
BipType
).
-
children
¶ Property which return a list of children types. All elements of this list will be object which inherit from
BipType
.This contain the type of the members and is equivalent to
members_type()
Returns: A list of object inheriting from BipType
which are “child” of this type.
-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-
-
class
bip.base.
BTypeUnion
(tinfo)¶ Class which represent the
BipType
for an union, this is a recursive type which can have several members.Todo
at the exception of the doc this is duplicate code for most of the methods with
BTypeStruct
, this should be fix. The simplest way would be to create a common parent class.-
_ida_udt_type_data
¶ Internal property which allow to get the
udt_type_data_t
for this union.Warning
Carefull to this! The information contain in this object (such as the types) do not reference the
udt_type_data_t
object. Meaning that as soon as theudt_type_data_t
object is delete by python, all the subobject will be deleted. All of those should be copied before the python object is destroyed or we may trigger use-after-free. For problematic of swig and memory management see http://www.swig.org/Doc1.3/Python.html#Python_nn30.Returns: the ida_typeinf.udt_type_data_t
for this object.
-
get_member_name
(num)¶ Get the name of a member.
Parameters: num (int) – The number corresponding to the member. This is its index in the enum, this index start at 0 up to the nb_members()
minus one.Returns: The name of the num
member for this struct type.
-
get_member_type
(num)¶ Get the
BipType
object corresponding to the type of a member.Todo
handle the recuperation of a member by name ?
Parameters: num (int) – The number corresponding to the member. This is the index in the enum, this index start at 0 up to the nb_members()
minus one.Returns: An object which inherit from BipType
class.
-
nb_members
¶ Property which return the number of members present in the enum.
Returns: an int.
-
members_type
¶ Property which return a list of the
BipType
object for the members of this enum.Returns: A list of objects which inherit from BipType
class.
-
members_info
¶ Property which return a dict providing information about the members of this enum. The keys of the dict correspond to their name (str) and the values to their type (
BipType
).
-
children
¶ Property which return a list of children types. All elements of this list will be object which inherit from
BipType
.This contain the type of the members and is equivalent to
members_type()
Returns: A list of object inheriting from BipType
which are “child” of this type.
-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-
-
class
bip.base.
BTypeEnum
(tinfo)¶ Class which represent the
BipType
for an enum.Todo
IDA BUG: its not possible to get the info about the enum members because the
enum_type_data_t
type which should be a vector on enum_member_t has apparently not been implemented in the IdaPython API.-
_ida_enum_type_data
¶ Internal property which allow to get the
enum_type_data_t
for this enum.Returns: the ida_typeinf.enum_type_data_t
for this object.
-
classmethod
is_handling_type
(tinfo)¶ Class method which allow to test if this class support a particular type info (IDA
tinfo_t
). Return True if the function handle the type, false otherwise.Parameters: tinfo – A tinfo_t
swig object from idapython.Returns: A boolean.
-