I want to analysis a Universal macOS Binary, it’s include a multi-arch binary (x64 & ARM), and when I use idalib in python, it’s cannot be select arch manually.
e.g.
import idapro
# copy /System/Applications/Books.app/Contents/MacOS/Books to ./Books
idapro.open_database("./Books", run_auto_analysis=True)
idaapi.auto_wait()
# do something here
idapro.close_database(save=False)
I believe for 9.0 you’ll have to pre-process the binary with lipo to extract the necessary slice. In 9.1 we’ll add a possibility to pass IDA-compatible command-line arguments to open_database(), so you’ll be able to specify -parm or -ppc, which should influence the default slice selection.
#!/usr/bin/env python3
"""
Database exploration example for IDA Domain API.
This example demonstrates how to open an IDA database and explore its basic properties.
"""
import argparse
from dataclasses import asdict
import ida_domain
from ida_domain import Database
from ida_domain.database import IdaCommandOptions
def explore_database(db_path):
"""Explore basic database information."""
ida_options = IdaCommandOptions(auto_analysis=True, new_database=True, file_type='Fat Mach-O file, 2')
with Database.open(db_path, ida_options) as db:
# Get basic information
print(f'Address range: {hex(db.minimum_ea)} - {hex(db.maximum_ea)}')
# Get metadata
print('Database metadata:')
metadata_dict = asdict(db.metadata)
for key, value in metadata_dict.items():
print(f' {key}: {value}')
# Count functions
function_count = 0
for _ in db.functions:
function_count += 1
print(f'Total functions: {function_count}')
def main():
"""Main entry point with argument parsing."""
parser = argparse.ArgumentParser(description='Database exploration example')
parser.add_argument(
'-f', '--input-file', help='Binary input file to be loaded', type=str, required=True
)
args = parser.parse_args()
explore_database(args.input_file)
if __name__ == '__main__':
from dotenv import load_dotenv
load_dotenv()
main()
to see analysis messages you need to call idapro.enable_console_messages(True), and/or add -Llogfile.txt to the commandline options to copy them to a file.
Possible file format: Fat Mach-O file, 1. X86_64 (/Applications/IDA Professional 9.1.app/Contents/MacOS/loaders/macho.dylib)
Possible file format: Fat Mach-O file, 2. ARM64 (/Applications/IDA Professional 9.1.app/Contents/MacOS/loaders/macho.dylib)
bytes pages size description
--------- ----- ---- --------------------------------------------
1327104 162 8192 allocating memory for b-tree...
1327104 162 8192 allocating memory for virtual array...
262144 32 8192 allocating memory for name pointers...
-----------------------------------------------------------------
2916352 total memory allocated
Unknown switch '-T' -> OK
it’s seems cannot process `-T`
and moreever, I cannot use idapro in 9.2:
import os
os.environ['IDADIR'] = '/Applications/IDA Professional 9.2.app/Contents/MacOS'
import idapro
import idaapi
log:
Import failed: dlopen(/Applications/IDA Professional 9.2.app/Contents/MacOS/python/lib-dynload/_ida_pro.so, 0x0002): symbol not found in flat namespace '_bitcountr_zero'. Current sys.path:
/Applications/IDA Professional 9.2.app/Contents/MacOS/python
/Applications/IDA Professional 9.2.app/Contents/MacOS/python/lib-dynload
...
/Applications/IDA Professional 9.2.app/Contents/MacOS/python
Traceback (most recent call last):
File "xxx", line 5, in <module>
import idapro
File "xxx/.venv/lib/python3.12/site-packages/idapro/__init__.py", line 75, in <module>
raise ImportError(f"Failed to initialize IDA library, {error_description}, check logging for additional information\n")
ImportError: Failed to initialize IDA library, exception <_FuncPtr object at 0x100605a90> returned a result with an exception set, check logging for additional information
but it’s cannot works for any version for normal python
$ uv venv --python 3.13
...
$ source .venv/bin/activate
$ python test.py
Import failed: dlopen(/Applications/IDA Professional 9.2.app/Contents/MacOS/python/lib-dynload/_ida_pro.so, 0x0002): symbol not found in flat namespace '_bitcountr_zero'. Current sys.path:
/Applications/IDA Professional 9.2.app/Contents/MacOS/python
/Applications/IDA Professional 9.2.app/Contents/MacOS/python/lib-dynload
...
/Applications/IDA Professional 9.2.app/Contents/MacOS/python
Traceback (most recent call last):
File "/Applications/IDA Professional 9.2.app/Contents/MacOS/python/init.py", line 53, in <module>
globals()[f"ida_{mod}"] = __import__(f"ida_{mod}")
~~~~~~~~~~^^^^^^^^^^^^^^
File "/Applications/IDA Professional 9.2.app/Contents/MacOS/python/ida_hexrays.py", line 105, in <module>
import ida_pro
File "/Applications/IDA Professional 9.2.app/Contents/MacOS/python/ida_pro.py", line 20, in <module>
import _ida_pro
ImportError: dlopen(/Applications/IDA Professional 9.2.app/Contents/MacOS/python/lib-dynload/_ida_pro.so, 0x0002): symbol not found in flat namespace '_bitcountr_zero'
Traceback (most recent call last):
File "test.py", line 10, in <module>
import idaapi
File "/Applications/IDA Professional 9.2.app/Contents/MacOS/python/idaapi.py", line 5, in <module>
from ida_hexrays import *
File "/Applications/IDA Professional 9.2.app/Contents/MacOS/python/ida_hexrays.py", line 105, in <module>
import ida_pro
File "/Applications/IDA Professional 9.2.app/Contents/MacOS/python/ida_pro.py", line 20, in <module>
import _ida_pro
ImportError: dlopen(/Applications/IDA Professional 9.2.app/Contents/MacOS/python/lib-dynload/_ida_pro.so, 0x0002): symbol not found in flat namespace '_bitcountr_zero'