Skip to content

Commit ce1a25a

Browse files
committed
Add new license APIs.
1 parent 06611c1 commit ce1a25a

5 files changed

Lines changed: 96 additions & 1 deletion

File tree

binaryninjaapi.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,36 @@ string BinaryNinja::GetSerialNumber()
272272
}
273273

274274

275+
string BinaryNinja::GetLicenseUserId()
276+
{
277+
char* str = BNGetLicenseUserId();
278+
string result = str;
279+
BNFreeString(str);
280+
return result;
281+
}
282+
283+
284+
string BinaryNinja::GetLicenseAddonsJson()
285+
{
286+
char* str = BNGetLicenseAddonsJson();
287+
string result = str;
288+
BNFreeString(str);
289+
return result;
290+
}
291+
292+
293+
vector<string> BinaryNinja::GetLicenseAddons()
294+
{
295+
size_t count = 0;
296+
char** addons = BNGetLicenseAddons(&count);
297+
vector<string> result;
298+
for (size_t i = 0; i < count; i++)
299+
result.emplace_back(addons[i]);
300+
BNFreeStringList(addons, count);
301+
return result;
302+
}
303+
304+
275305
int BinaryNinja::GetLicenseCount()
276306
{
277307
return BNGetLicenseCount();

binaryninjaapi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,9 @@ namespace BinaryNinja {
20272027
std::string GetProduct();
20282028
std::string GetProductType();
20292029
std::string GetSerialNumber();
2030+
std::string GetLicenseUserId();
2031+
std::string GetLicenseAddonsJson();
2032+
std::vector<std::string> GetLicenseAddons();
20302033
int GetLicenseCount();
20312034
bool IsUIEnabled();
20322035
uint32_t GetBuildId();

binaryninjacore.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4072,6 +4072,9 @@ extern "C"
40724072
BINARYNINJACOREAPI char* BNGetLicensedUserEmail(void);
40734073
BINARYNINJACOREAPI char* BNGetProduct(void);
40744074
BINARYNINJACOREAPI char* BNGetProductType(void);
4075+
BINARYNINJACOREAPI char* BNGetLicenseUserId(void);
4076+
BINARYNINJACOREAPI char* BNGetLicenseAddonsJson(void);
4077+
BINARYNINJACOREAPI char** BNGetLicenseAddons(size_t* count);
40754078
BINARYNINJACOREAPI int BNGetLicenseCount(void);
40764079
BINARYNINJACOREAPI bool BNIsUIEnabled(void);
40774080
BINARYNINJACOREAPI void BNSetLicense(const char* licenseData);

python/__init__.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
import atexit
2222
import sys
2323
import ctypes
24+
import json
2425
from time import gmtime, struct_time
2526
import os
26-
from typing import Mapping, Optional
27+
from typing import Any, List, Mapping, Optional
2728
import functools
2829

2930
# Binary Ninja components
@@ -373,6 +374,36 @@ def core_license_count() -> int:
373374
return core.BNGetLicenseCount()
374375

375376

377+
def core_license_addons() -> List[str]:
378+
'''License addons from the license file'''
379+
_init_plugins()
380+
count = ctypes.c_ulonglong()
381+
addons = core.BNGetLicenseAddons(ctypes.byref(count))
382+
if not addons:
383+
return []
384+
result = [core.pyNativeStr(addons[i]) for i in range(count.value)]
385+
core.BNFreeStringList(addons, count.value)
386+
return result
387+
388+
389+
def core_license_addons_json() -> str:
390+
'''Structured license addons JSON from the license file'''
391+
_init_plugins()
392+
return core.BNGetLicenseAddonsJson()
393+
394+
395+
def core_license_addon_data() -> List[Mapping[str, Any]]:
396+
'''Structured license addons from the license file'''
397+
return json.loads(core_license_addons_json())
398+
399+
400+
def core_license_user_id() -> Optional[int]:
401+
'''License user id from the license file'''
402+
_init_plugins()
403+
uid = core.BNGetLicenseUserId()
404+
return int(uid) if uid else None
405+
406+
376407
def core_ui_enabled() -> bool:
377408
'''Indicates that a UI exists and the UI has invoked BNInitUI'''
378409
return core.BNIsUIEnabled()

rust/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,34 @@ pub fn license_count() -> i32 {
540540
unsafe { BNGetLicenseCount() }
541541
}
542542

543+
pub fn license_addons() -> Vec<String> {
544+
let mut count = 0;
545+
let addons = unsafe { BNGetLicenseAddons(&mut count) };
546+
if addons.is_null() {
547+
return Vec::new();
548+
}
549+
550+
let result = unsafe { std::slice::from_raw_parts(addons, count) }
551+
.iter()
552+
.map(|addon| unsafe { CStr::from_ptr(*addon).to_string_lossy().into_owned() })
553+
.collect();
554+
unsafe { BNFreeStringList(addons, count) };
555+
result
556+
}
557+
558+
pub fn license_addons_json() -> String {
559+
unsafe { BnString::into_string(BNGetLicenseAddonsJson()) }
560+
}
561+
562+
pub fn license_user_id() -> Option<String> {
563+
let uid = unsafe { BnString::into_string(BNGetLicenseUserId()) };
564+
if uid.is_empty() {
565+
None
566+
} else {
567+
Some(uid)
568+
}
569+
}
570+
543571
/// Set the license that will be used once the core initializes. You can reset the license by passing `None`.
544572
///
545573
/// If not set, the normal license retrieval will occur:

0 commit comments

Comments
 (0)