octopus.capture.frida
- class octopus.capture.frida.FridaCapture(device, output_dir, gated=True, debug=False)[source]
Bases:
AbstractCaptureCaptures data from an Android device using Frida instrumentation.
Manages Frida scripts, dynamic hooks, and data collection during an instrumentation session on a connected Android device.
- device
The Android device to instrument.
- output_dir
Directory where captured data files are saved.
- gated
Whether to use gated instrumentation.
- debug
Whether to enable debug mode (e.g., write the agent script to disk).
- dynamic_hook_dir
Path to the directory containing dynamic hook JSON definitions.
- frida_scripts_dir
Path to the directory containing Frida JS scripts.
- output_files
Mapping of output filenames to their captured records.
- captured_data
Mapping of data types to their output file metadata.
- agent_script
The concatenated Frida agent JS script content.
- frida_instrumentation
The
FridaGatedInstrumentationinstance managing the Frida session.
- __init__(device, output_dir, gated=True, debug=False)[source]
Initializes FridaCapture with device and output configuration.
- Parameters:
device (AndroidDevice) – The Android device to capture data from.
output_dir (Path) – Directory path where output files will be written.
gated (bool) – Whether to use gated instrumentation mode. Defaults to True.
debug (bool) – Whether to enable debug output, such as writing the agent script to a temporary file. Defaults to False.
- capture_data(data)[source]
Processes and stores a single data record received from Frida.
Handles console log messages for debug output and accumulates data records into
self.output_fileskeyed by their target filename. Records without adumpfield are ignored.- Parameters:
data – A dict payload sent by the Frida agent, expected to contain keys such as
contentType,dump,type, anddata.
- get_agent_script(extra_scripts_dir=None, reload=False)[source]
Builds and returns the concatenated Frida agent JS script.
Reads all
.jsfiles from the default Frida scripts directory and optionally from an additional directory. The result is cached inself.agent_scriptand can be reloaded by settingreload=True.When debug mode is enabled, the assembled script is also written to
/tmp/octopus_agent.jsfor inspection.
- get_dynamic_hooks_definitions()[source]
Loads all dynamic hook definitions from JSON files.
Iterates over all
.jsonfiles in the dynamic hooks directory and aggregates their contents into a single list.- Returns:
A tuple of (hook_definitions, success) where hook_definitions is a list of hook definition dicts and success is False if no hook files were found, True otherwise.
- get_result()[source]
Retrieve the result of the capture.
- Returns:
The result data from the capture.
- Return type:
- save_data_files()[source]
Writes all captured data records to their respective output files.
Iterates over
self.output_filesand serializes each collection of records. JSON records are pretty-printed; other records are written one per line using theirdatafield.
- start_capture()[source]
Starts the Frida capture session on the device.
Disables USAP pool pre-forking on Android 10+ (API 29) to ensure Frida can attach correctly, starts the Frida server on the device, and begins instrumentation.
- stop_capture()[source]
Stops the Frida capture session and persists collected data.
Stops the instrumentation, shuts down the Frida server on the device, and flushes all captured data to disk with
save_data_files().