@@ -2433,23 +2433,6 @@ namespace BinaryNinja {
24332433 */
24342434 Ref<BinaryView> Load(Ref<BinaryView> rawData, bool updateAnalysis, ProgressFunction progress, Ref<Metadata> options = new Metadata(MetadataType::KeyValueDataType), bool isDatabase = false);
24352435
2436- /*! Attempt to demangle a mangled name, trying all relevant demanglers and using whichever one accepts it
2437-
2438- \see Demangler::Demangle for a discussion on which demangler will be used.
2439-
2440- \param[in] platform Platform for the symbol. Used for pointer/integer sizes and calling conventions.
2441- \param[in] mangledName a mangled Microsoft Visual Studio C++ name
2442- \param[out] outType Pointer to Type to output
2443- \param[out] outVarName QualifiedName reference to write the output name to.
2444- \param[in] view (Optional) view of the binary containing the mangled name
2445- \param[in] simplify (Optional) Whether to simplify demangled names.
2446- \return True if the name was demangled and written to the out* parameters
2447-
2448- \ingroup demangle
2449- */
2450- bool DemangleGeneric(Platform* platform, const std::string& mangledName, Ref<Type>& outType, QualifiedName& outVarName,
2451- Ref<BinaryView> view = nullptr, bool simplify = false);
2452-
24532436 /*! Demangles using LLVM's demangler
24542437
24552438 \param[in] mangledName a mangled (msvc/gnu3/rust/dlang) name
@@ -2459,18 +2442,7 @@ namespace BinaryNinja {
24592442
24602443 \ingroup demangle
24612444 */
2462- bool DemangleLLVM(const std::string& mangledName, QualifiedName& outVarName, bool simplify = false);
2463-
2464- /*! Demangles using LLVM's demangler
2465-
2466- \param[in] mangledName a mangled (msvc/gnu3/rust/dlang) name
2467- \param[out] outVarName QualifiedName reference to write the output name to.
2468- \param[in] view View to check the analysis.types.templateSimplifier for
2469- \return True if the name was demangled and written to the out* parameters
2470-
2471- \ingroup demangle
2472- */
2473- bool DemangleLLVM(const std::string& mangledName, QualifiedName& outVarName, BinaryView* view);
2445+ bool DemangleLLVM(const std::string& mangledName, QualifiedName& outVarName, bool simplify = true);
24742446
24752447 /*! Demangles a Microsoft Visual Studio C++ name
24762448
@@ -2483,8 +2455,16 @@ namespace BinaryNinja {
24832455
24842456 \ingroup demangle
24852457 */
2486- bool DemangleMS(Platform* platform, const std::string& mangledName, Ref<Type>& outType, QualifiedName& outVarName,
2487- bool simplify = false);
2458+ bool DemangleMS(const Platform* platform, const std::string& mangledName, Ref<Type>& outType, QualifiedName& outVarName,
2459+ bool simplify = true);
2460+
2461+ /*! Determines if a symbol name is a mangled Microsoft Visual Studio C++ name
2462+
2463+ \param[in] mangledName a potentially mangled name
2464+
2465+ \ingroup demangle
2466+ */
2467+ bool IsMSVCMangledString(const std::string& mangledName);
24882468
24892469 /*! Demangles a GNU3 name
24902470
@@ -2497,8 +2477,8 @@ namespace BinaryNinja {
24972477
24982478 \ingroup demangle
24992479 */
2500- bool DemangleGNU3(Platform* platform, const std::string& mangledName, Ref<Type>& outType,
2501- QualifiedName& outVarName, bool simplify = false );
2480+ bool DemangleGNU3(const Platform* platform, const std::string& mangledName, Ref<Type>& outType,
2481+ QualifiedName& outVarName, bool simplify = true );
25022482
25032483 /*! Determines if a symbol name is a mangled GNU3 name
25042484
@@ -4786,18 +4766,21 @@ namespace BinaryNinja {
47864766 static DemanglerConfig Default();
47874767 static DemanglerConfig ForPlatform(Platform* platform, bool simplifyTemplates = false);
47884768 static DemanglerConfig ForBinaryView(BinaryView* view);
4769+ static DemanglerConfig FromAPIObject(const BNDemanglerConfig* config);
47894770
4790- BNDemanglerConfig GetAPIObject() const;
4771+ Platform& GetPlatform() const;
4772+ BNDemanglerConfig ToAPIObject() const;
47914773 };
47924774
47934775 struct DemanglerResult
47944776 {
47954777 QualifiedName name;
47964778 Ref<Type> type;
4797- };
47984779
4799- std::optional<DemanglerResult> TryDemangle(
4800- const std::string& mangledName, const DemanglerConfig& config = DemanglerConfig::Default());
4780+ static DemanglerResult FromAPIObject(const BNDemanglerResult* result);
4781+ static DemanglerResult FromAPIObjectAndFree(BNDemanglerResult* result);
4782+ BNDemanglerResult ToAPIObject() const;
4783+ };
48014784
48024785 /*!
48034786
@@ -22487,70 +22470,87 @@ namespace BinaryNinja {
2248722470 std::string m_nameForRegister;
2248822471
2248922472 protected:
22490- explicit Demangler(const std::string& name );
22473+ explicit Demangler(std::string demanglerName );
2249122474 Demangler(BNDemangler* demangler);
2249222475 virtual ~Demangler() = default;
2249322476
22494- static bool IsMangledStringCallback(void* ctxt, const char* name );
22495- static bool DemangleCallback(void* ctxt, const char* name , const BNDemanglerConfig* config,
22477+ static bool IsMangledStringCallback(void* ctxt, const char* mangledName );
22478+ static bool DemangleCallback(void* ctxt, const char* mangledName , const BNDemanglerConfig* config,
2249622479 BNDemanglerResult* result);
2249722480 static void FreeResultCallback(void* ctxt, BNDemanglerResult* result);
2249822481
2249922482 public:
22500- /*! Register a custom Demangler. Newly registered demanglers will get priority over
22483+ /*! Register a custom Demangler. Newly registered demanglers get priority over
2250122484 previously registered demanglers and built-in demanglers.
22485+
22486+ Demanglers must be registered and promoted during plugin initialization. After plugin
22487+ loading is complete, the demangler registry is finalized so named demangler lookups
22488+ and priority order can be cached efficiently, and further registration attempts fail.
22489+
22490+ \return True if registration succeeded; false if the demangler was invalid
22491+ or registration has already been finalized.
2250222492 */
22503- static void Register(Demangler* demangler);
22493+ static bool Register(Demangler* demangler);
2250422494
2250522495 /*! Get the list of currently registered demanglers, sorted by lowest to highest priority.
2250622496
2250722497 \return List of demanglers
2250822498 */
2250922499 static std::vector<Ref<Demangler>> GetList();
22510- static Ref<Demangler> GetByName(const std::string& name );
22500+ static Ref<Demangler> GetByName(const std::string& demanglerName );
2251122501
2251222502 /*! Promote a demangler to the highest-priority position.
2251322503
22504+ Demanglers must be promoted during plugin initialization. After plugin loading is
22505+ complete, the demangler registry is finalized so the priority order can be cached
22506+ efficiently, and further promotion attempts fail.
22507+
2251422508 \param demangler Demangler to promote
22509+ \return True if promotion succeeded; false if the demangler was invalid, not registered,
22510+ or promotion has already been finalized.
22511+ */
22512+ static bool Promote(const Ref<Demangler>& demangler);
22513+
22514+ /*!
22515+ Attempt to demangle a mangled name, trying all relevant demanglers and using whichever one accepts it.
22516+
22517+ \param[in] mangledName Raw mangled name
22518+ \param[in] config Platform/view/options used while demangling
22519+ \return Demangled type/name if successful
2251522520 */
22516- static void Promote(Ref<Demangler> demangler);
22521+ static std::optional<Result> DemangleAny(
22522+ const std::string& mangledName, const Config& config = DemanglerConfig::Default());
2251722523
2251822524 std::string GetName() const;
2251922525
2252022526 /*! Determine if a given name is mangled and this demangler can process it
2252122527
2252222528 The most recently registered demangler that claims a name is a mangled string
2252322529 (returns true from this function), and then returns a value from Demangle will
22524- determine the result of a call to DemangleGeneric . Returning True from this
22530+ determine the result of a call to DemangleAny . Returning True from this
2252522531 does not require the demangler to succeed the call to Demangle, but simply
2252622532 implies that it may succeed.
2252722533
22528- \param name Raw mangled name string
22534+ \param mangledName Raw mangled name string
2252922535 \return True if the demangler thinks it can handle the name
2253022536 */
22531- virtual bool IsMangledString(const std::string& name ) = 0;
22537+ virtual bool IsMangledString(const std::string& mangledName ) = 0;
2253222538
2253322539 /*! Demangle a raw name into a Type and QualifiedName.
2253422540
22535- Any unresolved named types referenced by the resulting Type will be created as
22536- empty structures or void typedefs in the view, if the result is used on
22537- a data structure in the view. Given this, the call to Demangle should NOT
22538- cause any side-effects creating types in the view trying to resolve this
22539- and instead just return a type with unresolved named type references.
22540-
2254122541 The most recently registered demangler that claims a name is a mangled string
2254222542 (returns true from IsMangledString), and then returns a value from
22543- this function will determine the result of a call to DemangleGeneric .
22543+ this function will determine the result of a call to DemangleAny .
2254422544 If this call returns None, the next most recently used demangler(s) will be tried instead.
2254522545
2254622546 If the mangled name has no type information, but a name is still possible to extract,
2254722547 this function may return a successful result with outType=nullptr, which will be accepted.
2254822548
22549- \param name Raw mangled name
22549+ \param mangledName Raw mangled name
2255022550 \param config Platform/view/options used while demangling
2255122551 \return Demangled type/name if successful
2255222552 */
22553- virtual std::optional<Result> Demangle(const std::string& name , const Config& config) = 0;
22553+ virtual std::optional<Result> Demangle(const std::string& mangledName , const Config& config) = 0;
2255422554 };
2255522555
2255622556 /*!
0 commit comments