23
23
24
24
using namespace BinaryNinja ::Enterprise;
25
25
26
+
27
+ bool BinaryNinja::Enterprise::IsInitialized ()
28
+ {
29
+ return BNIsEnterpriseServerInitialized ();
30
+ }
31
+
32
+
33
+ bool BinaryNinja::Enterprise::Initialize ()
34
+ {
35
+ return BNInitializeEnterpriseServer ();
36
+ }
37
+
38
+
26
39
bool BinaryNinja::Enterprise::AuthenticateWithCredentials (const std::string& username, const std::string& password, bool remember)
27
40
{
28
41
return BNAuthenticateEnterpriseServerWithCredentials (username.c_str (), password.c_str (), remember);
@@ -99,6 +112,8 @@ bool BinaryNinja::Enterprise::IsAuthenticated()
99
112
std::string BinaryNinja::Enterprise::GetUsername ()
100
113
{
101
114
char * value = BNGetEnterpriseServerUsername ();
115
+ if (!value)
116
+ return " " ;
102
117
std::string result = value;
103
118
BNFreeString (value);
104
119
return result;
@@ -108,6 +123,8 @@ std::string BinaryNinja::Enterprise::GetUsername()
108
123
std::string BinaryNinja::Enterprise::GetToken ()
109
124
{
110
125
char * value = BNGetEnterpriseServerToken ();
126
+ if (!value)
127
+ return " " ;
111
128
std::string result = value;
112
129
BNFreeString (value);
113
130
return result;
@@ -117,6 +134,8 @@ std::string BinaryNinja::Enterprise::GetToken()
117
134
std::string BinaryNinja::Enterprise::GetServerName ()
118
135
{
119
136
char * value = BNGetEnterpriseServerName ();
137
+ if (!value)
138
+ return " " ;
120
139
std::string result = value;
121
140
BNFreeString (value);
122
141
return result;
@@ -126,6 +145,8 @@ std::string BinaryNinja::Enterprise::GetServerName()
126
145
std::string BinaryNinja::Enterprise::GetServerUrl ()
127
146
{
128
147
char * value = BNGetEnterpriseServerUrl ();
148
+ if (!value)
149
+ return " " ;
129
150
std::string result = value;
130
151
BNFreeString (value);
131
152
return result;
@@ -135,6 +156,8 @@ std::string BinaryNinja::Enterprise::GetServerUrl()
135
156
std::string BinaryNinja::Enterprise::GetServerId ()
136
157
{
137
158
char * value = BNGetEnterpriseServerId ();
159
+ if (!value)
160
+ return " " ;
138
161
std::string result = value;
139
162
BNFreeString (value);
140
163
return result;
@@ -150,6 +173,8 @@ uint64_t BinaryNinja::Enterprise::GetServerVersion()
150
173
std::string BinaryNinja::Enterprise::GetServerBuildId ()
151
174
{
152
175
char * value = BNGetEnterpriseServerBuildId ();
176
+ if (!value)
177
+ return " " ;
153
178
std::string result = value;
154
179
BNFreeString (value);
155
180
return result;
@@ -188,7 +213,6 @@ bool BinaryNinja::Enterprise::IsLicenseStillActivated()
188
213
189
214
std::string BinaryNinja::Enterprise::GetLastError ()
190
215
{
191
- return BNGetEnterpriseServerLastError ();
192
216
char * str = BNGetEnterpriseServerLastError ();
193
217
std::string value = str;
194
218
BNFreeString (str);
@@ -208,14 +232,36 @@ void BinaryNinja::Enterprise::UnregisterNotification(BNEnterpriseServerCallbacks
208
232
}
209
233
210
234
211
- BinaryNinja::Enterprise::LicenseCheckout::LicenseCheckout (int64_t duration)
235
+ BinaryNinja::Enterprise::LicenseCheckout::LicenseCheckout (int64_t duration): m_acquiredLicense( false )
212
236
{
213
237
// This is a port of python's binaryninja.enterprise.LicenseCheckout
214
238
215
239
// UI builds have their own license manager
216
240
if (BNIsUIEnabled ())
217
241
return ;
218
242
243
+ if (!IsInitialized ())
244
+ {
245
+ if (!Initialize ())
246
+ {
247
+ // Named/computer licenses don't need this flow at all
248
+ if (!IsFloatingLicense ())
249
+ {
250
+ return ;
251
+ }
252
+
253
+ // Floating licenses though, this is an error. Probably the error
254
+ // for needing to set enterprise.server.url in settings.json
255
+ throw EnterpriseException (
256
+ " Could not initialize Binary Ninja Enterprise: " + GetLastError ()
257
+ );
258
+ }
259
+ }
260
+
261
+ if (!IsFloatingLicense ())
262
+ {
263
+ return ;
264
+ }
219
265
if (!IsConnected ())
220
266
{
221
267
Connect ();
0 commit comments