0

i'm actually quite new to IDApython programing and i'm trying to get, for a "switch-case" jump table, the list of basic blocks for a given value of the case.

While experimenting, i was trying to access the switch-case table using the following code as following the official documentation.

import idautils
import idaapi
import idc

myfunc=0
jump_table = dict()
switch_map = {}

for func in idautils.Functions():
    if 'Myfunction_name' == idc.GetFunctionName(func):
        print 'function found'
        myfunc = func
        break

for (startea, endea) in Chunks(myfunc):
    for head in Heads(startea, endea):
        switch_info = idaapi.get_switch_info_ex(head)
        if switch_info != None:
            num_cases = switch_info.get_jtable_size()
            if num_cases == 148:
                print 'good jump table found'
                results = idaapi.calc_switch_cases(head, switch_info)
                for idx in xrange(results.cases.size()):
                    cur_case = results.cases[idx]
                    """
         --->       #can't use the following

           -->      for cidx in xrange(len(cur_case)):
           -->          print "case: %d" % cur_case[cidx]
                    """
                    print "  goto 0x%x" % results.targets[idx]
                #for cidx in xrange(cur_case.size()):
                print cur_case
                print "  goto 0x%x" % results.targets[idx]
            else:
                continue
        else:
            continue

Unfortunately, i am not able to access correctly the cases values, as shown by the arrows in the code. Indeed, the "cur_case" object is a PySwigObject, which is not iterable.

Any idea on how to get that code to work? (notes : i'm using IDA 64 bits)

thanks in advance!

0

OK, my bad... I was actually using IDA 6.8, and the API for this version does not create iterable Objects.

Using IDA 7 solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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