Skip to content

Commit 6f12ffb

Browse files
committed
Refactor RepositoryManager; No longer ref counted object (one global plugin manager going forward); Move user plugin/repo plugin logic to core under single streamlined function
1 parent 1956f69 commit 6f12ffb

File tree

7 files changed

+23
-112
lines changed

7 files changed

+23
-112
lines changed

binaryninjaapi.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,6 @@ bool BinaryNinja::InitPlugins(bool allowUserPlugins)
4949
}
5050

5151

52-
void BinaryNinja::InitCorePlugins()
53-
{
54-
BNInitCorePlugins();
55-
}
56-
57-
58-
void BinaryNinja::InitUserPlugins()
59-
{
60-
BNInitUserPlugins();
61-
}
62-
63-
64-
void BinaryNinja::InitRepoPlugins()
65-
{
66-
BNInitRepoPlugins();
67-
}
68-
69-
7052
string BinaryNinja::GetBundledPluginDirectory()
7153
{
7254
char* path = BNGetBundledPluginDirectory();

binaryninjaapi.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18211,17 +18211,13 @@ namespace BinaryNinja {
1821118211
/*!
1821218212
\ingroup pluginmanager
1821318213
*/
18214-
class RepositoryManager :
18215-
public CoreRefCountObject<BNRepositoryManager, BNNewRepositoryManagerReference, BNFreeRepositoryManager>
18214+
class RepositoryManager
1821618215
{
1821718216
public:
18218-
RepositoryManager(const std::string& enabledPluginsPath);
18219-
RepositoryManager(BNRepositoryManager* repoManager);
18220-
RepositoryManager();
18221-
bool CheckForUpdates();
18222-
std::vector<Ref<Repository>> GetRepositories();
18223-
Ref<Repository> GetRepositoryByPath(const std::string& repoName);
18224-
bool AddRepository(const std::string& url, // URL to raw plugins.json file
18217+
static bool CheckForUpdates();
18218+
static std::vector<Ref<Repository>> GetRepositories();
18219+
static Ref<Repository> GetRepositoryByPath(const std::string& repoName);
18220+
static bool AddRepository(const std::string& url, // URL to raw plugins.json file
1822518221
const std::string& repoPath); // Relative path within the repositories directory
1822618222
Ref<Repository> GetDefaultRepository();
1822718223
};

binaryninjacore.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ extern "C"
255255
typedef struct BNBackgroundTask BNBackgroundTask;
256256
typedef struct BNRepository BNRepository;
257257
typedef struct BNRepoPlugin BNRepoPlugin;
258-
typedef struct BNRepositoryManager BNRepositoryManager;
259258
typedef struct BNComponent BNComponent;
260259
typedef struct BNSettings BNSettings;
261260
typedef struct BNMetadata BNMetadata;
@@ -3839,11 +3838,8 @@ extern "C"
38393838

38403839
// Plugin initialization
38413840
BINARYNINJACOREAPI bool BNInitPlugins(bool allowUserPlugins);
3842-
BINARYNINJACOREAPI bool BNInitCorePlugins(void); // Deprecated, use BNInitPlugins
38433841
BINARYNINJACOREAPI void BNDisablePlugins(void);
38443842
BINARYNINJACOREAPI bool BNIsPluginsEnabled(void);
3845-
BINARYNINJACOREAPI void BNInitUserPlugins(void); // Deprecated, use BNInitPlugins
3846-
BINARYNINJACOREAPI void BNInitRepoPlugins(void);
38473843

38483844
BINARYNINJACOREAPI char* BNGetInstallDirectory(void);
38493845
BINARYNINJACOREAPI char* BNGetBundledPluginDirectory(void);
@@ -7551,18 +7547,13 @@ extern "C"
75517547
BINARYNINJACOREAPI BNRepoPlugin* BNRepositoryGetPluginByPath(BNRepository* r, const char* pluginPath);
75527548
BINARYNINJACOREAPI const char* BNRepositoryGetPluginsPath(BNRepository* r);
75537549

7554-
BINARYNINJACOREAPI BNRepositoryManager* BNCreateRepositoryManager(const char* enabledPluginsPath);
7555-
BINARYNINJACOREAPI BNRepositoryManager* BNNewRepositoryManagerReference(BNRepositoryManager* r);
7556-
BINARYNINJACOREAPI void BNFreeRepositoryManager(BNRepositoryManager* r);
7557-
BINARYNINJACOREAPI bool BNRepositoryManagerCheckForUpdates(BNRepositoryManager* r);
7558-
BINARYNINJACOREAPI BNRepository** BNRepositoryManagerGetRepositories(BNRepositoryManager* r, size_t* count);
7550+
BINARYNINJACOREAPI bool BNRepositoryManagerCheckForUpdates();
7551+
BINARYNINJACOREAPI BNRepository** BNRepositoryManagerGetRepositories(size_t* count);
75597552
BINARYNINJACOREAPI void BNFreeRepositoryManagerRepositoriesList(BNRepository** r);
7560-
BINARYNINJACOREAPI bool BNRepositoryManagerAddRepository(
7561-
BNRepositoryManager* r, const char* url, const char* repoPath);
7562-
BINARYNINJACOREAPI BNRepository* BNRepositoryGetRepositoryByPath(BNRepositoryManager* r, const char* repoPath);
7563-
BINARYNINJACOREAPI BNRepositoryManager* BNGetRepositoryManager(void);
7553+
BINARYNINJACOREAPI bool BNRepositoryManagerAddRepository(const char* url, const char* repoPath);
7554+
BINARYNINJACOREAPI BNRepository* BNRepositoryGetRepositoryByPath(const char* repoPath);
75647555

7565-
BINARYNINJACOREAPI BNRepository* BNRepositoryManagerGetDefaultRepository(BNRepositoryManager* r);
7556+
BINARYNINJACOREAPI BNRepository* BNRepositoryManagerGetDefaultRepository();
75667557

75677558
// Components
75687559

pluginmanager.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -310,31 +310,16 @@ string Repository::GetFullPath() const
310310
RETURN_STRING(BNRepositoryGetPluginsPath(m_object));
311311
}
312312

313-
RepositoryManager::RepositoryManager(const string& enabledPluginsPath)
314-
{
315-
m_object = BNCreateRepositoryManager(enabledPluginsPath.c_str());
316-
}
317-
318-
RepositoryManager::RepositoryManager(BNRepositoryManager* mgr)
319-
{
320-
m_object = mgr;
321-
}
322-
323-
RepositoryManager::RepositoryManager()
324-
{
325-
m_object = BNGetRepositoryManager();
326-
}
327-
328313
bool RepositoryManager::CheckForUpdates()
329314
{
330-
return BNRepositoryManagerCheckForUpdates(m_object);
315+
return BNRepositoryManagerCheckForUpdates();
331316
}
332317

333318
vector<Ref<Repository>> RepositoryManager::GetRepositories()
334319
{
335320
vector<Ref<Repository>> repos;
336321
size_t count = 0;
337-
BNRepository** reposPtr = BNRepositoryManagerGetRepositories(m_object, &count);
322+
BNRepository** reposPtr = BNRepositoryManagerGetRepositories(&count);
338323
for (size_t i = 0; i < count; i++)
339324
repos.push_back(new Repository(BNNewRepositoryReference(reposPtr[i])));
340325
BNFreeRepositoryManagerRepositoriesList(reposPtr);
@@ -344,15 +329,15 @@ vector<Ref<Repository>> RepositoryManager::GetRepositories()
344329
bool RepositoryManager::AddRepository(const std::string& url,
345330
const std::string& repoPath) // Relative path within the repositories directory
346331
{
347-
return BNRepositoryManagerAddRepository(m_object, url.c_str(), repoPath.c_str());
332+
return BNRepositoryManagerAddRepository(url.c_str(), repoPath.c_str());
348333
}
349334

350335
Ref<Repository> RepositoryManager::GetRepositoryByPath(const std::string& repoPath)
351336
{
352-
return new Repository(BNRepositoryGetRepositoryByPath(m_object, repoPath.c_str()));
337+
return new Repository(BNRepositoryGetRepositoryByPath(repoPath.c_str()));
353338
}
354339

355340
Ref<Repository> RepositoryManager::GetDefaultRepository()
356341
{
357-
return new Repository(BNRepositoryManagerGetDefaultRepository(m_object));
342+
return new Repository(BNRepositoryManagerGetDefaultRepository());
358343
}

python/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ def _init_plugins():
248248
if _enable_default_log and is_headless_init_once and min_level in LogLevel.__members__ and not core_ui_enabled(
249249
) and sys.stderr.isatty():
250250
log_to_stderr(LogLevel[min_level])
251-
core.BNInitRepoPlugins()
252251
if core.BNIsLicenseValidated():
253252
_plugin_init = True
254253
else:

rust/src/headless.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::enterprise::EnterpriseCheckoutStatus;
2626
use crate::main_thread::{MainThreadAction, MainThreadHandler};
2727
use crate::progress::ProgressCallback;
2828
use crate::rc::Ref;
29-
use binaryninjacore_sys::{BNInitPlugins, BNInitRepoPlugins};
29+
use binaryninjacore_sys::{BNInitPlugins};
3030
use std::sync::mpsc::Sender;
3131
use std::sync::Mutex;
3232
use std::thread::JoinHandle;
@@ -221,10 +221,6 @@ pub fn init_with_opts(options: InitializationOptions) -> Result<(), Initializati
221221

222222
unsafe {
223223
BNInitPlugins(options.user_plugins);
224-
if options.repo_plugins {
225-
// We are allowed to initialize repo plugins, so do it!
226-
BNInitRepoPlugins();
227-
}
228224
}
229225

230226
if !is_license_validated() {

rust/src/repository/manager.rs

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use crate::rc::{Array, Ref, RefCountable};
1+
use crate::rc::{Array, Ref};
22
use crate::repository::Repository;
33
use crate::string::IntoCStr;
4-
use binaryninjacore_sys::{
5-
BNCreateRepositoryManager, BNFreeRepositoryManager, BNGetRepositoryManager,
6-
BNNewRepositoryManagerReference, BNRepositoryGetRepositoryByPath, BNRepositoryManager,
4+
use binaryninjacore_sys::{BNRepositoryGetRepositoryByPath,
75
BNRepositoryManagerAddRepository, BNRepositoryManagerCheckForUpdates,
86
BNRepositoryManagerGetDefaultRepository, BNRepositoryManagerGetRepositories,
97
};
@@ -15,36 +13,20 @@ use std::ptr::NonNull;
1513
/// file coherent with the plugins that are installed/uninstalled enabled/disabled
1614
#[repr(transparent)]
1715
pub struct RepositoryManager {
18-
handle: NonNull<BNRepositoryManager>,
1916
}
2017

2118
impl RepositoryManager {
22-
#[allow(clippy::should_implement_trait)]
23-
pub fn default() -> Ref<Self> {
24-
let result = unsafe { BNGetRepositoryManager() };
25-
unsafe { Self::ref_from_raw(NonNull::new(result).unwrap()) }
26-
}
27-
28-
pub(crate) unsafe fn ref_from_raw(handle: NonNull<BNRepositoryManager>) -> Ref<Self> {
29-
Ref::new(Self { handle })
30-
}
31-
32-
pub fn new(plugins_path: &str) -> Ref<Self> {
33-
let plugins_path = plugins_path.to_cstr();
34-
let result = unsafe { BNCreateRepositoryManager(plugins_path.as_ptr()) };
35-
unsafe { Self::ref_from_raw(NonNull::new(result).unwrap()) }
36-
}
3719

3820
/// Check for updates for all managed [`Repository`] objects
3921
pub fn check_for_updates(&self) -> bool {
40-
unsafe { BNRepositoryManagerCheckForUpdates(self.handle.as_ptr()) }
22+
unsafe { BNRepositoryManagerCheckForUpdates() }
4123
}
4224

4325
/// List of [`Repository`] objects being managed
4426
pub fn repositories(&self) -> Array<Repository> {
4527
let mut count = 0;
4628
let result =
47-
unsafe { BNRepositoryManagerGetRepositories(self.handle.as_ptr(), &mut count) };
29+
unsafe { BNRepositoryManagerGetRepositories(&mut count) };
4830
assert!(!result.is_null());
4931
unsafe { Array::new(result, count, ()) }
5032
}
@@ -64,20 +46,20 @@ impl RepositoryManager {
6446
let url = url.to_cstr();
6547
let repo_path = repository_path.to_cstr();
6648
unsafe {
67-
BNRepositoryManagerAddRepository(self.handle.as_ptr(), url.as_ptr(), repo_path.as_ptr())
49+
BNRepositoryManagerAddRepository(url.as_ptr(), repo_path.as_ptr())
6850
}
6951
}
7052

7153
pub fn repository_by_path(&self, path: &Path) -> Option<Repository> {
7254
let path = path.to_cstr();
7355
let result =
74-
unsafe { BNRepositoryGetRepositoryByPath(self.handle.as_ptr(), path.as_ptr()) };
56+
unsafe { BNRepositoryGetRepositoryByPath(path.as_ptr()) };
7557
NonNull::new(result).map(|raw| unsafe { Repository::from_raw(raw) })
7658
}
7759

7860
/// Gets the default [`Repository`]
7961
pub fn default_repository(&self) -> Ref<Repository> {
80-
let result = unsafe { BNRepositoryManagerGetDefaultRepository(self.handle.as_ptr()) };
62+
let result = unsafe { BNRepositoryManagerGetDefaultRepository() };
8163
assert!(!result.is_null());
8264
unsafe { Repository::ref_from_raw(NonNull::new(result).unwrap()) }
8365
}
@@ -90,23 +72,3 @@ impl Debug for RepositoryManager {
9072
.finish()
9173
}
9274
}
93-
94-
impl ToOwned for RepositoryManager {
95-
type Owned = Ref<Self>;
96-
97-
fn to_owned(&self) -> Self::Owned {
98-
unsafe { RefCountable::inc_ref(self) }
99-
}
100-
}
101-
102-
unsafe impl RefCountable for RepositoryManager {
103-
unsafe fn inc_ref(handle: &Self) -> Ref<Self> {
104-
Self::ref_from_raw(
105-
NonNull::new(BNNewRepositoryManagerReference(handle.handle.as_ptr())).unwrap(),
106-
)
107-
}
108-
109-
unsafe fn dec_ref(handle: &Self) {
110-
BNFreeRepositoryManager(handle.handle.as_ptr())
111-
}
112-
}

0 commit comments

Comments
 (0)