Skip to content

Commit

Permalink
Add address display mode options
Browse files Browse the repository at this point in the history
  • Loading branch information
CouleeApps committed May 2, 2024
1 parent ee9248c commit 0911568
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
12 changes: 12 additions & 0 deletions basicblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ void DisassemblySettings::SetGutterWidth(size_t width)
}


BNDisassemblyAddressMode DisassemblySettings::GetAddressMode() const
{
return BNGetDisassemblyAddressMode(m_object);
}


void DisassemblySettings::SetAddressMode(BNDisassemblyAddressMode mode)
{
BNSetDisassemblyAddressMode(m_object, mode);
}


DisassemblyTextLine::DisassemblyTextLine()
{
addr = 0;
Expand Down
3 changes: 3 additions & 0 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,7 @@ namespace BinaryNinja {
TextToken Used for anything not of another type.
CommentToken Comments
TypeNameToken **Not emitted by architectures**
AddressSeparatorToken **Not emitted by architectures**
========================== ============================================
*/
struct InstructionTextToken
Expand Down Expand Up @@ -9699,6 +9700,8 @@ namespace BinaryNinja {
void SetMaximumSymbolWidth(size_t width);
size_t GetGutterWidth() const;
void SetGutterWidth(size_t width);
BNDisassemblyAddressMode GetAddressMode() const;
void SetAddressMode(BNDisassemblyAddressMode mode);
};

/*!
Expand Down
19 changes: 17 additions & 2 deletions binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ extern "C"
AddressDisplayToken = 68,
IndirectImportToken = 69,
ExternalSymbolToken = 70,
StackVariableToken = 71
StackVariableToken = 71,
AddressSeparatorToken = 72
} BNInstructionTextTokenType;

typedef enum BNInstructionTextTokenContext
Expand Down Expand Up @@ -700,6 +701,19 @@ extern "C"
ShowILOpcodes = 131,
} BNDisassemblyOption;

typedef enum BNDisassemblyAddressMode
{
AbsoluteDisassemblyAddressMode,
RelativeToBinaryStartDisassemblyAddressMode,
NameAndRelativeToBinaryStartDisassemblyAddressMode,
RelativeToSegmentStartDisassemblyAddressMode,
NameAndRelativeToSegmentStartDisassemblyAddressMode,
RelativeToSectionStartDisassemblyAddressMode,
NameAndRelativeToSectionStartDisassemblyAddressMode,
RelativeToFunctionStartDisassemblyAddressMode,
NameAndRelativeToFunctionStartDisassemblyAddressMode,
} BNDisassemblyAddressMode;

typedef enum BNTypeClass
{
VoidTypeClass = 0,
Expand Down Expand Up @@ -5060,7 +5074,8 @@ extern "C"
BINARYNINJACOREAPI void BNSetDisassemblyMaximumSymbolWidth(BNDisassemblySettings* settings, size_t width);
BINARYNINJACOREAPI size_t BNGetDisassemblyGutterWidth(BNDisassemblySettings* settings);
BINARYNINJACOREAPI void BNSetDisassemblyGutterWidth(BNDisassemblySettings* settings, size_t width);

BINARYNINJACOREAPI BNDisassemblyAddressMode BNGetDisassemblyAddressMode(BNDisassemblySettings* settings);
BINARYNINJACOREAPI void BNSetDisassemblyAddressMode(BNDisassemblySettings* settings, BNDisassemblyAddressMode mode);

// Flow graphs
BINARYNINJACOREAPI BNFlowGraph* BNCreateFlowGraph(void);
Expand Down
1 change: 1 addition & 0 deletions python/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -2808,6 +2808,7 @@ class InstructionTextToken:
TextToken Used for anything not of another type.
CommentToken Comments
TypeNameToken **Not emitted by architectures**
AddressSeparatorToken **Not emitted by architectures**
========================== ============================================

"""
Expand Down
2 changes: 1 addition & 1 deletion python/examples/export_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def render_svg(function, offset, mode, form, showOpcodes, showAddresses, orignam
.BaseStructureNameToken, .BaseStructureSeparatorToken {{
fill: {rgbStr('BaseStructureNameColor')};
}}
.TextToken, .BeginMemoryOperandToken, .EndMemoryOperandToken {{
.TextToken, .BeginMemoryOperandToken, .EndMemoryOperandToken, .AddressSeparatorToken {{
fill: {rgbStr('TextToken')};
}}
</style>
Expand Down
2 changes: 2 additions & 0 deletions ui/disassemblyview.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class BINARYNINJAUIAPI DisassemblyView : public FlowGraphWidget

void setOption(BNDisassemblyOption option, bool state = true);
void toggleOption(BNDisassemblyOption option);
void setAddressMode(BNDisassemblyAddressMode mode);

virtual DisassemblySettingsRef getDisassemblySettings() override;
virtual void setDisassemblySettings(DisassemblySettingsRef settings) override;
Expand Down Expand Up @@ -129,6 +130,7 @@ class BINARYNINJAUIAPI DisassemblyView : public FlowGraphWidget

BNFunctionGraphType m_ilViewType;
std::set<BNDisassemblyOption> m_options;
BNDisassemblyAddressMode m_addressMode;
DisassemblyContainer* m_container;
SettingsRef m_settings;

Expand Down
3 changes: 2 additions & 1 deletion ui/linearview.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub
void getHexDumpLineBytes(
const BinaryNinja::LinearDisassemblyLine& line, size_t& skippedBytes, size_t& totalBytes, size_t& totalCols);

void paintHexDumpLine(QPainter& p, const LinearViewLine& line, int xoffset, int y, uint32_t addrLen, int tagOffset);
void paintHexDumpLine(QPainter& p, const LinearViewLine& line, int xoffset, int y, int tagOffset);
void paintAnalysisWarningLine(QPainter& p, const LinearViewLine& line, int xoffset, int y);
void paintTokenLine(QPainter& p, const LinearViewLine& line, int xoffset, int y, QRect eventRect, int tagOffset);

Expand Down Expand Up @@ -478,6 +478,7 @@ private Q_SLOTS:
void setContrast(HexEditorHighlightContrast mode);

void toggleOption(BNDisassemblyOption option);
void setAddressMode(BNDisassemblyAddressMode mode);

virtual bool goToReference(FunctionRef func, uint64_t source, uint64_t target) override;
QFont getFont() override { return m_render.getFont(); }
Expand Down

0 comments on commit 0911568

Please sign in to comment.