-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy path__init__.py
More file actions
164 lines (127 loc) · 3.81 KB
/
__init__.py
File metadata and controls
164 lines (127 loc) · 3.81 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import binaryninja
from .changeset import *
from .databasesync import *
from .file import *
from .folder import *
from .group import *
from .project import *
from .remote import *
from .snapshot import *
from .user import *
from .util import _last_error
"""
Collaboration Remote API
Python wrappers around C++ wrappers around the various REST apis exposed by the collaboration server.
Many methods throw RuntimeError, as documented.
None of these classes are thread-safe. Python's GIL probably helps with this but if you are
doing heavily multi-threaded work with these you may want the C++ api.
"""
def active_remote() -> Optional['Remote']:
"""
Get the single actively connected Remote (for ux simplification)
:return: Active Remote, if one is set. None, otherwise.
"""
binaryninja._init_plugins()
value = core.BNCollaborationGetActiveRemote()
if value is None:
return None
result = Remote(handle=value)
return result
def set_active_remote(remote: Optional['Remote']):
"""
Set the single actively connected Remote
:param remote: New active Remote, or None to clear it.
"""
binaryninja._init_plugins()
if remote is not None:
core.BNCollaborationSetActiveRemote(remote._handle)
else:
core.BNCollaborationSetActiveRemote(None)
def known_remotes() -> List['Remote']:
"""
List of known/connected Remotes
:return: All known remotes
"""
binaryninja._init_plugins()
count = ctypes.c_size_t()
value = core.BNCollaborationGetRemotes(count)
result = []
for i in range(count.value):
result.append(Remote(handle=value[i]))
return result
def enterprise_remote() -> Optional['Remote']:
"""
Get whichever known Remote has the same address as the Enterprise license server
:return: Relevant known Remote, or None if one is not found
"""
for remote in known_remotes():
if remote.is_enterprise:
return remote
return None
def create_remote(name: str, address: str) -> 'Remote':
"""
Create a Remote and add it to the list of known remotes (saved to Settings)
:param name: Identifier for remote
:param address: Base address (HTTPS) for all api requests
"""
binaryninja._init_plugins()
return Remote(core.BNCollaborationCreateRemote(name, address))
def remove_known_remote(remote: 'Remote') -> None:
"""
Remove a Remote from the list of known remotes (saved to Settings)
:param remote: Remote to remove
"""
binaryninja._init_plugins()
core.BNCollaborationRemoveRemote(remote._handle)
def get_remote_by_id(id: str) -> Optional['Remote']:
"""
Get Remote by unique id
:param id: Unique id of the Remote
:return: Remote, if known, else None
"""
binaryninja._init_plugins()
value = core.BNCollaborationGetRemoteById(id)
if value is None:
return None
result = Remote(handle=value)
return result
def get_remote_by_address(address: str) -> Optional['Remote']:
"""
Get Remote by address
:param address: Base address of remote api
:return: Remote, if found, else None
"""
binaryninja._init_plugins()
value = core.BNCollaborationGetRemoteByAddress(address)
if value is None:
return None
result = Remote(handle=value)
return result
def get_remote_by_name(name: str) -> Optional['Remote']:
"""
Get Remote by name
:param name: Name of Remote
:return: Remote, if found, else None
"""
binaryninja._init_plugins()
value = core.BNCollaborationGetRemoteByName(name)
if value is None:
return None
result = Remote(handle=value)
return result
def load_remotes():
"""
Load the list of known Remotes from local Settings
:raises RuntimeError: If there was an error
"""
binaryninja._init_plugins()
if not core.BNCollaborationLoadRemotes():
raise RuntimeError(_last_error())
def save_remotes():
"""
Save the list of known Remotes to local Settings
:raises RuntimeError: If there was an error
"""
binaryninja._init_plugins()
if not core.BNCollaborationSaveRemotes():
raise RuntimeError(_last_error())