intellicrack.bridges.base
Base protocol for tool bridges.
This module defines the abstract interface that all tool bridge implementations must follow, enabling consistent interaction across Ghidra, x64dbg, Frida, Cutter/Rizin, and other reverse engineering tools.
- TOOL_CAPABILITY_MAP: dict[str, str] = {'allocate_memory': 'memory_access', 'animate_start': 'debugging', 'animate_stop': 'debugging', 'apply_patch': 'patching', 'attach': 'debugging', 'compile_typescript': 'scripting', 'configure_breakpoint': 'debugging', 'create_cmodule': 'scripting', 'decompile': 'decompilation', 'detach': 'debugging', 'disable_breakpoint': 'debugging', 'disassemble': 'static_analysis', 'disassemble_at': 'static_analysis', 'disassemble_function': 'static_analysis', 'disassemble_instruction': 'static_analysis', 'dump_memory_to_file': 'memory_access', 'enable_breakpoint': 'debugging', 'execute_script': 'scripting', 'execute_script_with_params': 'scripting', 'execute_til_return': 'debugging', 'export_patches': 'patching', 'export_patches_bps': 'patching', 'export_patches_ups': 'patching', 'free_memory': 'memory_access', 'frida.attach': 'dynamic_analysis', 'frida.detach': 'dynamic_analysis', 'frida.disassemble_instruction': 'dynamic_analysis', 'get_basic_blocks': 'static_analysis', 'get_breakpoints': 'debugging', 'get_call_graph': 'static_analysis', 'get_call_tree': 'static_analysis', 'get_callers': 'static_analysis', 'get_memory_map': 'memory_access', 'get_memory_regions': 'memory_access', 'get_modules': 'debugging', 'get_patches': 'patching', 'get_pcode': 'static_analysis', 'get_registers': 'debugging', 'get_threads': 'debugging', 'get_trace_record': 'debugging', 'get_watchpoints': 'debugging', 'get_xrefs_from': 'static_analysis', 'get_xrefs_to': 'static_analysis', 'ghidra.get_memory_map': 'static_analysis', 'ghidra.write_bytes': 'static_analysis', 'hex_editor.run_python_script': 'static_analysis', 'import_patches': 'patching', 'import_patches_bps': 'patching', 'import_patches_ups': 'patching', 'kernel_alloc': 'memory_access', 'kernel_protect': 'memory_access', 'kernel_read': 'memory_access', 'kernel_write': 'memory_access', 'nop_range': 'patching', 'patch_anti_debug': 'patching', 'patch_code': 'patching', 'patch_instruction': 'patching', 'pause': 'debugging', 'process.get_modules': 'memory_access', 'process.get_threads': 'memory_access', 'protect_memory': 'memory_access', 'read_memory': 'memory_access', 'read_peb': 'memory_access', 'read_teb': 'memory_access', 'remove_breakpoint': 'debugging', 'remove_watchpoint': 'debugging', 'replace_function': 'patching', 'restart': 'debugging', 'restore_patch': 'patching', 'revert_patch': 'patching', 'run': 'debugging', 'run_python_script': 'scripting', 'run_to': 'debugging', 'sandbox.stop': 'dynamic_analysis', 'scan_memory': 'memory_access', 'script_abort': 'scripting', 'script_cmd': 'scripting', 'script_load': 'scripting', 'script_run': 'scripting', 'set_breakpoint': 'debugging', 'set_breakpoint_on_api': 'debugging', 'set_dll_breakpoint': 'debugging', 'set_ip': 'debugging', 'set_logging_breakpoint': 'debugging', 'set_register': 'debugging', 'set_trace_record': 'debugging', 'set_watchpoint': 'debugging', 'skip_instruction': 'debugging', 'step_count': 'debugging', 'step_into': 'debugging', 'step_out': 'debugging', 'step_over': 'debugging', 'stop': 'debugging', 'trace_into': 'debugging', 'trace_over': 'debugging', 'trace_start': 'debugging', 'trace_stop': 'debugging', 'write_bytes': 'patching', 'write_code': 'patching', 'write_memory': 'memory_access'}
Mapping from bridge tool-function name to required capability.
Each key is either the unqualified method/tool name exposed by a bridge (the
namefield of itsToolFunctionentries with the<bridge>.prefix stripped) or a fully-qualified<bridge>.<method>name. Each value is the capability name that would appear inBridgeCapabilitiesassupports_<value>.ToolRegistryconsults this mapping inexecute_tool_calland prefers a fully- qualified match over the short-name match, so a bridge whose method name collides with an unrelated bridge’s (for example the sandbox’sstopversus a debugger’sstop) can require the capability that actually fits its own operation instead of inheriting the short name’s capability. It raisesToolErrorwhen a bridge is asked to execute a tool whose required capability it does not advertise. The mapping lives inbridges.baseso that bridge implementations and the registry share a single source of truth, andintellicrack.core.toolsimports it from here.
- class BinaryOperationsBridge[source]
Bases:
ToolBridgeBaseBase class for direct binary file operations.
Provides interface for reading, modifying, and patching binary files without running a full analysis tool.
- abstractmethod async load_file(path)[source]
Load a binary file.
- Parameters:
path (Path) – Path to the binary.
- Returns:
Information about the loaded binary.
- Return type:
- abstractmethod async save(path=None)[source]
Save the binary to file.
- Parameters:
path (Path | None) – Optional new path. Uses original if None.
- Returns:
Path where the file was saved.
- Return type:
Path
- class BridgeCapabilities[source]
Bases:
objectDescribes the capabilities of a tool bridge.
- Variables:
supports_static_analysis (bool) – Whether the tool supports static analysis.
supports_dynamic_analysis (bool) – Whether the tool supports dynamic analysis.
supports_decompilation (bool) – Whether the tool can decompile to pseudocode.
supports_debugging (bool) – Whether the tool can debug processes.
supports_patching (bool) – Whether the tool can patch binaries.
supports_scripting (bool) – Whether the tool supports custom scripts.
supports_memory_access (bool) – Whether the tool can read/write process memory.
supported_architectures (list[str]) – List of supported CPU architectures.
supported_formats (list[str]) – List of supported binary formats.
- __init__(supports_static_analysis=False, supports_dynamic_analysis=False, supports_decompilation=False, supports_debugging=False, supports_patching=False, supports_scripting=False, supports_memory_access=False, supported_architectures=<factory>, supported_formats=<factory>)
- class BridgeState[source]
Bases:
objectCurrent state of a tool bridge.
- Variables:
connected (bool) – Whether connected to the tool.
tool_running (bool) – Whether the tool process is running.
binary_loaded (bool) – Whether a binary is loaded.
process_attached (bool) – Whether attached to a process.
target_path (Path | None) – Path to the loaded binary.
target_pid (int | None) – PID of attached process.
last_error (str | None) – Last error message if any.
- is_ready()[source]
Check if bridge is connected and tool is running.
- Returns:
True if both connected and tool_running are True.
- Return type:
- __init__(connected=False, tool_running=False, binary_loaded=False, process_attached=False, target_path=None, target_pid=None, last_error=None)
- class DebuggerBridge[source]
Bases:
DynamicAnalysisBridgeBase class for full debuggers (x64dbg).
Extends DynamicAnalysisBridge with breakpoints, stepping, and register manipulation.
- abstractmethod async step_into()[source]
Single step into.
- Returns:
New instruction pointer.
- Return type:
- abstractmethod async step_over()[source]
Single step over.
- Returns:
New instruction pointer.
- Return type:
- abstractmethod async step_out()[source]
Step out of current function.
- Returns:
New instruction pointer.
- Return type:
- abstractmethod async set_breakpoint(address, bp_type='software', condition=None)[source]
Set a breakpoint.
- abstractmethod async get_breakpoints()[source]
Get all breakpoints.
- Returns:
List of breakpoint information.
- Return type:
- abstractmethod async get_registers()[source]
Get all register values.
- Returns:
Current register state.
- Return type:
- abstractmethod async get_stack_trace()[source]
Get current stack trace.
- Returns:
List of stack frames.
- Return type:
- class DynamicAnalysisBridge[source]
Bases:
ToolBridgeBaseBase class for dynamic analysis tools (x64dbg, Frida).
Provides interface for process attachment, memory manipulation, breakpoints, and runtime instrumentation.
- abstractmethod async attach(pid)[source]
Attach to a running process.
- Parameters:
pid (int) – Process ID to attach to.
- Return type:
None
- abstractmethod async get_memory_regions()[source]
Get process memory map.
- Returns:
List of memory regions.
- Return type:
- class InstrumentationBridge[source]
Bases:
DynamicAnalysisBridgeBase class for instrumentation tools (Frida).
Extends DynamicAnalysisBridge with function hooking and script execution capabilities.
- abstractmethod async enumerate_modules()[source]
List all loaded modules in the process.
- Returns:
List of loaded module information.
- Return type:
- abstractmethod async enumerate_exports(module_name)[source]
List exports of a module.
- Parameters:
module_name (str) – Name of the module.
- Returns:
List of export information.
- Return type:
- abstractmethod async hook_function(target, on_enter=None, on_leave=None)[source]
Attach a hook to a function by name or address.
- abstractmethod async intercept_return(target, return_value)[source]
Intercept a function and replace its return value.
- abstractmethod async call_function(address, args=None)[source]
Call a function in the target process.
- abstractmethod async enumerate_imports(module_name)[source]
List imports of a module.
- Parameters:
module_name (str) – Name of the module.
- Returns:
List of import information.
- Return type:
- class StackFrame[source]
Bases:
objectSingle stack frame in a call stack.
- Variables:
index (int) – Frame index (0 = top/current).
address (int) – Instruction pointer for this frame.
return_address (int) – Return address for this frame.
frame_pointer (int) – Base/frame pointer (RBP/EBP).
stack_pointer (int) – Stack pointer (RSP/ESP).
function_name (str | None) – Function name if resolved, None otherwise.
module_name (str | None) – Module name if resolved, None otherwise.
- class StaticAnalysisBridge[source]
Bases:
ToolBridgeBaseBase class for static analysis tools (Ghidra, Cutter/Rizin).
Provides interface for binary loading, disassembly, decompilation, and cross-reference analysis without executing the target.
- abstractmethod async load_binary(path)[source]
Load a binary for analysis.
- Parameters:
path (Path) – Path to the binary file.
- Returns:
Information about the loaded binary.
- Return type:
- abstractmethod async get_functions(filter_pattern=None)[source]
Get all analyzed functions.
- Parameters:
filter_pattern (str | None) – Optional regex pattern to filter function names.
- Returns:
List of analyzed function information.
- Return type:
- abstractmethod async get_function(address)[source]
Get function at specific address.
- Parameters:
address (int) – Function address.
- Returns:
Function info or None if not found.
- Return type:
FunctionInfo | None
- abstractmethod async disassemble(address, count=20)[source]
Disassemble instructions at address.
- Parameters:
- Returns:
List of disassembly lines.
- Return type:
- abstractmethod async get_xrefs_to(address)[source]
Get cross-references to an address.
- Parameters:
address (int) – Target address.
- Returns:
List of cross-references to the address.
- Return type:
- abstractmethod async get_xrefs_from(address)[source]
Get cross-references from an address.
- Parameters:
address (int) – Source address.
- Returns:
List of cross-references from the address.
- Return type:
- abstractmethod async search_strings(pattern)[source]
Search for strings matching pattern.
- Parameters:
pattern (str) – Regex pattern to match.
- Returns:
List of matching strings.
- Return type:
- abstractmethod async get_imports()[source]
Get all imported functions.
- Returns:
List of import information.
- Return type:
- abstractmethod async get_exports()[source]
Get all exported functions.
- Returns:
List of export information.
- Return type:
- class ToolBridgeBase[source]
Bases:
ABCBase class for tool bridges.
All bridge implementations must inherit from this class and override the methods defined here. This ensures a consistent interface for the orchestrator to interact with any reverse engineering tool.
Note
The use of a per-instance self._logger attribute is intentional and justified in this class to dynamically encode the concrete subclass name into the logger metadata.
- abstract property name: ToolName
Tool name enum value.
- Returns:
The tool’s name enum value.
- Return type:
- property state: BridgeState
Current bridge state.
- Returns:
Current BridgeState instance.
- Return type:
- set_session(session)[source]
Attach (or detach) the session that this bridge reports state into.
When a session is attached, the bridge immediately publishes its current
BridgeStateas aToolStateentry on the session so the persisted view reflects any state changes that happened before the session was wired in. PassingNonedetaches the bridge without modifying the previously held session.- Parameters:
session (Session | None) – The active
Sessionwhosetool_statesregistry should receive this bridge’s lifecycle updates, orNoneto detach.- Return type:
None
- property capabilities: BridgeCapabilities
Bridge capabilities.
- Returns:
BridgeCapabilities describing what this tool can do.
- Return type:
- abstract property tool_definition: ToolDefinition
Tool definition for LLM function calling.
- Returns:
Tool definition with available functions.
- Return type:
- abstractmethod async initialize(tool_path=None)[source]
Initialize the tool bridge.
- Parameters:
tool_path (Path | None) – Optional path to tool installation. If None, will auto-detect or download.
- Return type:
None
- abstractmethod async shutdown()[source]
Shutdown the tool and cleanup resources.
Each concrete bridge MUST override this method to release any external handles (debugger sessions, RPC bridges, sandbox VMs, etc.). Subclasses should call
await super().shutdown()at the end of their cleanup so the shared bookkeeping in_finalize_shutdown()runs after tool-specific teardown.- Return type:
None
- class WatchpointInfo[source]
Bases:
objectMemory watchpoint information.
- Variables:
id (int) – Watchpoint identifier.
address (int) – Memory address being watched.
size (int) – Size of the watched region in bytes.
watch_type (str) – Access type to watch (read, write, or exec).
enabled (bool) – Whether the watchpoint is active.
hit_count (int) – Number of times the watchpoint has triggered.