### Run Example Script Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/examples.md Command to run example scripts with an IDA database path. ```bash python example_script.py ``` -------------------------------- ### Quick Example of IDA Domain API Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/index.md This is a quick example demonstrating the usage of the IDA Domain API. It requires IDA Pro 9.1.0 or later and can be installed via pip. ```python --8<-- "examples/quick_example.py" ``` -------------------------------- ### Install IDA Domain from PyPI Source: https://github.com/hexrayssa/ida-domain/blob/main/README.md Install the ida-domain library using pip. ```bash pip install ida-domain ``` -------------------------------- ### Register IDA Installation Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Register your IDA Pro installation to set up the necessary Python environment for the `idapro` module. This is a one-time setup. ```bash python "[Your IDA Installation Directory]/idalib/python/py-activate-idalib.py" ``` -------------------------------- ### Install IDA Domain Package Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/getting_started.md Steps to create a virtual environment and install the ida-domain package using pip. ```bash # Create and activate virtual environment python -m venv ida-env source ida-env/bin/activate # On Windows: ida-env\Scripts\activate # Install the package pip install ida-domain ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Install project dependencies, including development tools, using UV. This also installs pre-commit hooks. ```bash uv sync --extra dev uv run pre-commit install ``` -------------------------------- ### Analyze Database Example Source: https://github.com/hexrayssa/ida-domain/blob/main/README.md Run a Python script to analyze a database using the IDA Domain project's example. ```bash uv run python examples/analyze_database.py ``` -------------------------------- ### Test with actual IDA binaries Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Run example scripts to test changes with actual IDA binaries. ```bash python examples/explore_database.py -f /path/to/test/binary ``` -------------------------------- ### IDA Domain Example Template Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md A template for creating new Python examples for IDA Domain. It includes argument parsing and a basic structure for demonstrating functionality. ```python #!/usr/bin/env python3 """ Brief description of what this example demonstrates. This example shows how to use IDA Domain to [specific functionality]. """ import argparse import ida_domain def main_functionality(db_path): """Main function demonstrating the feature.""" # Your implementation here pass def main(): """Main entry point with argument parsing.""" parser = argparse.ArgumentParser(description='Example description') parser.add_argument( '-f', '--input-file', help='Binary input file to be loaded', type=str, required=True ) args = parser.parse_args() main_functionality(args.input_file) if __name__ == '__main__': main() ``` -------------------------------- ### Activate IDA Library (Windows) Source: https://github.com/hexrayssa/ida-domain/blob/main/README.md Run this script to auto-detect and configure the IDA installation path for the idapro module on Windows. ```cmd python "C:\Program Files\IDA Professional 9.1\idalib\python\py-activate-idalib.py" ``` -------------------------------- ### Activate IDA SDK Access (Linux) Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/getting_started.md Run this script to configure the idapro Python module with the IDA Pro installation path on Linux. ```bash python3 "/opt/ida-9.2/idalib/python/py-activate-idalib.py" ``` -------------------------------- ### Activate IDA Library (Linux/macOS) Source: https://github.com/hexrayssa/ida-domain/blob/main/README.md Run this script to auto-detect and configure the IDA installation path for the idapro module on Linux or macOS. ```bash python3 "/path/to/ida/idalib/python/py-activate-idalib.py" ``` -------------------------------- ### Activate IDA SDK Access (Windows) Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/getting_started.md Run this script to configure the idapro Python module with the IDA Pro installation path on Windows. ```cmd python "C:\Program Files\IDA Professional 9.2\idalib\python\py-activate-idalib.py" ``` -------------------------------- ### Verify IDA Domain Installation Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/getting_started.md A Python script to check if the ida_domain module can be imported successfully. ```python # test_install.py try: from ida_domain import Database print("✓ Installation successful!") except ImportError as e: print(f"✗ Installation failed: {e}") ``` -------------------------------- ### Run First IDA Domain Script Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/getting_started.md Example of a Python script to explore an IDA database in library mode. Run using `python my_first_script.py -f `. ```python #--8<-- "examples/my_first_script.py" ``` -------------------------------- ### Activate IDA SDK Access (macOS) Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/getting_started.md Run this script to configure the idapro Python module with the IDA Pro installation path on macOS. ```bash python3 "/Applications/IDA Professional 9.2.app/Contents/MacOS/idalib/python/py-activate-idalib.py" ``` -------------------------------- ### Accessing IDA Domain Entities Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/usage.md Open a database and access its entities through the database handle. This is the typical starting point for using the library. ```python db = Database() db.open('/path/to/your/database.idb') db.functions.get_all() db.segments.get_all() db.entries.get_all() ... ``` -------------------------------- ### Rebuild Assembly Test Binary Source: https://github.com/hexrayssa/ida-domain/blob/main/tests/resources/README.md Use this command to rebuild the tiny_asm.bin binary from the tiny_asm.asm source file. Ensure NASM is installed. ```bash nasm -f elf64 tiny_asm.asm -o tiny_asm.bin ``` -------------------------------- ### Format Code with Black Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Run the Black code formatter on the ida_domain, examples, and tests directories to ensure consistent code style. ```bash # Format code uv run black ida_domain/ examples/ tests/ ``` -------------------------------- ### Run Script Inside IDA Console Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/getting_started.md Example of using IDA Domain from within the IDA GUI. Use `Database.open()` with no arguments to access the currently open database. ```python #--8<-- "examples/ida_console_example.py" ``` -------------------------------- ### Run Linting with Ruff Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Execute the Ruff linter to check for code quality and style issues in the ida_domain, examples, and tests directories. ```bash # Run linting uv run ruff check ida_domain/ examples/ tests/ ``` -------------------------------- ### Get Functions: Old vs. New API Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md Illustrates the change in function retrieval from implicit global state to explicit dependency injection with the Database object. ```python def get_functions(): for ea in idautils.Functions(): f = idaapi.get_func(ea) yield f ``` ```python def get_functions(db: Database): for f in db.functions.get_all(): yield f ``` -------------------------------- ### Override IDA Install Directory (Linux) Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/getting_started.md Set the IDADIR environment variable to specify a particular IDA Pro installation directory for a single session on Linux. ```bash export IDADIR="/opt/ida-9.2/" ``` -------------------------------- ### Override IDA Install Directory (Windows) Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/getting_started.md Set the IDADIR environment variable to specify a particular IDA Pro installation directory for a single session on Windows. ```cmd set "IDADIR=C:\Program Files\IDA Professional 9.2" ``` -------------------------------- ### Override IDA Install Directory (macOS) Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/getting_started.md Set the IDADIR environment variable to specify a particular IDA Pro installation directory for a single session on macOS. ```bash export IDADIR="/Applications/IDA Professional 9.2.app/Contents/MacOS/" ``` -------------------------------- ### Run Specific Tests Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Examples of how to run tests using 'uv run pytest'. You can run all tests, a specific test file, or run tests with verbose output. ```bash # Run all tests uv run pytest tests/ ``` ```bash # Run specific test file uv run pytest tests/ida_domain_test.py ``` ```bash # Run with verbose output uv run pytest tests/ -v ``` -------------------------------- ### Get Bytes at Address Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md Use `db.bytes.get_bytes_at` to retrieve bytes from a given address. Always use a fallback like `b""` as it can return None. ```python return db.bytes.get_bytes_at(ea, count) or b"" ``` -------------------------------- ### Set IDADIR Environment Variable (Windows) Source: https://github.com/hexrayssa/ida-domain/blob/main/README.md Temporarily set the IDADIR environment variable to specify an IDA installation path for the current session or script on Windows. Do not set this globally. ```cmd set "IDADIR=C:\Program Files\IDA Professional 9.1" ``` -------------------------------- ### Set IDADIR Environment Variable (Linux/macOS) Source: https://github.com/hexrayssa/ida-domain/blob/main/README.md Temporarily set the IDADIR environment variable to specify an IDA installation path for the current session or script on Linux/macOS. Do not set this globally. ```bash export IDADIR="/path/to/your/ida/installation" ``` -------------------------------- ### Enumerate Function Objects Directly Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md The new API provides function objects directly via `db.functions.get_all()`, simplifying iteration compared to the old method of enumerating addresses and then getting the function object. ```python # Old: enumerate addresses, then get function for ea in idautils.Functions(): f = idaapi.get_func(ea) # use ea and f # New: enumerate function objects directly for f in db.functions.get_all(): # f is already the function object ea = f.start_ea # get address from object ``` -------------------------------- ### Set IDA Directory for Current Shell Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Temporarily override the registered IDA installation for the current shell session to test specific builds. Avoid persistent export to prevent interference with the IDA GUI. ```bash # Override the registered IDA install for this shell only (e.g. to test against a specific build) export IDADIR="/Applications/IDA Professional 9.1.app/Contents/MacOS/" ``` -------------------------------- ### Build documentation Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Navigate to the docs directory and build the HTML documentation. ```bash cd docs && make html ``` -------------------------------- ### Build Documentation Source: https://github.com/hexrayssa/ida-domain/blob/main/README.md Build the documentation for the IDA Domain project. ```bash uv run mkdocs build ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/hexrayssa/ida-domain/blob/main/README.md Synchronize documentation dependencies and serve the documentation locally using mkdocs. ```bash uv sync --extra docs uv run mkdocs serve ``` -------------------------------- ### Build Documentation with Sphinx Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Build the project's HTML documentation using Sphinx and the Sphinx Read the Docs theme. Ensure you are in the 'docs' directory. ```bash cd docs uv run --with sphinx --with sphinx-rtd-theme --with sphinx-autodoc-typehints make html ``` -------------------------------- ### Build Package Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Build the project package using the uv build command. ```bash # Build package uv build ``` -------------------------------- ### Test with Different Binary Types Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Execute the explore_database.py script with a sample binary file to test IDA's handling of different binary formats. ```bash # Test with different binary types python examples/explore_database.py -f tests/resources/tiny_asm.bin ``` -------------------------------- ### Clone Repository and Sync Dependencies Source: https://github.com/hexrayssa/ida-domain/blob/main/README.md Clone the IDA Domain repository and synchronize development dependencies using uv. ```bash git clone https://github.com/HexRaysSA/ida-domain.git cd ida-domain uv sync --extra dev uv run pre-commit install ``` -------------------------------- ### Explore Database Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/examples.md Demonstrates basic operations for opening and exploring an IDA database. ```python # examples/explore_database.py # This file is intentionally left blank. It serves as a placeholder for the actual example code. # The content is expected to be included via a directive like --8<-- "examples/explore_database.py" ``` -------------------------------- ### Analyze Database Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/examples.md Demonstrates a complete traversal of an IDA database. ```python # examples/analyze_database.py # This file is intentionally left blank. It serves as a placeholder for the actual example code. # The content is expected to be included via a directive like --8<-- "examples/analyze_database.py" ``` -------------------------------- ### Compatibility with IDA Python SDK Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/usage.md Illustrates the compatibility of the IDA Domain API with the IDA Python SDK, showing how to use both in conjunction. ```APIDOC ## Compatibility with IDA Python SDK The IDA Domain API is fully compatible with the IDA Python SDK shipped with IDA. It means the while we are extending the coverage of IDA Domain API, you can always fallback to using the IDA Python SDK. Here is an example: ```python import ida_domain import ida_funcs db = ida_domain.Database() db.open('/path/to/your/database.idb') for i, func in enumerate(db.functions.get_all()): print(ida_funcs.get_func_name(func.start_ea)) # <== this is calling IDA Python SDK ``` ``` -------------------------------- ### Explore FLIRT Signatures Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/examples.md Demonstrates working with FLIRT signature files in IDA. ```python # examples/explore_flirt.py # This file is intentionally left blank. It serves as a placeholder for the actual example code. # The content is expected to be included via a directive like --8<-- "examples/explore_flirt.py" ``` -------------------------------- ### Explore IDA Database Properties Source: https://github.com/hexrayssa/ida-domain/blob/main/README.md This script opens an IDA database, prints its address range, metadata, and the total number of functions. It requires the path to the binary file as an argument. ```python #!/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=False) 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__': main() ``` -------------------------------- ### Manage Types Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/examples.md Demonstrates analyzing and working with types in an IDA database. ```python # examples/manage_types.py # This file is intentionally left blank. It serves as a placeholder for the actual example code. # The content is expected to be included via a directive like --8<-- "examples/manage_types.py" ``` -------------------------------- ### Compatibility with IDA Python SDK Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/usage.md Demonstrates how to use IDA Domain API alongside the IDA Python SDK. You can call IDA Python SDK functions directly when needed. ```python import ida_domain import ida_funcs db = ida_domain.Database() db.open('/path/to/your/database.idb') for i, func in enumerate(db.functions.get_all()): print(ida_funcs.get_func_name(func.start_ea)) # <== this is calling IDA Python SDK ``` -------------------------------- ### Hook and Log Events Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/examples.md Demonstrates hooking and logging events using the IDA Domain API. ```python # examples/hooks_example.py # This file is intentionally left blank. It serves as a placeholder for the actual example code. # The content is expected to be included via a directive like --8<-- "examples/hooks_example.py" ``` -------------------------------- ### Analyze Functions Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/examples.md Demonstrates finding and analyzing functions within an IDA database. ```python # examples/analyze_functions.py # This file is intentionally left blank. It serves as a placeholder for the actual example code. # The content is expected to be included via a directive like --8<-- "examples/analyze_functions.py" ``` -------------------------------- ### Run Test Suite with Pytest Source: https://github.com/hexrayssa/ida-domain/blob/main/README.md Synchronize development dependencies and run the test suite using pytest. ```bash uv sync --extra dev uv run pytest ``` -------------------------------- ### Accessing IDA Domain Entities Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/usage.md Demonstrates how to open a database and access various entities like functions, segments, and entries through the Database object. ```APIDOC ## Accessing the entities The first thing that you will usually want to do is opening a **[Database](ref/database.md)**. Once the database is opened, you can access all other entities from the database handle itself through their respective property. ```python db = Database() db.open('/path/to/your/database.idb') db.functions.get_all() db.segments.get_all() db.entries.get_all() ... ``` ``` -------------------------------- ### Clone IDA Domain Repository Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Clone the IDA Domain repository to your local machine and navigate into the project directory. ```bash git clone https://github.com/HexRaysSA/ida-domain.git cd ida-domain ``` -------------------------------- ### Rebuild Test Binaries Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Commands to rebuild the assembly and C test binaries. Ensure you are in the 'tests/resources' directory before running these commands. ```bash cd tests/resources nasm -f elf64 tiny_asm.asm -o tiny_asm.bin gcc -O0 -fno-pie -c tiny_c.c -o tiny_c.bin ``` -------------------------------- ### Rebuild C Test Binary Source: https://github.com/hexrayssa/ida-domain/blob/main/tests/resources/README.md Use this command to rebuild the tiny_c.bin binary from the tiny_c.c source file. This binary is used for testing complex variable access patterns. ```bash gcc -O0 -fno-pie -c tiny_c.c -o tiny_c.bin ``` -------------------------------- ### Test Directory Structure Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md This is the standard directory structure for tests within the project. It includes the main test suite and a resources directory for test binaries and other assets. ```bash tests/ ├── ida_domain_test.py # Main test suite └── resources/ # Test binaries and resources ├── README.md # Instructions for rebuilding test binaries ├── tiny_asm.asm # Comprehensive assembly test source ├── tiny_asm.bin # Compiled test binary (from tiny_asm.asm) ├── tiny_c.c # C test source for complex patterns ├── tiny_c.bin # Compiled C test binary └── example.til # Type information library ``` -------------------------------- ### Load Database with Domain API Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md Opens a database using the Domain API with specified command options for auto-analysis and resource loading. Useful for batch processing files with IDA. ```python from pathlib import Path from ida_domain import Database from ida_domain.database import IdaCommandOptions def analyze_file(input_path: Path, save=True): """Open and analyze a file using the Domain API.""" opts = IdaCommandOptions( auto_analysis=True, # Enable auto-analysis load_resources=True, # Load Windows resources (helps find embedded PEs) # Disable Lumina via plugin options plugin_options="lumina:host=0.0.0.0;secondary_lumina:host=0.0.0.0", ) with Database.open(str(input_path), args=opts, save_on_close=save) as db: for f in db.functions.get_all(): print(db.functions.get_name(f)) ``` -------------------------------- ### Analyze Cross-References Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/examples.md Demonstrates analyzing cross-references within an IDA database. ```python # examples/analyze_xrefs.py # This file is intentionally left blank. It serves as a placeholder for the actual example code. # The content is expected to be included via a directive like --8<-- "examples/analyze_xrefs.py" ``` -------------------------------- ### Enumerate Functions with Flag Checking using IDA Domain Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md Replaces manual flag checking with a unified Domain API for function enumeration. Requires `Database` object. ```python def get_functions(skip_thunks=False, skip_libs=False): for ea in idautils.Functions(): f = idaapi.get_func(ea) if skip_thunks and (f.flags & idaapi.FUNC_THUNK): continue if skip_libs and (f.flags & idaapi.FUNC_LIB): continue yield f ``` ```python def get_functions(db: Database, skip_thunks=False, skip_libs=False): for f in db.functions.get_all(): flags = db.functions.get_flags(f) if skip_thunks and (flags & FunctionFlags.THUNK): continue if skip_libs and (flags & FunctionFlags.LIB): continue yield f ``` -------------------------------- ### Rebuild Imports Test Binary Source: https://github.com/hexrayssa/ida-domain/blob/main/tests/resources/README.md Use this command to rebuild the tiny_imports.bin binary from the tiny_imports.c source file. This dynamically-linked binary is used for testing the Imports API. ```bash gcc -O0 -no-pie -fno-stack-protector tiny_imports.c -o tiny_imports.bin ``` -------------------------------- ### Analyze Strings Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/examples.md Demonstrates finding and analyzing strings within an IDA database. ```python # examples/analyze_strings.py # This file is intentionally left blank. It serves as a placeholder for the actual example code. # The content is expected to be included via a directive like --8<-- "examples/analyze_strings.py" ``` -------------------------------- ### Extract Exports using EntryInfo with IDA Domain Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md Replaces tuple unpacking for entry points with the `EntryInfo` dataclass from the Domain API. Requires `Database` object. ```python def extract_exports(): for _, ordinal, ea, name in idautils.Entries(): forwarded_name = ida_entry.get_entry_forwarder(ordinal) if forwarded_name is None: yield Export(name), ea else: yield Export(forwarded_name), ea ``` ```python def extract_exports(db: Database): for entry in db.entries.get_all(): if entry.has_forwarder(): yield Export(entry.forwarder_name), entry.address else: yield Export(entry.name), entry.address ``` -------------------------------- ### Run Tests with pytest Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Execute all project tests using pytest, managed by UV. ```bash uv run pytest tests/ ``` -------------------------------- ### Detect Architecture with Unified Comparison using IDA Domain Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md Simplifies architecture detection by using unified string and integer comparisons provided by the Domain API. Requires `Database` object. ```python # IDA < 9 info = idaapi.get_inf_structure() procname = info.procname if procname == "metapc" and info.is_64bit(): yield Arch(ARCH_AMD64) elif procname == "metapc" and info.is_32bit(): yield Arch(ARCH_I386) # IDA 9+ procname = idc.get_processor_name() if procname == "metapc" and idaapi.inf_is_64bit(): yield Arch(ARCH_AMD64) elif procname == "metapc" and idaapi.inf_is_32bit_exactly(): yield Arch(ARCH_I386) ``` ```python arch = db.architecture bitness = db.bitness if arch == "metapc" and bitness == 64: yield Arch(ARCH_AMD64) elif arch == "metapc" and bitness == 32: yield Arch(ARCH_I386) ``` -------------------------------- ### Analyze in Temporary Directory Context Manager Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md A context manager that copies a file to a temporary directory before analysis to prevent IDA from creating database files in the original location. Useful for read-only file systems or parallel processing. ```python import shutil import tempfile from pathlib import Path from contextlib import contextmanager from ida_domain import Database from ida_domain.database import IdaCommandOptions @contextmanager def analyze_in_temp_directory(input_path: Path): """ Copy file to a temp directory before analysis to avoid creating .i64/.idb files in the original location. """ input_path = Path(input_path) with tempfile.TemporaryDirectory() as tmpdir: # Copy the input file to temp directory temp_file = Path(tmpdir) / input_path.name shutil.copy2(input_path, temp_file) # see this function above analyze_file(temp_file, save=False) # Usage: with analyze_in_temp_directory(Path("/path/to/sample.exe")) as db: for f in db.functions.get_all(): print(db.functions.get_name(f)) ``` -------------------------------- ### Simplify Binary Search with IDA Domain Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md Replaces version-specific branching for binary search with a unified Domain API call. Requires `Database` object. ```python IDA_NALT_ENCODING = ida_nalt.get_default_encoding_idx(ida_nalt.BPU_1B) def find_byte_sequence(start: int, end: int, seq: bytes) -> Iterator[int]: patterns = ida_bytes.compiled_binpat_vec_t() seqstr = " ".join([f"{b:02x}" for b in seq]) err = ida_bytes.parse_binpat_str(patterns, 0, seqstr, 16, IDA_NALT_ENCODING) if err: return while True: ea = ida_bytes.bin_search(start, end, patterns, ida_bytes.BIN_SEARCH_FORWARD) if isinstance(ea, tuple): ea = ea[0] # IDA 9 returns tuple if ea == idaapi.BADADDR: break start = ea + 1 yield ea ``` ```python def find_byte_sequence(db: Database, start: int, end: int, seq: bytes) -> Iterator[int]: for match in db.bytes.find_binary_sequence(seq, start, end): yield match ``` -------------------------------- ### Commit changes with a clear message Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Commit your changes using Git, providing a descriptive commit message. ```bash git commit -m "Add feature: description of your changes" ``` -------------------------------- ### Analyze and Manipulate Bytes Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/examples.md Demonstrates analyzing and manipulating bytes within an IDA database. ```python # examples/analyze_bytes.py # This file is intentionally left blank. It serves as a placeholder for the actual example code. # The content is expected to be included via a directive like --8<-- "examples/analyze_bytes.py" ``` -------------------------------- ### Dispatch Mnemonic with String Comparison using IDA Domain Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md Replaces `itype` constants with string comparison for mnemonic-based dispatch using the Domain API. Requires `Database` object. ```python if insn.itype in (idaapi.NN_xor, idaapi.NN_xorpd, idaapi.NN_xorps, idaapi.NN_pxor): # handle xor ``` ```python mnem = db.instructions.get_mnemonic(insn) if mnem in ("xor", "xorpd", "xorps", "pxor"): # handle xor ``` -------------------------------- ### Perform Type Checking with Mypy Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Run Mypy for static type checking on the ida_domain directory to catch potential type errors. ```bash # Type checking uv run mypy ida_domain/ ``` -------------------------------- ### Check for None Before Using Name Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md When retrieving names using `db.names.get_at`, always check if the result is None before attempting string operations. ```python # Old name = idaapi.get_name(ea) if name.startswith("sub_"): ... # New - must check for None first! name = db.names.get_at(ea) if not name or name.startswith("sub_"): ... ``` -------------------------------- ### Create a new feature branch Source: https://github.com/hexrayssa/ida-domain/blob/main/CONTRIBUTING.md Before making changes, create a new branch for your feature using Git. ```bash git checkout -b feature/your-feature-name ``` -------------------------------- ### Use Explicit Keyword Argument for Flow Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md When specifying flow behavior for cross-references, use the explicit `flow=False` keyword argument with `db.xrefs.code_refs_from_ea` instead of a positional boolean. ```python # Old - positional boolean idautils.CodeRefsFrom(ea, False) # New - explicit keyword argument db.xrefs.code_refs_from_ea(ea, flow=False) ``` -------------------------------- ### Retrieve Comments using CommentInfo with IDA Domain Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md Handles comment retrieval by checking for `CommentInfo` dataclass or `None` from the Domain API, replacing direct string return. Requires `Database` object. ```python if contains_keywords(idaapi.get_cmt(ea, False)): return True ``` ```python cmt_info = db.comments.get_at(ea) cmt = cmt_info.comment if cmt_info else "" if contains_keywords(cmt): return True ``` -------------------------------- ### API Consistency with Unused DB Parameter Source: https://github.com/hexrayssa/ida-domain/blob/main/docs/migration-guide.md Some functions retain the `db` parameter for API consistency, even if it's not directly used within the function body. ```python def get_file_imports(db: Database): # db unused, kept for API consistency # Still uses idaapi.get_import_module_qty() etc. ... ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.