From 64bf95dcca785098465a16d67d35e9a0ce715af1 Mon Sep 17 00:00:00 2001 From: Alexander Khosrowshahi Date: Tue, 1 Jul 2025 12:17:37 -0400 Subject: [PATCH 1/2] Add GetSystemCacheDirectory to C++ API --- binaryninjaapi.cpp | 11 +++++++++++ binaryninjaapi.h | 2 ++ binaryninjacore.h | 1 + 3 files changed, 14 insertions(+) diff --git a/binaryninjaapi.cpp b/binaryninjaapi.cpp index f526320a10..c35e28c860 100644 --- a/binaryninjaapi.cpp +++ b/binaryninjaapi.cpp @@ -95,6 +95,17 @@ string BinaryNinja::GetUserDirectory(void) } +string BinaryNinja::GetSystemCacheDirectory() +{ + char* dir = BNGetSystemCacheDirectory(); + if (!dir) + return string(); + std::string result(dir); + BNFreeString(dir); + return result; +} + + string BinaryNinja::GetSettingsFileName() { char* dir = BNGetSettingsFileName(); diff --git a/binaryninjaapi.h b/binaryninjaapi.h index bab743d34f..a3d319e58b 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1241,6 +1241,8 @@ namespace BinaryNinja { void SetBundledPluginDirectory(const std::string& path); std::string GetUserDirectory(); + std::string GetSystemCacheDirectory(); + std::string GetSettingsFileName(); std::string GetRepositoriesDirectory(); std::string GetInstallDirectory(); diff --git a/binaryninjacore.h b/binaryninjacore.h index deca98e52d..dbeef41c71 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -7530,6 +7530,7 @@ extern "C" BINARYNINJACOREAPI char** BNGetFilePathsInDirectory(const char* path, size_t* count); BINARYNINJACOREAPI char* BNAppendPath(const char* path, const char* part); BINARYNINJACOREAPI void BNFreePath(char* path); + BINARYNINJACOREAPI char* BNGetSystemCacheDirectory(); // Settings APIs BINARYNINJACOREAPI BNSettings* BNCreateSettings(const char* schemaId); From 172f51c918264aa29e7bfd90e8e35de80be49bce Mon Sep 17 00:00:00 2001 From: Alexander Khosrowshahi Date: Wed, 2 Jul 2025 12:55:11 -0400 Subject: [PATCH 2/2] Add get_system_cache_directory to python API --- python/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/__init__.py b/python/__init__.py index 2e6857f9cb..3f258e1f50 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -462,6 +462,19 @@ def connect_vscode_debugger(port=5678): debugpy.wait_for_client() execute_on_main_thread(lambda: debugpy.debug_this_thread()) +def get_system_cache_directory() -> Optional[str]: + """ + Returns Binary Ninja's system cache directory on the system. + + Supported default locations: + - macOS: ~/Library/Caches/Binary Ninja + - Linux: $XDG_CACHE_HOME/Binary Ninja or ~/.cache/Binary Ninja + - Windows: %LOCALAPPDATA%/Binary Ninja/cache + + :return: Returns a string containing the system cache directory, or None on failure. + """ + return core.BNGetSystemCacheDirectory() + class UIPluginInHeadlessError(Exception): """