GUI: resolved issue #249 (data copy)
This commit is contained in:
parent
74087d1cca
commit
6c81049ead
|
|
@ -6,6 +6,7 @@
|
|||
#include "LineEditDialog.h"
|
||||
#include "HexEditDialog.h"
|
||||
#include "YaraRuleSelectionDialog.h"
|
||||
#include "DataCopyDialog.h"
|
||||
|
||||
CPUDump::CPUDump(QWidget* parent) : HexDump(parent)
|
||||
{
|
||||
|
|
@ -239,6 +240,10 @@ void CPUDump::setupContextMenu()
|
|||
this->addAction(mYaraAction);
|
||||
connect(mYaraAction, SIGNAL(triggered()), this, SLOT(yaraSlot()));
|
||||
|
||||
//Data copy
|
||||
mDataCopyAction = new QAction(QIcon(":/icons/images/data-copy.png"), "Data copy...", this);
|
||||
connect(mDataCopyAction, SIGNAL(triggered()), this, SLOT(dataCopySlot()));
|
||||
|
||||
//Find References
|
||||
mFindReferencesAction = new QAction("Find &References", this);
|
||||
mFindReferencesAction->setShortcutContext(Qt::WidgetShortcut);
|
||||
|
|
@ -473,6 +478,7 @@ void CPUDump::contextMenuEvent(QContextMenuEvent* event)
|
|||
wMenu->addMenu(mBreakpointMenu);
|
||||
wMenu->addAction(mFindPatternAction);
|
||||
wMenu->addAction(mYaraAction);
|
||||
wMenu->addAction(mDataCopyAction);
|
||||
wMenu->addMenu(mGotoMenu);
|
||||
wMenu->addSeparator();
|
||||
wMenu->addMenu(mHexMenu);
|
||||
|
|
@ -1346,3 +1352,14 @@ void CPUDump::yaraSlot()
|
|||
emit displayReferencesWidget();
|
||||
}
|
||||
}
|
||||
|
||||
void CPUDump::dataCopySlot()
|
||||
{
|
||||
int_t selStart = getSelectionStart();
|
||||
int_t selSize = getSelectionEnd() - selStart + 1;
|
||||
QVector<byte_t> data;
|
||||
data.resize(selSize);
|
||||
mMemPage->read(data.data(), selStart, selSize);
|
||||
DataCopyDialog dataDialog(&data, this);
|
||||
dataDialog.exec();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ public slots:
|
|||
|
||||
void selectionUpdatedSlot();
|
||||
void yaraSlot();
|
||||
void dataCopySlot();
|
||||
|
||||
private:
|
||||
QMenu* mBreakpointMenu;
|
||||
|
|
@ -160,6 +161,7 @@ private:
|
|||
QAction* mFindPatternAction;
|
||||
QAction* mFindReferencesAction;
|
||||
QAction* mYaraAction;
|
||||
QAction* mDataCopyAction;
|
||||
QAction* mUndoSelection;
|
||||
|
||||
QMenu* mSpecialMenu;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,175 @@
|
|||
#include "DataCopyDialog.h"
|
||||
#include "ui_DataCopyDialog.h"
|
||||
#include "Bridge.h"
|
||||
|
||||
DataCopyDialog::DataCopyDialog(const QVector<byte_t>* data, QWidget* parent) : QDialog(parent), ui(new Ui::DataCopyDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
|
||||
#endif
|
||||
setFixedSize(this->size()); //fixed size
|
||||
mData = data;
|
||||
|
||||
ui->comboType->addItem("C-Style BYTE (Hex)");
|
||||
ui->comboType->addItem("C-Style WORD (Hex)");
|
||||
ui->comboType->addItem("C-Style DWORD (Hex)");
|
||||
ui->comboType->addItem("C-Style String");
|
||||
ui->comboType->addItem("C-Style Unicode String");
|
||||
|
||||
ui->comboType->setCurrentIndex(DataCByte);
|
||||
|
||||
printData((DataType)ui->comboType->currentIndex());
|
||||
}
|
||||
|
||||
QString DataCopyDialog::printEscapedString(bool & bPrevWasHex, int ch, const char* hexFormat)
|
||||
{
|
||||
QString data="";
|
||||
switch(ch) //escaping
|
||||
{
|
||||
case '\t':
|
||||
data = "\\t";
|
||||
bPrevWasHex = false;
|
||||
break;
|
||||
case '\f':
|
||||
data = "\\f";
|
||||
bPrevWasHex = false;
|
||||
break;
|
||||
case '\v':
|
||||
data = "\\v";
|
||||
bPrevWasHex = false;
|
||||
break;
|
||||
case '\n':
|
||||
data = "\\n";
|
||||
bPrevWasHex = false;
|
||||
break;
|
||||
case '\r':
|
||||
data = "\\r";
|
||||
bPrevWasHex = false;
|
||||
break;
|
||||
case '\\':
|
||||
data = "\\\\";
|
||||
bPrevWasHex = false;
|
||||
break;
|
||||
case '\"':
|
||||
data = "\\\"";
|
||||
bPrevWasHex = false;
|
||||
break;
|
||||
default:
|
||||
if(ch>=' ' && ch<='~')
|
||||
{
|
||||
if(bPrevWasHex && isxdigit(ch))
|
||||
data = QString().sprintf("\"\"%c", ch);
|
||||
else
|
||||
data = QString().sprintf("%c", ch);
|
||||
bPrevWasHex = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bPrevWasHex=true;
|
||||
data = QString().sprintf(hexFormat, ch);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void DataCopyDialog::printData(DataType type)
|
||||
{
|
||||
ui->editCode->clear();
|
||||
QString data;
|
||||
switch(type)
|
||||
{
|
||||
case DataCByte:
|
||||
{
|
||||
data += "{";
|
||||
for(int i = 0; i < mData->size(); i++)
|
||||
{
|
||||
if(i)
|
||||
data += ", ";
|
||||
data += QString().sprintf("0x%02X", mData->at(i));
|
||||
}
|
||||
data += "};";
|
||||
}
|
||||
break;
|
||||
|
||||
case DataCWord:
|
||||
{
|
||||
int numwords = mData->size() / sizeof(unsigned short);
|
||||
data += "{";
|
||||
for(int i = 0; i < numwords; i++)
|
||||
{
|
||||
if(i)
|
||||
data += ", ";
|
||||
data += QString().sprintf("0x%04X", ((unsigned short*)mData->constData())[i]);
|
||||
}
|
||||
data += "};";
|
||||
}
|
||||
break;
|
||||
|
||||
case DataCDword:
|
||||
{
|
||||
int numdwords = mData->size() / sizeof(unsigned int);
|
||||
data += "{";
|
||||
for(int i = 0; i < numdwords; i++)
|
||||
{
|
||||
if(i)
|
||||
data += ", ";
|
||||
data += QString().sprintf("0x%08X", ((unsigned int*)mData->constData())[i]);
|
||||
}
|
||||
data += "};";
|
||||
}
|
||||
break;
|
||||
|
||||
case DataCString:
|
||||
{
|
||||
data += "\"";
|
||||
bool bPrevWasHex=false;
|
||||
for(int i = 0; i < mData->size(); i++)
|
||||
{
|
||||
byte_t ch = mData->at(i);
|
||||
data += printEscapedString(bPrevWasHex, ch, "\\x%02X");
|
||||
}
|
||||
data += "\"";
|
||||
}
|
||||
break;
|
||||
|
||||
case DataCUnicodeString: //extended ASCII + hex escaped only
|
||||
{
|
||||
data += "L\"";
|
||||
int numwchars = mData->size() / sizeof(unsigned short);
|
||||
bool bPrevWasHex = false;
|
||||
for(int i = 0; i < numwchars; i++)
|
||||
{
|
||||
unsigned short ch = ((unsigned short*)mData->constData())[i];
|
||||
if((ch & 0xFF00) == 0) //extended ASCII
|
||||
{
|
||||
data += printEscapedString(bPrevWasHex, ch, "\\x%04X");
|
||||
}
|
||||
else //full unicode character
|
||||
{
|
||||
bPrevWasHex=true;
|
||||
data += QString().sprintf("\\x%04X", ch);
|
||||
}
|
||||
}
|
||||
data += "\"";
|
||||
}
|
||||
break;
|
||||
}
|
||||
ui->editCode->setPlainText(data);
|
||||
}
|
||||
|
||||
DataCopyDialog::~DataCopyDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DataCopyDialog::on_comboType_currentIndexChanged(int index)
|
||||
{
|
||||
printData((DataType)index);
|
||||
}
|
||||
|
||||
void DataCopyDialog::on_buttonCopy_clicked()
|
||||
{
|
||||
Bridge::CopyToClipboard(ui->editCode->toPlainText());
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef DATACOPYDIALOG_H
|
||||
#define DATACOPYDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QVector>
|
||||
#include "NewTypes.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class DataCopyDialog;
|
||||
}
|
||||
|
||||
class DataCopyDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DataCopyDialog(const QVector<byte_t>* data, QWidget* parent = 0);
|
||||
~DataCopyDialog();
|
||||
|
||||
private slots:
|
||||
void on_comboType_currentIndexChanged(int index);
|
||||
void on_buttonCopy_clicked();
|
||||
|
||||
private:
|
||||
Ui::DataCopyDialog* ui;
|
||||
const QVector<byte_t>* mData;
|
||||
|
||||
enum DataType
|
||||
{
|
||||
DataCByte = 0,
|
||||
DataCWord,
|
||||
DataCDword,
|
||||
DataCString,
|
||||
DataCUnicodeString,
|
||||
};
|
||||
|
||||
void printData(DataType type);
|
||||
QString printEscapedString(bool & bPrevWasHex, int ch, const char* hexFormat);
|
||||
};
|
||||
|
||||
#endif // DATACOPYDIALOG_H
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DataCopyDialog</class>
|
||||
<widget class="QDialog" name="DataCopyDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>242</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Data Copy</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../../resource.qrc">
|
||||
<normaloff>:/icons/images/data-copy.png</normaloff>:/icons/images/data-copy.png</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>381</width>
|
||||
<height>225</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="editCode">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="plainText">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonCopy">
|
||||
<property name="text">
|
||||
<string>Copy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboType"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../resource.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 664 B |
|
|
@ -52,5 +52,6 @@
|
|||
<file>images/close-all-tabs.png</file>
|
||||
<file>images/bug-report.png</file>
|
||||
<file>images/yara.png</file>
|
||||
<file>images/data-copy.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
|||
|
|
@ -87,7 +87,8 @@ SOURCES += \
|
|||
Src/Gui/SelectFields.cpp \
|
||||
Src/Gui/ReferenceManager.cpp \
|
||||
Src/Bridge/BridgeResult.cpp \
|
||||
Src/Gui/YaraRuleSelectionDialog.cpp
|
||||
Src/Gui/YaraRuleSelectionDialog.cpp \
|
||||
Src/Gui/DataCopyDialog.cpp
|
||||
|
||||
|
||||
HEADERS += \
|
||||
|
|
@ -153,7 +154,8 @@ HEADERS += \
|
|||
Src/Gui/SelectFields.h \
|
||||
Src/Gui/ReferenceManager.h \
|
||||
Src/Bridge/BridgeResult.h \
|
||||
Src/Gui/YaraRuleSelectionDialog.h
|
||||
Src/Gui/YaraRuleSelectionDialog.h \
|
||||
Src/Gui/DataCopyDialog.h
|
||||
|
||||
|
||||
INCLUDEPATH += \
|
||||
|
|
@ -189,7 +191,8 @@ FORMS += \
|
|||
Src/Gui/AttachDialog.ui \
|
||||
Src/Gui/PageMemoryRights.ui \
|
||||
Src/Gui/SelectFields.ui \
|
||||
Src/Gui/YaraRuleSelectionDialog.ui
|
||||
Src/Gui/YaraRuleSelectionDialog.ui \
|
||||
Src/Gui/DataCopyDialog.ui
|
||||
|
||||
INCLUDEPATH += $$PWD/Src/Bridge
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue