IDA SDK

- Main Page
- Header Files
- Classes
- Modules

- File List
- File Members

Classes | Functions | Macros | Typedefs | Variables
enum.hpp File Reference

## Detailed Description

Assembly level enum management.

Enums and bitfields are represented as enum_t.

## Classes
struct | enum_member_visitor_t
| Enum member visitor - see for_all_enum_members(). More...

## Functions
size_t | get_enum_qty (void)
| Get number of declared enum_t types.
enum_t | getn_enum (size_t n)
| Get enum by its ordinal number (0..n).
uval_t | get_enum_idx (enum_t id)
| Get serial number of enum. More...
idaman enum_t ida_export | get_enum (const char *name)
| Get enum by name.
bool | is_bf (enum_t id)
| Is enum a bitfield? (otherwise - plain enum, no bitmasks except for DEFMASK are allowed)
bool | is_enum_hidden (enum_t id)
| Is enum collapsed?
bool | set_enum_hidden (enum_t id, bool hidden)
| Collapse enum.
bool | is_enum_fromtil (enum_t id)
| Does enum come from type library?
bool | set_enum_fromtil (enum_t id, bool fromtil)
| Specify that enum comes from a type library.
bool | is_ghost_enum (enum_t id)
| Is a ghost copy of a local type?
bool | set_enum_ghost (enum_t id, bool ghost)
| Specify that enum is a ghost copy of a local type.
ssize_t | get_enum_name (qstring *out, enum_t id)
| Get name of enum.
qstring | get_enum_name (tid_t id)
size_t | get_enum_width (enum_t id)
| Get the width of a enum element. More...
idaman bool ida_export | set_enum_width (enum_t id, int width)
| See comment for get_enum_width()
ssize_t | get_enum_cmt (enum_t id, bool repeatable, char *buf, size_t bufsize)
| Get enum comment.
size_t | get_enum_size (enum_t id)
| Get the number of the members of the enum.
flags_t | get_enum_flag (enum_t id)
| Get flags determining the representation of the enum. More...
idaman const_t ida_export | get_enum_member_by_name (const char *name)
| Get a reference to an enum member by its name.
uval_t | get_enum_member_value (const_t id)
| Get value of an enum member.
enum_t | get_enum_member_enum (const_t id)
| Get the parent enum of an enum member.
bmask_t | get_enum_member_bmask (const_t id)
| Get bitmask of an enum member.
idaman const_t ida_export | get_enum_member (enum_t id, uval_t value, uchar serial, bmask_t mask)
| Find an enum member by enum, value and bitmask.
ssize_t | get_enum_member_name (qstring *out, const_t id)
| Get name of an enum member by const_t.
ssize_t | get_enum_member_cmt (const_t id, bool repeatable, char *buf, size_t bufsize)
| Get enum member's comment.
idaman int ida_export | for_all_enum_members (enum_t id, enum_member_visitor_t &cv)
| Visit all members of a given enum.
uchar | get_enum_member_serial (const_t cid)
| Get serial number of an enum member.
int32 | get_enum_type_ordinal (enum_t id)
| Get corresponding type ordinal number.
void | set_enum_type_ordinal (enum_t id, int32 ord)
| Set corresponding type ordinal number.
idaman enum_t ida_export | add_enum (size_t idx, const char *name, flags_t flag)
| Add new enum type. More...
idaman void ida_export | del_enum (enum_t id)
| Delete an enum type.
idaman bool ida_export | set_enum_idx (enum_t id, size_t idx)
| Set serial number of enum. More...
idaman bool ida_export | set_enum_bf (enum_t id, bool bf)
| Set 'bitfield' bit of enum (i.e. convert it to a bitfield)
idaman bool ida_export | set_enum_name (enum_t id, const char *name)
| Set name of enum type.
idaman bool ida_export | set_enum_cmt (enum_t id, const char *cmt, bool repeatable)
| Set comment for enum type.
bool | set_enum_flag (enum_t id, flags_t flag)
| Set data representation flags.
idaman int ida_export | add_enum_member (enum_t id, const char *name, uval_t value, bmask_t bmask=DEFMASK)
| Add member to enum type. More...
idaman bool ida_export | del_enum_member (enum_t id, uval_t value, uchar serial, bmask_t bmask)
| Delete member of enum type.
idaman bool ida_export | set_enum_member_name (const_t id, const char *name)
| Set name of enum member.
bool | set_enum_member_cmt (const_t id, const char *cmt, bool repeatable)
| Set comment for enum member.
bool | is_one_bit_mask (bmask_t mask)
| Is bitmask one bit?
netnode | get_bmask_node (enum_t id, bmask_t bmask)
| Get bitmask node if bf-scheme is used, otherwise return BADNODE.
Access to all used bitmasks in an enum
bmask_t | get_first_bmask (enum_t id)
bmask_t | get_last_bmask (enum_t id)
bmask_t | get_next_bmask (enum_t id, bmask_t bmask)
bmask_t | get_prev_bmask (enum_t id, bmask_t bmask)
Access to all enum members with specified bitmask
Note these functions return values, not const_t!
idaman uval_t ida_export | get_first_enum_member (enum_t id, bmask_t bmask=DEFMASK)
idaman uval_t ida_export | get_last_enum_member (enum_t id, bmask_t bmask=DEFMASK)
idaman uval_t ida_export | get_next_enum_member (enum_t id, uval_t value, bmask_t bmask=DEFMASK)
idaman uval_t ida_export | get_prev_enum_member (enum_t id, uval_t value, bmask_t bmask=DEFMASK)
Access to all enum members with specified value and mask
A sample loop looks like this: const_t main_cid; uchar serial; for ( const_t cid=main_cid=get_first_serial_enum_member(id, v, &serial, mask); cid != BADNODE; cid = get_next_serial_enum_member(main_cid, &serial) ) { ... } The 'out_serial' argument of get_first_serial_enum_member/get_last_serial_enum_member can be NULL. The 'in_out_serial' is required for the other functions.
idaman const_t ida_export | get_first_serial_enum_member (enum_t id, uval_t value, uchar *out_serial, bmask_t bmask)
idaman const_t ida_export | get_last_serial_enum_member (enum_t id, uval_t value, uchar *out_serial, bmask_t bmask)
idaman const_t ida_export | get_next_serial_enum_member (const_t first_cid, uchar *in_out_serial)
idaman const_t ida_export | get_prev_serial_enum_member (const_t first_cid, uchar *in_out_serial)
Work with the bitmask name & comment
bool | set_bmask_name (enum_t id, bmask_t bmask, const char *name)
ssize_t | get_bmask_name (qstring *out, enum_t id, bmask_t bmask)
bool | set_bmask_cmt (enum_t id, bmask_t bmask, const char *cmt, bool repeatable)
ssize_t | get_bmask_cmt (enum_t id, bmask_t bmask, bool repeatable, char *buf, size_t bufsize)

## Macros
#define | DEFMASK (bmask_t(-1))
| default bitmask
#define | ENUM_MEMBER_ERROR_NAME 1
| already have member with this name (bad name)
#define | ENUM_MEMBER_ERROR_VALUE 2
| already have 256 members with this value
#define | ENUM_MEMBER_ERROR_ENUM 3
| bad enum id
#define | ENUM_MEMBER_ERROR_MASK 4
| bad bmask
#define | ENUM_MEMBER_ERROR_ILLV 5
| bad bmask and value combination (~bmask & value != 0)
#define | enums dont_use_enums_directly
| prohibit access to 'enums' netnode

## Typedefs
typedef tid_t | enum_t
| simple netnode that provides information about an enum. More...
typedef uval_t | bmask_t
| unsigned value that describes a bitmask (also see enum_t). More...
typedef uval_t | const_t
| members of enums are kept as netnodes. More...

## Variables
const uchar | MAX_ENUM_SERIAL = 255
| Max number of identical constants allowed for one enum type.

## Typedef Documentation

typedef tid_t enum_t

simple netnode that provides information about an enum.

name(), cmt() and rptcmt() are kept in the usual form. memqty is kept in altval(-1).

bitfields:

- have altval(-5) bit0 set to 1.
- altval('M') keeps ptrs to nodes by bitmasks

enums:

- all members are kept in altval('E',member_value)-1

typedef uval_t bmask_t

unsigned value that describes a bitmask (also see enum_t).

a bit mask is 32/64 bits. if a mask is one-bit, then ptr to const_t is kept immediately in altval('M'). otherwise, masknode.altval('E') keeps ptrs to const_t by values (the same as with enums).

typedef uval_t const_t

members of enums are kept as netnodes.

name(), cmt() and rptcmt() are kept in the usual form. altval(-2) is enum_t.

## Function Documentation

uval_t get_enum_idx | ( | enum_t | id | ) |
| inline

Get serial number of enum.

The serial number determines the place of the enum in the enum window.

size_t get_enum_width | ( | enum_t | id | ) |
| inline

Get the width of a enum element.

0 means unspecified, 1 means 1 byte, 2 means 2 bytes, 3 means 4 bytes, 4 means 8 bytes, etc. max allowed value is 7.

flags_t get_enum_flag | ( | enum_t | id | ) |
| inline

Get flags determining the representation of the enum.

(currently they define the numeric base: octal, decimal, hex, bin) and signness.

idaman enum_t ida_export add_enum | ( | size_t | idx,
|  | const char * | name,
|  | flags_t | flag
| ) |  |

Add new enum type.

- if idx==BADADDR then add as the last idx
- if name==NULL then generate a unique name "enum_%d"

idaman bool ida_export set_enum_idx | ( | enum_t | id,
|  | size_t | idx
| ) |  |

Set serial number of enum.

Also see get_enum_idx().

idaman int ida_export add_enum_member | ( | enum_t | id,
|  | const char * | name,
|  | uval_t | value,
|  | bmask_t | bmask = `DEFMASK`
| ) |  |

Add member to enum type.

Returns
  0 if ok, otherwise one of Add enum member result codes