IDA SDK
Modules | Macros | Functions
Functions: string conversion

Detailed Description

functions that convert between string encodings

Modules

 String to address conversion flags
 passed as 'flags' parameter to str2ea_ex()
 

Macros

#define MAX_NUMBUF   (128+8)
 16-byte value in binary base (0b00101010...)
 
#define b2a   b2a32
 shortcut for number->string conversion, see b2a32()
 
#define btoa   btoa32
 shortcut for number->string conversion, see btoa32()
 
#define atob   atob32
 shortcut for string->number conversion, see atob32()
 

Functions

bool ea2str (qstring *out, ea_t ea)
 Convert linear address to UTF-8 string.
 
idaman bool ida_export str2ea (ea_t *ea_ptr, const char *str, ea_t screen_ea)
 Convert string to linear address. More...
 
idaman bool ida_export str2ea_ex (ea_t *ea_ptr, const char *str, ea_t screen_ea, int flags)
 Same as str2ea() but possibly with some steps skipped. More...
 
idaman bool ida_export atoea (ea_t *pea, const char *str)
 Convert a number in C notation to an address. More...
 
idaman size_t ida_export stoa (qstring *buf, ea_t from, sel_t seg)
 Convert segment selector to UTF-8 string.
 
idaman int ida_export atos (sel_t *seg, const char *str)
 Convert UTF-8 string to segment selector. More...
 
idaman size_t ida_export b2a_width (int nbytes, int radix)
 Get the number of UTF-8 characters required to represent a number with the specified number of bytes and radix. More...
 
idaman size_t ida_export b2a32 (char *buf, size_t bufsize, uint32 x, int nbytes, int radix)
 Convert number to UTF-8 string (includes leading zeroes). More...
 
idaman size_t ida_export b2a64 (char *buf, size_t bufsize, uint64 x, int nbytes, int radix)
 Same as b2a32(), but can handle 'nbytes' = 8.
 
idaman size_t ida_export btoa_width (int nbytes, flags_t flag, int n)
 Get max number of UTF-8 characters required to represent a given type of value, with a given size (without leading zeroes). More...
 
idaman size_t ida_export btoa32 (char *buf, size_t bufsize, uint32 x, int radix=0)
 Same as b2a32(), but will generate a string without any leading zeroes. More...
 
idaman size_t ida_export btoa64 (char *buf, size_t bufsize, uint64 x, int radix=0)
 64-bit equivalent of btoa32()
 
idaman size_t ida_export btoa128 (char *buf, size_t bufsize, uint128 x, int radix=0)
 128-bit equivalent of btoa32()
 
idaman size_t ida_export numop2str (char *buf, size_t bufsize, ea_t ea, int n, uint64 x, int nbytes, int radix=0)
 Convert instruction operand immediate number to UTF-8. More...
 
idaman bool ida_export atob32 (uint32 *x, const char *str)
 Convert UTF-8 to a number using the current assembler formats. More...
 
idaman bool ida_export atob64 (uint64 *x, const char *str)
 64-bit equivalent of atob32()
 
idaman void ida_export append_disp (qstring *buf, adiff_t disp, bool tag=true)
 Auxiliary function. More...
 
idaman THREAD_SAFE int ida_export r50_to_asc (char *p, const ushort *r, int k)
 Convert RADIX50 -> UTF-8. More...
 
int THREAD_SAFE asc_to_r50 (ushort *r, const char *p, int k)
 Convert UTF-8 -> RADIX50 (see r50_to_asc())
 

Function Documentation

idaman bool ida_export str2ea ( ea_t ea_ptr,
const char *  str,
ea_t  screen_ea 
)

Convert string to linear address.

Tries to interpret the string as:
1) "current IP" keyword if supported by assembler (e.g. "$" in x86)
2) segment:offset expression, where "segment" may be a name or a fixed segment register (e.g. cs, ds)
3) just segment name/register (translated to segment's start address)
4) a name in the database (or debug name during debugging)
5) +delta or -delta, where numerical 'delta' is added to or subtracted from 'screenEA'
6) if all else fails, try to evaluate 'str' as an IDC expression

idaman bool ida_export str2ea_ex ( ea_t ea_ptr,
const char *  str,
ea_t  screen_ea,
int  flags 
)

Same as str2ea() but possibly with some steps skipped.

Parameters
flagsString to address conversion flags
idaman bool ida_export atoea ( ea_t pea,
const char *  str 
)

Convert a number in C notation to an address.

decimal: 1234
octal: 0123
hexadecimal: 0xabcd
binary: 0b00101010

idaman int ida_export atos ( sel_t seg,
const char *  str 
)

Convert UTF-8 string to segment selector.

Return values
0- fail
1- ok (hex)
2- ok (segment name or reg)
idaman size_t ida_export b2a_width ( int  nbytes,
int  radix 
)

Get the number of UTF-8 characters required to represent a number with the specified number of bytes and radix.

Parameters
nbytesif 0, use default number of bytes, usually 4 or 8 depending on __EA64__
radixif 0, use default radix, usually 16
idaman size_t ida_export b2a32 ( char *  buf,
size_t  bufsize,
uint32  x,
int  nbytes,
int  radix 
)

Convert number to UTF-8 string (includes leading zeroes).

Parameters
xvalue to convert
bufoutput buffer
bufsizesize of output buffer
nbytes1, 2, 3, or 4
radix2, 8, 10, or 16
Returns
size of resulting string
idaman size_t ida_export btoa_width ( int  nbytes,
flags_t  flag,
int  n 
)

Get max number of UTF-8 characters required to represent a given type of value, with a given size (without leading zeroes).

Parameters
nbytessize of number
flagshould be one of FF_ for MS_0TYPE
nif 1, shr 'flag' by 4
idaman size_t ida_export btoa32 ( char *  buf,
size_t  bufsize,
uint32  x,
int  radix = 0 
)

Same as b2a32(), but will generate a string without any leading zeroes.

Can be used to output some numbers in the instructions.

idaman size_t ida_export numop2str ( char *  buf,
size_t  bufsize,
ea_t  ea,
int  n,
uint64  x,
int  nbytes,
int  radix = 0 
)

Convert instruction operand immediate number to UTF-8.

This is the main function to output numbers in the instruction operands.
It prints the number with or without the leading zeroes depending on the flags.
This function is called from out_value(). Please use out_value() if you can.

idaman bool ida_export atob32 ( uint32 x,
const char *  str 
)

Convert UTF-8 to a number using the current assembler formats.

e.g. for ibmpc, '12o' is octal, '12h' is hex, etc.

Returns
success
idaman void ida_export append_disp ( qstring buf,
adiff_t  disp,
bool  tag = true 
)

Auxiliary function.

Print displacement to a name (+disp or -disp) in the natural radix

Parameters
bufoutput buffer to append to
dispdisplacement to output. 0 leads to no modifications
tagwhether to output color tags
idaman THREAD_SAFE int ida_export r50_to_asc ( char *  p,
const ushort r,
int  k 
)

Convert RADIX50 -> UTF-8.

Parameters
ppointer to UTF-8 string
rpointer to radix50 string
knumber of elements in the input string
(element of radix50 string is a word)
(element of UTF-8 string is a character)
Returns
number of elements left unprocessed in the input string,
because the input string contains unconvertible elements.
0-ok, all elements are converted