6

I was not able to find an API function to get the CPU architecture of the loaded binary. In idaapi.py, there is a function def set_processor_type(*args) but no equivalent such as get_processor_type.

I don't want to fall back to running some additional (python) tool such as file, readelf or a python ELF parser. I also don't like the idea of parsing the strings displayed at the beginning of the IDA assembly listing.

There must be a way to use idc.py, idaapi.py or idautils.py for this.

2
  • Sorry for resurrecting this old thread, but for reasons I'm unable to figure out, both info.is_64bit() and info.is_32bit() are not working for me. I'm using IDA C++ SDK v7.1. Even if the executable in the database is 64-bit, it still goes through the 32-bit check. Any idea why this is happening?
    – Pocanatos
    Feb 26, 2020 at 16:20
  • 1
    If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – knx
    Feb 27, 2020 at 8:58

3 Answers 3

8

You can get the name of the processor from the idainfo struct:

import idaapi

info = idaapi.get_inf_structure()

if info.is_64bit():
    bits = 64
elif info.is_32bit():
    bits = 32
else:
    bits = 16

try:
    is_be = info.is_be()
except:
    is_be = info.mf
endian = "big" if is_be else "little"

print 'Processor: {}, {}bit, {} endian'.format(info.procName, bits, endian)
# Result: Processor: mipsr, 32bit, big endian

Still haven't found the endian, though.

EDIT: Endian can be determined by processor name. For example, mipsr is big endian, and mipsrl is little endian.

EDIT:
Added a proper endian check (mf == MSB First). Based on this answer.

EDIT:
Since IDA7 beta 3 (170724), idainfo.mf was removed, and idainfo.is_be() must be used. Based on keypatch

3

Not all processor name has endian information. Generally it can be determinded as:

BIG_ENDIAN if _idaapi.cvar.inf.mf else LITTLE_ENDIAN
0
2

This is definitely not exact answer, but probably you could make use of

idaapi.ph_get_regnames() 

Returns the list of register names as defined in the processor module

Different platforms has different register sets, and if you will not find your solution about exact cpu you can give it a try. This function exists in IDA 6.8.

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.