scriptingprovider module

binaryninja.scriptingprovider.BlacklistedDict(...)

binaryninja.scriptingprovider.PythonScriptingInstance(...)

binaryninja.scriptingprovider.PythonScriptingProvider([...])

binaryninja.scriptingprovider.ScriptingInstance(...)

binaryninja.scriptingprovider.ScriptingOutputListener()

binaryninja.scriptingprovider.ScriptingProvider([...])

class BlacklistedDict(blacklist, *args)[source]

Bases: dict

add_blacklist_item(item)[source]
enable_blacklist(enabled)[source]
is_blacklisted_item(item)[source]
remove_blacklist_item(item)[source]
property blacklist_enabled
class PythonScriptingInstance(provider)[source]

Bases: ScriptingInstance

class InterpreterThread(instance)[source]

Bases: Thread

add_input(data)[source]
apply_locals()[source]
end()[source]
execute(_code)[source]
get_selected_data()[source]
read(size)[source]
run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

update_locals()[source]
update_magic_variables()[source]
write_at_cursor(data)[source]
abstract perform_cancel_script_input()[source]
abstract perform_complete_input(text, state)[source]
abstract perform_execute_script_input(text)[source]
abstract perform_execute_script_input_from_filename(filename)[source]
abstract perform_set_current_address(addr)[source]
abstract perform_set_current_basic_block(block)[source]
abstract perform_set_current_binary_view(view)[source]
abstract perform_set_current_function(func)[source]
abstract perform_set_current_selection(begin, end)[source]
abstract perform_stop()[source]
class PythonScriptingProvider(handle=None)[source]

Bases: ScriptingProvider

class MagicVariable(get_value: Callable[[PythonScriptingInstance], Any], set_value: Callable[[PythonScriptingInstance, Any, Any], None] | None, depends_on: List[str])[source]

Bases: object

Represents an automatically-populated (magic) variable in the python scripting console

Parameters:
depends_on: List[str]

List of other variables whose values on which this variable’s value depends

get_value: Callable[[PythonScriptingInstance], Any]

Function to call, before every time a script is evaluated, to get the value of the variable

set_value: Callable[[PythonScriptingInstance, Any, Any], None] | None

(Optional) function to call after a script is evaluated, if the value of the variable has changed during the course of the script. If None, a warning will be printed stating that the variable is read-only. Signature: (instance: PythonScriptingInstance, old_value: any, new_value: any) -> None

instance_class

alias of PythonScriptingInstance

classmethod register_magic_variable(name: str, get_value: Callable[[PythonScriptingInstance], Any], set_value: Callable[[PythonScriptingInstance, Any, Any], None] | None = None, depends_on: List[str] | None = None)[source]

Add a magic variable to all scripting instances created by the scripting provider :param name: Variable name identifier to be used in the interpreter :param get_value: Function to call, before every time a script is evaluated,

to get the value of the variable

Parameters:
  • set_value (Callable[[PythonScriptingInstance, Any, Any], None] | None) – (Optional) Function to call after a script is evaluated, if the value of the variable has changed during the course of the script. If None, a warning will be printed stating that the variable is read-only. Signature: (instance: PythonScriptingInstance, old_value: any, new_value: any) -> None

  • depends_on (List[str] | None) – List of other variables whose values on which this variable’s value depends

  • name (str) –

  • get_value (Callable[[PythonScriptingInstance], Any]) –

classmethod unregister_magic_variable(name: str)[source]

Remove a magic variable by name :param name: Variable name

Parameters:

name (str) –

apiName = 'python3'
magic_variables: Dict[str, MagicVariable] = {'bv': PythonScriptingProvider.MagicVariable(get_value=<function <lambda>>, set_value=None, depends_on=[]), 'current_address': PythonScriptingProvider.MagicVariable(get_value=<function _get_here>, set_value=<function _set_here>, depends_on=['current_ui_context']), 'current_basic_block': PythonScriptingProvider.MagicVariable(get_value=<function <lambda>>, set_value=None, depends_on=[]), 'current_comment': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_comment>, set_value=<function _set_current_comment>, depends_on=[]), 'current_data_var': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_data_var>, set_value=None, depends_on=[]), 'current_function': PythonScriptingProvider.MagicVariable(get_value=<function <lambda>>, set_value=None, depends_on=[]), 'current_hlil': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_hlil>, set_value=None, depends_on=[]), 'current_hlil_ssa': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_hlil_ssa>, set_value=None, depends_on=['current_hlil']), 'current_il_basic_block': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_il_basic_block>, set_value=None, depends_on=['current_il_instruction']), 'current_il_function': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_il_function>, set_value=None, depends_on=['current_ui_view_location', 'current_llil', 'current_llil_ssa', 'current_mlil', 'current_mlil_ssa', 'current_hlil', 'current_hlil_ssa']), 'current_il_index': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_il_index>, set_value=None, depends_on=['current_ui_view_location']), 'current_il_instruction': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_il_instruction>, set_value=None, depends_on=['current_il_index', 'current_il_function']), 'current_il_instructions': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_il_instructions>, set_value=None, depends_on=['current_il_index', 'current_il_function', 'current_ui_view']), 'current_llil': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_llil>, set_value=None, depends_on=[]), 'current_llil_ssa': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_llil_ssa>, set_value=None, depends_on=['current_llil']), 'current_mlil': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_mlil>, set_value=None, depends_on=[]), 'current_mlil_ssa': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_mlil_ssa>, set_value=None, depends_on=['current_mlil']), 'current_project': PythonScriptingProvider.MagicVariable(get_value=<function <lambda>>, set_value=None, depends_on=[]), 'current_raw_offset': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_raw_offset>, set_value=<function _set_current_raw_offset>, depends_on=['current_ui_context']), 'current_sections': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_sections>, set_value=None, depends_on=[]), 'current_segment': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_segment>, set_value=None, depends_on=[]), 'current_selection': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_selection>, set_value=<function _set_current_selection>, depends_on=['current_ui_view']), 'current_symbol': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_symbol>, set_value=None, depends_on=[]), 'current_symbols': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_symbols>, set_value=None, depends_on=[]), 'current_thread': PythonScriptingProvider.MagicVariable(get_value=<function <lambda>>, set_value=None, depends_on=[]), 'current_token': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_token>, set_value=None, depends_on=['current_ui_token_state']), 'current_ui_action_context': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_ui_action_context>, set_value=None, depends_on=['current_ui_view', 'current_ui_action_handler']), 'current_ui_action_handler': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_ui_action_handler>, set_value=None, depends_on=['current_ui_context']), 'current_ui_context': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_ui_context>, set_value=None, depends_on=[]), 'current_ui_token_state': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_ui_token_state>, set_value=None, depends_on=['current_ui_action_context']), 'current_ui_view': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_ui_view>, set_value=None, depends_on=['current_ui_context']), 'current_ui_view_frame': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_ui_view_frame>, set_value=None, depends_on=['current_ui_context']), 'current_ui_view_location': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_ui_view_location>, set_value=None, depends_on=['current_ui_view_frame']), 'current_variable': PythonScriptingProvider.MagicVariable(get_value=<function _get_current_variable>, set_value=None, depends_on=['current_ui_token_state']), 'current_view': PythonScriptingProvider.MagicVariable(get_value=<function <lambda>>, set_value=None, depends_on=[]), 'dbg': PythonScriptingProvider.MagicVariable(get_value=<function <lambda>>, set_value=None, depends_on=[]), 'here': PythonScriptingProvider.MagicVariable(get_value=<function _get_here>, set_value=<function _set_here>, depends_on=['current_ui_context'])}
name = 'Python'
class ScriptingInstance(provider, handle=None)[source]

Bases: object

cancel_script_input(text)[source]
complete_input(text, state)[source]
error(text)[source]
execute_script_input(text)[source]
execute_script_input_from_filename(filename)[source]
output(text)[source]
abstract perform_cancel_script_input()[source]
abstract perform_complete_input(text: str, state) str[source]
Parameters:

text (str) –

Return type:

str

abstract perform_execute_script_input(text)[source]
abstract perform_execute_script_input_from_filename(text)[source]
abstract perform_set_current_address(addr)[source]
abstract perform_set_current_basic_block(block)[source]
abstract perform_set_current_binary_view(view)[source]
abstract perform_set_current_function(func)[source]
abstract perform_set_current_selection(begin, end)[source]
abstract perform_stop()[source]
register_output_listener(listener)[source]
set_current_address(addr)[source]
set_current_basic_block(block)[source]
set_current_binary_view(view)[source]
set_current_function(func)[source]
set_current_selection(begin, end)[source]
stop()[source]
unregister_output_listener(listener)[source]
warning(text)[source]
property delimiters
property input_ready_state
class ScriptingOutputListener[source]

Bases: object

notify_error(text)[source]
notify_input_ready_state_changed(state)[source]
notify_output(text)[source]
notify_warning(text)[source]
class ScriptingProvider(handle=None)[source]

Bases: object

create_instance() ScriptingInstance | None[source]
Return type:

ScriptingInstance | None

register() None[source]
Return type:

None

apiName = ''
instance_class: Type[ScriptingInstance] | None = None
name = ''
bninspect(code_, globals_, locals_)[source]

bninspect prints documentation about a command that is about to be run The interpreter will invoke this function if you input a line ending in ? e.g. bv?

Parameters:
  • code (str) – Python code to be evaluated

  • globals (dict) – globals() from callsite

  • locals (dict) – locals() from callsite

redirect_stdio()[source]