diff options
| author | Mark Rowe <mark@vector35.com> | 2026-02-13 18:33:54 -0800 |
|---|---|---|
| committer | Mark Rowe <mark@vector35.com> | 2026-02-13 19:42:13 -0800 |
| commit | c9dbb48365bf1a0c5c06daa2234e21e64d9bc2f7 (patch) | |
| tree | dd476df611f5d74590d48afb869896670a8f560c /view/sharedcache/api | |
| parent | e2feac85c58785640a2760f137a44c08ef953931 (diff) | |
[DSC] Correctly mark symbols as having local, global, or weak binding
Diffstat (limited to 'view/sharedcache/api')
| -rw-r--r-- | view/sharedcache/api/python/generator.cpp | 18 | ||||
| -rw-r--r-- | view/sharedcache/api/python/sharedcache.py | 3 | ||||
| -rw-r--r-- | view/sharedcache/api/python/sharedcache_enums.py | 7 | ||||
| -rw-r--r-- | view/sharedcache/api/sharedcache.cpp | 3 | ||||
| -rw-r--r-- | view/sharedcache/api/sharedcacheapi.h | 1 | ||||
| -rw-r--r-- | view/sharedcache/api/sharedcachecore.h | 20 |
6 files changed, 45 insertions, 7 deletions
diff --git a/view/sharedcache/api/python/generator.cpp b/view/sharedcache/api/python/generator.cpp index 81463b51..062f2e27 100644 --- a/view/sharedcache/api/python/generator.cpp +++ b/view/sharedcache/api/python/generator.cpp @@ -331,7 +331,23 @@ int main(int argc, char* argv[]) continue; } - fprintf(out, "%sEnum = ctypes.c_int\n", name.c_str()); + const char* ctypesType = nullptr; + switch (i.second->GetWidth()) + { + case 1: + ctypesType = i.second->IsSigned() ? "ctypes.c_int8" : "ctypes.c_uint8"; + break; + case 2: + ctypesType = i.second->IsSigned() ? "ctypes.c_int16" : "ctypes.c_uint16"; + break; + case 4: + ctypesType = i.second->IsSigned() ? "ctypes.c_int32" : "ctypes.c_uint32"; + break; + default: + ctypesType = i.second->IsSigned() ? "ctypes.c_int64" : "ctypes.c_uint64"; + break; + } + fprintf(out, "%sEnum = %s\n", name.c_str(), ctypesType); fprintf(enums, "\n\nclass %s(enum.IntEnum):\n", name.c_str()); for (auto& j : i.second->GetEnumeration()->GetMembers()) diff --git a/view/sharedcache/api/python/sharedcache.py b/view/sharedcache/api/python/sharedcache.py index dff9bcc3..cac4050e 100644 --- a/view/sharedcache/api/python/sharedcache.py +++ b/view/sharedcache/api/python/sharedcache.py @@ -40,6 +40,7 @@ class CacheImage: @dataclasses.dataclass class CacheSymbol: symbol_type: sccore.SymbolTypeEnum + symbol_binding: sccore.SymbolBindingEnum address: int name: str @@ -94,6 +95,7 @@ def image_to_api(image: CacheImage) -> sccore.BNSharedCacheImage: def symbol_from_api(symbol: sccore.BNSharedCacheSymbol) -> CacheSymbol: return CacheSymbol( symbol_type=symbol.symbolType, + symbol_binding=symbol.symbolBinding, address=symbol.address, name=symbol.name ) @@ -101,6 +103,7 @@ def symbol_from_api(symbol: sccore.BNSharedCacheSymbol) -> CacheSymbol: def symbol_to_api(symbol: CacheSymbol) -> sccore.BNSharedCacheSymbol: return sccore.BNSharedCacheSymbol( symbolType=symbol.symbol_type, + symbolBinding=symbol.symbol_binding, address=symbol.address, _name=BNAllocString(symbol.name) ) diff --git a/view/sharedcache/api/python/sharedcache_enums.py b/view/sharedcache/api/python/sharedcache_enums.py index 9a98eba4..d772adda 100644 --- a/view/sharedcache/api/python/sharedcache_enums.py +++ b/view/sharedcache/api/python/sharedcache_enums.py @@ -26,6 +26,13 @@ class SharedCacheRegionType(enum.IntEnum): SharedCacheRegionTypeNonImage = 3 +class SymbolBinding(enum.IntEnum): + NoBinding = 0 + LocalBinding = 1 + GlobalBinding = 2 + WeakBinding = 3 + + class SymbolType(enum.IntEnum): FunctionSymbol = 0 ImportAddressSymbol = 1 diff --git a/view/sharedcache/api/sharedcache.cpp b/view/sharedcache/api/sharedcache.cpp index d1ec680d..d90f2799 100644 --- a/view/sharedcache/api/sharedcache.cpp +++ b/view/sharedcache/api/sharedcache.cpp @@ -107,6 +107,7 @@ CacheSymbol SymbolFromApi(BNSharedCacheSymbol apiSymbol) symbol.name = apiSymbol.name; symbol.address = apiSymbol.address; symbol.type = apiSymbol.symbolType; + symbol.binding = apiSymbol.symbolBinding; return symbol; } @@ -140,7 +141,7 @@ std::pair<std::string, Ref<Type>> CacheSymbol::DemangledName(BinaryView &view) c Ref<Symbol> CacheSymbol::GetBNSymbol(BinaryView &view) const { auto [shortName, _] = DemangledName(view); - return new Symbol(type, shortName, shortName, name, address, nullptr); + return new Symbol(type, shortName, shortName, name, address, binding); } std::string SharedCacheAPI::GetSymbolTypeAsString(const BNSymbolType &type) diff --git a/view/sharedcache/api/sharedcacheapi.h b/view/sharedcache/api/sharedcacheapi.h index 097c185b..070b10f6 100644 --- a/view/sharedcache/api/sharedcacheapi.h +++ b/view/sharedcache/api/sharedcacheapi.h @@ -286,6 +286,7 @@ namespace SharedCacheAPI { struct CacheSymbol { BNSymbolType type; + BNSymbolBinding binding = NoBinding; uint64_t address; std::string name; diff --git a/view/sharedcache/api/sharedcachecore.h b/view/sharedcache/api/sharedcachecore.h index 1324fe16..f8e9c48b 100644 --- a/view/sharedcache/api/sharedcachecore.h +++ b/view/sharedcache/api/sharedcachecore.h @@ -27,9 +27,10 @@ extern "C" { #endif - // binaryninjacore.h is not included so we must duplicate enum types here. + // binaryninjacore.h is not included so we must duplicate enum types here. + // TODO: Why isn't it?! #ifdef BN_TYPE_PARSER - typedef enum BNSegmentFlag + enum BNSegmentFlag : uint8_t { SegmentExecutable = 1, SegmentWritable = 2, @@ -38,9 +39,9 @@ extern "C" SegmentContainsCode = 0x10, SegmentDenyWrite = 0x20, SegmentDenyExecute = 0x40 - } BNSegmentFlag; + }; - typedef enum BNSymbolType + enum BNSymbolType : uint8_t { FunctionSymbol = 0, ImportAddressSymbol = 1, @@ -51,7 +52,15 @@ extern "C" LibraryFunctionSymbol = 6, SymbolicFunctionSymbol = 7, LocalLabelSymbol = 8, - } BNSymbolType; + }; + + enum BNSymbolBinding : uint8_t + { + NoBinding = 0, + LocalBinding = 1, + GlobalBinding = 2, + WeakBinding = 3, + }; #endif typedef struct BNBinaryView BNBinaryView; @@ -105,6 +114,7 @@ extern "C" typedef struct BNSharedCacheSymbol { BNSymbolType symbolType; + BNSymbolBinding symbolBinding; uint64_t address; char* name; } BNSharedCacheSymbol; |
