summaryrefslogtreecommitdiff
path: root/view/sharedcache
diff options
context:
space:
mode:
authorWeiN76LQh <WeiN76LQh@github.com>2024-11-25 19:54:44 +0000
committerkat <kat@vector35.com>2024-12-26 10:42:54 -0500
commit2cce2ab6c79879a4d64df1fc7375e2c871565f8f (patch)
tree9e6c5273eff573f28b99fd59f98472582df2d639 /view/sharedcache
parent934104743a0e3071606277692822be4b853288ac (diff)
[SharedCache] Add the ability to skip Objective-C processing when loading a library
This is useful when batch loading libraries to avoid extra processing (once the next commit has landed).
Diffstat (limited to 'view/sharedcache')
-rw-r--r--view/sharedcache/api/python/_sharedcachecore.py12
-rw-r--r--view/sharedcache/api/python/sharedcache.py8
-rw-r--r--view/sharedcache/api/sharedcache.cpp8
-rw-r--r--view/sharedcache/api/sharedcacheapi.h4
-rw-r--r--view/sharedcache/api/sharedcachecore.h4
-rw-r--r--view/sharedcache/core/SharedCache.cpp59
-rw-r--r--view/sharedcache/core/SharedCache.h4
7 files changed, 53 insertions, 46 deletions
diff --git a/view/sharedcache/api/python/_sharedcachecore.py b/view/sharedcache/api/python/_sharedcachecore.py
index d208048b..bd9e0764 100644
--- a/view/sharedcache/api/python/_sharedcachecore.py
+++ b/view/sharedcache/api/python/_sharedcachecore.py
@@ -528,15 +528,17 @@ _BNDSCViewLoadImageContainingAddress.restype = ctypes.c_bool
_BNDSCViewLoadImageContainingAddress.argtypes = [
ctypes.POINTER(BNSharedCache),
ctypes.c_ulonglong,
+ ctypes.c_bool,
]
# noinspection PyPep8Naming
def BNDSCViewLoadImageContainingAddress(
cache: ctypes.POINTER(BNSharedCache),
- address: int
+ address: int,
+ skipObjC: bool
) -> bool:
- return _BNDSCViewLoadImageContainingAddress(cache, address)
+ return _BNDSCViewLoadImageContainingAddress(cache, address, skipObjC)
# -------------------------------------------------------
@@ -547,15 +549,17 @@ _BNDSCViewLoadImageWithInstallName.restype = ctypes.c_bool
_BNDSCViewLoadImageWithInstallName.argtypes = [
ctypes.POINTER(BNSharedCache),
ctypes.c_char_p,
+ ctypes.c_bool,
]
# noinspection PyPep8Naming
def BNDSCViewLoadImageWithInstallName(
cache: ctypes.POINTER(BNSharedCache),
- name: Optional[str]
+ name: Optional[str],
+ skipObjC: bool
) -> bool:
- return _BNDSCViewLoadImageWithInstallName(cache, cstr(name))
+ return _BNDSCViewLoadImageWithInstallName(cache, cstr(name), skipObjC)
# -------------------------------------------------------
diff --git a/view/sharedcache/api/python/sharedcache.py b/view/sharedcache/api/python/sharedcache.py
index b660d9d9..7902c76a 100644
--- a/view/sharedcache/api/python/sharedcache.py
+++ b/view/sharedcache/api/python/sharedcache.py
@@ -108,14 +108,14 @@ class SharedCache:
def __init__(self, view):
self.handle = sccore.BNGetSharedCache(view.handle)
- def load_image_with_install_name(self, installName):
- return sccore.BNDSCViewLoadImageWithInstallName(self.handle, installName)
+ def load_image_with_install_name(self, installName, skipObjC = False):
+ return sccore.BNDSCViewLoadImageWithInstallName(self.handle, installName, skipObjC)
def load_section_at_address(self, addr):
return sccore.BNDSCViewLoadSectionAtAddress(self.handle, addr)
- def load_image_containing_address(self, addr):
- return sccore.BNDSCViewLoadImageContainingAddress(self.handle, addr)
+ def load_image_containing_address(self, addr, skipObjC = False):
+ return sccore.BNDSCViewLoadImageContainingAddress(self.handle, addr, skipObjC)
@property
def caches(self):
diff --git a/view/sharedcache/api/sharedcache.cpp b/view/sharedcache/api/sharedcache.cpp
index 71d190da..6498de32 100644
--- a/view/sharedcache/api/sharedcache.cpp
+++ b/view/sharedcache/api/sharedcache.cpp
@@ -20,10 +20,10 @@ namespace SharedCacheAPI {
return BNDSCViewFastGetBackingCacheCount(view->GetObject());
}
- bool SharedCache::LoadImageWithInstallName(std::string installName)
+ bool SharedCache::LoadImageWithInstallName(std::string installName, bool skipObjC)
{
char* str = BNAllocString(installName.c_str());
- return BNDSCViewLoadImageWithInstallName(m_object, str);
+ return BNDSCViewLoadImageWithInstallName(m_object, str, skipObjC);
}
bool SharedCache::LoadSectionAtAddress(uint64_t addr)
@@ -31,9 +31,9 @@ namespace SharedCacheAPI {
return BNDSCViewLoadSectionAtAddress(m_object, addr);
}
- bool SharedCache::LoadImageContainingAddress(uint64_t addr)
+ bool SharedCache::LoadImageContainingAddress(uint64_t addr, bool skipObjC)
{
- return BNDSCViewLoadImageContainingAddress(m_object, addr);
+ return BNDSCViewLoadImageContainingAddress(m_object, addr, skipObjC);
}
std::vector<std::string> SharedCache::GetAvailableImages()
diff --git a/view/sharedcache/api/sharedcacheapi.h b/view/sharedcache/api/sharedcacheapi.h
index 7b049bc4..f556b1a8 100644
--- a/view/sharedcache/api/sharedcacheapi.h
+++ b/view/sharedcache/api/sharedcacheapi.h
@@ -257,9 +257,9 @@ namespace SharedCacheAPI {
static BNDSCViewLoadProgress GetLoadProgress(Ref<BinaryView> view);
static uint64_t FastGetBackingCacheCount(Ref<BinaryView> view);
- bool LoadImageWithInstallName(std::string installName);
+ bool LoadImageWithInstallName(std::string installName, bool skipObjC = false);
bool LoadSectionAtAddress(uint64_t addr);
- bool LoadImageContainingAddress(uint64_t addr);
+ bool LoadImageContainingAddress(uint64_t addr, bool skipObjC = false);
std::vector<std::string> GetAvailableImages();
std::vector<DSCSymbol> LoadAllSymbolsAndWait();
diff --git a/view/sharedcache/api/sharedcachecore.h b/view/sharedcache/api/sharedcachecore.h
index 9fc33275..967a7d0b 100644
--- a/view/sharedcache/api/sharedcachecore.h
+++ b/view/sharedcache/api/sharedcachecore.h
@@ -120,9 +120,9 @@ extern "C"
SHAREDCACHE_FFI_API char** BNDSCViewGetInstallNames(BNSharedCache* cache, size_t* count);
- SHAREDCACHE_FFI_API bool BNDSCViewLoadImageWithInstallName(BNSharedCache* cache, char* name);
+ SHAREDCACHE_FFI_API bool BNDSCViewLoadImageWithInstallName(BNSharedCache* cache, char* name, bool skipObjC);
SHAREDCACHE_FFI_API bool BNDSCViewLoadSectionAtAddress(BNSharedCache* cache, uint64_t name);
- SHAREDCACHE_FFI_API bool BNDSCViewLoadImageContainingAddress(BNSharedCache* cache, uint64_t address);
+ SHAREDCACHE_FFI_API bool BNDSCViewLoadImageContainingAddress(BNSharedCache* cache, uint64_t address, bool skipObjC);
SHAREDCACHE_FFI_API char* BNDSCViewGetNameForAddress(BNSharedCache* cache, uint64_t address);
SHAREDCACHE_FFI_API char* BNDSCViewGetImageNameForAddress(BNSharedCache* cache, uint64_t address);
diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp
index 7bbacf63..d4ce0921 100644
--- a/view/sharedcache/core/SharedCache.cpp
+++ b/view/sharedcache/core/SharedCache.cpp
@@ -1406,7 +1406,7 @@ SharedCache::SharedCache(BinaryNinja::Ref<BinaryNinja::BinaryView> dscView) : m_
{
lock.unlock();
m_logger->LogInfo("Loading core libsystem_c.dylib library");
- LoadImageWithInstallName(header.installName);
+ LoadImageWithInstallName(header.installName, false);
lock.lock();
break;
}
@@ -1518,7 +1518,7 @@ std::string SharedCache::ImageNameForAddress(uint64_t address)
return "";
}
-bool SharedCache::LoadImageContainingAddress(uint64_t address)
+bool SharedCache::LoadImageContainingAddress(uint64_t address, bool skipObjC)
{
for (const auto& [start, header] : State().headers)
{
@@ -1526,7 +1526,7 @@ bool SharedCache::LoadImageContainingAddress(uint64_t address)
{
if (segment.vmaddr <= address && segment.vmaddr + segment.vmsize > address)
{
- return LoadImageWithInstallName(header.installName);
+ return LoadImageWithInstallName(header.installName, skipObjC);
}
}
}
@@ -1727,7 +1727,7 @@ bool SharedCache::LoadSectionAtAddress(uint64_t address)
return true;
}
-bool SharedCache::LoadImageWithInstallName(std::string installName)
+bool SharedCache::LoadImageWithInstallName(std::string installName, bool skipObjC)
{
auto settings = m_dscView->GetLoadSettings(VIEW_NAME);
@@ -1837,28 +1837,31 @@ bool SharedCache::LoadImageWithInstallName(std::string installName)
SharedCache::InitializeHeader(m_dscView, vm.get(), *h, regions);
- try
+ if (!skipObjC)
{
- auto objc = std::make_unique<DSCObjC::DSCObjCProcessor>(m_dscView, this, false);
+ try
+ {
+ auto objc = std::make_unique<DSCObjC::DSCObjCProcessor>(m_dscView, this, false);
- bool processCFStrings = true;
- bool processObjCMetadata = true;
- if (settings && settings->Contains("loader.dsc.processCFStrings"))
- processCFStrings = settings->Get<bool>("loader.dsc.processCFStrings", m_dscView);
- if (settings && settings->Contains("loader.dsc.processObjC"))
- processObjCMetadata = settings->Get<bool>("loader.dsc.processObjC", m_dscView);
- if (processObjCMetadata)
- objc->ProcessObjCData(vm, h->identifierPrefix);
- if (processCFStrings)
- objc->ProcessCFStrings(vm, h->identifierPrefix);
- }
- catch (const std::exception& ex)
- {
- m_logger->LogWarn("Error processing ObjC data: %s", ex.what());
- }
- catch (...)
- {
- m_logger->LogWarn("Error processing ObjC data");
+ bool processCFStrings = true;
+ bool processObjCMetadata = true;
+ if (settings && settings->Contains("loader.dsc.processCFStrings"))
+ processCFStrings = settings->Get<bool>("loader.dsc.processCFStrings", m_dscView);
+ if (settings && settings->Contains("loader.dsc.processObjC"))
+ processObjCMetadata = settings->Get<bool>("loader.dsc.processObjC", m_dscView);
+ if (processObjCMetadata)
+ objc->ProcessObjCData(vm, h->identifierPrefix);
+ if (processCFStrings)
+ objc->ProcessCFStrings(vm, h->identifierPrefix);
+ }
+ catch (const std::exception& ex)
+ {
+ m_logger->LogWarn("Error processing ObjC data: %s", ex.what());
+ }
+ catch (...)
+ {
+ m_logger->LogWarn("Error processing ObjC data");
+ }
}
m_dscView->AddAnalysisOption("linearsweep");
@@ -3033,13 +3036,13 @@ extern "C"
cache->object->ReleaseAPIRef();
}
- bool BNDSCViewLoadImageWithInstallName(BNSharedCache* cache, char* name)
+ bool BNDSCViewLoadImageWithInstallName(BNSharedCache* cache, char* name, bool skipObjC)
{
std::string imageName = std::string(name);
// FIXME !!!!!!!! BNFreeString(name);
if (cache->object)
- return cache->object->LoadImageWithInstallName(imageName);
+ return cache->object->LoadImageWithInstallName(imageName, skipObjC);
return false;
}
@@ -3054,11 +3057,11 @@ extern "C"
return false;
}
- bool BNDSCViewLoadImageContainingAddress(BNSharedCache* cache, uint64_t address)
+ bool BNDSCViewLoadImageContainingAddress(BNSharedCache* cache, uint64_t address, bool skipObjC)
{
if (cache->object)
{
- return cache->object->LoadImageContainingAddress(address);
+ return cache->object->LoadImageContainingAddress(address, skipObjC);
}
return false;
diff --git a/view/sharedcache/core/SharedCache.h b/view/sharedcache/core/SharedCache.h
index 924d81f2..c82dea5c 100644
--- a/view/sharedcache/core/SharedCache.h
+++ b/view/sharedcache/core/SharedCache.h
@@ -571,9 +571,9 @@ namespace SharedCacheCore {
void ParseAndApplySlideInfoForFile(std::shared_ptr<MMappedFileAccessor> file);
std::optional<uint64_t> GetImageStart(std::string installName);
std::optional<SharedCacheMachOHeader> HeaderForAddress(uint64_t);
- bool LoadImageWithInstallName(std::string installName);
+ bool LoadImageWithInstallName(std::string installName, bool skipObjC);
bool LoadSectionAtAddress(uint64_t address);
- bool LoadImageContainingAddress(uint64_t address);
+ bool LoadImageContainingAddress(uint64_t address, bool skipObjC);
std::string NameForAddress(uint64_t address);
std::string ImageNameForAddress(uint64_t address);
std::vector<std::string> GetAvailableImages();