I'm trying to programmatically link decompiled code generated by HexRays with the disassembly code of a given binary by mapping memory addresses between the two. The mapping exists, as I can see view it through IDA on a case by case basis (see the line of decompiled code in green, associated with the memory address in gold, which lets me reference the disassembly. Clicking through different decompiled source lines links to different memory addresses/sets of disassembly lines). But I can't find any way to get at these associations via scripting (IDC, IDAPython, etc) or via the command line. This strikes me as strange, as I can't imagine that this functionality hasn't been sought out or used before.

My end goal is to be able to read in a set of decompiled code line numbers, then return all the lines of disassembly which map to those decompiled code lines.


enter image description here

1 Answer 1


In hexrays.hpp, citem_t is the base class for both cinsn_t ("instructions", such as for loops, if statements, etc.) and cexpr_t ("expressions", such as addition, memory dereference, function calls, etc.) citem_t has a field ea_t ea;. That field stores the address of the corresponding line in the assembly language (unless it's BADADDR, in which case, the decompiler machinery lost track of the address).

To accomplish your goal specifically, you're going to want to get your hands on the cinsn_t objects on certain lines in the decompilation listing. Here are three separate ideas for how to accomplish this:

  1. Grab the function body directly out of the cfunc_t and process it yourself;
  2. Use a ctree_visitor_t object to visit all cinsn_t objects within the decompilation listing;
  3. Call kernwin.hpp::read_selection to get a selection of lines within the decompilation listing (there will be some work to do in mapping these back to positions within the decompiled function body).
  • Thanks a ton for your detailed help! I'll give this a shot tomorrow morning.
    – TFD
    Oct 6, 2020 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.