Skip to content

Commit beda605

Browse files
committed
Add get_system_cache_directory and GetSystemCacheDirectory to API
1 parent 44e4155 commit beda605

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

binaryninjaapi.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ string BinaryNinja::GetUserDirectory(void)
9595
}
9696

9797

98+
string BinaryNinja::GetSystemCacheDirectory()
99+
{
100+
char* dir = BNGetSystemCacheDirectory();
101+
if (!dir)
102+
return string();
103+
std::string result(dir);
104+
BNFreeString(dir);
105+
return result;
106+
}
107+
108+
98109
string BinaryNinja::GetSettingsFileName()
99110
{
100111
char* dir = BNGetSettingsFileName();

binaryninjaapi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,12 @@ namespace BinaryNinja {
12411241
void SetBundledPluginDirectory(const std::string& path);
12421242
std::string GetUserDirectory();
12431243

1244+
/*! Get the Binary Ninja system cache directory
1245+
*
1246+
* @return std::string - Binary Ninja's cache directory on a given system
1247+
*/
1248+
std::string GetSystemCacheDirectory();
1249+
12441250
std::string GetSettingsFileName();
12451251
std::string GetRepositoriesDirectory();
12461252
std::string GetInstallDirectory();

binaryninjacore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7558,6 +7558,7 @@ extern "C"
75587558
BINARYNINJACOREAPI char** BNGetFilePathsInDirectory(const char* path, size_t* count);
75597559
BINARYNINJACOREAPI char* BNAppendPath(const char* path, const char* part);
75607560
BINARYNINJACOREAPI void BNFreePath(char* path);
7561+
BINARYNINJACOREAPI char* BNGetSystemCacheDirectory();
75617562

75627563
// Settings APIs
75637564
BINARYNINJACOREAPI BNSettings* BNCreateSettings(const char* schemaId);

python/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,19 @@ def connect_vscode_debugger(port=5678):
461461
debugpy.wait_for_client()
462462
execute_on_main_thread(lambda: debugpy.debug_this_thread())
463463

464+
def get_system_cache_directory() -> Optional[str]:
465+
"""
466+
Returns Binary Ninja's system cache directory on the system.
467+
468+
Supported default locations:
469+
470+
- macOS: ~/Library/Caches/Binary Ninja
471+
- Linux: $XDG_CACHE_HOME/Binary Ninja or ~/.cache/Binary Ninja
472+
- Windows: %LOCALAPPDATA%/Binary Ninja/cache
473+
474+
:return: Returns a string containing the system cache directory, or None on failure.
475+
"""
476+
return core.BNGetSystemCacheDirectory()
464477

465478
class UIPluginInHeadlessError(Exception):
466479
"""

0 commit comments

Comments
 (0)