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,65 +569,65 @@ void HexdumpWidget::on_hexHexText_selectionChanged()
ui->bytesEntropy->setText(""); ui->bytesEntropy->setText("");
ui->bytesMD5->setText(""); ui->bytesMD5->setText("");
ui->bytesSHA1->setText(""); ui->bytesSHA1->setText("");
}
else
{
if (parsing == "Dissasembly")
{
QString dText = QString(sel_text);
dText.replace(" ", "");
if (dText.length() % 2 != 0) {
return; return;
} }
// Get selected combos // Get selected combos
QString arch = ui->hexArchComboBox_2->currentText(); QString arch = ui->parseArchComboBox->currentText();
QString bits = ui->hexBitsComboBox_2->currentText(); QString bits = ui->parseBitsComboBox->currentText();
bool bigEndian = ui->parseEndianComboBox->currentIndex() == 1;
QString oarch = Core()->getConfig("asm.arch"); { // scope for TempConfig
QString obits = Core()->getConfig("asm.bits"); TempConfig tempConfig;
tempConfig
.set("asm.arch", arch)
.set("asm.bits", bits)
.set("cfg.bigendian", bigEndian);
Core()->setConfig("asm.arch", arch); switch(ui->parseTypeComboBox->currentIndex())
Core()->setConfig("asm.bits", bits); {
QString str = Core()->cmd("pad " + dText); case 0: // Disassembly
{
QStringRef disasBytes = sel_text.leftRef((sel_text.length() / 2) * 2);
QString str = "";
if (disasBytes.length() > 0)
{
QString cmd = "pad ";
str = Core()->cmd(cmd.append(disasBytes));
}
ui->hexDisasTextEdit->setPlainText(str); ui->hexDisasTextEdit->setPlainText(str);
Core()->setConfig("asm.arch", oarch);
Core()->setConfig("asm.bits", obits);
//qDebug() << "Selected Arch: " << arch;
//qDebug() << "Selected Bits: " << bits;
//qDebug() << "Selected Text: " << sel_text;
} }
// TODO: update on selection changes.. use cmd("pc "+len+"@"+off) break;
else if (parsing == "C byte array") case 1: // String
{
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)); ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcs@x:" + sel_text));
} break;
else if (parsing == "JSON") case 2: // Assembler
{ ui->hexDisasTextEdit->setPlainText(Core()->cmd("pca@x:" + sel_text));
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcj@x:" + sel_text)); break;
} case 3: // C byte array
else if (parsing == "Javascript") ui->hexDisasTextEdit->setPlainText(Core()->cmd("pc@x:" + sel_text));
{ break;
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcJ@x:" + sel_text)); case 4: // C half-word
} ui->hexDisasTextEdit->setPlainText(Core()->cmd("pch@x:" + sel_text));
else if (parsing == "Python") break;
{ case 5: // C word
ui->hexDisasTextEdit->setPlainText(Core()->cmd("pcw@x:" + 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)); 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("");
}
} }
// Fill the information tab hashes and entropy // Fill the information tab hashes and entropy
@ -637,14 +636,15 @@ void HexdumpWidget::on_hexHexText_selectionChanged()
ui->bytesEntropy->setText(Core()->cmd("ph entropy@x:" + sel_text).trimmed()); ui->bytesEntropy->setText(Core()->cmd("ph entropy@x:" + sel_text).trimmed());
ui->bytesMD5->setCursorPosition(0); ui->bytesMD5->setCursorPosition(0);
ui->bytesSHA1->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>