summaryrefslogtreecommitdiff
path: root/view/sharedcache/core/ffi.cpp
diff options
context:
space:
mode:
authorMark Rowe <mark@vector35.com>2025-07-09 19:03:14 -0700
committerMark Rowe <mark@vector35.com>2025-07-10 16:13:22 -0700
commit83684ec8fd3aae8a4db3f0d35251677fd82954ac (patch)
tree40dd2e6c77f5df1daf4577c9978da293117f53bd /view/sharedcache/core/ffi.cpp
parenta2ccfa22aa3f04484cba5dd8e58aeda51d518287 (diff)
[DSC] Use BNAllocStringWithLength when copying strings for the API
We're copying `std::string` objects that know their length. There's no reason to force a call to `strlen`.
Diffstat (limited to 'view/sharedcache/core/ffi.cpp')
-rw-r--r--view/sharedcache/core/ffi.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/view/sharedcache/core/ffi.cpp b/view/sharedcache/core/ffi.cpp
index 1ae561ae..81c3acf7 100644
--- a/view/sharedcache/core/ffi.cpp
+++ b/view/sharedcache/core/ffi.cpp
@@ -7,7 +7,7 @@ using namespace BinaryNinja::DSC;
BNSharedCacheImage ImageToApi(const CacheImage& image)
{
BNSharedCacheImage apiImage;
- apiImage.name = BNAllocString(image.path.c_str());
+ apiImage.name = BNAllocStringWithLength(image.path.c_str(), image.path.size());
apiImage.headerAddress = image.headerAddress;
apiImage.regionStartCount = image.regionStarts.size();
uint64_t* regionStarts = new uint64_t[image.regionStarts.size()];
@@ -65,7 +65,7 @@ BNSharedCacheRegion RegionToApi(const CacheRegion& region)
{
BNSharedCacheRegion apiRegion;
apiRegion.vmAddress = region.start;
- apiRegion.name = BNAllocString(region.name.c_str());
+ apiRegion.name = BNAllocStringWithLength(region.name.c_str(), region.name.size());
apiRegion.size = region.size;
apiRegion.flags = region.flags;
apiRegion.regionType = RegionTypeToApi(region.type);
@@ -88,7 +88,7 @@ CacheRegion RegionFromApi(const BNSharedCacheRegion& apiRegion)
BNSharedCacheSymbol SymbolToApi(const CacheSymbol& symbol)
{
BNSharedCacheSymbol apiSymbol;
- apiSymbol.name = BNAllocString(symbol.name.c_str());
+ apiSymbol.name = BNAllocStringWithLength(symbol.name.data(), symbol.name.size());
apiSymbol.address = symbol.address;
apiSymbol.symbolType = symbol.type;
return apiSymbol;
@@ -133,8 +133,10 @@ BNSharedCacheMappingInfo MappingToApi(const dyld_cache_mapping_info& mapping)
BNSharedCacheEntry EntryToApi(const CacheEntry& entry)
{
BNSharedCacheEntry apiEntry;
- apiEntry.path = BNAllocString(entry.GetFilePath().c_str());
- apiEntry.name = BNAllocString(entry.GetFileName().c_str());
+ auto path = entry.GetFilePath();
+ auto name = entry.GetFileName();
+ apiEntry.path = BNAllocStringWithLength(path.c_str(), path.size());
+ apiEntry.name = BNAllocStringWithLength(name.c_str(), name.size());
apiEntry.entryType = EntryTypeToApi(entry.GetType());
const auto& mappings = entry.GetMappings();
apiEntry.mappingCount = mappings.size();