@@ -4057,6 +4057,10 @@ namespace BinaryNinja {
4057
4057
DisassemblyTextLineTypeInfo typeInfo;
4058
4058
4059
4059
DisassemblyTextLine();
4060
+
4061
+ size_t GetTotalWidth() const;
4062
+ size_t GetAddressAndIndentationWidth() const;
4063
+ std::vector<InstructionTextToken> GetAddressAndIndentationTokens() const;
4060
4064
};
4061
4065
4062
4066
/*!
@@ -10175,6 +10179,10 @@ namespace BinaryNinja {
10175
10179
DisassemblySettings(BNDisassemblySettings* settings);
10176
10180
DisassemblySettings* Duplicate();
10177
10181
10182
+ static Ref<DisassemblySettings> GetDefaultSettings();
10183
+ static Ref<DisassemblySettings> GetDefaultGraphSettings();
10184
+ static Ref<DisassemblySettings> GetDefaultLinearSettings();
10185
+
10178
10186
bool IsOptionSet(BNDisassemblyOption option) const;
10179
10187
void SetOption(BNDisassemblyOption option, bool state = true);
10180
10188
@@ -13698,6 +13706,82 @@ namespace BinaryNinja {
13698
13706
std::set<SSAVariable> GetSSAVariables();
13699
13707
};
13700
13708
13709
+ struct LineFormatterSettings
13710
+ {
13711
+ Ref<HighLevelILFunction> highLevelIL;
13712
+ size_t desiredLineLength;
13713
+ size_t minimumContentLength;
13714
+ size_t tabWidth;
13715
+ std::string languageName;
13716
+ std::string commentStartString;
13717
+ std::string commentEndString;
13718
+ std::string annotationStartString;
13719
+ std::string annotationEndString;
13720
+
13721
+ /*! Gets the default line formatter settings for High Level IL code.
13722
+
13723
+ \param settings The settings for reformatting.
13724
+ \param func High Level IL function to be reformatted.
13725
+ \return Settings for reformatting.
13726
+ */
13727
+ static LineFormatterSettings GetDefault(DisassemblySettings* settings, HighLevelILFunction* func);
13728
+
13729
+ /*! Gets the default line formatter settings for a language representation function.
13730
+
13731
+ \param settings The settings for reformatting.
13732
+ \param func Language representation function to be reformatted.
13733
+ \return Settings for reformatting.
13734
+ */
13735
+ static LineFormatterSettings GetLanguageRepresentationSettings(
13736
+ DisassemblySettings* settings, LanguageRepresentationFunction* func);
13737
+
13738
+ static LineFormatterSettings FromAPIObject(const BNLineFormatterSettings* settings);
13739
+ BNLineFormatterSettings ToAPIObject() const;
13740
+ };
13741
+
13742
+ class LineFormatter : public StaticCoreRefCountObject<BNLineFormatter>
13743
+ {
13744
+ std::string m_nameForRegister;
13745
+
13746
+ static BNDisassemblyTextLine* FormatLinesCallback(void* ctxt, BNDisassemblyTextLine* inLines, size_t inCount,
13747
+ const BNLineFormatterSettings* settings, size_t* outCount);
13748
+ static void FreeLinesCallback(void* ctxt, BNDisassemblyTextLine* lines, size_t count);
13749
+
13750
+ public:
13751
+ LineFormatter(const std::string& name);
13752
+ LineFormatter(BNLineFormatter* formatter);
13753
+
13754
+ /*! Registers the line formatter.
13755
+
13756
+ \param formatter The line formatter to register.
13757
+ */
13758
+ static void Register(LineFormatter* formatter);
13759
+
13760
+ static std::vector<Ref<LineFormatter>> GetList();
13761
+ static Ref<LineFormatter> GetByName(const std::string& name);
13762
+ static Ref<LineFormatter> GetDefault();
13763
+
13764
+ /*! Reformats the given list of lines. Returns a new list of lines containing the reformatted code.
13765
+
13766
+ \param lines The lines to reformat.
13767
+ \param settings The settings for reformatting.
13768
+ \return A new list of reformatted lines.
13769
+ */
13770
+ virtual std::vector<DisassemblyTextLine> FormatLines(
13771
+ const std::vector<DisassemblyTextLine>& lines, const LineFormatterSettings& settings) = 0;
13772
+ };
13773
+
13774
+ class CoreLineFormatter : public LineFormatter
13775
+ {
13776
+ public:
13777
+ CoreLineFormatter(BNLineFormatter* formatter);
13778
+
13779
+ std::vector<DisassemblyTextLine> FormatLines(
13780
+ const std::vector<DisassemblyTextLine>& lines, const LineFormatterSettings& settings) override;
13781
+ };
13782
+
13783
+ class LanguageRepresentationFunctionType;
13784
+
13701
13785
/*! LanguageRepresentationFunction represents a single function in a registered high level language.
13702
13786
13703
13787
\ingroup highlevelil
@@ -13707,7 +13791,8 @@ namespace BinaryNinja {
13707
13791
BNFreeLanguageRepresentationFunction>
13708
13792
{
13709
13793
public:
13710
- LanguageRepresentationFunction(Architecture* arch, Function* func, HighLevelILFunction* highLevelIL);
13794
+ LanguageRepresentationFunction(LanguageRepresentationFunctionType* type, Architecture* arch, Function* func,
13795
+ HighLevelILFunction* highLevelIL);
13711
13796
LanguageRepresentationFunction(BNLanguageRepresentationFunction* func);
13712
13797
13713
13798
/*! Gets the lines of tokens for a given High Level IL instruction.
@@ -13746,6 +13831,7 @@ namespace BinaryNinja {
13746
13831
*/
13747
13832
BNHighlightColor GetHighlight(BasicBlock* block);
13748
13833
13834
+ Ref<LanguageRepresentationFunctionType> GetLanguage() const;
13749
13835
Ref<Architecture> GetArchitecture() const;
13750
13836
Ref<Function> GetFunction() const;
13751
13837
Ref<HighLevelILFunction> GetHighLevelILFunction() const;
@@ -13894,6 +13980,13 @@ namespace BinaryNinja {
13894
13980
*/
13895
13981
virtual Ref<TypeParser> GetTypeParser() { return nullptr; }
13896
13982
13983
+ /*! Returns the line formatter for formatting code in this language. If NULL is returned, the default
13984
+ formatter will be used.
13985
+
13986
+ \return The optional formatter for formatting code in this language.
13987
+ */
13988
+ virtual Ref<LineFormatter> GetLineFormatter() { return nullptr; }
13989
+
13897
13990
/*! Returns a list of lines representing a function prototype in this language. If no lines are returned, the
13898
13991
default C-style prototype will be used.
13899
13992
@@ -13920,6 +14013,7 @@ namespace BinaryNinja {
13920
14013
static bool IsValidCallback(void* ctxt, BNBinaryView* view);
13921
14014
static BNTypePrinter* GetTypePrinterCallback(void* ctxt);
13922
14015
static BNTypeParser* GetTypeParserCallback(void* ctxt);
14016
+ static BNLineFormatter* GetLineFormatterCallback(void* ctxt);
13923
14017
static BNDisassemblyTextLine* GetFunctionTypeTokensCallback(
13924
14018
void* ctxt, BNFunction* func, BNDisassemblySettings* settings, size_t* count);
13925
14019
static void FreeLinesCallback(void* ctxt, BNDisassemblyTextLine* lines, size_t count);
@@ -13934,6 +14028,7 @@ namespace BinaryNinja {
13934
14028
bool IsValid(BinaryView* view) override;
13935
14029
Ref<TypePrinter> GetTypePrinter() override;
13936
14030
Ref<TypeParser> GetTypeParser() override;
14031
+ Ref<LineFormatter> GetLineFormatter() override;
13937
14032
std::vector<DisassemblyTextLine> GetFunctionTypeTokens(
13938
14033
Function* func, DisassemblySettings* settings = nullptr) override;
13939
14034
};
0 commit comments