1

I am using the hexray api to get all the items of the AST tree (the ctree) obtained by decompiling a function.

Unfortunately, the treeitems vector is always empty. Specifically, the function paaaa in this code returns always '0' or 'E'.

from idautils import *
from idaapi import *
import idc
import ida_hexrays as hexray

def load_hex_ray():
    if not init_hexrays_plugin():
        idc.RunPlugin("hexx64", 0)
    if not init_hexrays_plugin():
        idc.RunPlugin("hexrays", 0)
    if not init_hexrays_plugin():
        idc.RunPlugin("hexarm", 0)

def paaaaa(address):
        try:
            cfun=hexray.decompile(address)
            #if I print cfun it shows correct decompiled code.
            cfun.refcnt=cfun.refcnt+1
            cfun.build_c_tree()
            return str((cfun.treeitems.size()))
        except:
            return 'E'

load_hex_ray()
#code that compute functions addresses and calls paaaaa

Any idea on what can be wrong? I am using an old version of IDA 7.0

1 Answer 1

0

I fixed the issue even if I do not fully understand why this solution work:

def paaaaa(address):
    try:
        cfun=hexray.decompile(address)
        print(cfun)
        return str((cfun.treeitems.size()))
    except:
        return 'E'

probably the print forces ida to correctly populate the ctree. I do not understand why the api cfun.build_c_tree() does not do the same.

However, for now, I am good with this workaround.

Your Answer

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

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