IDA SDK

- Main Page
- Header Files
- Classes
- Modules

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Friends | List of all members
tinfo_t Class Reference

## Detailed Description

Primary mechanism for managing type information.

## Public Member Functions
| tinfo_t (type_t decl_type=BT_UNK)
| Constructor - can only be used to initialize simple types!
| tinfo_t (const tinfo_t &r)
| Constructor.
tinfo_t & | operator= (const tinfo_t &r)
| Copy contents of given tinfo into this one.
| ~tinfo_t (void)
| Destructor.
void | clear (void)
| Clear contents of this tinfo, and remove from the type system.
void | swap (tinfo_t &r)
| Assign this = r and r = this.
bool | get_named_type (const til_t *til, const char *name, type_t decl_type=BTF_TYPEDEF, bool resolve=true, bool try_ordinal=true)
| Create a tinfo_t object for an existing named type. More...
bool | get_numbered_type (const til_t *til, uint32 ordinal, type_t decl_type=BTF_TYPEDEF, bool resolve=true)
| Create a tinfo_t object for an existing ordinal type. More...
bool | serialize (qtype *type, qtype *fields=NULL, qtype *fldcmts=NULL, int sudt_flags=SUDT_FAST|SUDT_TRUNC) const
| Serialize tinfo_t object into a type string.
bool | deserialize (const til_t *til, const type_t **ptype, const p_list **pfields=NULL, const p_list **pfldcmts=NULL)
| Deserialize a type string into a tinfo_t object.
bool | deserialize (const til_t *til, const qtype *ptype, const qtype *pfields=NULL, const qtype *pfldcmts=NULL)
| Deserialize a type string into a tinfo_t object. More...
bool | is_correct (void) const
| Is the type object correct?. More...
type_t | get_realtype (bool full=false) const
| Get the resolved base type. More...
type_t | get_decltype (void) const
| Get declared type (without resolving type references; they are returned as is). More...
bool | empty (void) const
| Was tinfo_t initialized with some type info or not?
bool | present (void) const
| Is the type really present? (not a reference to a missing type, for example)
size_t | get_size (uint32 *p_effalign=NULL, int gts_code=0) const
| Get the type size in bytes. More...
size_t | get_unpadded_size (void) const
| Get the type size in bytes without the final padding, in bytes. More...
type_sign_t | get_sign (void) const
| Get type sign.
bool | is_signed (void) const
| Is this a signed type?
bool | is_unsigned (void) const
| Is this an unsigned type?
uchar | get_declalign (void) const
| Get declared alignment of the type.
bool | set_declalign (uchar declalign)
| Set declared alignment of the type.
bool | is_typeref (void) const
| Is this type a type reference?. More...
bool | has_details (void) const
| Does this type refer to a nontrivial type?
bool | get_type_name (qstring *out) const
| Does a type refer to a name?. More...
bool | get_final_type_name (qstring *out) const
| Use in the case of typedef chain (TYPE1 -> TYPE2 -> TYPE3...TYPEn). More...
bool | get_next_type_name (qstring *out) const
| Use In the case of typedef chain (TYPE1 -> TYPE2 -> TYPE3...TYPEn). More...
uint32 | get_ordinal (void) const
| Get type ordinal (only if the type was created as a numbered type, 0 if none)
uint32 | get_final_ordinal (void) const
| Get final type ordinal (0 is none)
const til_t * | get_til (void) const
| Get the type library for tinfo_t.
bool | is_from_subtil (void) const
| Was the named type found in some base type library (not the top level type library)?. More...
bool | is_forward_decl (void) const
| Is this a forward declaration?. More...
bool | is_decl_const (void) const
| is_type_const(get_decltype())
bool | is_decl_volatile (void) const
| is_type_volatile(get_decltype())
bool | is_decl_void (void) const
| is_type_void(get_decltype())
bool | is_decl_partial (void) const
| is_type_partial(get_decltype())
bool | is_decl_unknown (void) const
| is_type_unknown(get_decltype())
bool | is_decl_last (void) const
| is_typeid_last(get_decltype())
bool | is_decl_ptr (void) const
| is_type_ptr(get_decltype())
bool | is_decl_array (void) const
| is_type_array(get_decltype())
bool | is_decl_func (void) const
| is_type_func(get_decltype())
bool | is_decl_complex (void) const
| is_type_complex(get_decltype())
bool | is_decl_typedef (void) const
| is_type_typedef(get_decltype())
bool | is_decl_sue (void) const
| is_type_sue(get_decltype())
bool | is_decl_struct (void) const
| is_type_struct(get_decltype())
bool | is_decl_union (void) const
| is_type_union(get_decltype())
bool | is_decl_udt (void) const
| is_type_struni(get_decltype())
bool | is_decl_enum (void) const
| is_type_enum(get_decltype())
bool | is_decl_bitfield (void) const
| is_type_bitfld(get_decltype())
bool | is_decl_int128 (void) const
| is_type_int128(get_decltype())
bool | is_decl_int64 (void) const
| is_type_int64(get_decltype())
bool | is_decl_int32 (void) const
| is_type_int32(get_decltype())
bool | is_decl_int16 (void) const
| is_type_int16(get_decltype())
bool | is_decl_char (void) const
| is_type_char(get_decltype())
bool | is_decl_uint (void) const
| is_type_uint(get_decltype())
bool | is_decl_uchar (void) const
| is_type_uchar(get_decltype())
bool | is_decl_uint16 (void) const
| is_type_uint16(get_decltype())
bool | is_decl_uint32 (void) const
| is_type_uint32(get_decltype())
bool | is_decl_uint64 (void) const
| is_type_uint64(get_decltype())
bool | is_decl_uint128 (void) const
| is_type_uint128(get_decltype())
bool | is_decl_ldouble (void) const
| is_type_ldouble(get_decltype())
bool | is_decl_double (void) const
| is_type_double(get_decltype())
bool | is_decl_float (void) const
| is_type_float(get_decltype())
bool | is_decl_floating (void) const
| is_type_floating(get_decltype())
bool | is_decl_bool (void) const
| is_type_bool(get_decltype())
bool | is_decl_paf (void) const
| is_type_paf(get_decltype())
bool | is_well_defined (void) const
| !(empty()) && !(is_decl_partial())
bool | is_const (void) const
| is_type_const(get_realtype())
bool | is_volatile (void) const
| is_type_volatile(get_realtype())
bool | is_void (void) const
| is_type_void(get_realtype())
bool | is_partial (void) const
| is_type_partial(get_realtype())
bool | is_unknown (void) const
| is_type_unknown(get_realtype())
bool | is_ptr (void) const
| is_type_ptr(get_realtype())
bool | is_array (void) const
| is_type_array(get_realtype())
bool | is_func (void) const
| is_type_func(get_realtype())
bool | is_complex (void) const
| is_type_complex(get_realtype())
bool | is_struct (void) const
| is_type_struct(get_realtype())
bool | is_union (void) const
| is_type_union(get_realtype())
bool | is_udt (void) const
| is_type_struni(get_realtype())
bool | is_enum (void) const
| is_type_enum(get_realtype())
bool | is_sue (void) const
| is_type_sue(get_realtype())
bool | is_bitfield (void) const
| is_type_bitfld(get_realtype())
bool | is_int128 (void) const
| is_type_int128(get_realtype())
bool | is_int64 (void) const
| is_type_int64(get_realtype())
bool | is_int32 (void) const
| is_type_int32(get_realtype())
bool | is_int16 (void) const
| is_type_int16(get_realtype())
bool | is_char (void) const
| is_type_char(get_realtype())
bool | is_uint (void) const
| is_type_uint(get_realtype())
bool | is_uchar (void) const
| is_type_uchar(get_realtype())
bool | is_uint16 (void) const
| is_type_uint16(get_realtype())
bool | is_uint32 (void) const
| is_type_uint32(get_realtype())
bool | is_uint64 (void) const
| is_type_uint64(get_realtype())
bool | is_uint128 (void) const
| is_type_uint128(get_realtype())
bool | is_ldouble (void) const
| is_type_ldouble(get_realtype())
bool | is_double (void) const
| is_type_double(get_realtype())
bool | is_float (void) const
| is_type_float(get_realtype())
bool | is_bool (void) const
| is_type_bool(get_realtype())
bool | is_paf (void) const
| is_type_paf(get_realtype())
bool | is_ptr_or_array (void) const
| is_type_ptr_or_array(get_realtype())
bool | is_integral (void) const
| is_type_integral(get_realtype())
bool | is_ext_integral (void) const
| is_type_ext_integral(get_realtype())
bool | is_floating (void) const
| is_type_floating(get_realtype())
bool | is_arithmetic (void) const
| is_type_arithmetic(get_realtype())
bool | is_ext_arithmetic (void) const
| is_type_ext_arithmetic(get_realtype())
bool | is_scalar (void) const
| Does the type represent a single number?
bool | get_ptr_details (ptr_type_data_t *pi) const
| Get only the pointer specific info for this tinfo_t.
bool | get_array_details (array_type_data_t *ai) const
| Get only the array specific info for this tinfo_t.
bool | get_enum_details (enum_type_data_t *ei) const
| Get only the enum specific info for this tinfo_t.
bool | get_bitfield_details (bitfield_type_data_t *bi) const
| Get only the bitfield specific info for this tinfo_t.
bool | get_udt_details (udt_type_data_t *udt, gtd_udt_t gtd=GTD_CALC_LAYOUT) const
| Get only the udt specific info for this tinfo_t.
bool | get_func_details (func_type_data_t *fi, gtd_func_t gtd=GTD_CALC_ARGLOCS) const
| Get only the function specific info for this tinfo_t.
bool | is_funcptr (void) const
| Is this pointer to a function?
int | get_ptrarr_objsize (void) const
| BT_PTR & BT_ARRAY: get size of pointed object or array element. On error returns -1
tinfo_t | get_ptrarr_object (void) const
| BT_PTR & BT_ARRAY: get the pointed object or array element. More...
tinfo_t | get_pointed_object (void) const
| BT_PTR: get type of pointed object. More...
bool | is_pvoid (void) const
| Is "void *"?. This function does not check the pointer attributes and type modifiers.
tinfo_t | get_array_element (void) const
| BT_ARRAY: get type of array element. See also get_ptrarr_object()
int | get_array_nelems (void) const
| BT_ARRAY: get number of elements (-1 means error)
tinfo_t | get_nth_arg (int n) const
| BT_FUNC or BT_PTR BT_FUNC: Get type of n-th arg (-1 means return type, see get_rettype())
tinfo_t | get_rettype (void) const
| BT_FUNC or BT_PTR BT_FUNC: Get the function's return type
int | get_nargs (void) const
| BT_FUNC or BT_PTR BT_FUNC: Calculate number of arguments (-1 - error)
cm_t | get_cc (void) const
| BT_FUNC or BT_PTR BT_FUNC: Get calling convention
bool | is_user_cc (void) const
| is_user_cc(get_cc())
bool | is_vararg_cc (void) const
| is_vararg_cc(get_cc())
bool | is_purging_cc (void) const
| is_purging_cc(get_cc())
int | calc_purged_bytes (void) const
| BT_FUNC: Calculate number of purged bytes
bool | is_high_func (void) const
| BT_FUNC: Is high level type?
int | find_udt_member (int strmem_flags, struct udt_member_t *udm) const
| BTF_STRUCT,BTF_UNION: Find a udt member. More...
int | get_udt_nmembers (void) const
| Get number of udt members. -1-error.
bool | is_empty_udt (void) const
| Is an empty struct/union? (has no fields)
bool | is_small_udt (void) const
| Is a small udt? (can fit a register or a pair of registers)
bool | append_covered (areaset_t *out, uint64 offset=0) const
| Calculate set of covered bytes for the type. More...
bool | calc_gaps (areaset_t *out) const
| Calculate set of padding bytes for the type. More...
bool | is_one_fpval (void) const
| Floating value or an object consisting of one floating member entirely.
bool | is_sse_type (void) const
| Is a SSE vector type?
type_t | get_enum_base_type (void) const
| Get enum base type (convert enum to integer type) Returns BT_UNK if failed to convert.
tinfo_t | get_onemember_type (void) const
| For objects consisting of one member entirely: return type of the member.
uint32 | calc_score (void) const
| Calculate the type score (the higher - the nicer is the type)
bool | print (qstring *out, const char *name=NULL, int prtype_flags=PRTYPE_1LINE, int indent=0, int cmtindent=0, const char *prefix=NULL, const char *cmt=NULL) const
| Get a C-like string representation of the type. More...
const char * | dstr (void) const
| Function to facilitate debugging.
bool | get_attrs (type_attrs_t *tav, bool all_attrs=false) const
| Get type attributes (all_attrs: include attributes of referenced types, if any)
bool | get_attr (const qstring &key, bytevec_t *bv, bool all_attrs=true) const
| Get a type attribute.
bool | set_attrs (type_attrs_t *tav)
| Set type attributes. More...
bool | set_attr (const type_attr_t &ta, bool may_overwrite=true)
| Set a type attribute. If necessary, a new typid will be created.
void | del_attrs (void)
| Del all type attributes. typerefs can not be modified by this function.
bool | del_attr (const qstring &key)
| Del a type attribute. typerefs can not be modified by this function.
bool | create_simple_type (type_t decl_type)
bool | create_ptr (const ptr_type_data_t &p, type_t decl_type=BT_PTR)
bool | create_array (const array_type_data_t &p, type_t decl_type=BT_ARRAY)
bool | create_bitfield (const bitfield_type_data_t &p, type_t decl_type=BT_BITFIELD)
bool | create_typedef (const typedef_type_data_t &p, type_t decl_type=BTF_TYPEDEF, bool try_ordinal=true)
bool | create_forward_decl (til_t *til, type_t decl_type, const char *name, int ntf_flags=0)
| Create a forward declaration. More...
bool | convert_array_to_ptr (void)
| Convert an array into a pointer. More...
bool | remove_ptr_or_array (void)
| Replace the current type with the ptr obj or array element. More...
bool | change_sign (type_sign_t sign)
| Change the type sign. Works only for the types that may have sign.
bool | calc_udt_aligns (int sudt_flags=SUDT_GAPS)
| Calculate the udt alignments using the field offsets/sizes and the total udt size This function does not work on typerefs.
bool | compare_with (const tinfo_t &r, int tcflags=0) const
| Compare two types, based on given flags (see tinfo_t comparison flags)
bool | equals_to (const tinfo_t &r) const
bool | is_castable_to (const tinfo_t &target) const
bool | is_manually_castable_to (const tinfo_t &target) const
Convenience functions
bool | create_ptr (const tinfo_t &tif, uchar bps=0, type_t decl_type=BT_PTR)
bool | create_array (const tinfo_t &tif, uint32 nelems=0, uint32 base=0, type_t decl_type=BT_ARRAY)
void | create_typedef (const til_t *til, const char *name, type_t decl_type=BTF_TYPEDEF, bool try_ordinal=true)
void | create_typedef (const til_t *til, uint ord, type_t decl_type=BTF_TYPEDEF)
bool | create_bitfield (uchar nbytes, uchar width, bool is_unsigned=false, type_t decl_type=BT_BITFIELD)
Warning
These functions consume 'p' (make it empty)
bool | create_udt (udt_type_data_t &p, type_t decl_type)
bool | create_enum (enum_type_data_t &p, type_t decl_type=BTF_ENUM)
bool | create_func (func_type_data_t &p, type_t decl_type=BT_FUNC)
Store type
Store the type info in the type library as a named or numbered type. The tinfo_t object will be replaced by a reference to the created type. Allowed bits for ntf_flags: NTF_NOBASE, NTF_REPLACE
tinfo_code_t | set_named_type (til_t *til, const char *name, int ntf_flags=0)
tinfo_code_t | set_numbered_type (til_t *til, uint32 ord, int ntf_flags=0, const char *name=NULL)
Bitfields
Helper functions to store/extract bitfield values
uint64 | read_bitfield_value (uint64 v, int bitoff) const
uint64 | write_bitfield_value (uint64 dst, uint64 v, int bitoff) const
Modifiers
Work with type modifiers: const and volatile
type_t | get_modifiers (void) const
void | set_modifiers (type_t mod)
void | set_const (void)
void | set_volatile (void)
void | clr_const (void)
void | clr_volatile (void)
void | clr_const_volatile (void)

## Static Public Member Functions
static tinfo_t | get_stock (stock_type_id_t id)
| Get stock type information. More...

## Friends
struct | type_detail_t
tinfo_t | remove_pointer (const tinfo_t &tif)
| BT_PTR: If the current type is a pointer, return the pointed object. More...

## Member Function Documentation

bool tinfo_t::get_named_type | ( | const til_t * | til,
|  | const char * | name,
|  | type_t | decl_type = `BTF_TYPEDEF`,
|  | bool | resolve = `true`,
|  | bool | try_ordinal = `true`
| ) |  |
| inline

Create a tinfo_t object for an existing named type.

Parameters

  til | type library to use
  name | name of the type to link to
  decl_type | if the reference was explicitly specified with the type tag (BTF_STRUCT/BTF_UNION/BTF_ENUM) you may specify it. the kernel will accept only the specified tag after resolving the type. If the resolved type does not correspond to the explicitly specified tag, the type will be considered as undefined
  resolve | true: immediately resolve the type and return success code. false: return true but do not immediately resolve the type
  try_ordinal | true: try to replace name reference by an ordinal reference

bool tinfo_t::get_numbered_type | ( | const til_t * | til,
|  | uint32 | ordinal,
|  | type_t | decl_type = `BTF_TYPEDEF`,
|  | bool | resolve = `true`
| ) |  |
| inline

Create a tinfo_t object for an existing ordinal type.

Parameters

  til | type library to use
  ordinal | number of the type to link to
  decl_type | if the reference was explicitly specified with the type tag (BTF_STRUCT/BTF_UNION/BTF_ENUM) you may specify it. the kernel will accept only the specified tag after resolving the type. If the resolved type does not correspond to the explicitly specified tag, the type will be considered as undefined
  resolve | true: immediately resolve the type and return success code false: return true but do not immediately resolve the type

bool tinfo_t::deserialize | ( | const til_t * | til,
|  | const qtype * | ptype,
|  | const qtype * | pfields = `NULL`,
|  | const qtype * | pfldcmts = `NULL`
| ) |  |
| inline

Deserialize a type string into a tinfo_t object.

bool tinfo_t::is_correct | ( | void |  | ) | const
| inline

Is the type object correct?.

It is possible to create incorrect types. For example, we can define a function that returns a enum and then delete the enum type. If this function returns false, the type should not be used in disassembly. Please note that this function does not verify all involved types: for example, pointers to undefined types are permitted.

type_t tinfo_t::get_realtype | ( | bool | full = `false` | ) | const
| inline

Get the resolved base type.

Deserialization options:

- if full=true, the referenced type will be deserialized fully, this may not always be desirable (slows down things)
- if full=false, we just return the base type, the referenced type will be resolved again later if necessary (this may lead to multiple resolvings of the same type) imho full=false is a better approach because it does not perform unnecessary actions just in case. however, in some cases the caller knows that it is very likely that full type info will be required. in those cases full=true makes sense

type_t tinfo_t::get_decltype | ( | void |  | ) | const
| inline

Get declared type (without resolving type references; they are returned as is).

Obviously this is a very fast function and should be used instead of get_realtype() if possible.

size_t tinfo_t::get_size | ( | uint32 * | p_effalign = `NULL`,
|  | int | gts_code = `0`
| ) |  | const
| inline

Get the type size in bytes.

Parameters

  p_effalign | buffer for the alignment value
  gts_code | combination of GTS_... constants

Returns
  BADSIZE in case of problems

size_t tinfo_t::get_unpadded_size | ( | void |  | ) | const
| inline

Get the type size in bytes without the final padding, in bytes.

For some UDTs get_unpadded_size() != get_size()

bool tinfo_t::is_typeref | ( | void |  | ) | const
| inline

Is this type a type reference?.

Type references can not be modified. Once created, they do not change. Because of this, the set_... functions applied to typerefs create a new type id. Other types are modified directly.

bool tinfo_t::get_type_name | ( | qstring * | out | ) | const
| inline

Does a type refer to a name?.

If yes, fill the provided buffer with the type name and return true. Names are returned for numbered types too: either a user-defined nice name or, if a user-provided name does not exist, an ordinal name (like #xx, see create_numbered_type_name()).

bool tinfo_t::get_final_type_name | ( | qstring * | out | ) | const
| inline

Use in the case of typedef chain (TYPE1 -> TYPE2 -> TYPE3...TYPEn).

Returns
  the name of the last type in the chain (TYPEn). if there is no chain, returns TYPE1

bool tinfo_t::get_next_type_name | ( | qstring * | out | ) | const
| inline

Use In the case of typedef chain (TYPE1 -> TYPE2 -> TYPE3...TYPEn).

Returns
  the name of the next type in the chain (TYPE2). if there is no chain, returns failure

bool tinfo_t::is_from_subtil | ( | void |  | ) | const
| inline

Was the named type found in some base type library (not the top level type library)?.

If yes, it usually means that the type comes from some loaded type library, not the local type library for the database

bool tinfo_t::is_forward_decl | ( | void |  | ) | const
| inline

Is this a forward declaration?.

Forward declarations are placeholders: the type definition does not exist

tinfo_t tinfo_t::get_ptrarr_object | ( | void |  | ) | const
| inline

BT_PTR & BT_ARRAY: get the pointed object or array element.

If the current type is not a pointer or array, return empty type info.

tinfo_t tinfo_t::get_pointed_object | ( | void |  | ) | const
| inline

BT_PTR: get type of pointed object.

If the current type is not a pointer, return empty type info. See also get_ptrarr_object() and remove_pointer()

int tinfo_t::find_udt_member | ( | int | strmem_flags,
|  | struct udt_member_t * | udm
| ) |  | const
| inline

BTF_STRUCT,BTF_UNION: Find a udt member.

- at the specified offset (STRMEM_OFFSET)
- with the specified index (STRMEM_INDEX)
- with the specified type (STRMEM_TYPE)
- with the specified name (STRMEM_NAME)
  Returns
    the index of the found member or -1

bool tinfo_t::append_covered | ( | areaset_t * | out,
|  | uint64 | offset = `0`
| ) |  | const
| inline

Calculate set of covered bytes for the type.

Parameters

  out | pointer to the output buffer. covered bytes will be appended to it.

bool tinfo_t::calc_gaps | ( | areaset_t * | out | ) | const
| inline

Calculate set of padding bytes for the type.

Parameters

  out | pointer to the output buffer; old buffer contents will be lost.

bool tinfo_t::print | ( | qstring * | out,
|  | const char * | name = `NULL`,
|  | int | prtype_flags = `PRTYPE_1LINE`,
|  | int | indent = `0`,
|  | int | cmtindent = `0`,
|  | const char * | prefix = `NULL`,
|  | const char * | cmt = `NULL`
| ) |  | const
| inline

Get a C-like string representation of the type.

Parameters

  out | output string
  name | name of type
  prtype_flags | Type printing flags
  indent | structure level indent
  cmtindent | comment indent
  prefix | string prepended to each line
  cmt | comment text

Returns
  success

bool tinfo_t::set_attrs | ( | type_attrs_t * | tav | ) |
| inline

Set type attributes.

If necessary, a new typid will be created. this function modifies tav! (returns old attributes, if any)

Returns
  false: bad attributes

bool tinfo_t::create_forward_decl | ( | til_t * | til,
|  | type_t | decl_type,
|  | const char * | name,
|  | int | ntf_flags = `0`
| ) |  |
| inline

Create a forward declaration.

decl_type: BTF_STRUCT, BTF_UNION, or BTF_ENUM

static tinfo_t tinfo_t::get_stock | ( | stock_type_id_t | id | ) |
| inline static

Get stock type information.

This function can be used to get tinfo_t for some common types. The same tinfo_t will be returned for the same id, thus saving memory and increasing the speed

bool tinfo_t::convert_array_to_ptr | ( | void |  | ) |
| inline

Convert an array into a pointer.

type[] => type *

bool tinfo_t::remove_ptr_or_array | ( | void |  | ) |
| inline

Replace the current type with the ptr obj or array element.

This function performs one of the following conversions:

- type[] => type
- type* => type If the conversion is performed successfully, return true

## Friends And Related Function Documentation

tinfo_t remove_pointer | ( | const tinfo_t & | tif | ) |
| friend

BT_PTR: If the current type is a pointer, return the pointed object.

If the current type is not a pointer, return the current type. See also get_ptrarr_object() and get_pointed_object()

The documentation for this class was generated from the following file:

- typeinf.hpp