From a358a9fbbbf780cdfd5a2b0090876dd6d71df5b7 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Mon, 22 Aug 2022 13:01:02 -0400 Subject: Demangler improvements --- binaryninjacore.h | 22 +++++++++++++++++++--- python/demangle.py | 29 +++++++++++++++++++---------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/binaryninjacore.h b/binaryninjacore.h index 18ceb971..cb0d9b10 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -36,7 +36,7 @@ // Current ABI version for linking to the core. This is incremented any time // there are changes to the API that affect linking, including new functions, // new types, or modifications to existing functions or types. -#define BN_CURRENT_CORE_ABI_VERSION 24 +#define BN_CURRENT_CORE_ABI_VERSION 25 // Minimum ABI version that is supported for loading of plugins. Plugins that // are linked to an ABI version less than this will not be able to load and @@ -789,7 +789,19 @@ extern "C" OperatorUnaryMinusNameType, OperatorUnaryPlusNameType, OperatorUnaryBitAndNameType, - OperatorUnaryStarNameType + OperatorUnaryStarNameType, + OmniCallSigNameType, + ManagedVectorConstructorIteratorNameType, + ManagedVectorDestructorIteratorNameType, + EHVectorCopyConstructorIteratorNameType, + EHVectorVBaseCopyConstructorIteratorNameType, + DynamicInitializerNameType, + DynamicAtExitDestructorNameType, + VectorCopyConstructorIteratorNameType, + VectorVBaseCopyConstructorIteratorNameType, + ManagedVectorCopyConstructorIteratorNameType, + LocalStaticThreadGuardNameType, + UserDefinedLiteralOperatorNameType, }; enum BNCallingConventionName @@ -802,7 +814,9 @@ extern "C" FastcallCallingConvention, CLRCallCallingConvention, EabiCallCallingConvention, - VectorCallCallingConvention + VectorCallCallingConvention, + SwiftCallingConvention, + SwiftAsyncCallingConvention }; enum BNStringType @@ -5732,6 +5746,8 @@ extern "C" char*** outVarName, size_t* outVarNameElements, const bool simplify); BINARYNINJACOREAPI bool BNDemangleMSWithOptions(BNArchitecture* arch, const char* mangledName, BNType** outType, char*** outVarName, size_t* outVarNameElements, const BNBinaryView* const view); + BINARYNINJACOREAPI bool BNDemangleMSPlatform(BNPlatform* platform, const char* mangledName, BNType** outType, + char*** outVarName, size_t* outVarNameElements, const bool simplify); // Download providers BINARYNINJACOREAPI BNDownloadProvider* BNRegisterDownloadProvider( diff --git a/python/demangle.py b/python/demangle.py index 6e9185ec..11a32424 100644 --- a/python/demangle.py +++ b/python/demangle.py @@ -24,7 +24,9 @@ import ctypes from . import _binaryninjacore as core from . import binaryview from . import types - +from .architecture import Architecture +from .platform import Platform +from typing import Union def get_qualified_name(names): """ @@ -44,11 +46,11 @@ def get_qualified_name(names): return "::".join(names) -def demangle_ms(arch, mangled_name, options=False): +def demangle_ms(archOrPlatform:Union[Architecture, Platform], mangled_name:str, options=False): """ ``demangle_ms`` demangles a mangled Microsoft Visual Studio C++ name to a Type object. - :param Architecture arch: Architecture for the symbol. Required for pointer and integer sizes. + :param Union[Architecture, Platform] archOrPlatform: Architecture or Platform for the symbol. Required for pointer/integer sizes and calling conventions. :param str mangled_name: a mangled Microsoft Visual Studio C++ name :param options: (optional) Whether to simplify demangled names : None falls back to user settings, a BinaryView uses that BinaryView's settings, or a boolean to set it directly :type options: Tuple[bool, BinaryView, None] @@ -56,7 +58,7 @@ def demangle_ms(arch, mangled_name, options=False): :rtype: Tuple :Example: - >>> demangle_ms(Architecture["x86_64"], "?testf@Foobar@@SA?AW4foo@1@W421@@Z") + >>> demangle_ms(Platform["x86_64"], "?testf@Foobar@@SA?AW4foo@1@W421@@Z") (, ['Foobar', 'testf']) >>> """ @@ -64,17 +66,24 @@ def demangle_ms(arch, mangled_name, options=False): outName = ctypes.POINTER(ctypes.c_char_p)() outSize = ctypes.c_ulonglong() names = [] + + demangle = core.BNDemangleMS + demangleWithOptions = core.BNDemangleMSWithOptions + + if isinstance(archOrPlatform, Platform): + demangle = core.BNDemangleMSPlatform + if ( - isinstance(options, binaryview.BinaryView) and core.BNDemangleMSWithOptions( - arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), options + isinstance(options, binaryview.BinaryView) and demangleWithOptions( + archOrPlatform.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), options ) ) or ( - isinstance(options, bool) and core.BNDemangleMS( - arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), options + isinstance(options, bool) and demangle( + archOrPlatform.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), options ) ) or ( - options is None and core.BNDemangleMSWithOptions( - arch.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), None + options is None and demangleWithOptions( + archOrPlatform.handle, mangled_name, ctypes.byref(handle), ctypes.byref(outName), ctypes.byref(outSize), None ) ): for i in range(outSize.value): -- cgit v1.3.1