Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SharedCache] Fix DSCObjCProcessor::PostProcessObjCSections and improve Objective-C processing #6198

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions view/sharedcache/api/python/_sharedcachecore.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,15 +528,17 @@ def BNDSCViewLoadAllSymbolsAndWait(
_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)


# -------------------------------------------------------
Expand All @@ -547,15 +549,17 @@ def BNDSCViewLoadImageContainingAddress(
_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)


# -------------------------------------------------------
Expand All @@ -577,6 +581,44 @@ def BNDSCViewLoadSectionAtAddress(
return _BNDSCViewLoadSectionAtAddress(cache, name)


# -------------------------------------------------------
# _BNDSCViewProcessAllObjCSections

_BNDSCViewProcessAllObjCSections = core.BNDSCViewProcessAllObjCSections
_BNDSCViewProcessAllObjCSections.restype = None
_BNDSCViewProcessAllObjCSections.argtypes = [
ctypes.POINTER(BNSharedCache),
]


# noinspection PyPep8Naming
def BNDSCViewProcessAllObjCSections(
cache: ctypes.POINTER(BNSharedCache)
) -> None:
return _BNDSCViewProcessAllObjCSections(cache)


# -------------------------------------------------------
# _BNDSCViewProcessObjCSectionsForImageWithInstallName

_BNDSCViewProcessObjCSectionsForImageWithInstallName = core.BNDSCViewProcessObjCSectionsForImageWithInstallName
_BNDSCViewProcessObjCSectionsForImageWithInstallName.restype = None
_BNDSCViewProcessObjCSectionsForImageWithInstallName.argtypes = [
ctypes.POINTER(BNSharedCache),
ctypes.c_char_p,
ctypes.c_bool,
]


# noinspection PyPep8Naming
def BNDSCViewProcessObjCSectionsForImageWithInstallName(
cache: ctypes.POINTER(BNSharedCache),
name: Optional[str],
deallocName: bool
) -> None:
return _BNDSCViewProcessObjCSectionsForImageWithInstallName(cache, cstr(name), deallocName)


# -------------------------------------------------------
# _BNFreeSharedCacheReference

Expand Down
14 changes: 10 additions & 4 deletions view/sharedcache/api/python/sharedcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,20 @@ 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)

def process_objc_sections_for_image_with_install_name(self, installName):
return sccore.BNDSCViewProcessObjCSectionsForImageWithInstallName(self.handle, installName, False)

def process_all_objc_sections(self):
return sccore.BNDSCViewProcessAllObjCSections(self.handle)

@property
def caches(self):
Expand Down
19 changes: 15 additions & 4 deletions view/sharedcache/api/sharedcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ 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)
{
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()
Expand All @@ -55,6 +55,17 @@ namespace SharedCacheAPI {
return result;
}

void SharedCache::ProcessObjCSectionsForImageWithInstallName(std::string installName)
{
char* str = BNAllocString(installName.c_str());
BNDSCViewProcessObjCSectionsForImageWithInstallName(m_object, str, true);
}

void SharedCache::ProcessAllObjCSections()
{
BNDSCViewProcessAllObjCSections(m_object);
}

std::vector<DSCMemoryRegion> SharedCache::GetLoadedMemoryRegions()
{
size_t count;
Expand Down
7 changes: 5 additions & 2 deletions view/sharedcache/api/sharedcacheapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,13 @@ 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();

void ProcessObjCSectionsForImageWithInstallName(std::string installName);
void ProcessAllObjCSections();

std::vector<DSCSymbol> LoadAllSymbolsAndWait();

Expand Down
7 changes: 5 additions & 2 deletions view/sharedcache/api/sharedcachecore.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ 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 void BNDSCViewProcessObjCSectionsForImageWithInstallName(BNSharedCache* cache, char* name, bool deallocName);
SHAREDCACHE_FFI_API void BNDSCViewProcessAllObjCSections(BNSharedCache* cache);

SHAREDCACHE_FFI_API char* BNDSCViewGetNameForAddress(BNSharedCache* cache, uint64_t address);
SHAREDCACHE_FFI_API char* BNDSCViewGetImageNameForAddress(BNSharedCache* cache, uint64_t address);
Expand Down
16 changes: 8 additions & 8 deletions view/sharedcache/core/ObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,16 +1087,16 @@ void DSCObjCProcessor::ApplyMethodTypes(Class& cls)
}
}

void DSCObjCProcessor::PostProcessObjCSections(VMReader* reader)
void DSCObjCProcessor::PostProcessObjCSections(VMReader* reader, std::string baseName)
{
auto ptrSize = m_data->GetAddressSize();
if (auto imageInfo = m_data->GetSectionByName("__objc_imageinfo"))
if (auto imageInfo = m_data->GetSectionByName(baseName + "::__objc_imageinfo"))
{
auto start = imageInfo->GetStart();
auto type = Type::NamedType(m_data, m_typeNames.imageInfo);
m_data->DefineDataVariable(start, type);
}
if (auto selrefs = m_data->GetSectionByName("__objc_selrefs"))
if (auto selrefs = m_data->GetSectionByName(baseName + "::__objc_selrefs"))
{
auto start = selrefs->GetStart();
auto end = selrefs->GetEnd();
Expand All @@ -1119,7 +1119,7 @@ void DSCObjCProcessor::PostProcessObjCSections(VMReader* reader)
DefineObjCSymbol(DataSymbol, type, "selRef_" + sel, i, true);
}
}
if (auto superRefs = m_data->GetSectionByName("__objc_classrefs"))
if (auto superRefs = m_data->GetSectionByName(baseName + "::__objc_classrefs"))
{
auto start = superRefs->GetStart();
auto end = superRefs->GetEnd();
Expand All @@ -1137,7 +1137,7 @@ void DSCObjCProcessor::PostProcessObjCSections(VMReader* reader)
}
}
}
if (auto superRefs = m_data->GetSectionByName("__objc_superrefs"))
if (auto superRefs = m_data->GetSectionByName(baseName + "::__objc_superrefs"))
{
auto start = superRefs->GetStart();
auto end = superRefs->GetEnd();
Expand All @@ -1155,7 +1155,7 @@ void DSCObjCProcessor::PostProcessObjCSections(VMReader* reader)
}
}
}
if (auto protoRefs = m_data->GetSectionByName("__objc_protorefs"))
if (auto protoRefs = m_data->GetSectionByName(baseName + "::__objc_protorefs"))
{
auto start = protoRefs->GetStart();
auto end = protoRefs->GetEnd();
Expand All @@ -1173,7 +1173,7 @@ void DSCObjCProcessor::PostProcessObjCSections(VMReader* reader)
}
}
}
if (auto ivars = m_data->GetSectionByName("__objc_ivar"))
if (auto ivars = m_data->GetSectionByName(baseName + "::__objc_ivar"))
{
auto start = ivars->GetStart();
auto end = ivars->GetEnd();
Expand Down Expand Up @@ -1416,7 +1416,7 @@ void DSCObjCProcessor::ProcessObjCData(std::shared_ptr<VM> vm, std::string baseN
if (auto protoList = m_data->GetSectionByName(baseName + "::__objc_protolist"))
LoadProtocols(&reader, protoList);

PostProcessObjCSections(&reader);
PostProcessObjCSections(&reader, baseName);

auto id = m_data->BeginUndoActions();
m_symbolQueue->Process();
Expand Down
2 changes: 1 addition & 1 deletion view/sharedcache/core/ObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ namespace DSCObjC {
void GenerateClassTypes();
bool ApplyMethodType(Class& cls, Method& method, bool isInstanceMethod);
void ApplyMethodTypes(Class& cls);
void PostProcessObjCSections(VMReader* reader);
void PostProcessObjCSections(VMReader* reader, std::string baseName);
public:
DSCObjCProcessor(BinaryView* data, SharedCacheCore::SharedCache* cache, bool isBackedByDatabase);
void ProcessObjCData(std::shared_ptr<VM> vm, std::string baseName);
Expand Down
Loading