@@ -5372,6 +5372,11 @@ namespace BinaryNinja {
53725372 std::vector<TypeReferenceSource> typeRefs;
53735373 };
53745374
5375+ /*! Represents a custom string type. String types contain the name of the string type and the prefix
5376+ and postfix used to render them in code.
5377+
5378+ \ingroup stringrecognizer
5379+ */
53755380 class CustomStringType: public StaticCoreRefCountObject<BNCustomStringType>
53765381 {
53775382 public:
@@ -5384,6 +5389,10 @@ namespace BinaryNinja {
53845389 const std::string& name, const std::string& stringPrefix = "", const std::string& stringPostfix = "");
53855390 };
53865391
5392+ /*! Location associated with a derived string. Locations are optional.
5393+
5394+ \ingroup stringrecognizer
5395+ */
53875396 struct DerivedStringLocation
53885397 {
53895398 BNDerivedStringLocationType locationType;
@@ -5418,6 +5427,12 @@ namespace BinaryNinja {
54185427 }
54195428 };
54205429
5430+ /*! Contains a string derived from code or data. The string does not need to be directly present in
5431+ the binary in its raw form. Derived strings can have optional locations to data or code. When
5432+ creating new derived strings, a custom type should be registered with \c CustomStringType::register.
5433+
5434+ \ingroup stringrecognizer
5435+ */
54215436 struct DerivedString
54225437 {
54235438 StringRef value;
@@ -21425,6 +21440,10 @@ namespace BinaryNinja {
2142521440 ) override;
2142621441 };
2142721442
21443+ /*! \c ConstantRenderer allows custom rendering of constants in high level representations.
21444+
21445+ \ingroup constantrenderer
21446+ */
2142821447 class ConstantRenderer : public StaticCoreRefCountObject<BNConstantRenderer>
2142921448 {
2143021449 std::string m_nameForRegister;
@@ -21435,9 +21454,47 @@ namespace BinaryNinja {
2143521454
2143621455 std::string GetName() const;
2143721456
21457+ /*! Determines if the rendering methods should be called for the given expression type. It is optional
21458+ to override this method. If the method isn't overridden, all expression types are passed to the
21459+ rendering methods.
21460+
21461+ \param func \c HighLevelILFunction representing the high level function to be queried
21462+ \param type Type of the expression
21463+ \return \c true if the constant should be passed to the rendering methods, \c false otherwise
21464+ */
2143821465 virtual bool IsValidForType(HighLevelILFunction* func, Type* type);
21466+
21467+ /*! Can be overridden to render a constant that is not a pointer. The expression type and value of the
21468+ expression are given. If the expression is not handled by this constant renderer, this method should
21469+ return \c false
21470+
21471+ To render a constant, emit the tokens to the tokens object and return \c true
21472+
21473+ \param instr High level expression
21474+ \param type Type of the expression
21475+ \param val Value of the expression
21476+ \param tokens Token emitter for adding the rendered tokens
21477+ \param settings Settings for rendering
21478+ \param precedence Operator precedence of the expression
21479+ \return \c true if the constant was rendered, \c false otherwise
21480+ */
2143921481 virtual bool RenderConstant(const HighLevelILInstruction& instr, Type* type, int64_t val,
2144021482 HighLevelILTokenEmitter& tokens, DisassemblySettings* settings, BNOperatorPrecedence precedence);
21483+
21484+ /*! Can be overridden to render a constant pointer. The expression type and value of the
21485+ expression are given. If the expression is not handled by this constant renderer, this method should
21486+ return \c false
21487+
21488+ To render a constant, emit the tokens to the tokens object and return \c true
21489+
21490+ \param instr High level expression
21491+ \param type Type of the expression
21492+ \param val Value of the expression
21493+ \param tokens Token emitter for adding the rendered tokens
21494+ \param settings Settings for rendering
21495+ \param precedence Operator precedence of the expression
21496+ \return \c true if the constant was rendered, \c false otherwise
21497+ */
2144121498 virtual bool RenderConstantPointer(const HighLevelILInstruction& instr, Type* type, int64_t val,
2144221499 HighLevelILTokenEmitter& tokens, DisassemblySettings* settings, BNSymbolDisplayType symbolDisplay,
2144321500 BNOperatorPrecedence precedence);
@@ -21473,6 +21530,10 @@ namespace BinaryNinja {
2147321530 BNOperatorPrecedence precedence) override;
2147421531 };
2147521532
21533+ /*! \c StringRecognizer recognizes custom strings found in high level expressions.
21534+
21535+ \ingroup stringrecognizer
21536+ */
2147621537 class StringRecognizer : public StaticCoreRefCountObject<BNStringRecognizer>
2147721538 {
2147821539 std::string m_nameForRegister;
@@ -21483,13 +21544,70 @@ namespace BinaryNinja {
2148321544
2148421545 std::string GetName() const;
2148521546
21547+ /*! Determines if the string recognizer should be called for the given expression type. It is optional
21548+ to override this method. If the method isn't overridden, all expression types are passed to the
21549+ string recognizer.
21550+
21551+ \param func \c HighLevelILFunction representing the high level function to be queried
21552+ \param type Type of the expression
21553+ \return \c true if the expression should be passed to the string recognizer, \c false otherwise
21554+ */
2148621555 virtual bool IsValidForType(HighLevelILFunction* func, Type* type);
21556+
21557+ /*! Can be overridden to recognize strings for a constant that is not a pointer. The expression type and
21558+ value of the expression are given. If no string is found for this expression, this method should
21559+ return \c std::nullopt
21560+
21561+ If a string is found, return a \c DerivedString with the string information.
21562+
21563+ \param instr High level expression
21564+ \param type Type of the expression
21565+ \param val Value of the expression
21566+ \return Optional \c DerivedString for any string that is found
21567+ */
2148721568 virtual std::optional<DerivedString> RecognizeConstant(
2148821569 const HighLevelILInstruction& instr, Type* type, int64_t val);
21570+
21571+ /*! Can be overridden to recognize strings for a constant pointer. The expression type and
21572+ value of the expression are given. If no string is found for this expression, this method should
21573+ return \c std::nullopt
21574+
21575+ If a string is found, return a \c DerivedString with the string information.
21576+
21577+ \param instr High level expression
21578+ \param type Type of the expression
21579+ \param val Value of the expression
21580+ \return Optional \c DerivedString for any string that is found
21581+ */
2148921582 virtual std::optional<DerivedString> RecognizeConstantPointer(
2149021583 const HighLevelILInstruction& instr, Type* type, int64_t val);
21584+
21585+ /*! Can be overridden to recognize strings for an external symbol. The expression type and
21586+ value of the expression are given. If no string is found for this expression, this method should
21587+ return \c std::nullopt
21588+
21589+ If a string is found, return a \c DerivedString with the string information.
21590+
21591+ \param instr High level expression
21592+ \param type Type of the expression
21593+ \param val Value of the expression
21594+ \param offset Offset into the external symbol
21595+ \return Optional \c DerivedString for any string that is found
21596+ */
2149121597 virtual std::optional<DerivedString> RecognizeExternPointer(
2149221598 const HighLevelILInstruction& instr, Type* type, int64_t val, uint64_t offset);
21599+
21600+ /*! Can be overridden to recognize strings for an imported symbol. The expression type and
21601+ value of the expression are given. If no string is found for this expression, this method should
21602+ return \c std::nullopt
21603+
21604+ If a string is found, return a \c DerivedString with the string information.
21605+
21606+ \param instr High level expression
21607+ \param type Type of the expression
21608+ \param val Value of the expression
21609+ \return Optional \c DerivedString for any string that is found
21610+ */
2149321611 virtual std::optional<DerivedString> RecognizeImport(
2149421612 const HighLevelILInstruction& instr, Type* type, int64_t val);
2149521613
0 commit comments