-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy path_debuggercore_template.py
More file actions
61 lines (51 loc) · 2.16 KB
/
_debuggercore_template.py
File metadata and controls
61 lines (51 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import binaryninja
import ctypes, os
from typing import Optional
from . import debugger_enums
# Load core module
import platform
core = None
core_platform = platform.system()
if os.environ.get('BN_STANDALONE_DEBUGGER'):
# By the time the debugger is loaded, binaryninja has not fully initialized.
# So we cannot call binaryninja.user_plugin_path()
from binaryninja._binaryninjacore import BNGetUserPluginDirectory
if core_platform == "Darwin":
_base_path = BNGetUserPluginDirectory()
core = ctypes.CDLL(os.path.join(_base_path, "libdebuggercore.dylib"))
elif core_platform == "Linux":
_base_path = BNGetUserPluginDirectory()
core = ctypes.CDLL(os.path.join(_base_path, "libdebuggercore.so"))
elif (core_platform == "Windows") or (core_platform.find("CYGWIN_NT") == 0):
_base_path = BNGetUserPluginDirectory()
core = ctypes.CDLL(os.path.join(_base_path, "debuggercore.dll"))
else:
raise Exception("OS not supported")
else:
# By the time the debugger is loaded, binaryninja has not fully initialized.
# So we cannot call binaryninja.bundled_plugin_path()
from binaryninja._binaryninjacore import BNGetBundledPluginDirectory
if core_platform == "Darwin":
_base_path = BNGetBundledPluginDirectory()
core = ctypes.CDLL(os.path.join(_base_path, "libdebuggercore.dylib"))
elif core_platform == "Linux":
_base_path = BNGetBundledPluginDirectory()
core = ctypes.CDLL(os.path.join(_base_path, "libdebuggercore.so"))
elif (core_platform == "Windows") or (core_platform.find("CYGWIN_NT") == 0):
_base_path = BNGetBundledPluginDirectory()
core = ctypes.CDLL(os.path.join(_base_path, "debuggercore.dll"))
else:
raise Exception("OS not supported")
def cstr(var) -> Optional[ctypes.c_char_p]:
if var is None:
return None
if isinstance(var, bytes):
return var
return var.encode("utf-8")
def pyNativeStr(arg):
if isinstance(arg, str):
return arg
else:
return arg.decode('utf8')
def free_string(value:ctypes.c_char_p) -> None:
BNDebuggerFreeString(ctypes.cast(value, ctypes.POINTER(ctypes.c_byte)))