IDA SDK

- Main Page
- Header Files
- Classes
- Modules

Modules | Macros | Functions | Variables
Functions: string conversion
Functions: strings

## Detailed Description

functions that convert between string encodings

## Modules
| String to address conversion flags
| passed as 'flags' parameter to str2ea_ex()
| Functions: c strings
| String C-style conversions (convert \n to a newline and vice versa)

## 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
idaman size_t ida_export | ea2str (ea_t ea, char *buf, size_t bufsize)
| Convert linear address to ascii string.
bool | ea2str (qstring *out, ea_t ea)
idaman bool ida_export | str2ea (const char *str, ea_t *ea_ptr, ea_t screen_ea)
| Convert string to linear address. More...
idaman bool ida_export | str2ea_ex (const char *str, ea_t *ea_ptr, ea_t screen_ea, int flags)
| Same as str2ea() but possibly with some steps skipped. More...
idaman bool ida_export | atoea (const char *str, ea_t *pea)
| Convert a number in C notation to an address. More...
idaman size_t ida_export | stoa (ea_t from, sel_t seg, char *buf, size_t bufsize)
| Convert segment selector to ascii string.
idaman int ida_export | atos (const char *str, sel_t *seg)
| Convert ascii string to segment selector. More...
idaman size_t ida_export | b2a_width (int nbytes, int radix)
| Get the number of ascii characters required to represent a number with the specified number of bytes and radix. More...
idaman size_t ida_export | b2a32 (uint32 x, char *buf, size_t bufsize, int nbytes, int radix)
| Convert number to ascii string (includes leading zeroes). More...
idaman size_t ida_export | b2a64 (uint64 x, char *buf, size_t bufsize, 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 ascii 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 ascii. More...
idaman bool ida_export | atob32 (const char *str, uint32 *x)
| Convert ascii to a number using the current assembler formats. More...
idaman bool ida_export | atob64 (const char *str, uint64 *x)
| 64-bit equivalent of atob32()
idaman size_t ida_export | print_disp (char *buf, char *end, adiff_t disp)
| Auxiliary function. More...
idaman THREAD_SAFE int ida_export | r50_to_asc (const ushort *r, char *p, int k)
| Convert RADIX50 -> ASCII. More...
int THREAD_SAFE | asc_to_r50 (const char *p, ushort *r, int k)
| Convert ASCII -> RADIX50 (see r50_to_asc())

## Variables
idaman char ida_export_data | AsciiStringChars [256+1]
| Maintain a collection of characters that are allowed in ASCII strings. More...

## Function Documentation

idaman bool ida_export str2ea | ( | const char * | str,
|  | ea_t * | ea_ptr,
|  | 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 | ( | const char * | str,
|  | ea_t * | ea_ptr,
|  | ea_t | screen_ea,
|  | int | flags
| ) |  |

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

Parameters

  flags | String to address conversion flags

idaman bool ida_export atoea | ( | const char * | str,
|  | ea_t * | pea
| ) |  |

Convert a number in C notation to an address.

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

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

Convert ascii 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 ascii characters required to represent a number with the specified number of bytes and radix.

Parameters

  radix | if 0, use default radix, usually 16
  nbytes | if 0, use default number of bytes, usually 4 or 8 depending on __EA64__

idaman size_t ida_export b2a32 | ( | uint32 | x,
|  | char * | buf,
|  | size_t | bufsize,
|  | int | nbytes,
|  | int | radix
| ) |  |

Convert number to ascii string (includes leading zeroes).

Parameters

  x | value to convert
  buf | output buffer
  bufsize | size of output buffer
  nbytes | 1, 2, 3, or 4
  radix | 2, 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 ascii characters required to represent a given type of value, with a given size (without leading zeroes).

Parameters

  nbytes | size of number
  flag | should be one of FF_ for MS_0TYPE
  n | if 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 ascii.

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 OutValue(). please use OutValue() if you can.

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

Convert ascii to a number using the current assembler formats.

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

Returns
  success

idaman size_t ida_export print_disp | ( | char * | buf,
|  | char * | end,
|  | adiff_t | disp
| ) |  |

Auxiliary function.

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

Parameters

  buf | pointer to the output buffer
  end | pointer to the end of the output buffer
  disp | displacement to output. 0 leads to no modifications

Returns
  length of resulting string

idaman THREAD_SAFE int ida_export r50_to_asc | ( | const ushort * | r,
|  | char * | p,
|  | int | k
| ) |  |

Convert RADIX50 -> ASCII.

Parameters

  r | pointer to radix50 string
  p | pointer to ascii string
  k | number of elements in the input string (element of radix50 string is a word) (element of ascii 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

## Variable Documentation

idaman char ida_export_data AsciiStringChars[256+1]

Maintain a collection of characters that are allowed in ASCII strings.

In order to find the end of a string IDA looks for a character which doesn't belong to this array.