Skip to content

Commit 9879389

Browse files
committed
Cookbook entry on adding a magic variable
1 parent 4520939 commit 9879389

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/dev/cookbook.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,17 @@ def invoke_plugin(name: str, bv: BinaryView, address=0, length = 0,function=None
287287
cmds = PluginCommand.get_valid_list(ctx)
288288
cmds[name].execute(ctx)
289289
```
290+
291+
### Add variable to the Python Console
292+
```python
293+
from binaryninja import PythonScriptingProvider, PythonScriptingInstance
294+
295+
def get_my_foo(instance: PythonScriptingInstance):
296+
# See scriptingprovider.py for details and implementations of other variables
297+
return instance.interpreter.active_addr & 0xffffff
298+
299+
PythonScriptingProvider.register_magic_variable(
300+
"my_foo",
301+
get_my_foo
302+
)
303+
```

0 commit comments

Comments
 (0)