Skip to content
Closed
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "rust/examples/pdb-ng/pdb-0.8.0-patched"]
path = rust/examples/pdb-ng/pdb-0.8.0-patched
url = https://github.com/Vector35/pdb-rs.git
[submodule "vendor/immer"]
path = vendor/immer
url = https://github.com/arximboldi/immer.git
1 change: 1 addition & 0 deletions vendor/immer
Submodule immer added at df6ef4
2 changes: 1 addition & 1 deletion view/sharedcache/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ set_target_properties(sharedcache PROPERTIES
POSITION_INDEPENDENT_CODE ON
)

target_include_directories(sharedcache PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/core ${CMAKE_CURRENT_SOURCE_DIR}/api ${CMAKE_CURRENT_SOURCE_DIR}/workflow)
target_include_directories(sharedcache PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/core ${CMAKE_CURRENT_SOURCE_DIR}/api ${CMAKE_CURRENT_SOURCE_DIR}/workflow ${BN_API_PATH}/vendor/immer)

target_link_libraries(sharedcache PUBLIC sharedcacheapi binaryninjaapi sharedcachecore sharedcacheworkflow)

Expand Down
2 changes: 1 addition & 1 deletion view/sharedcache/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ endfunction()
get_recursive_include_dirs(binaryninjaapi INCLUDES)

target_include_directories(sharedcacheapi
PUBLIC ${PROJECT_SOURCE_DIR} ${INCLUDES})
PUBLIC ${PROJECT_SOURCE_DIR} ${INCLUDES} ${BN_API_PATH}/vendor/immer)

set_target_properties(sharedcacheapi PROPERTIES
CXX_STANDARD 17
Expand Down
28 changes: 18 additions & 10 deletions view/sharedcache/api/sharedcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

#include "sharedcacheapi.h"
#include <string_view>

namespace SharedCacheAPI {

Expand All @@ -20,9 +21,9 @@ namespace SharedCacheAPI {
return BNDSCViewFastGetBackingCacheCount(view->GetObject());
}

bool SharedCache::LoadImageWithInstallName(std::string installName)
bool SharedCache::LoadImageWithInstallName(std::string_view installName)
{
char* str = BNAllocString(installName.c_str());
char* str = BNAllocString(installName.data());
return BNDSCViewLoadImageWithInstallName(m_object, str);
}

Expand All @@ -46,6 +47,7 @@ namespace SharedCacheAPI {
}

std::vector<std::string> result;
result.reserve(count);
for (size_t i = 0; i < count; i++)
{
result.push_back(value[i]);
Expand All @@ -65,13 +67,14 @@ namespace SharedCacheAPI {
}

std::vector<DSCMemoryRegion> result;
result.reserve(count);
for (size_t i = 0; i < count; i++)
{
DSCMemoryRegion region;
region.vmAddress = value[i].vmAddress;
region.size = value[i].size;
region.prettyName = value[i].name;
result.push_back(region);
result.push_back(std::move(region));
}

BNDSCViewFreeLoadedRegions(value, count);
Expand All @@ -87,20 +90,22 @@ namespace SharedCacheAPI {
}

std::vector<BackingCache> result;
result.reserve(count);
for (size_t i = 0; i < count; i++)
{
BackingCache cache;
cache.path = value[i].path;
cache.isPrimary = value[i].isPrimary;
cache.mappings.reserve(value[i].mappingCount);
for (size_t j = 0; j < value[i].mappingCount; j++)
{
BackingCacheMapping mapping;
mapping.vmAddress = value[i].mappings[j].vmAddress;
mapping.size = value[i].mappings[j].size;
mapping.fileOffset = value[i].mappings[j].fileOffset;
cache.mappings.push_back(mapping);
cache.mappings.push_back(std::move(mapping));
}
result.push_back(cache);
result.push_back(std::move(cache));
}

BNDSCViewFreeBackingCaches(value, count);
Expand All @@ -117,11 +122,13 @@ namespace SharedCacheAPI {
}

std::vector<DSCImage> result;
result.reserve(count);
for (size_t i = 0; i < count; i++)
{
DSCImage img;
img.name = value[i].name;
img.headerAddress = value[i].headerAddress;
img.mappings.reserve(value[i].mappingCount);
for (size_t j = 0; j < value[i].mappingCount; j++)
{
DSCImageMemoryMapping mapping;
Expand All @@ -131,9 +138,9 @@ namespace SharedCacheAPI {
mapping.rawViewOffset = value[i].mappings[j].rawViewOffset;
mapping.size = value[i].mappings[j].size;
mapping.loaded = value[i].mappings[j].loaded;
img.mappings.push_back(mapping);
img.mappings.push_back(std::move(mapping));
}
result.push_back(img);
result.push_back(std::move(img));
}

BNDSCViewFreeAllImages(value, count);
Expand All @@ -150,13 +157,14 @@ namespace SharedCacheAPI {
}

std::vector<DSCSymbol> result;
result.reserve(count);
for (size_t i = 0; i < count; i++)
{
DSCSymbol sym;
sym.address = value[i].address;
sym.name = value[i].name;
sym.image = value[i].image;
result.push_back(sym);
result.push_back(std::move(sym));
}

BNDSCViewFreeSymbols(value, count);
Expand All @@ -183,9 +191,9 @@ namespace SharedCacheAPI {
return result;
}

std::optional<SharedCacheMachOHeader> SharedCache::GetMachOHeaderForImage(std::string name)
std::optional<SharedCacheMachOHeader> SharedCache::GetMachOHeaderForImage(std::string_view name)
{
char* str = BNAllocString(name.c_str());
char* str = BNAllocString(name.data());
char* outputStr = BNDSCViewGetImageHeaderForName(m_object, str);
if (outputStr == nullptr)
return {};
Expand Down
4 changes: 2 additions & 2 deletions view/sharedcache/api/sharedcacheapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ namespace SharedCacheAPI {
static BNDSCViewLoadProgress GetLoadProgress(Ref<BinaryView> view);
static uint64_t FastGetBackingCacheCount(Ref<BinaryView> view);

bool LoadImageWithInstallName(std::string installName);
bool LoadImageWithInstallName(std::string_view installName);
bool LoadSectionAtAddress(uint64_t addr);
bool LoadImageContainingAddress(uint64_t addr);
std::vector<std::string> GetAvailableImages();
Expand All @@ -270,7 +270,7 @@ namespace SharedCacheAPI {
std::vector<BackingCache> GetBackingCaches();
std::vector<DSCImage> GetImages();

std::optional<SharedCacheMachOHeader> GetMachOHeaderForImage(std::string name);
std::optional<SharedCacheMachOHeader> GetMachOHeaderForImage(std::string_view name);
std::optional<SharedCacheMachOHeader> GetMachOHeaderForAddress(uint64_t address);

std::vector<DSCMemoryRegion> GetLoadedMemoryRegions();
Expand Down
2 changes: 1 addition & 1 deletion view/sharedcache/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ target_compile_definitions(sharedcachecore PRIVATE ${COMPILE_DEFS})

target_compile_definitions(sharedcachecore PRIVATE SHAREDCACHE_LIBRARY ${COMPILE_DEFS})

target_include_directories(sharedcachecore PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDES})
target_include_directories(sharedcachecore PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDES} ${BN_API_PATH}/vendor/immer)

set_target_properties(sharedcachecore PROPERTIES
CXX_STANDARD 17
Expand Down
Loading