# Porting guide for IDA 7.4 IDAPython and Python 3

IDAPython developers

## Scope of this guide

IDA 7.4 [comes with the possibility of using Python 3](https://docs.hex-rays.com/archive/idapython-and-python-3).

Using Python 3 means that some code, which used to work, might require porting:

* `print()` becoming a function, not a statement
* `xrange` becoming `range`
* `__builtin__` becoming `builtins`
* strings being unicode and not sets of bytes
* integer division uses `//` and not `/`
* `map()` returning a map object, not a list
* `{}.iteritems()` (and similar) are gone
* some changes in the `import` mechanism
* ...

Those are all well-documented Python 3 specifics, are [thoroughly documented](https://python-future.org/compatible_idioms.html), and Python even provides [tools](https://docs.python.org/2/library/2to3.html) to help with the transition.

This guide is not about those, but about IDAPython-specific changes to the API, but many of those being "ripples" of those Python 3 changes.

## The guide

Note: that all qualified names below use their originating IDAPython module's name (e.g., `ida_kernwin`) instead of the 'umbrella' `idaapi` module.

| Before                                                            | After                         | Notes                                                                                                |
| ----------------------------------------------------------------- | ----------------------------- | ---------------------------------------------------------------------------------------------------- |
| ida\_bytes.data\_format\_t.printf                                 |                               | The `value` parameter used to be a `str`, now is `bytes`                                             |
| ida\_bytes.get\_bytes, ida\_bytes.get\_bytes\_and\_mask           |                               | Used to return a `str`, now returns `bytes`                                                          |
| ida\_bytes.get\_strlit\_contents                                  |                               | Used to return a `str`, now returns `bytes`                                                          |
| ida\_hexrays.mbl\_array\_t.serialize                              |                               | Used to return a `str`, now returns `bytes`                                                          |
| ida\_idp.IDP\_Hooks.ev\_assemble                                  |                               | Used to return a `str`, now must return `bytes`                                                      |
| ida\_nalt.retrieve\_input\_file\_md5                              |                               | Used to return a `str` (the 'hex' representation of the bytes), now returns `bytes`                  |
| ida\_nalt.retrieve\_input\_file\_sha256                           |                               | Used to return a `str` (the 'hex' representation of the bytes), now returns `bytes`                  |
| ida\_netnode.netnode.getblob                                      |                               | Used to return a `str`, now returns `bytes`                                                          |
| ida\_registry.reg\_read\_binary                                   |                               | Used to return a `str`, now returns `bytes`                                                          |
| ida\_typeinf.tinfo\_t.serialize                                   |                               | Used to return `str` instances for the 'type' and 'fields' parts of the tuple, now those are `bytes` |
| ida\_typeinf.get\_numbered\_type                                  |                               | Used to return `str` instances for the 'type' and 'fields' parts of the tuple, now those are `bytes` |
| ida\_ua.insn\_t.insnpref                                          |                               | Used to return a `str`, now returns an `int`                                                         |
| ida\_ua.insn\_t.segpref                                           |                               | Used to return a `str`, now returns an `int`                                                         |
| `idautils._cpu.`\<large vector registers, such as xmm0, ymm0,...> |                               | Used to return a `str`, now returns `bytes`                                                          |
| idautils.Functions.next                                           | `idautils.Functions.__next__` | Required to turn the type into a proper iterator in Python 3                                         |
| idautils.GetInputFileMD5                                          |                               | Used to return a `str` (the 'hex' representation of the bytes), now returns `bytes`                  |
