Enum¶
This part describe the enum (BipEnum) and enum members
(BEnumMember). The BEnumMember class inherit from
BipRefElt which allow to get access to the enum members through xref
and possible to recuperate using the GetElt() function.
Those classes represent
the element view in the Enum tab. of IDA and are different from the
BipType which is used for referencing the type of some elements in
IDA, however they are obviously linked.
Except xrefs the most common way to get an enum is using the
BipEnum.get() class method which expect its name. For creating one
the BipEnum.create() class method is available. Once an enum has
been recuperated it is possible to access the members as a dict by using
their name or to iterate on all the members. It is also possible to use
the BEnumMember.get() class method for directly recuperating an enum
member.
BipEnum API¶
-
class
bip.base.BipEnum(eid)¶ Class for representing and manipulating an enum in IDA. Class method
get()andcreate()allows to easily create and recuperate aBipEnumobject.The enum in IDA do not support xref, however the enum members do.
Todo
allow to set an instruction operand as an enum
-
__init__(eid)¶ Constructor for a
BipEnumobject. There is few reason to directly use this constructor, see functions:get()orcreate()Parameters: eid (int) – The enum id ( enum_t) representing this enum.
-
__eq__(other)¶ Compare two BipEnum.
-
__ne__(other)¶ x.__ne__(y) <==> x!=y
-
classmethod
_is_this_elt(idelt)¶ Return true if
ideltcorrespond to an enum_t.
-
name¶ Property for getting the name of this enum. A setter exist for this property.
Return str: The name of this enum.
-
width¶ Property for getting the width in bytes of an enum. The width of an enum can be: 0 (unspecified),1,2,4,8,16,32,64.
Return int: The width of the enum.
-
is_bitfield¶ Property for getting or setting if an enum is a bitfield.
Return bool: True if this enum is a bitfield, false otherwise.
-
__str__() <==> str(x)¶
-
comment¶ Property which return the comment associated with an enum.
Returns: The comment as a string or None if no comment is associated with it.
-
rcomment¶ Property which return the repeatable comment associated with an enum.
Returns: The comment as a string or None if no comment is associated with it.
-
nb_members¶ Property which return the number of members present in this enum.
-
add(name, value)¶ Property for adding a new member to this enum.
Parameters: - name (str) – The name of the new member to add.
- value (int) – The value of the new member to add.
Raises: RuntimeError – If it was not possible to add the new member.
-
member_by_name(name)¶ Function for getting a member of this enum from its name.
Internally this function use
BEnumMember.get()and check that the parent of the member is indeed this enum.Parameters: name (str) – The name of the member to get. Returns: A :class`BEnumMember` object. Raises: ValueError – If the name for the enum member does not exist or if the enum member is not part of this enum.
-
__getitem__(key)¶ Getitem method which allow access to the members of the enum from their name.
This is just a convinient wrapper on top of
member_by_name().Parameters: key (str) – The name of the member to get. Returns: A :class`BEnumMember` object. Raises: ValueError – If the name for the enum member does not exist or if the enum member is not part of this enum.
-
members_by_value(value, _bmask=None)¶ Function for getting members with a particular value in this enum.
Parameters: - value (int) – The value for which to get the members.
- _bmask (int) – Optionnal value for precising the mask, by default use the default mask.
Returns: A list of
BEnumMemberrepresenting the enum member with that value
-
del_member(name)¶ Function for deleting a member from this enum by its name.
Internally this will first get the enum using
member_by_name()then try to delete it.Parameters: name (str) – The name of the member to delete.
Raises: - ValueError – If the name does not exist.
- RuntimeError – If was not able to delete the enum member.
-
members¶ Property for getting a list of the members of this enum.
Returns: A list of BEnumMember.
-
__iter__()¶ Iter method for allowing to iterate on all members of the enum.
This is just a wrapper on
BipEnum.members(). Update to the enum during the iteration will not be taken into account.
-
classmethod
get(name)¶ Class method for getting a
BipEnumobject from the name of an existing enum.Parameters: name (str) – The name of the enum to get. Raises: ValueError – If the enum namedoes not exist.Returns: A BipEnumobject corresponding to the enum identified by the name provided.
-
classmethod
create(name)¶ Class method allowing to create a new empty enum.
Parameters: name (str) – The name of the enum to create. If this is
Nonea default nameenum_INTwill be created by IDA.Raises: - ValueError – If the enum
namealready exist. - RuntimeError – If it was not possible to create the enum.
Returns: A
BipEnumobject corresponding to the newly created enum.- ValueError – If the enum
-
static
delete(arg)¶ Static method allowing to delete an enum by its name or its id.
Parm arg: String representing the name of the enum or id (int) representing the enum in IDA or a BipEnumobject (in that case the object will not be valid after that).Raises: ValueError – If the argument is invalid.
-
__weakref__¶ list of weak references to the object (if defined)
-
BEnumMember API¶
-
class
bip.base.BEnumMember(member_id)¶ Class for representing and manipulating an enum member. Object of this class can be access, created and delete through methods of
BipEnum. It is possible to directly get an object of this type usingBEnumMember.get().The object of this class support the xref API implemented in the parent class
BipRefElt.-
__init__(member_id)¶ Consctructor for a
BipBaseEltobject.Note
There is no reason to use this constructor, the
GetElt()orGetEltByName()functions should be used.Parameters: idelt (int) – The id for representing the IDA element. In most case this will be the address of the element.
-
classmethod
_is_this_elt(idelt)¶ Return true if
ideltcorrespond to a enum member id.In practice this try to get the associated enum for this potential enum id and check if it succeed or not.
-
_mid¶ Property which return the enum member id for this object.
Use for interfacing with IDAPython internals.
-
_serial¶ Property which return the “serial” of this enum member. This is used only for interfacing with native IDAPython API.
The serial is not a unique id for this enum, the serials for enum members always start at 0 and is incremented only when two enum members have the same value.
Returns: The serial integer for this enum member.
-
_bmask¶ Property for getting the bitmask of this enum member. This is used only for interfacting with native IDAPython API. Do not know what the bitmask is actual used for in IDA.
Returns: An integer representing the bitmask for this member.
-
__eq__(other)¶ Equality operator for two
BEnumMember.
-
__ne__(other)¶ x.__ne__(y) <==> x!=y
-
value¶ Property for getting the value of this enum member.
Return int: The value of this enum member.
-
name¶ Property for getting and setting the name of this enum member.
Return str: The name of this enum member.
-
enum¶ Property for getting the
BipEnumobject from this member.Returns: The BipEnumassociated with this member.
-
__str__() <==> str(x)¶
-
comment¶ Property which return the comment associated with an enum member.
Returns: The comment as a string or None if no comment is associated with it.
-
rcomment¶ Property which return the repeatable comment associated with an enum member.
Returns: The comment as a string or None if no comment is associated with it.
-
classmethod
get(name)¶ Class method for recuperating a
BEnumMemberobject from its name.Returns: A BEnumMemberobject associated with the name.Raises: ValueError – If no enum member with this name exist.
-