scriptingprovider module

Class

Description

binaryninja.scriptingprovider.BlacklistedDict

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping…

binaryninja.scriptingprovider.PythonScriptingInstance

binaryninja.scriptingprovider.PythonScriptingProvider

binaryninja.scriptingprovider.ScriptingInstance

binaryninja.scriptingprovider.ScriptingOutputListener

binaryninja.scriptingprovider.ScriptingProvider

binaryninja.scriptingprovider.bninspect

bninspect prints documentation about a command that is about to be run The interpreter will…

binaryninja.scriptingprovider.redirect_stdio

BlacklistedDict

classBlacklistedDict[source]

Bases:dict

__init__(blacklist,*args)[source]
add_blacklist_item(item)[source]
enable_blacklist(enabled)[source]
is_blacklisted_item(item)[source]
remove_blacklist_item(item)[source]
propertyblacklist_enabled

PythonScriptingInstance

classPythonScriptingInstance[source]

Bases:ScriptingInstance

classInterpreterThread[source]

Bases:Thread

__init__(instance)[source]

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroupclass is implemented.

target is the callable object to be invoked by the run()method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed ofthe form “Thread-N” where N is a small decimal number.

args is the argument tuple for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the targetinvocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invokethe base class constructor (Thread.__init__()) before doing anythingelse to the 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() methodinvokes the callable object passed to the object’s constructor as thetarget argument, if any, with sequential and keyword arguments takenfrom the args and kwargs arguments, respectively.

update_locals()[source]
update_magic_variables()[source]
write_at_cursor(data)[source]
__init__(provider)[source]
abstractperform_cancel_script_input()[source]
abstractperform_complete_input(text,state)[source]
abstractperform_execute_script_input(text)[source]
abstractperform_execute_script_input_from_filename(filename)[source]
abstractperform_set_current_address(addr)[source]
abstractperform_set_current_basic_block(block)[source]
abstractperform_set_current_binary_view(view)[source]
abstractperform_set_current_function(func)[source]
abstractperform_set_current_selection(begin,end)[source]
abstractperform_stop()[source]

PythonScriptingProvider

classPythonScriptingProvider[source]

Bases:ScriptingProvider

classMagicVariable[source]

Bases:object

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

__init__(get_value:Callable[[PythonScriptingInstance],Any],set_value:Callable[[PythonScriptingInstance,Any,Any],None]|None,depends_on:List[str])None
Parameters:
Return type:

None

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 thevariable has changed during the course of the script. If None, a warning will beprinted stating that the variable is read-only.Signature: (instance: PythonScriptingInstance, old_value: any, new_value: any) -> None

instance_class

alias ofPythonScriptingInstance

classmethodregister_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:param set_value: (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:param depends_on: List of other variables whose values on which this variable’s value depends

Parameters:
classmethodunregister_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_expr':PythonScriptingProvider.MagicVariable(get_value=<function_get_current_il_expr>,set_value=None,depends_on=['current_il_expr_index','current_il_function']),'current_il_expr_index':PythonScriptingProvider.MagicVariable(get_value=<function_get_current_il_expr_index>,set_value=None,depends_on=['current_token']),'current_il_function':PythonScriptingProvider.MagicVariable(get_value=<function_get_current_il_function>,set_value=None,depends_on=['current_ui_view_location','current_llil','current_lifted_il','current_llil_ssa','current_mapped_mlil','current_mapped_mlil_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_lifted_il':PythonScriptingProvider.MagicVariable(get_value=<function_get_current_lifted_il>,set_value=None,depends_on=[]),'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_mapped_mlil':PythonScriptingProvider.MagicVariable(get_value=<function_get_current_mapped_mlil>,set_value=None,depends_on=[]),'current_mapped_mlil_ssa':PythonScriptingProvider.MagicVariable(get_value=<function_get_current_mapped_mlil_ssa>,set_value=None,depends_on=['current_mapped_mlil']),'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_get_current_project>,set_value=None,depends_on=['current_ui_context','current_view']),'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'

ScriptingInstance

classScriptingInstance[source]

Bases:object

__init__(provider,handle=None)[source]
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]
abstractperform_cancel_script_input()[source]
abstractperform_complete_input(text:str,state)str[source]
Parameters:

text (str) –

Return type:

str

abstractperform_execute_script_input(text)[source]
abstractperform_execute_script_input_from_filename(text)[source]
abstractperform_set_current_address(addr)[source]
abstractperform_set_current_basic_block(block)[source]
abstractperform_set_current_binary_view(view)[source]
abstractperform_set_current_function(func)[source]
abstractperform_set_current_selection(begin,end)[source]
abstractperform_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]
propertydelimiters
propertyinput_ready_state

ScriptingOutputListener

classScriptingOutputListener[source]

Bases:object

notify_error(text)[source]
notify_input_ready_state_changed(state)[source]
notify_output(text)[source]
notify_warning(text)[source]

ScriptingProvider

classScriptingProvider[source]

Bases:object

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

ScriptingInstance |None

register()None[source]
Return type:

None

apiName=''
instance_class:Type[ScriptingInstance]|None=None
name=''

bninspect

classbninspect[source]

Bases:

bninspect prints documentation about a command that is about to be runThe 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

classredirect_stdio[source]

Bases: