Clean up Hexdump sidebar a bit more #121

This commit is contained in:
Florian Märkl 2017-12-03 11:50:14 +01:00
parent 4f1007a0cb
commit 40a3928ab6
3 changed files with 144 additions and 126 deletions

View File

@ -78,7 +78,7 @@ HexdumpWidget::HexdumpWidget(QWidget *parent, Qt::WindowFlags flags) :
refresh(Core()->getOffset()); refresh(Core()->getOffset());
}); });
fillPlugins(); initParsing();
selectHexPreview(); selectHexPreview();
} }
@ -476,10 +476,12 @@ void HexdumpWidget::updateHeaders()
* Content management functions * Content management functions
*/ */
void HexdumpWidget::fillPlugins() void HexdumpWidget::initParsing()
{ {
// Fill the plugins combo for the hexdump sidebar // Fill the plugins combo for the hexdump sidebar
ui->hexArchComboBox_2->insertItems(0, Core()->getAsmPluginNames()); ui->parseArchComboBox->insertItems(0, Core()->getAsmPluginNames());
ui->parseEndianComboBox->setCurrentIndex(Core()->getConfigb("cfg.bigendian") ? 1 : 0);
} }
std::array<QString, 3> HexdumpWidget::fetchHexdump(RVA offset, RVA bytes) std::array<QString, 3> HexdumpWidget::fetchHexdump(RVA offset, RVA bytes)
@ -555,14 +557,11 @@ void HexdumpWidget::adjustHexdumpLines()
void HexdumpWidget::on_hexHexText_selectionChanged() void HexdumpWidget::on_hexHexText_selectionChanged()
{ {
// Get selected partsing type
QString parsing = ui->codeCombo_2->currentText();
// Get selected text // Get selected text
QTextCursor cursor(ui->hexHexText->textCursor()); QTextCursor cursor(ui->hexHexText->textCursor());
QString sel_text = cursor.selectedText(); QString sel_text = cursor.selectedText();
sel_text = sel_text.simplified().remove(" "); sel_text = sel_text.simplified().remove(' ');
//eprintf ("-- (((%s))) --\n", sel_text.toUtf8().constData());
if (sel_text == "") if (sel_text == "")
{ {
@ -570,81 +569,82 @@ void HexdumpWidget::on_hexHexText_selectionChanged()
ui->bytesEntropy->setText(""); ui->bytesEntropy->setText("");
ui->bytesMD5->setText(""); ui->bytesMD5->setText("");
ui->bytesSHA1->setText(""); ui->bytesSHA1->setText("");
return;
} }
else
{ // Get selected combos
if (parsing == "Dissasembly") QString arch = ui->parseArchComboBox->currentText();
QString bits = ui->parseBitsComboBox->currentText();
bool bigEndian = ui->parseEndianComboBox->currentIndex() == 1;
{ // scope for TempConfig
TempConfig tempConfig;
tempConfig
.set("asm.arch", arch)
.set("asm.bits", bits)
.set("cfg.bigendian", bigEndian);
switch(ui->parseTypeComboBox->currentIndex())
{ {
QString dText = QString(sel_text); case 0: // Disassembly
dText.replace(" ", ""); {
if (dText.length() % 2 != 0) { QStringRef disasBytes = sel_text.leftRef((sel_text.length() / 2) * 2);
return; QString str = "";
if (disasBytes.length() > 0)
{
QString cmd = "pad ";
str = Core()->cmd(cmd.append(disasBytes));
}
ui->hexDisasTextEdit->setPlainText(str);
} }
// Get selected combos break;
QString arch = ui->hexArchComboBox_2->currentText(); case 1: // String
QString bits = ui->hexBitsComboBox_2->currentText(); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcs@x:" + sel_text));
break;
QString oarch = Core()->getConfig("asm.arch"); case 2: // Assembler
QString obits = Core()->getConfig("asm.bits"); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pca@x:" + sel_text));
break;
Core()->setConfig("asm.arch", arch); case 3: // C byte array
Core()->setConfig("asm.bits", bits); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pc@x:" + sel_text));
QString str = Core()->cmd("pad " + dText); break;
ui->hexDisasTextEdit->setPlainText(str); case 4: // C half-word
Core()->setConfig("asm.arch", oarch); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pch@x:" + sel_text));
Core()->setConfig("asm.bits", obits); break;
//qDebug() << "Selected Arch: " << arch; case 5: // C word
//qDebug() << "Selected Bits: " << bits; ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcw@x:" + sel_text));
//qDebug() << "Selected Text: " << sel_text; break;
case 6: // C dword
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcd@x:" + sel_text));
break;
case 7: // Python
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcp@x:" + sel_text));
break;
case 8: // JSON
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcj@x:" + sel_text));
break;
case 9: // JavaScript
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcJ@x:" + sel_text));
break;
default:
ui->hexDisasTextEdit->setPlainText("");
} }
// TODO: update on selection changes.. use cmd("pc "+len+"@"+off)
else if (parsing == "C byte array")
{
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pc@x:" + sel_text));
}
else if (parsing == "C dword array")
{
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcw@x:" + sel_text));
}
else if (parsing == "C qword array")
{
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcq@x:" + sel_text));
}
else if (parsing == "Assembler")
{
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pca@x:" + sel_text));
}
else if (parsing == "String")
{
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcs@x:" + sel_text));
}
else if (parsing == "JSON")
{
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcj@x:" + sel_text));
}
else if (parsing == "Javascript")
{
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcJ@x:" + sel_text));
}
else if (parsing == "Python")
{
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcp@x:" + sel_text));
}
// Fill the information tab hashes and entropy
ui->bytesMD5->setText(Core()->cmd("ph md5@x:" + sel_text).trimmed());
ui->bytesSHA1->setText(Core()->cmd("ph sha1@x:" + sel_text).trimmed());
ui->bytesEntropy->setText(Core()->cmd("ph entropy@x:" + sel_text).trimmed());
ui->bytesMD5->setCursorPosition(0);
ui->bytesSHA1->setCursorPosition(0);
} }
// Fill the information tab hashes and entropy
ui->bytesMD5->setText(Core()->cmd("ph md5@x:" + sel_text).trimmed());
ui->bytesSHA1->setText(Core()->cmd("ph sha1@x:" + sel_text).trimmed());
ui->bytesEntropy->setText(Core()->cmd("ph entropy@x:" + sel_text).trimmed());
ui->bytesMD5->setCursorPosition(0);
ui->bytesSHA1->setCursorPosition(0);
} }
void HexdumpWidget::on_hexArchComboBox_2_currentTextChanged(const QString &/*arg1*/) void HexdumpWidget::on_parseArchComboBox_currentTextChanged(const QString &/*arg1*/)
{ {
on_hexHexText_selectionChanged(); on_hexHexText_selectionChanged();
} }
void HexdumpWidget::on_hexBitsComboBox_2_currentTextChanged(const QString &/*arg1*/)
void HexdumpWidget::on_parseBitsComboBox_currentTextChanged(const QString &/*arg1*/)
{ {
on_hexHexText_selectionChanged(); on_hexHexText_selectionChanged();
} }
@ -808,9 +808,9 @@ void HexdumpWidget::on_action1column_triggered()
refresh(); refresh();
} }
void HexdumpWidget::on_codeCombo_2_currentTextChanged(const QString &arg1) void HexdumpWidget::on_parseTypeComboBox_currentTextChanged(const QString &arg1)
{ {
if (arg1 == "Dissasembly") if (ui->parseTypeComboBox->currentIndex() == 0)
{ {
ui->hexSideFrame_2->show(); ui->hexSideFrame_2->show();
} }
@ -821,6 +821,11 @@ void HexdumpWidget::on_codeCombo_2_currentTextChanged(const QString &arg1)
on_hexHexText_selectionChanged(); on_hexHexText_selectionChanged();
} }
void HexdumpWidget::on_parseEndianComboBox_currentTextChanged(const QString &arg1)
{
on_hexHexText_selectionChanged();
}
QString HexdumpWidget::normalize_addr(QString addr) QString HexdumpWidget::normalize_addr(QString addr)
{ {
QString base = Core()->cmd("s").split("0x")[1].trimmed(); QString base = Core()->cmd("s").split("0x")[1].trimmed();
@ -949,15 +954,15 @@ void HexdumpWidget::selectHexPreview()
QString bits = Core()->cmd("e asm.bits").trimmed(); QString bits = Core()->cmd("e asm.bits").trimmed();
//int arch_index = ui->hexArchComboBox_2->findText(arch); //int arch_index = ui->hexArchComboBox_2->findText(arch);
if (ui->hexArchComboBox_2->findText(arch) != -1) if (ui->parseArchComboBox->findText(arch) != -1)
{ {
ui->hexArchComboBox_2->setCurrentIndex(ui->hexArchComboBox_2->findText(arch)); ui->parseArchComboBox->setCurrentIndex(ui->parseArchComboBox->findText(arch));
} }
//int bits_index = ui->hexBitsComboBox_2->findText(bits); //int bits_index = ui->hexBitsComboBox_2->findText(bits);
if (ui->hexBitsComboBox_2->findText(bits) != -1) if (ui->parseBitsComboBox->findText(bits) != -1)
{ {
ui->hexBitsComboBox_2->setCurrentIndex(ui->hexBitsComboBox_2->findText(bits)); ui->parseBitsComboBox->setCurrentIndex(ui->parseBitsComboBox->findText(bits));
} }
} }

View File

@ -39,7 +39,7 @@ public:
// void fontChanged(QFont font); // void fontChanged(QFont font);
public slots: public slots:
void fillPlugins(); void initParsing();
QString normalize_addr(QString addr); QString normalize_addr(QString addr);
@ -90,8 +90,11 @@ private slots:
void showHexASCIIContextMenu(const QPoint &pt); void showHexASCIIContextMenu(const QPoint &pt);
void on_hexHexText_selectionChanged(); void on_hexHexText_selectionChanged();
void on_hexArchComboBox_2_currentTextChanged(const QString &arg1);
void on_hexBitsComboBox_2_currentTextChanged(const QString &arg1); void on_parseArchComboBox_currentTextChanged(const QString &arg1);
void on_parseBitsComboBox_currentTextChanged(const QString &arg1);
void on_parseTypeComboBox_currentTextChanged(const QString &arg1);
void on_parseEndianComboBox_currentTextChanged(const QString &arg1);
void on_action1column_triggered(); void on_action1column_triggered();
void on_action2columns_triggered(); void on_action2columns_triggered();
@ -106,7 +109,6 @@ private slots:
void fontsUpdated(); void fontsUpdated();
void colorsUpdatedSlot(); void colorsUpdatedSlot();
void on_codeCombo_2_currentTextChanged(const QString &arg1);
void on_hexSideTab_2_currentChanged(int index); void on_hexSideTab_2_currentChanged(int index);
void on_memSideToolButton_clicked(); void on_memSideToolButton_clicked();
void on_copyMD5_clicked(); void on_copyMD5_clicked();

View File

@ -361,7 +361,7 @@ QToolTip {
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QComboBox" name="codeCombo_2"> <widget class="QComboBox" name="parseTypeComboBox">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -369,11 +369,11 @@ QToolTip {
</sizepolicy> </sizepolicy>
</property> </property>
<property name="currentText"> <property name="currentText">
<string>Dissasembly</string> <string>Disassembly</string>
</property> </property>
<item> <item>
<property name="text"> <property name="text">
<string>Dissasembly</string> <string>Disassembly</string>
</property> </property>
</item> </item>
<item> <item>
@ -388,17 +388,22 @@ QToolTip {
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>C byte array</string> <string>C bytes</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>C dword array</string> <string>C half-words (2 byte)</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>C qword array</string> <string>C words (4 byte)</string>
</property>
</item>
<item>
<property name="text">
<string>C dwords (8 byte)</string>
</property> </property>
</item> </item>
<item> <item>
@ -413,7 +418,7 @@ QToolTip {
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>Javascript</string> <string>JavaScript</string>
</property> </property>
</item> </item>
</widget> </widget>
@ -432,7 +437,7 @@ QToolTip {
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="comboBox_2"> <widget class="QComboBox" name="parseEndianComboBox">
<property name="sizeAdjustPolicy"> <property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum> <enum>QComboBox::AdjustToMinimumContentsLength</enum>
</property> </property>
@ -503,7 +508,7 @@ QToolTip {
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="hexArchComboBox_2"> <widget class="QComboBox" name="parseArchComboBox">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -532,7 +537,7 @@ QToolTip {
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="hexBitsComboBox_2"> <widget class="QComboBox" name="parseBitsComboBox">
<property name="sizeAdjustPolicy"> <property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum> <enum>QComboBox::AdjustToMinimumContentsLength</enum>
</property> </property>
@ -654,36 +659,6 @@ QToolTip {
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>SHA1:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Entropy:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="bytesEntropy">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frame">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1"> <item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_8"> <layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="spacing"> <property name="spacing">
@ -758,6 +733,13 @@ QToolTip {
</item> </item>
</layout> </layout>
</item> </item>
<item row="2" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>SHA1:</string>
</property>
</widget>
</item>
<item row="2" column="1"> <item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_9"> <layout class="QHBoxLayout" name="horizontalLayout_9">
<property name="spacing"> <property name="spacing">
@ -832,14 +814,43 @@ QToolTip {
</item> </item>
</layout> </layout>
</item> </item>
<item row="3" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Entropy:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="bytesEntropy">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frame">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_22"> <spacer name="verticalSpacer">
<property name="topMargin"> <property name="orientation">
<number>0</number> <enum>Qt::Vertical</enum>
</property> </property>
</layout> <property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</widget> </widget>