summaryrefslogtreecommitdiff
path: root/view/kernelcache
diff options
context:
space:
mode:
Diffstat (limited to 'view/kernelcache')
-rw-r--r--view/kernelcache/api/kernelcache.cpp10
-rw-r--r--view/kernelcache/api/kernelcacheapi.h4
-rw-r--r--view/kernelcache/api/kernelcachecore.h4
-rw-r--r--view/kernelcache/api/python/_kernelcachecore_template.py1
-rw-r--r--view/kernelcache/api/python/kernelcache.py15
-rw-r--r--view/kernelcache/core/KernelCache.cpp7
-rw-r--r--view/kernelcache/ui/kctriage.cpp2
7 files changed, 15 insertions, 28 deletions
diff --git a/view/kernelcache/api/kernelcache.cpp b/view/kernelcache/api/kernelcache.cpp
index 86cd8e0d..7a650660 100644
--- a/view/kernelcache/api/kernelcache.cpp
+++ b/view/kernelcache/api/kernelcache.cpp
@@ -20,10 +20,9 @@ namespace KernelCacheAPI {
return BNKCViewFastGetImageCount(view->GetObject());
}
- bool KernelCache::LoadImageWithInstallName(std::string installName)
+ bool KernelCache::LoadImageWithInstallName(const std::string& installName)
{
- char* str = BNAllocString(installName.c_str());
- return BNKCViewLoadImageWithInstallName(m_object, str);
+ return BNKCViewLoadImageWithInstallName(m_object, installName.c_str());
}
bool KernelCache::LoadImageContainingAddress(uint64_t addr)
@@ -161,10 +160,9 @@ namespace KernelCacheAPI {
return result;
}
- std::optional<KernelCacheMachOHeader> KernelCache::GetMachOHeaderForImage(std::string name)
+ std::optional<KernelCacheMachOHeader> KernelCache::GetMachOHeaderForImage(const std::string& name)
{
- char* str = BNAllocString(name.c_str());
- char* outputStr = BNKCViewGetImageHeaderForName(m_object, str);
+ char* outputStr = BNKCViewGetImageHeaderForName(m_object, name.c_str());
if (outputStr == nullptr)
return {};
std::string output = outputStr;
diff --git a/view/kernelcache/api/kernelcacheapi.h b/view/kernelcache/api/kernelcacheapi.h
index a4462cb0..35c53d78 100644
--- a/view/kernelcache/api/kernelcacheapi.h
+++ b/view/kernelcache/api/kernelcacheapi.h
@@ -254,7 +254,7 @@ namespace KernelCacheAPI {
static BNKCViewLoadProgress GetLoadProgress(Ref<BinaryView> view);
static uint64_t FastGetImageCount(Ref<BinaryView> view);
- bool LoadImageWithInstallName(std::string installName);
+ bool LoadImageWithInstallName(const std::string& installName);
bool LoadImageContainingAddress(uint64_t addr);
std::vector<std::string> GetAvailableImages();
@@ -268,7 +268,7 @@ namespace KernelCacheAPI {
std::vector<KCImage> GetImages();
std::vector<KCImage> GetLoadedImages();
- std::optional<KernelCacheMachOHeader> GetMachOHeaderForImage(std::string name);
+ std::optional<KernelCacheMachOHeader> GetMachOHeaderForImage(const std::string& name);
std::optional<KernelCacheMachOHeader> GetMachOHeaderForAddress(uint64_t address);
};
} \ No newline at end of file
diff --git a/view/kernelcache/api/kernelcachecore.h b/view/kernelcache/api/kernelcachecore.h
index be274a6c..2f158131 100644
--- a/view/kernelcache/api/kernelcachecore.h
+++ b/view/kernelcache/api/kernelcachecore.h
@@ -106,7 +106,7 @@ extern "C"
KERNELCACHE_FFI_API char** BNKCViewGetInstallNames(BNKernelCache* cache, size_t* count);
- KERNELCACHE_FFI_API bool BNKCViewLoadImageWithInstallName(BNKernelCache* cache, char* name);
+ KERNELCACHE_FFI_API bool BNKCViewLoadImageWithInstallName(BNKernelCache* cache, const char* name);
KERNELCACHE_FFI_API bool BNKCViewLoadImageContainingAddress(BNKernelCache* cache, uint64_t address);
KERNELCACHE_FFI_API bool BNKCViewIsImageLoaded(BNKernelCache* cache, uint64_t address);
@@ -128,7 +128,7 @@ extern "C"
KERNELCACHE_FFI_API void BNKCViewFreeLoadedImages(BNKCImage* images, size_t count);
KERNELCACHE_FFI_API char* BNKCViewGetImageHeaderForAddress(BNKernelCache* cache, uint64_t address);
- KERNELCACHE_FFI_API char* BNKCViewGetImageHeaderForName(BNKernelCache* cache, char* name);
+ KERNELCACHE_FFI_API char* BNKCViewGetImageHeaderForName(BNKernelCache* cache, const char* name);
#ifdef __cplusplus
}
diff --git a/view/kernelcache/api/python/_kernelcachecore_template.py b/view/kernelcache/api/python/_kernelcachecore_template.py
index ecbcb35d..cac7eb42 100644
--- a/view/kernelcache/api/python/_kernelcachecore_template.py
+++ b/view/kernelcache/api/python/_kernelcachecore_template.py
@@ -8,6 +8,7 @@ import platform
core = None
core_platform = platform.system()
+from binaryninja._binaryninjacore import BNFreeString, BNFreeStringList, BNAllocString
from binaryninja import Settings
if Settings().get_bool("corePlugins.view.kernelCache"):
from binaryninja._binaryninjacore import BNGetBundledPluginDirectory
diff --git a/view/kernelcache/api/python/kernelcache.py b/view/kernelcache/api/python/kernelcache.py
index 2148f2a8..9425ef9c 100644
--- a/view/kernelcache/api/python/kernelcache.py
+++ b/view/kernelcache/api/python/kernelcache.py
@@ -207,15 +207,10 @@ class KernelCache:
"""
Return a KernelCacheMachOHeader for the image with the given install name.
"""
- s = BNAllocString(name)
- outputStr = kccore.BNKCViewGetImageHeaderForName(self.handle, s)
+ outputStr = kccore.BNKCViewGetImageHeaderForName(self.handle, name)
if outputStr is None:
return None
- output = outputStr
- BNFreeString(outputStr)
- if output == "":
- return None
- return KernelCacheMachOHeader.LoadFromString(output)
+ return KernelCacheMachOHeader.LoadFromString(outputStr)
def get_macho_header_for_address(self, address: int):
"""
@@ -224,11 +219,7 @@ class KernelCache:
outputStr = kccore.BNKCViewGetImageHeaderForAddress(self.handle, address)
if outputStr is None:
return None
- output = outputStr
- BNFreeString(outputStr)
- if output == "":
- return None
- return KernelCacheMachOHeader.LoadFromString(output)
+ return KernelCacheMachOHeader.LoadFromString(outputStr)
@property
def state(self):
diff --git a/view/kernelcache/core/KernelCache.cpp b/view/kernelcache/core/KernelCache.cpp
index be6a4eb6..6cb3fca6 100644
--- a/view/kernelcache/core/KernelCache.cpp
+++ b/view/kernelcache/core/KernelCache.cpp
@@ -2145,11 +2145,9 @@ extern "C"
cache->object->ReleaseAPIRef();
}
- bool BNKCViewLoadImageWithInstallName(BNKernelCache* cache, char* name)
+ bool BNKCViewLoadImageWithInstallName(BNKernelCache* cache, const char* name)
{
std::string imageName = std::string(name);
- // FIXME !!!!!!!! BNFreeString(name);
-
if (cache->object)
return cache->object->LoadImageWithInstallName(imageName);
@@ -2321,10 +2319,9 @@ extern "C"
return nullptr;
}
- char* BNKCViewGetImageHeaderForName(BNKernelCache* cache, char* name)
+ char* BNKCViewGetImageHeaderForName(BNKernelCache* cache, const char* name)
{
std::string imageName = std::string(name);
- BNFreeString(name);
if (cache->object)
{
auto header = cache->object->SerializedImageHeaderForName(imageName);
diff --git a/view/kernelcache/ui/kctriage.cpp b/view/kernelcache/ui/kctriage.cpp
index 5103bc51..bac39b5e 100644
--- a/view/kernelcache/ui/kctriage.cpp
+++ b/view/kernelcache/ui/kctriage.cpp
@@ -93,7 +93,7 @@ void KCTriageView::loadImagesWithAddr(const std::vector<uint64_t>& addresses) {
{
if (imageLoadTask.IsCancelled())
break;
- std::string newLoad = fmt::format("Loading images... ({}/{})", loadedImages++, images.size());
+ const std::string newLoad = fmt::format("Loading images... ({}/{})", loadedImages++, images.size());
imageLoadTask.SetProgressText(newLoad);
if (m_cache->LoadImageWithInstallName(imageName))
setImageLoaded(addr);