NativePlugin¶
NativePlugin
¶
Bases: BasePlugin
Native function interception plugin.
Patches ctypes.CDLL.init and optionally cffi.FFI.dlopen at the class level. Uses reference counting so nested sandboxes work correctly.
Each library:function pair has its own FIFO deque of NativeMockConfig objects.
Source code in src/tripwire/plugins/native_plugin.py
mock_call
¶
Register a mock for a single native function call.
Args: library: The library name (e.g., "libm"). function: The function name (e.g., "sqrt"). returns: Value to return when this mock is consumed. raises: If provided, this exception is raised instead of returning. required: If False, the mock is not reported as unused at teardown.
Source code in src/tripwire/plugins/native_plugin.py
check_conflicts
¶
Verify ctypes.CDLL.init has not been patched by a third party.
Source code in src/tripwire/plugins/native_plugin.py
install_patches
¶
Install ctypes.CDLL and optionally cffi.FFI patches.
Source code in src/tripwire/plugins/native_plugin.py
restore_patches
¶
Restore original ctypes.CDLL and cffi.FFI functions.
Source code in src/tripwire/plugins/native_plugin.py
matches
¶
Field-by-field comparison with dirty-equals support.
Source code in src/tripwire/plugins/native_plugin.py
get_unused_mocks
¶
Return all NativeMockConfig with required=True still in any queue.
Source code in src/tripwire/plugins/native_plugin.py
assert_call
¶
Typed helper: assert the next native function call interaction.
Wraps assert_interaction() for ergonomic use. All three fields (library, function, args) are required.