summaryrefslogtreecommitdiff
path: root/examples/triage/byte.cpp
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2022-01-27 22:43:28 -0500
committerKyleMiles <krm504@nyu.edu>2022-01-28 00:24:06 -0500
commit6812c973c9fa9b4ad642ab81856c05f87bd6fcc4 (patch)
treedace4156d03148bcaf02df138ab4e0d93e61bc6f /examples/triage/byte.cpp
parent519c9db22367f2659d1a54599fab47e6313be06e (diff)
Format All Files
Diffstat (limited to 'examples/triage/byte.cpp')
-rw-r--r--examples/triage/byte.cpp127
1 files changed, 60 insertions, 67 deletions
diff --git a/examples/triage/byte.cpp b/examples/triage/byte.cpp
index be25368a..b6318d1e 100644
--- a/examples/triage/byte.cpp
+++ b/examples/triage/byte.cpp
@@ -5,28 +5,21 @@
#include "theme.h"
-static const char* g_byteMapping[] =
-{
- " ", "☺", "☻", "♥", "♦", "♣", "♠", "•", "◘", "○", "◙", "♂", "♀", "♪", "♫", "☼",
- "▸", "◂", "↕", "‼", "¶", "§", "▬", "↨", "↑", "↓", "→", "←", "∟", "↔", "▴", "▾",
- " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?",
- "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
- "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_",
- "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
- "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "⌂",
- "Ç", "ü", "é", "â", "ä", "à", "å", "ç", "ê", "ë", "è", "ï", "î", "ì", "Ä", "Å",
- "É", "æ", "Æ", "ô", "ö", "ò", "û", "ù", "ÿ", "Ö", "Ü", "¢", "£", "¥", "₧", "ƒ",
- "á", "í", "ó", "ú", "ñ", "Ñ", "ª", "º", "¿", "⌐", "¬", "½", "¼", "¡", "«", "»",
- "░", "▒", "▓", "│", "┤", "╡", "╢", "╖", "╕", "╣", "║", "╗", "╝", "╜", "╛", "┐",
- "└", "┴", "┬", "├", "─", "┼", "╞", "╟", "╚", "╔", "╩", "╦", "╠", "═", "╬", "╧",
- "╨", "╤", "╥", "╙", "╘", "╒", "╓", "╫", "╪", "┘", "┌", "█", "▄", "▌", "▐", "▀",
- "α", "ß", "Γ", "π", "Σ", "σ", "µ", "τ", "Φ", "Θ", "Ω", "δ", "∞", "φ", "ε", "∩",
- "≡", "±", "≥", "≤", "⌠", "⌡", "÷", "≈", "°", "∙", "·", "√", "ⁿ", "²", "■", " "
-};
+static const char* g_byteMapping[] = {" ", "☺", "☻", "♥", "♦", "♣", "♠", "•", "◘", "○", "◙", "♂", "♀", "♪", "♫", "☼",
+ "▸", "◂", "↕", "‼", "¶", "§", "▬", "↨", "↑", "↓", "→", "←", "∟", "↔", "▴", "▾", " ", "!", "\"", "#", "$", "%", "&",
+ "'", "(", ")", "*", "+", ",", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=",
+ ">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
+ "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_", "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
+ "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "⌂", "Ç", "ü", "é",
+ "â", "ä", "à", "å", "ç", "ê", "ë", "è", "ï", "î", "ì", "Ä", "Å", "É", "æ", "Æ", "ô", "ö", "ò", "û", "ù", "ÿ", "Ö",
+ "Ü", "¢", "£", "¥", "₧", "ƒ", "á", "í", "ó", "ú", "ñ", "Ñ", "ª", "º", "¿", "⌐", "¬", "½", "¼", "¡", "«", "»", "░",
+ "▒", "▓", "│", "┤", "╡", "╢", "╖", "╕", "╣", "║", "╗", "╝", "╜", "╛", "┐", "└", "┴", "┬", "├", "─", "┼", "╞", "╟",
+ "╚", "╔", "╩", "╦", "╠", "═", "╬", "╧", "╨", "╤", "╥", "╙", "╘", "╒", "╓", "╫", "╪", "┘", "┌", "█", "▄", "▌", "▐",
+ "▀", "α", "ß", "Γ", "π", "Σ", "σ", "µ", "τ", "Φ", "Θ", "Ω", "δ", "∞", "φ", "ε", "∩", "≡", "±", "≥", "≤", "⌠", "⌡",
+ "÷", "≈", "°", "∙", "·", "√", "ⁿ", "²", "■", " "};
-ByteView::ByteView(QWidget* parent, BinaryViewRef data): QAbstractScrollArea(parent), m_render(this)
+ByteView::ByteView(QWidget* parent, BinaryViewRef data) : QAbstractScrollArea(parent), m_render(this)
{
setBinaryDataNavigable(true);
setupView(this);
@@ -72,7 +65,7 @@ ByteView::ByteView(QWidget* parent, BinaryViewRef data): QAbstractScrollArea(par
m_updateTimer = new QTimer(this);
m_updateTimer->setInterval(200);
m_updateTimer->setSingleShot(false);
- //connect(m_updateTimer, &QTimer::timeout, this, &ByteView::updateTimerEvent);
+ // connect(m_updateTimer, &QTimer::timeout, this, &ByteView::updateTimerEvent);
actionHandler()->bindAction("Move Cursor Up", UIAction([=]() { up(false); }));
actionHandler()->bindAction("Move Cursor Down", UIAction([=]() { down(false); }));
@@ -155,7 +148,7 @@ BNAddressRange ByteView::getSelectionOffsets()
start = end;
end = t;
}
- return { start, end };
+ return {start, end};
}
void ByteView::setSelectionOffsets(BNAddressRange range)
@@ -169,11 +162,11 @@ void ByteView::updateRanges()
{
m_ranges = m_data->GetAllocatedRanges();
// Remove regions not backed by the file
- for (auto& i: m_data->GetSegments())
+ for (auto& i : m_data->GetSegments())
if (i->GetDataLength() < i->GetLength())
removeRange(i->GetStart() + i->GetDataLength(), i->GetEnd());
m_allocatedLength = 0;
- for (auto& i: m_ranges)
+ for (auto& i : m_ranges)
m_allocatedLength += i.end - i.start;
}
@@ -181,7 +174,7 @@ void ByteView::updateRanges()
void ByteView::removeRange(uint64_t begin, uint64_t end)
{
std::vector<BNAddressRange> newRanges;
- for (auto& i: m_ranges)
+ for (auto& i : m_ranges)
{
if ((end <= i.start) || (begin >= i.end))
{
@@ -193,16 +186,16 @@ void ByteView::removeRange(uint64_t begin, uint64_t end)
}
else if ((begin <= i.start) && (end < i.end))
{
- newRanges.push_back(BNAddressRange { end, i.end });
+ newRanges.push_back(BNAddressRange {end, i.end});
}
else if ((begin > i.start) && (end >= i.end))
{
- newRanges.push_back(BNAddressRange { i.start, begin });
+ newRanges.push_back(BNAddressRange {i.start, begin});
}
else
{
- newRanges.push_back(BNAddressRange { i.start, begin });
- newRanges.push_back(BNAddressRange { end, i.end });
+ newRanges.push_back(BNAddressRange {i.start, begin});
+ newRanges.push_back(BNAddressRange {end, i.end});
}
}
m_ranges = newRanges;
@@ -211,7 +204,7 @@ void ByteView::removeRange(uint64_t begin, uint64_t end)
void ByteView::setTopToAddress(uint64_t addr)
{
- for (auto& i: m_ranges)
+ for (auto& i : m_ranges)
{
if ((addr >= i.start) && (addr <= i.end))
{
@@ -237,7 +230,7 @@ bool ByteView::navigate(uint64_t addr)
if (addr > getEnd())
return false;
m_cursorAddr = getStart();
- for (auto& i: m_ranges)
+ for (auto& i : m_ranges)
{
if (i.start > addr)
break;
@@ -293,7 +286,7 @@ void ByteView::adjustSize(int width, int height)
uint64_t ByteView::getContiguousOffsetForAddress(uint64_t addr)
{
uint64_t offset = 0;
- for (auto& i: m_ranges)
+ for (auto& i : m_ranges)
{
if ((addr >= i.start) && (addr <= i.end))
{
@@ -309,7 +302,7 @@ uint64_t ByteView::getContiguousOffsetForAddress(uint64_t addr)
uint64_t ByteView::getAddressForContiguousOffset(uint64_t offset)
{
uint64_t cur = 0;
- for (auto& i: m_ranges)
+ for (auto& i : m_ranges)
{
if (offset < (cur + (i.end - i.start)))
return i.start + (offset - cur);
@@ -352,7 +345,7 @@ ByteViewLine ByteView::createLine(uint64_t addr, size_t length, bool separator)
{
if (separator)
{
- return ByteViewLine { addr, length, "", true };
+ return ByteViewLine {addr, length, "", true};
}
else
{
@@ -360,7 +353,7 @@ ByteViewLine ByteView::createLine(uint64_t addr, size_t length, bool separator)
QString line;
for (size_t i = 0; i < data.GetLength(); i++)
line.append(QString(g_byteMapping[data[i]]));
- return ByteViewLine { addr, length, line, false };
+ return ByteViewLine {addr, length, line, false};
}
}
@@ -369,7 +362,7 @@ bool ByteView::cachePreviousLines()
{
bool prevEndValid = false;
uint64_t prevEnd = 0;
- for (auto& i: m_ranges)
+ for (auto& i : m_ranges)
{
if ((m_topAddr > i.start) && (m_topAddr <= i.end))
{
@@ -410,7 +403,7 @@ bool ByteView::cachePreviousLines()
bool ByteView::cacheNextLines()
{
uint64_t lastAddr = m_data->GetStart();
- for (auto& i: m_ranges)
+ for (auto& i : m_ranges)
{
if ((m_bottomAddr >= i.start) && (m_bottomAddr < i.end))
{
@@ -519,8 +512,8 @@ void ByteView::repositionCaret()
bool found = false;
for (size_t i = 0; i < m_lines.size(); i++)
{
- if (((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr < (m_lines[i].address + m_lines[i].length))) ||
- (((i + 1) == m_lines.size()) && (m_cursorAddr == (m_lines[i].address + m_lines[i].length))))
+ if (((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr < (m_lines[i].address + m_lines[i].length)))
+ || (((i + 1) == m_lines.size()) && (m_cursorAddr == (m_lines[i].address + m_lines[i].length))))
{
if (i < m_topLine)
m_topLine = i;
@@ -557,11 +550,11 @@ void ByteView::updateCaret()
// Rerender both the old caret position and the new caret position
for (size_t i = m_topLine; (i < m_lines.size()) && (i < (m_topLine + m_visibleRows)); i++)
{
- if (((m_prevCursorAddr >= m_lines[i].address) && (m_prevCursorAddr <= (m_lines[i].address + m_lines[i].length))) ||
- ((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr <= (m_lines[i].address + m_lines[i].length))))
+ if (((m_prevCursorAddr >= m_lines[i].address) && (m_prevCursorAddr <= (m_lines[i].address + m_lines[i].length)))
+ || ((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr <= (m_lines[i].address + m_lines[i].length))))
{
- viewport()->update(0, (int)(i - m_topLine) * m_render.getFontHeight(),
- viewport()->size().width(), m_render.getFontHeight() + 3);
+ viewport()->update(0, (int)(i - m_topLine) * m_render.getFontHeight(), viewport()->size().width(),
+ m_render.getFontHeight() + 3);
}
}
}
@@ -628,22 +621,22 @@ void ByteView::paintEvent(QPaintEvent* event)
if (startY == endY)
{
p.drawRect(2 + ((int)m_addrWidth + 2 + startX) * charWidth, 2 + startY * charHeight,
- (endX - startX) * charWidth, charHeight + 1);
+ (endX - startX) * charWidth, charHeight + 1);
}
else
{
p.drawRect(2 + ((int)m_addrWidth + 2 + startX) * charWidth, 2 + startY * charHeight,
- ((int)m_cols - startX) * charWidth, charHeight + 1);
+ ((int)m_cols - startX) * charWidth, charHeight + 1);
if (endX > 0)
{
- p.drawRect(2 + ((int)m_addrWidth + 2) * charWidth, 2 + endY * charHeight,
- endX * charWidth, charHeight + 1);
+ p.drawRect(2 + ((int)m_addrWidth + 2) * charWidth, 2 + endY * charHeight, endX * charWidth,
+ charHeight + 1);
}
}
if ((endY - startY) > 1)
{
p.drawRect(2 + ((int)m_addrWidth + 2) * charWidth, 2 + (startY + 1) * charHeight,
- (int)m_cols * charWidth, ((endY - startY) - 1) * charHeight + 1);
+ (int)m_cols * charWidth, ((endY - startY) - 1) * charHeight + 1);
}
}
}
@@ -658,8 +651,8 @@ void ByteView::paintEvent(QPaintEvent* event)
break;
if (m_lines[y + m_topLine].separator)
{
- m_render.drawLinearDisassemblyLineBackground(p, NonContiguousSeparatorLineType,
- QRect(0, 2 + y * charHeight, event->rect().width(), charHeight), 0);
+ m_render.drawLinearDisassemblyLineBackground(
+ p, NonContiguousSeparatorLineType, QRect(0, 2 + y * charHeight, event->rect().width(), charHeight), 0);
continue;
}
@@ -670,8 +663,8 @@ void ByteView::paintEvent(QPaintEvent* event)
bool hasCursor = false;
int cursorCol = 0;
- if (((m_cursorAddr >= lineStartAddr) && (m_cursorAddr < (lineStartAddr + length))) ||
- (((y + (int)m_topLine + 1) >= (int)m_lines.size()) && (m_cursorAddr == (lineStartAddr + length))))
+ if (((m_cursorAddr >= lineStartAddr) && (m_cursorAddr < (lineStartAddr + length)))
+ || (((y + (int)m_topLine + 1) >= (int)m_lines.size()) && (m_cursorAddr == (lineStartAddr + length))))
{
cursorCol = (int)(m_cursorAddr - lineStartAddr);
hasCursor = true;
@@ -684,13 +677,15 @@ void ByteView::paintEvent(QPaintEvent* event)
{
p.setPen(Qt::NoPen);
p.setBrush(palette().color(QPalette::WindowText));
- p.drawRect(2 + ((int)m_addrWidth + 2 + cursorCol) * charWidth, 2 + y * charHeight, charWidth, charHeight + 1);
+ p.drawRect(
+ 2 + ((int)m_addrWidth + 2 + cursorCol) * charWidth, 2 + y * charHeight, charWidth, charHeight + 1);
QColor caretTextColor = palette().color(QPalette::Base);
BinaryNinja::DataBuffer byteValue = m_data->ReadBuffer(lineStartAddr + cursorCol, 1);
if (byteValue.GetLength() == 1)
{
QString byteStr = g_byteMapping[byteValue[0]];
- m_render.drawText(p, 2 + ((int)m_addrWidth + 2 + cursorCol) * charWidth, 2 + y * charHeight, caretTextColor, byteStr);
+ m_render.drawText(
+ p, 2 + ((int)m_addrWidth + 2 + cursorCol) * charWidth, 2 + y * charHeight, caretTextColor, byteStr);
}
}
}
@@ -699,7 +694,7 @@ void ByteView::paintEvent(QPaintEvent* event)
void ByteView::wheelEvent(QWheelEvent* event)
{
- if (event->angleDelta().x()) // ignore horizontal scrolling
+ if (event->angleDelta().x()) // ignore horizontal scrolling
return;
m_wheelDelta -= event->angleDelta().y();
@@ -796,7 +791,7 @@ void ByteView::focusOutEvent(QFocusEvent*)
void ByteView::selectNone()
{
- for (auto& i: m_lines)
+ for (auto& i : m_lines)
{
if ((m_cursorAddr >= i.address) && (m_cursorAddr < (i.address + i.length)) && i.separator)
{
@@ -825,7 +820,7 @@ void ByteView::selectAll()
void ByteView::adjustAddressAfterBackwardMovement()
{
uint64_t lastAddr = getStart();
- for (auto& i: m_ranges)
+ for (auto& i : m_ranges)
{
if ((m_cursorAddr >= i.start) && (m_cursorAddr < i.end))
break;
@@ -841,7 +836,7 @@ void ByteView::adjustAddressAfterBackwardMovement()
void ByteView::adjustAddressAfterForwardMovement()
{
- for (auto& i: m_ranges)
+ for (auto& i : m_ranges)
{
if ((m_cursorAddr >= i.start) && (m_cursorAddr < i.end))
break;
@@ -900,8 +895,8 @@ void ByteView::pageUp(bool selecting)
{
for (size_t i = 0; i < m_lines.size(); i++)
{
- if (((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr < (m_lines[i].address + m_lines[i].length))) ||
- (((i + 1) == m_lines.size()) && (m_cursorAddr == (m_lines[i].address + m_lines[i].length))))
+ if (((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr < (m_lines[i].address + m_lines[i].length)))
+ || (((i + 1) == m_lines.size()) && (m_cursorAddr == (m_lines[i].address + m_lines[i].length))))
{
if (i < m_visibleRows)
{
@@ -942,8 +937,8 @@ void ByteView::pageDown(bool selecting)
{
for (size_t i = 0; i < m_lines.size(); i++)
{
- if (((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr < (m_lines[i].address + m_lines[i].length))) ||
- (((i + 1) == m_lines.size()) && (m_cursorAddr == (m_lines[i].address + m_lines[i].length))))
+ if (((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr < (m_lines[i].address + m_lines[i].length)))
+ || (((i + 1) == m_lines.size()) && (m_cursorAddr == (m_lines[i].address + m_lines[i].length))))
{
if (i >= (m_lines.size() - m_visibleRows))
{
@@ -982,7 +977,7 @@ void ByteView::pageDown(bool selecting)
void ByteView::moveToStartOfLine(bool selecting)
{
- for (auto& i: m_lines)
+ for (auto& i : m_lines)
{
if ((m_cursorAddr >= i.address) && (m_cursorAddr < (i.address + i.length)))
{
@@ -1000,7 +995,7 @@ void ByteView::moveToStartOfLine(bool selecting)
void ByteView::moveToEndOfLine(bool selecting)
{
- for (auto& i: m_lines)
+ for (auto& i : m_lines)
{
if ((m_cursorAddr >= i.address) && (m_cursorAddr < (i.address + i.length)))
{
@@ -1095,9 +1090,7 @@ void ByteView::mouseMoveEvent(QMouseEvent* event)
}
-ByteViewType::ByteViewType(): ViewType("Bytes", "Byte Overview")
-{
-}
+ByteViewType::ByteViewType() : ViewType("Bytes", "Byte Overview") {}
int ByteViewType::getPriority(BinaryViewRef, const QString&)