For every selected byte Ida Pro displays the offset in the input file where the byte can be found (displayed in the buttom bar of the Ida-View and the Hex-View). How can I retrieve this information when using the idapython API?
1 Answer
When looking for functions, you should always check the SDK headers. These two are listed in loader.hpp
:
// Get offset in the input file which corresponds to the given ea
// If the specified ea can't be mapped into the input file offset,
// return -1.
idaman int32 ida_export get_fileregion_offset(ea_t ea);
// Get linear address which corresponds to the specified input file offset.
// If can't be found, then return BADADDR
idaman ea_t ida_export get_fileregion_ea(int32 offset);
So you can use them from IDAPython like this:
offset = idaapi.get_fileregion_offset(ea)
ea = idaapi.get_fileregion_ea(offset)
NB: not all SDK functions are exposed in Python. If you absolutely need something which is only available in C API, you can use ctypes
to call it.