format ****(seed)

This commit is contained in:
mrexodia 2017-04-09 21:55:06 +02:00
parent b91ea94543
commit b12f665668
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
59 changed files with 2049 additions and 1175 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
# The final executable after `make clean`
iaito
AStyle*
# C++ objects and libs

View File

@ -18,6 +18,16 @@ Iaitō is not aimed at existing radare2 users, it is focused on those whose are
Yes, the code sucks. Hopefully we will be able to remove this statement from the README one day, but I had never coded Qt nor C++ until I started Iaitō, so obviously the code is ugly and not well designed.
### Code formatting
We use [AStyle 2.06](https://sourceforge.net/projects/astyle/files/astyle/astyle%202.06/) to format the code. The command line for formatting the code according to the style is:
```bash
AStyle --style=allman --convert-tabs --align-pointer=name --align-reference=name --indent=spaces --indent-namespaces --indent-col1-comments --pad-oper --pad-header --unpad-paren --keep-one-line-blocks --close-templates $(git ls-files *.cpp *.h *.c *.hpp)
```
**If in doubt, check the source around you and follow that style!**
## Requirements
- **Radare2**: Make sure that, when cloning the project, you use `git clone --recurse-submodules` or run `git submodule init` and `git submodule update` to clone the correct radare2 version. Then execute the following command in the radare2 folder:

View File

@ -11,7 +11,8 @@ AnalThread::AnalThread(QWidget *parent) :
AnalThread::~AnalThread()
{
if (isRunning()) {
if (isRunning())
{
quit();
wait();
}

View File

@ -35,24 +35,36 @@ void createNewDialog::on_exampleButton_clicked()
{
QString type = ui->comboType->currentText();
QString str;
if (type == "Assembler") {
if (type == "Assembler")
{
str = "; Sample program code\nmov eax, 1\nint 0x80";
} else if (type == "Text") {
}
else if (type == "Text")
{
str = "Hello World";
} else if (type == "Rapatch") {
}
else if (type == "Rapatch")
{
str = "; Sample rapatch script\n"
"0x0 \"Hello World\n"
"0x10 909090";
} else if (type == "C Code") {
}
else if (type == "C Code")
{
str = "int main() {\n"
" write (1, \"Hello World\", 12);\n"
" exit (0);\n"
"}";
} else if (type == "Radare2 script") {
}
else if (type == "Radare2 script")
{
str = "w Hello\ns+5\nw World";
} else if (type == "Hexpairs") {
}
else if (type == "Hexpairs")
{
str = "48656c6c6f20576f726c6400";
} else fprintf (stderr, "Unknown combo value selected");
}
else fprintf(stderr, "Unknown combo value selected");
if (str.length() > 0)
ui->plainTextEdit->setPlainText(str);
// }
@ -69,102 +81,148 @@ void createNewDialog::on_buttonCreate_clicked()
int fsize = r_num_math(NULL, ui->entrySize->text().toUtf8().constData());
QString format = ui->comboFormat->currentText();
if (type == "Assembler") {
if (type == "Assembler")
{
RAsmCode *code = r_asm_massemble(lcore->assembler, ui->plainTextEdit->toPlainText().toUtf8().constData());
if (code && code->len>0) {
if (code && code->len > 0)
{
char file[32];
snprintf(file, sizeof(file) - 1, "malloc://%d", code->len);
if (w->core->loadFile(file,0,0,1,0,0,false)) {
if (w->core->loadFile(file, 0, 0, 1, 0, 0, false))
{
created = true;
r_core_write_at(lcore, 0, code->buf, code->len);
} else {
}
else
{
__alert("Failed to create file");
}
} else {
}
else
{
__alert("Invalid assembler code");
}
r_asm_code_free(code);
} else if (type == "Rapatch") {
if (fsize>0) {
}
else if (type == "Rapatch")
{
if (fsize > 0)
{
char file[32];
created = true;
snprintf(file, sizeof(file) - 1, "malloc://%d", fsize);
if (w->core->loadFile(file,0,0,1,0,0,false)) {
if (w->core->loadFile(file, 0, 0, 1, 0, 0, false))
{
r_core_patch(lcore, ui->plainTextEdit->toPlainText().toUtf8().constData());
r_core_seek(lcore, 0, 1);
created = true;
} else {
}
else
{
__alert("failed to open file");
}
} else {
}
else
{
__alert("Invalid file size");
}
} else if (type == "C Code") {
}
else if (type == "C Code")
{
__alert("C Code: TODO");
// ragg2-cc -x
} else if (type == "Radare2 script") {
if (fsize>0) {
}
else if (type == "Radare2 script")
{
if (fsize > 0)
{
char file[32];
created = true;
snprintf(file, sizeof(file) - 1, "malloc://%d", fsize);
if (w->core->loadFile(file,0,0,1,0,0,false)) {
if (w->core->loadFile(file, 0, 0, 1, 0, 0, false))
{
created = true;
QString str = ui->plainTextEdit->toPlainText();
QList <QString> lines = str.split("\n");
foreach (QString str, lines) {
foreach (QString str, lines)
{
w->core->cmd(str);
}
} else {
}
else
{
__alert("failed to open file");
}
} else {
}
else
{
__alert("Invalid file size");
}
} else if (type == "Text") {
}
else if (type == "Text")
{
char file[32];
QByteArray hexpairs = ui->plainTextEdit->toPlainText().toUtf8();
int sz = strlen(hexpairs.constData());
if (sz>0) {
if (sz > 0)
{
snprintf(file, sizeof(file) - 1, "malloc://%d", sz);
if (w->core->loadFile(file,0,0,1,0,0,false)) {
if (w->core->loadFile(file, 0, 0, 1, 0, 0, false))
{
created = true;
r_core_write_at(lcore, 0, (const ut8 *)hexpairs.constData(), sz);
} else {
}
else
{
__alert("failed to open file");
}
} else {
}
else
{
__alert("Empty string?");
}
} else if (type == "Hexpairs") {
}
else if (type == "Hexpairs")
{
char file[32];
int sz;
QByteArray hexpairs = ui->plainTextEdit->toPlainText().toUtf8();
ut8 *buf = (ut8 *)malloc(strlen(hexpairs.constData()) + 1);
sz = r_hex_str2bin(hexpairs.constData(), buf);
if (sz>0) {
if (sz > 0)
{
snprintf(file, sizeof(file) - 1, "malloc://%d", sz);
if (w->core->loadFile(file,0,0,1,0,0,false)) {
if (w->core->loadFile(file, 0, 0, 1, 0, 0, false))
{
created = true;
r_core_write_at(lcore, 0, buf, sz);
} else {
}
else
{
__alert("failed to open file");
}
} else {
}
else
{
__alert("Invalid hexpair string");
}
free(buf);
} else {
}
else
{
__alert("Unknown combo value selected");
return;
}
if (format != "Raw") {
if (format != "Raw")
{
__alert("TODO: non-raw fileformat is not yet supported");
created = false;
delete w->core;
}
if (created) {
if (created)
{
// Close dialog and open OptionsDialog
close();
@ -174,7 +232,9 @@ void createNewDialog::on_buttonCreate_clicked()
w->setFilename("-");
w->add_output("Finished, check its contents");
w->showMaximized();
} else {
}
else
{
__alert("No file created.");
}

View File

@ -4,7 +4,8 @@
#include <QDialog>
#include "mainwindow.h"
namespace Ui {
namespace Ui
{
class createNewDialog;
}

View File

@ -3,7 +3,8 @@
#include <QDialog>
namespace Ui {
namespace Ui
{
class AboutDialog;
}

View File

@ -24,7 +24,8 @@ void CommentsDialog::on_buttonBox_rejected()
close();
}
QString CommentsDialog::getComment() {
QString CommentsDialog::getComment()
{
QString ret = ui->lineEdit->text();
return ret;
}

View File

@ -3,7 +3,8 @@
#include <QDialog>
namespace Ui {
namespace Ui
{
class CommentsDialog;
}

View File

@ -3,7 +3,8 @@
#include <QDialog>
namespace Ui {
namespace Ui
{
class RenameDialog;
}

View File

@ -27,9 +27,11 @@ XrefsDialog::~XrefsDialog()
delete ui;
}
void XrefsDialog::fillRefs(QList<QStringList> refs, QList<QStringList> xrefs) {
void XrefsDialog::fillRefs(QList<QStringList> refs, QList<QStringList> xrefs)
{
ui->fromTreeWidget->clear();
for (int i = 0; i < refs.size(); ++i) {
for (int i = 0; i < refs.size(); ++i)
{
//this->add_debug_output(refs.at(i).at(0) + " " + refs.at(i).at(1));
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
tempItem->setText(0, refs.at(i).at(0));
@ -40,12 +42,14 @@ void XrefsDialog::fillRefs(QList<QStringList> refs, QList<QStringList> xrefs) {
}
// Adjust columns to content
int count = ui->fromTreeWidget->columnCount();
for (int i = 0; i != count; ++i) {
for (int i = 0; i != count; ++i)
{
ui->fromTreeWidget->resizeColumnToContents(i);
}
ui->toTreeWidget->clear();
for (int i = 0; i < xrefs.size(); ++i) {
for (int i = 0; i < xrefs.size(); ++i)
{
//this->add_debug_output(xrefs.at(i).at(0) + " " + xrefs.at(i).at(1));
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
tempItem->setText(0, xrefs.at(i).at(0));
@ -56,7 +60,8 @@ void XrefsDialog::fillRefs(QList<QStringList> refs, QList<QStringList> xrefs) {
}
// Adjust columns to content
int count2 = ui->toTreeWidget->columnCount();
for (int i = 0; i != count2; ++i) {
for (int i = 0; i != count2; ++i)
{
ui->toTreeWidget->resizeColumnToContents(i);
}
@ -84,24 +89,30 @@ void XrefsDialog::on_toTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int c
this->close();
}
QString XrefsDialog::normalizeAddr(QString addr) {
QString XrefsDialog::normalizeAddr(QString addr)
{
QString base = addr.split("0x")[1].trimmed();
int len = base.length();
if (len < 8) {
if (len < 8)
{
int padding = 8 - len;
QString zero = "0";
QString zeroes = zero.repeated(padding);
QString s = "0x" + zeroes + base;
return s;
} else {
}
else
{
return addr;
}
}
void XrefsDialog::highlightCurrentLine() {
void XrefsDialog::highlightCurrentLine()
{
QList<QTextEdit::ExtraSelection> extraSelections;
if (ui->previewTextEdit->isReadOnly()) {
if (ui->previewTextEdit->isReadOnly())
{
QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(190, 144, 212);
@ -139,7 +150,8 @@ void XrefsDialog::on_toTreeWidget_itemSelectionChanged()
ui->previewTextEdit->moveCursor(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
}
void XrefsDialog::updateLabels(QString name) {
void XrefsDialog::updateLabels(QString name)
{
ui->label_2->setText(ui->label_2->text() + name);
ui->label_3->setText(ui->label_3->text() + name);
}

View File

@ -8,7 +8,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class XrefsDialog;
}

View File

@ -8,7 +8,8 @@ namespace qhelpers
// TODO: wouldn't it be enough to setFont on the QWidget?
void normalizeFont(QPlainTextEdit *edit) {
void normalizeFont(QPlainTextEdit *edit)
{
#ifdef Q_OS_LINUX
QFont anonFont("Inconsolata", 12);
QTextDocument *out_doc = edit->document();
@ -16,7 +17,8 @@ void normalizeFont(QPlainTextEdit *edit) {
#endif
}
void normalizeEditFont(QTextEdit *edit) {
void normalizeEditFont(QTextEdit *edit)
{
#ifdef Q_OS_LINUX
QFont anonFont("Inconsolata", 12);
QTextDocument *out_doc = edit->document();

View File

@ -18,10 +18,12 @@ AsciiHighlighter::AsciiHighlighter(QTextDocument *parent)
void AsciiHighlighter::highlightBlock(const QString &text)
{
foreach (const HighlightingRule &rule, highlightingRules) {
foreach (const HighlightingRule &rule, highlightingRules)
{
QRegExp expression(rule.pattern);
int index = expression.indexIn(text);
while (index >= 0) {
while (index >= 0)
{
int length = expression.matchedLength();
setFormat(index, length, rule.format);
index = expression.indexIn(text, index + length);
@ -33,13 +35,17 @@ void AsciiHighlighter::highlightBlock(const QString &text)
if (previousBlockState() != 1)
startIndex = commentStartExpression.indexIn(text);
while (startIndex >= 0) {
while (startIndex >= 0)
{
int endIndex = commentEndExpression.indexIn(text, startIndex);
int commentLength;
if (endIndex == -1) {
if (endIndex == -1)
{
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
}
else
{
commentLength = endIndex - startIndex
+ commentEndExpression.matchedLength();
}

View File

@ -25,7 +25,8 @@ HexHighlighter::HexHighlighter(QTextDocument *parent)
<< "\\b6e\\b" << "\\b6f\\b" << "\\b70\\b" << "\\b71\\b" << "\\b72\\b" << "\\b73\\b" << "\\b74\\b"
<< "\\b75\\b" << "\\b76\\b" << "\\b77\\b" << "\\b78\\b" << "\\b79\\b" << "\\b7a\\b" << "\\b7b\\b"
<< "\\b7c\\b" << "\\b7d\\b" << "\\b7e\\b" << "\\b7f\\b";
foreach (const QString &pattern, keywordPatterns) {
foreach (const QString &pattern, keywordPatterns)
{
rule.pattern = QRegExp(pattern);
rule.pattern.setCaseSensitivity(Qt::CaseInsensitive);
rule.format = keywordFormat;
@ -44,10 +45,12 @@ HexHighlighter::HexHighlighter(QTextDocument *parent)
void HexHighlighter::highlightBlock(const QString &text)
{
foreach (const HighlightingRule &rule, highlightingRules) {
foreach (const HighlightingRule &rule, highlightingRules)
{
QRegExp expression(rule.pattern);
int index = expression.indexIn(text);
while (index >= 0) {
while (index >= 0)
{
int length = expression.matchedLength();
setFormat(index, length, rule.format);
index = expression.indexIn(text, index + length);
@ -59,13 +62,17 @@ void HexHighlighter::highlightBlock(const QString &text)
if (previousBlockState() != 1)
startIndex = commentStartExpression.indexIn(text);
while (startIndex >= 0) {
while (startIndex >= 0)
{
int endIndex = commentEndExpression.indexIn(text, startIndex);
int commentLength;
if (endIndex == -1) {
if (endIndex == -1)
{
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
}
else
{
commentLength = endIndex - startIndex
+ commentEndExpression.matchedLength();
}

View File

@ -14,7 +14,8 @@ Highlighter::Highlighter(MainWindow *main, QTextDocument *parent) :
keywordFormat.setForeground(QColor(65, 131, 215));
keywordFormat.setFontWeight(QFont::Bold);
foreach (const QString &pattern, this->main->core->opcodes) {
foreach (const QString &pattern, this->main->core->opcodes)
{
rule.pattern = QRegExp("\\b" + pattern + "\\b");
rule.pattern.setCaseSensitivity(Qt::CaseInsensitive);
rule.format = keywordFormat;
@ -24,7 +25,8 @@ Highlighter::Highlighter(MainWindow *main, QTextDocument *parent) :
regFormat.setForeground(QColor(236, 100, 75));
regFormat.setFontWeight(QFont::Bold);
foreach (const QString &pattern, this->main->core->regs) {
foreach (const QString &pattern, this->main->core->regs)
{
rule.pattern = QRegExp("\\b" + pattern + "\\b");
rule.pattern.setCaseSensitivity(Qt::CaseInsensitive);
rule.format = regFormat;
@ -44,10 +46,12 @@ Highlighter::Highlighter(MainWindow *main, QTextDocument *parent) :
void Highlighter::highlightBlock(const QString &text)
{
foreach (const HighlightingRule &rule, highlightingRules) {
foreach (const HighlightingRule &rule, highlightingRules)
{
QRegExp expression(rule.pattern);
int index = expression.indexIn(text);
while (index >= 0) {
while (index >= 0)
{
int length = expression.matchedLength();
setFormat(index, length, rule.format);
index = expression.indexIn(text, index + length);
@ -59,13 +63,17 @@ void Highlighter::highlightBlock(const QString &text)
if (previousBlockState() != 1)
startIndex = commentStartExpression.indexIn(text);
while (startIndex >= 0) {
while (startIndex >= 0)
{
int endIndex = commentEndExpression.indexIn(text, startIndex);
int commentLength;
if (endIndex == -1) {
if (endIndex == -1)
{
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
}
else
{
commentLength = endIndex - startIndex
+ commentEndExpression.matchedLength();
}

View File

@ -232,12 +232,14 @@ MainWindow::MainWindow(QWidget *parent, QRCore *kore) :
connect(&webserverThread, SIGNAL(finished()), this, SLOT(webserverThreadFinished()));
}
MainWindow::~MainWindow() {
MainWindow::~MainWindow()
{
delete ui;
delete core;
}
void MainWindow::start_web_server() {
void MainWindow::start_web_server()
{
// Start web server
webserverThread.startServer();
}
@ -252,15 +254,18 @@ void MainWindow::webserverThreadFinished()
//}
}
void MainWindow::adjustColumns(QTreeWidget *tw) {
void MainWindow::adjustColumns(QTreeWidget *tw)
{
int count = tw->columnCount();
for (int i = 0; i != count; ++i) {
for (int i = 0; i != count; ++i)
{
tw->resizeColumnToContents(i);
}
}
void MainWindow::appendRow(QTreeWidget *tw, const QString &str, const QString &str2,
const QString &str3, const QString &str4, const QString &str5) {
const QString &str3, const QString &str4, const QString &str5)
{
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
// Fill dummy hidden column
tempItem->setText(0, "0");
@ -278,19 +283,23 @@ void MainWindow::appendRow(QTreeWidget *tw, const QString &str, const QString &s
void MainWindow::setWebServerState(bool start)
{
if (start) {
if (start)
{
webserverThread.startServer();
// Open web interface on default browser
// ballessay: well isn't this possible with =H&
//QString link = "http://localhost:9090/";
//QDesktopServices::openUrl(QUrl(link));
} else {
}
else
{
webserverThread.stopServer();
}
}
void MainWindow::hideDummyColumns() {
void MainWindow::hideDummyColumns()
{
// UGLY, should be a loop over all treewidgets...
this->functionsDock->functionsTreeWidget->setColumnHidden(0, true);
this->importsDock->importsTreeWidget->setColumnHidden(0, true);
@ -301,7 +310,8 @@ void MainWindow::hideDummyColumns() {
this->commentsDock->commentsTreeWidget->setColumnHidden(0, true);
}
void MainWindow::setFilename(QString fn) {
void MainWindow::setFilename(QString fn)
{
// Add file name to window title
this->filename = fn;
@ -328,7 +338,8 @@ void MainWindow::closeEvent(QCloseEvent *event)
"Do you really want to exit?\nSave your project before closing!",
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
//qDebug() << ret;
if (ret == QMessageBox::Save) {
if (ret == QMessageBox::Save)
{
QSettings settings;
settings.setValue("geometry", saveGeometry());
settings.setValue("size", size());
@ -339,13 +350,17 @@ void MainWindow::closeEvent(QCloseEvent *event)
//this->add_debug_output(notes);
this->core->cmd("Pnj " + notes);
QMainWindow::closeEvent(event);
} else if (ret == QMessageBox::Discard) {
}
else if (ret == QMessageBox::Discard)
{
QSettings settings;
settings.setValue("geometry", saveGeometry());
settings.setValue("size", size());
settings.setValue("pos", pos());
settings.setValue("state", saveState());
} else {
}
else
{
event->ignore();
}
}
@ -357,20 +372,23 @@ void MainWindow::readSettings()
restoreGeometry(geo);
QByteArray state = settings.value("state", QByteArray()).toByteArray();
restoreState(state);
if (settings.value("dark").toBool()) {
if (settings.value("dark").toBool())
{
this->dark();
}
this->responsive = settings.value("responsive").toBool();
}
void MainWindow::dark() {
void MainWindow::dark()
{
qApp->setStyleSheet("QPlainTextEdit { background-color: rgb(64, 64, 64); color: rgb(222, 222, 222);} QTextEdit { background-color: rgb(64, 64, 64); color: rgb(222, 222, 222);} ");
this->memoryDock->switchTheme(true);
QSettings settings;
settings.setValue("dark", true);
}
void MainWindow::def_theme() {
void MainWindow::def_theme()
{
qApp->setStyleSheet("");
this->memoryDock->switchTheme(false);
QSettings settings;
@ -381,20 +399,24 @@ void MainWindow::def_theme() {
* Refresh widget functions
*/
void MainWindow::refreshFunctions() {
void MainWindow::refreshFunctions()
{
this->functionsDock->refreshTree();
}
void MainWindow::refreshComments() {
void MainWindow::refreshComments()
{
this->commentsDock->refreshTree();
}
void MainWindow::refreshFlagspaces() {
void MainWindow::refreshFlagspaces()
{
int cur_idx = this->flagsDock->flagspaceCombo->currentIndex();
if (cur_idx < 0)cur_idx = 0;
this->flagsDock->flagspaceCombo->clear();
this->flagsDock->flagspaceCombo->addItem("(all)");
for (auto i : core->getList("flagspaces")) {
for (auto i : core->getList("flagspaces"))
{
this->flagsDock->flagspaceCombo->addItem(i);
}
if (cur_idx > 0)
@ -402,7 +424,8 @@ void MainWindow::refreshFlagspaces() {
refreshFlags();
}
void MainWindow::refreshFlags() {
void MainWindow::refreshFlags()
{
QString flagspace = this->flagsDock->flagspaceCombo->currentText();
this->omnibar->clearFlags();
if (flagspace == "(all)")
@ -410,13 +433,16 @@ void MainWindow::refreshFlags() {
this->flagsDock->flagsTreeWidget->clear();
for (auto i: core->getList("flags", flagspace)) {
for (auto i : core->getList("flags", flagspace))
{
QStringList a = i.split(",");
if (a.length()>3) {
if (a.length() > 3)
{
appendRow(this->flagsDock->flagsTreeWidget, a[1], a[2], a[0], a[3]);
this->omnibar->fillFlags(a[0]);
}
else if (a.length()>2) {
else if (a.length() > 2)
{
appendRow(this->flagsDock->flagsTreeWidget, a[1], a[2], a[0], "");
this->omnibar->fillFlags(a[0]);
}
@ -426,18 +452,22 @@ void MainWindow::refreshFlags() {
this->omnibar->setupCompleter();
}
void MainWindow::updateFrames() {
void MainWindow::updateFrames()
{
if (core == NULL)
return;
static bool first_time = true;
if (first_time) {
if (first_time)
{
setup_mem();
this->add_output(" > Adding binary information to notepad");
notepadDock->setText("# Binary information\n\n" + core->cmd("i") +
"\n" + core->cmd("ie") + "\n" + core->cmd("iM") + "\n");
//first_time = false;
} else {
}
else
{
refreshMem("");
}
@ -448,7 +478,8 @@ void MainWindow::updateFrames() {
// TODO: make this configurable by the user?
const bool use_scrollperpixel = true;
if (use_scrollperpixel) {
if (use_scrollperpixel)
{
this->flagsDock->flagsTreeWidget->setVerticalScrollMode(spp);
this->symbolsDock->symbolsTreeWidget->setVerticalScrollMode(spp);
this->importsDock->importsTreeWidget->setVerticalScrollMode(spp);
@ -457,7 +488,9 @@ void MainWindow::updateFrames() {
this->relocsDock->relocsTreeWidget->setVerticalScrollMode(spp);
this->memoryDock->xreFromTreeWidget_2->setVerticalScrollMode(spp);
this->memoryDock->xrefToTreeWidget_2->setVerticalScrollMode(spp);
} else {
}
else
{
this->flagsDock->flagsTreeWidget->setVerticalScrollMode(spi);
this->symbolsDock->symbolsTreeWidget->setVerticalScrollMode(spi);
this->importsDock->importsTreeWidget->setVerticalScrollMode(spi);
@ -485,7 +518,8 @@ void MainWindow::updateFrames() {
adjustColumns(this->importsDock->importsTreeWidget);
this->relocsDock->relocsTreeWidget->clear();
for (auto i: core->getList ("bin","relocs")) {
for (auto i : core->getList("bin", "relocs"))
{
QStringList pieces = i.split(",");
if (pieces.length() == 3)
appendRow(this->relocsDock->relocsTreeWidget, pieces[0], pieces[1], pieces[2]);
@ -495,7 +529,8 @@ void MainWindow::updateFrames() {
this->symbolsDock->fillSymbols();
this->stringsDock->stringsTreeWidget->clear();
for (auto i : core->getList ("bin", "strings")) {
for (auto i : core->getList("bin", "strings"))
{
QStringList pieces = i.split(",");
if (pieces.length() == 2)
appendRow(this->stringsDock->stringsTreeWidget, pieces[0], pieces[1]);
@ -504,7 +539,8 @@ void MainWindow::updateFrames() {
this->commentsDock->commentsTreeWidget->clear();
QList<QList<QString>> comments = this->core->getComments();
for (QList<QString> comment: comments) {
for (QList<QString> comment : comments)
{
/*
QString name;
//this->add_debug_output("Comment: " + comment[1] + ": " + comment[0]);
@ -522,11 +558,13 @@ void MainWindow::updateFrames() {
// Add nested comments
QMap<QString, QList<QList<QString>>> cmts = this->core->getNestedComments();
for(auto cmt : cmts.keys()) {
for (auto cmt : cmts.keys())
{
QTreeWidgetItem *item = new QTreeWidgetItem(this->commentsDock->nestedCommentsTreeWidget);
item->setText(0, cmt);
QList<QList<QString>> meow = cmts.value(cmt);
for (int i = 0; i < meow.size(); ++i) {
for (int i = 0; i < meow.size(); ++i)
{
QList<QString> tmp = meow.at(i);
QTreeWidgetItem *it = new QTreeWidgetItem();
it->setText(0, tmp[1]);
@ -538,15 +576,19 @@ void MainWindow::updateFrames() {
adjustColumns(this->commentsDock->nestedCommentsTreeWidget);
// TODO: FIXME: Remove the check for first_time;
if (first_time) {
if (first_time)
{
sectionsWidget->tree->clear();
int row = 0;
for (auto i: core->getList("bin","sections")) {
for (auto i : core->getList("bin", "sections"))
{
QStringList a = i.split(",");
if (a.length()>2) {
if (a.length() > 2)
{
// Fix to work with ARM bins
//if (a[4].startsWith(".")) {
if (a[4].contains(".")) {
if (a[4].contains("."))
{
QString addr = a[1];
QString addr_end = "0x0" + core->itoa(core->math(a[1] + "+" + a[2]));
QString size = QString::number(core->math(a[2]));
@ -554,9 +596,12 @@ void MainWindow::updateFrames() {
this->sectionsWidget->fillSections(row, name, size, addr, addr_end);
// Used to select a color for the sections graph
if (row == 10) {
if (row == 10)
{
row = 0;
} else {
}
else
{
row++;
}
}
@ -578,12 +623,17 @@ void MainWindow::updateFrames() {
void MainWindow::on_actionLock_triggered()
{
doLock = !doLock;
if (doLock) {
foreach (QDockWidget *dockWidget, findChildren<QDockWidget *>()) {
if (doLock)
{
foreach (QDockWidget *dockWidget, findChildren<QDockWidget *>())
{
dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
}
} else {
foreach (QDockWidget *dockWidget, findChildren<QDockWidget *>()) {
}
else
{
foreach (QDockWidget *dockWidget, findChildren<QDockWidget *>())
{
dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
}
}
@ -591,12 +641,17 @@ void MainWindow::on_actionLock_triggered()
void MainWindow::lockUnlock_Docks(bool what)
{
if(what) {
foreach (QDockWidget *dockWidget, findChildren<QDockWidget *>()) {
if (what)
{
foreach (QDockWidget *dockWidget, findChildren<QDockWidget *>())
{
dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
}
} else {
foreach (QDockWidget *dockWidget, findChildren<QDockWidget *>()) {
}
else
{
foreach (QDockWidget *dockWidget, findChildren<QDockWidget *>())
{
dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
}
}
@ -607,12 +662,16 @@ void MainWindow::on_actionLockUnlock_triggered()
{
if (ui->actionLockUnlock->isChecked())
{
foreach (QDockWidget *dockWidget, findChildren<QDockWidget *>()) {
foreach (QDockWidget *dockWidget, findChildren<QDockWidget *>())
{
dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
}
ui->actionLockUnlock->setIcon(QIcon(":/new/prefix1/lock"));
} else {
foreach (QDockWidget *dockWidget, findChildren<QDockWidget *>()) {
}
else
{
foreach (QDockWidget *dockWidget, findChildren<QDockWidget *>())
{
dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
}
ui->actionLockUnlock->setIcon(QIcon(":/new/prefix1/unlock"));
@ -621,11 +680,14 @@ void MainWindow::on_actionLockUnlock_triggered()
void MainWindow::on_actionTabs_triggered()
{
if (ui->centralTabWidget->tabPosition() == QTabWidget::South) {
if (ui->centralTabWidget->tabPosition() == QTabWidget::South)
{
ui->centralTabWidget->setTabPosition(QTabWidget::North);
this->memoryDock->memTabWidget->setTabPosition(QTabWidget::North);
this->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
} else {
}
else
{
ui->centralTabWidget->setTabPosition(QTabWidget::South);
this->memoryDock->memTabWidget->setTabPosition(QTabWidget::South);
this->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::South);
@ -646,9 +708,12 @@ void MainWindow::on_actionMem_triggered()
void MainWindow::on_actionFunctions_triggered()
{
if (this->functionsDock->isVisible()) {
if (this->functionsDock->isVisible())
{
this->functionsDock->close();
} else {
}
else
{
this->functionsDock->show();
this->functionsDock->raise();
}
@ -656,9 +721,12 @@ void MainWindow::on_actionFunctions_triggered()
void MainWindow::on_actionImports_triggered()
{
if (this->importsDock->isVisible()) {
if (this->importsDock->isVisible())
{
this->importsDock->close();
} else {
}
else
{
this->importsDock->show();
this->importsDock->raise();
}
@ -666,9 +734,12 @@ void MainWindow::on_actionImports_triggered()
void MainWindow::on_actionSymbols_triggered()
{
if (this->symbolsDock->isVisible()) {
if (this->symbolsDock->isVisible())
{
this->symbolsDock->close();
} else {
}
else
{
this->symbolsDock->show();
this->symbolsDock->raise();
}
@ -676,9 +747,12 @@ void MainWindow::on_actionSymbols_triggered()
void MainWindow::on_actionReloc_triggered()
{
if (this->relocsDock->isVisible()) {
if (this->relocsDock->isVisible())
{
this->relocsDock->close();
} else {
}
else
{
this->relocsDock->show();
this->relocsDock->raise();
}
@ -686,9 +760,12 @@ void MainWindow::on_actionReloc_triggered()
void MainWindow::on_actionStrings_triggered()
{
if (this->stringsDock->isVisible()) {
if (this->stringsDock->isVisible())
{
this->stringsDock->close();
} else {
}
else
{
this->stringsDock->show();
this->stringsDock->raise();
}
@ -696,9 +773,12 @@ void MainWindow::on_actionStrings_triggered()
void MainWindow::on_actionSections_triggered()
{
if (this->sectionsDock->isVisible()) {
if (this->sectionsDock->isVisible())
{
this->sectionsDock->close();
} else {
}
else
{
this->sectionsDock->show();
this->sectionsDock->raise();
}
@ -706,9 +786,12 @@ void MainWindow::on_actionSections_triggered()
void MainWindow::on_actionFlags_triggered()
{
if (this->flagsDock->isVisible()) {
if (this->flagsDock->isVisible())
{
this->flagsDock->close();
} else {
}
else
{
this->flagsDock->show();
this->flagsDock->raise();
}
@ -716,9 +799,12 @@ void MainWindow::on_actionFlags_triggered()
void MainWindow::on_actionComents_triggered()
{
if (this->commentsDock->isVisible()) {
if (this->commentsDock->isVisible())
{
this->commentsDock->close();
} else {
}
else
{
this->commentsDock->show();
this->commentsDock->raise();
}
@ -726,9 +812,12 @@ void MainWindow::on_actionComents_triggered()
void MainWindow::on_actionNotepad_triggered()
{
if (this->notepadDock->isVisible()) {
if (this->notepadDock->isVisible())
{
this->notepadDock->close();
} else {
}
else
{
this->notepadDock->show();
this->notepadDock->raise();
}
@ -742,13 +831,15 @@ void MainWindow::on_actionAbout_triggered()
void MainWindow::on_consoleInputLineEdit_returnPressed()
{
if (this->core) {
if (this->core)
{
QString input = ui->consoleInputLineEdit->text();
ui->consoleOutputTextEdit->appendPlainText(this->core->cmd(input));
ui->consoleOutputTextEdit->verticalScrollBar()->setValue(ui->consoleOutputTextEdit->verticalScrollBar()->maximum());
// Add new command to history
QCompleter *completer = ui->consoleInputLineEdit->completer();
if ( completer != NULL ) {
if (completer != NULL)
{
QStringListModel *completerModel = (QStringListModel *)(completer->model());
if (completerModel != NULL)
completerModel->setStringList(completerModel->stringList() << input);
@ -764,11 +855,14 @@ void MainWindow::on_showHistoToolButton_clicked()
if (completer == NULL)
return;
if (ui->showHistoToolButton->isChecked()) {
if (ui->showHistoToolButton->isChecked())
{
completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
// Uhm... shouldn't it be called always?
completer->complete();
} else {
}
else
{
completer->setCompletionMode(QCompleter::PopupCompletion);
}
}
@ -783,7 +877,8 @@ void MainWindow::on_actionRefresh_Panels_triggered()
this->updateFrames();
}
void MainWindow::seek(const QString& offset, const QString& name) {
void MainWindow::seek(const QString &offset, const QString &name)
{
if (offset.length() == 0)
return;
if (name != NULL)
@ -796,7 +891,8 @@ void MainWindow::seek(const QString& offset, const QString& name) {
this->memoryDock->disasTextEdit->setFocus();
}
void MainWindow::setup_mem() {
void MainWindow::setup_mem()
{
QString off = this->core->cmd("afo entry0").trimmed();
//graphicsBar->refreshColorBar();
graphicsBar->fillData();
@ -807,7 +903,8 @@ void MainWindow::setup_mem() {
this->memoryDock->setFcnName(off);
}
void MainWindow::refreshMem(QString off) {
void MainWindow::refreshMem(QString off)
{
//add_debug_output("Refreshing to: " + off);
//graphicsBar->refreshColorBar();
this->memoryDock->refreshDisasm(off);
@ -821,7 +918,8 @@ void MainWindow::on_backButton_clicked()
{
this->core->cmd("s-");
QString back_offset = this->core->cmd("s=").split(" > ").last().trimmed();
if (back_offset != "") {
if (back_offset != "")
{
QString fcn = this->core->cmdFunctionAt(back_offset);
this->seek(this->memoryDock->normalizeAddr(back_offset), fcn);
}
@ -829,7 +927,8 @@ void MainWindow::on_backButton_clicked()
void MainWindow::on_actionCalculator_triggered()
{
if (!this->sideBar->isVisible()) {
if (!this->sideBar->isVisible())
{
this->on_actionShow_Hide_mainsidebar_triggered();
}
}
@ -842,7 +941,8 @@ void MainWindow::on_actionCreate_File_triggered()
void MainWindow::on_actionAssembler_triggered()
{
if (!this->sideBar->isVisible()) {
if (!this->sideBar->isVisible())
{
this->on_actionShow_Hide_mainsidebar_triggered();
}
}
@ -859,9 +959,12 @@ void MainWindow::on_actionStart_Web_Server_triggered()
void MainWindow::on_actionConsoleSync_with_core_triggered()
{
if (ui->actionConsoleSync_with_core->isChecked()) {
if (ui->actionConsoleSync_with_core->isChecked())
{
//Enable core syncronization
} else {
}
else
{
// Disable core sync
}
}
@ -928,9 +1031,12 @@ void MainWindow::showDefaultDocks()
void MainWindow::on_actionhide_bottomPannel_triggered()
{
if (ui->centralWidget->isVisible()) {
if (ui->centralWidget->isVisible())
{
ui->centralWidget->hide();
} else {
}
else
{
ui->centralWidget->show();
}
}
@ -1022,18 +1128,24 @@ void MainWindow::on_actionLoad_triggered()
void MainWindow::on_actionShow_Hide_mainsidebar_triggered()
{
if (ui->sideToolBar->isVisible()) {
if (ui->sideToolBar->isVisible())
{
ui->sideToolBar->hide();
} else {
}
else
{
ui->sideToolBar->show();
}
}
void MainWindow::on_actionDashboard_triggered()
{
if (this->dashboardDock->isVisible()) {
if (this->dashboardDock->isVisible())
{
this->dashboardDock->close();
} else {
}
else
{
this->dashboardDock->show();
this->dashboardDock->raise();
}
@ -1047,10 +1159,13 @@ void MainWindow::showSectionsContextMenu(const QPoint &pt)
menu->addAction(ui->actionSectionsHorizontal);
menu->addAction(ui->actionSectionsVertical);
if (this->sectionsWidget->orientation() == 1) {
if (this->sectionsWidget->orientation() == 1)
{
ui->actionSectionsHorizontal->setChecked(true);
ui->actionSectionsVertical->setChecked(false);
} else {
}
else
{
ui->actionSectionsVertical->setChecked(true);
ui->actionSectionsHorizontal->setChecked(false);
}
@ -1074,13 +1189,15 @@ void MainWindow::on_actionForward_triggered()
{
this->core->cmd("s+");
QString offset = this->core->cmd("s=").split(" > ").last().trimmed();
if (offset != "") {
if (offset != "")
{
this->add_debug_output(offset);
this->seek(offset);
}
}
void MainWindow::toggleResponsive(bool maybe) {
void MainWindow::toggleResponsive(bool maybe)
{
this->responsive = maybe;
// Save options in settings
QSettings settings;
@ -1097,7 +1214,8 @@ void MainWindow::on_actionReset_settings_triggered()
QMessageBox::StandardButton ret = QMessageBox::question(this, "Iaito",
"Do you really want to clear all settings?",
QMessageBox::Ok | QMessageBox::Cancel);
if (ret == QMessageBox::Ok) {
if (ret == QMessageBox::Ok)
{
// Save options in settings
QSettings settings;
settings.clear();

View File

@ -35,7 +35,8 @@
#include "newfiledialog.h"
#include "helpers.h"
namespace Ui {
namespace Ui
{
class MainWindow;
}

View File

@ -15,7 +15,8 @@ MdHighlighter::MdHighlighter(QTextDocument *parent)
<< "\\*([^\\\\]+)\\*" << "\\_([^\\\\]+)\\_"
<< "\\_\\_([^\\\\]+)\\_\\_";
foreach (const QString &pattern, keywordPatterns) {
foreach (const QString &pattern, keywordPatterns)
{
rule.pattern = QRegExp(pattern);
rule.format = keywordFormat;
highlightingRules.append(rule);
@ -30,10 +31,12 @@ MdHighlighter::MdHighlighter(QTextDocument *parent)
void MdHighlighter::highlightBlock(const QString &text)
{
foreach (const HighlightingRule &rule, highlightingRules) {
foreach (const HighlightingRule &rule, highlightingRules)
{
QRegExp expression(rule.pattern);
int index = expression.indexIn(text);
while (index >= 0) {
while (index >= 0)
{
int length = expression.matchedLength();
setFormat(index, length, rule.format);
index = expression.indexIn(text, index + length);

View File

@ -10,7 +10,8 @@
const int NewFileDialog::MaxRecentFiles;
static QColor getColorFor(QString str, int pos) {
static QColor getColorFor(QString str, int pos)
{
QNOTUSED(str);
QList<QColor> Colors;
@ -25,7 +26,8 @@ static QColor getColorFor(QString str, int pos) {
}
static QIcon getIconFor(QString str, int pos) {
static QIcon getIconFor(QString str, int pos)
{
// Add to the icon list
int w = 64;
int h = 64;
@ -60,7 +62,8 @@ NewFileDialog::NewFileDialog(QWidget *parent) :
int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
for (int i = 0; i < numRecentFiles; ++i) {
for (int i = 0; i < numRecentFiles; ++i)
{
// Get stored files
//QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
@ -93,11 +96,14 @@ void NewFileDialog::on_loadFileButton_clicked()
// Check that there is a file selected
QString fname = ui->newFileEdit->text();
QFileInfo checkfile(fname);
if (!checkfile.exists() || !checkfile.isFile()) {
if (!checkfile.exists() || !checkfile.isFile())
{
QMessageBox msgBox;
msgBox.setText("Select a new program or a previous one\nbefore continue");
msgBox.exec();
} else {
}
else
{
// Add file to recent file list
QSettings settings;
QStringList files = settings.value("recentFileList").toStringList();
@ -125,7 +131,8 @@ void NewFileDialog::on_newFileButton_clicked()
QString fileName;
fileName = dialog.getOpenFileName(this, "Select file");
if (!fileName.isEmpty()) {
if (!fileName.isEmpty())
{
ui->newFileEdit->setText(fileName);
ui->loadFileButton->setFocus();
}

View File

@ -4,7 +4,8 @@
#include <QDialog>
#include <QListWidgetItem>
namespace Ui {
namespace Ui
{
class NewFileDialog;
}

View File

@ -21,7 +21,8 @@ OptionsDialog::OptionsDialog(QString filename, QWidget *parent):
// Fill the plugins combo
QStringList plugins;
for (auto i: this->core->getList ("asm", "plugins")) {
for (auto i : this->core->getList("asm", "plugins"))
{
this->asm_plugins.append(i);
plugins.append(i);
}
@ -51,7 +52,8 @@ OptionsDialog::~OptionsDialog()
delete ui;
}
void OptionsDialog::setFilename(QString fn, QString shortfn) {
void OptionsDialog::setFilename(QString fn, QString shortfn)
{
this->filename = fn;
this->shortfn = shortfn;
//qDebug() << QFileInfo(fn).fileName();
@ -94,7 +96,8 @@ void OptionsDialog::on_okButton_clicked()
ut64 mapaddr = 0LL;
int bits = 0;
QString sel_bits = ui->bitsComboBox->currentText();
if (sel_bits != "Auto") {
if (sel_bits != "Auto")
{
bits = sel_bits.toInt();
}
@ -102,51 +105,69 @@ void OptionsDialog::on_okButton_clicked()
QSettings settings;
// Show asm bytes
if (ui->bytesCheckBox->isChecked()) {
if (ui->bytesCheckBox->isChecked())
{
this->w->core->config("asm.bytes", "true");
this->w->core->config("asm.cmtcol", "100");
} else {
}
else
{
this->w->core->config("asm.bytes", "false");
this->w->core->config("asm.cmtcol", "70");
}
settings.setValue("bytes", ui->bytesCheckBox->isChecked());
// Show AT&T syntax
if (ui->attCheckBox->isChecked()) {
if (ui->attCheckBox->isChecked())
{
this->w->core->config("asm.syntax", "att");
} else {
}
else
{
this->w->core->config("asm.syntax", "intel");
}
settings.setValue("syntax", ui->attCheckBox->isChecked());
// Show opcode description
if (ui->descriptionCheckBox->isChecked()) {
if (ui->descriptionCheckBox->isChecked())
{
this->w->core->config("asm.describe", "true");
} else {
}
else
{
this->w->core->config("asm.describe", "false");
}
settings.setValue("describe", ui->descriptionCheckBox->isChecked());
// Show stack pointer
if (ui->stackCheckBox->isChecked()) {
if (ui->stackCheckBox->isChecked())
{
this->w->core->config("asm.stackptr", "true");
} else {
}
else
{
this->w->core->config("asm.stackptr", "false");
}
settings.setValue("stackptr", ui->stackCheckBox->isChecked());
// Show uppercase dasm
if (ui->ucaseCheckBox->isChecked()) {
if (ui->ucaseCheckBox->isChecked())
{
this->w->core->config("asm.ucase", "true");
} else {
}
else
{
this->w->core->config("asm.ucase", "false");
}
settings.setValue("ucase", ui->ucaseCheckBox->isChecked());
// Show spaces in dasm
if (ui->spacyCheckBox->isChecked()) {
if (ui->spacyCheckBox->isChecked())
{
this->w->core->config("asm.spacy", "true");
} else {
}
else
{
this->w->core->config("asm.spacy", "false");
}
settings.setValue("spacy", ui->spacyCheckBox->isChecked());
@ -154,14 +175,18 @@ void OptionsDialog::on_okButton_clicked()
bool rw = false;
bool load_bininfo = ui->binCheckBox->isChecked();
if (load_bininfo) {
if (!va) {
if (load_bininfo)
{
if (!va)
{
va = 2;
loadaddr = UT64_MAX;
r_config_set_i(this->core->core()->config, "bin.laddr", loadaddr);
mapaddr = 0;
}
} else {
}
else
{
va = false;
loadaddr = mapaddr = 0;
}
@ -181,7 +206,8 @@ void OptionsDialog::on_okButton_clicked()
// connect signal/slot
int level = 0;
if (anal_level == true) {
if (anal_level == true)
{
level = ui->analSlider->value();
}
@ -201,9 +227,12 @@ void OptionsDialog::anal_finished()
ui->statusLabel->setText("Loading interface");
this->w->add_output(" > Analysis finished");
QString initial_seek = ui->entry_initialSeek->text();
if (initial_seek.length()>0) {
if (initial_seek.length() > 0)
{
this->w->core->seek(initial_seek);
} else {
}
else
{
this->w->core->seek("entry0");
}
this->w->add_output(" > Populating UI");
@ -215,7 +244,8 @@ void OptionsDialog::anal_finished()
// Restore project notes
QString notes = this->core->cmd("Pn");
//qDebug() << "Notes:" << notes;
if (notes != "") {
if (notes != "")
{
QByteArray ba;
ba.append(notes);
this->w->notepadDock->notesTextEdit->setPlainText(QByteArray::fromBase64(ba));
@ -250,9 +280,12 @@ void OptionsDialog::on_cancelButton_clicked()
void OptionsDialog::on_analSlider_valueChanged(int value)
{
ui->analLevel->setText(QString::number(value));
if (value == 0) {
if (value == 0)
{
ui->analCheckBox->setChecked(false);
} else {
}
else
{
ui->analCheckBox->setChecked(true);
}
}
@ -263,7 +296,9 @@ void OptionsDialog::on_AdvOptButton_clicked()
{
ui->hideFrame->setVisible(true);
ui->AdvOptButton->setArrowType(Qt::DownArrow);
} else {
}
else
{
ui->hideFrame->setVisible(false);
ui->AdvOptButton->setArrowType(Qt::RightArrow);

View File

@ -9,7 +9,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class OptionsDialog;
}

View File

@ -61,13 +61,15 @@ QRCore::QRCore(QObject *parent) :
this->db = sdb_new(NULL, NULL, 0); // WTF NOES
}
QList<QString> QRCore::getFunctionXrefs(ut64 addr) {
QList<QString> QRCore::getFunctionXrefs(ut64 addr)
{
CORE_LOCK();
QList<QString> ret = QList<QString>();
RList *list = r_anal_xrefs_get(core_->anal, addr);
RAnalRef *ref;
RListIter *it;
QRListForeach (list, it, RAnalRef, ref) {
QRListForeach(list, it, RAnalRef, ref)
{
ret << QString("%1,0x%2,0x%3").arg(
QString(ref->type),
QString::number(ref->addr, 16),
@ -76,19 +78,22 @@ QList<QString> QRCore::getFunctionXrefs(ut64 addr) {
return ret;
}
QList<QString> QRCore::getFunctionRefs(ut64 addr, char type) {
QList<QString> QRCore::getFunctionRefs(ut64 addr, char type)
{
CORE_LOCK();
QList<QString> ret = QList<QString>();
//RAnalFunction *fcn = r_anal_get_fcn_at(core_->anal, addr, addr);
RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0);
if (!fcn) {
if (!fcn)
{
eprintf("qcore->getFunctionRefs: No function found\n");
return ret;
}
//eprintf(fcn->name);
RAnalRef *ref;
RListIter *it;
QRListForeach (fcn->refs, it, RAnalRef, ref) {
QRListForeach(fcn->refs, it, RAnalRef, ref)
{
if (type == ref->type || type == 0)
ret << QString("%1,0x%2,0x%3").arg(
QString(ref->type),
@ -98,42 +103,53 @@ QList<QString> QRCore::getFunctionRefs(ut64 addr, char type) {
return ret;
}
int QRCore::getCycloComplex(ut64 addr) {
int QRCore::getCycloComplex(ut64 addr)
{
CORE_LOCK();
QString ret = "";
RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0);
if (fcn) {
if (fcn)
{
ret = cmd("afcc @ " + QString(fcn->name));
return ret.toInt();
} else {
}
else
{
eprintf("qcore->getCycloComplex: no fcn found");
return 0;
}
}
int QRCore::getFcnSize(ut64 addr) {
int QRCore::getFcnSize(ut64 addr)
{
CORE_LOCK();
QString ret = "";
QString tmp_ret = "";
RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0);
if (fcn) {
if (fcn)
{
tmp_ret = cmd("afi~size[1] " + QString(fcn->name));
ret = tmp_ret.split("\n")[0];
return ret.toInt() / 10;
} else {
}
else
{
eprintf("qcore->getFcnSize: no fcn found");
return 0;
}
}
QList<QString> QRCore::sdbList(QString path) {
QList<QString> QRCore::sdbList(QString path)
{
CORE_LOCK();
QList<QString> list = QList<QString>();
Sdb *root = sdb_ns_path(core_->sdb, path.toUtf8().constData(), 0);
if (root) {
if (root)
{
void *vsi;
ls_iter_t *iter;
ls_foreach(root->ns, iter, vsi) {
ls_foreach(root->ns, iter, vsi)
{
SdbNs *nsi = (SdbNs *)vsi;
list << nsi->name;
}
@ -141,15 +157,18 @@ QList<QString> QRCore::sdbList(QString path) {
return list;
}
QList<QString> QRCore::sdbListKeys(QString path) {
QList<QString> QRCore::sdbListKeys(QString path)
{
CORE_LOCK();
QList<QString> list = QList<QString>();
Sdb *root = sdb_ns_path(core_->sdb, path.toUtf8().constData(), 0);
if (root) {
if (root)
{
void *vsi;
ls_iter_t *iter;
SdbList *l = sdb_foreach_list(root, false);
ls_foreach(l, iter, vsi) {
ls_foreach(l, iter, vsi)
{
SdbKv *nsi = (SdbKv *)vsi;
list << nsi->key;
}
@ -157,10 +176,12 @@ QList<QString> QRCore::sdbListKeys(QString path) {
return list;
}
QString QRCore::sdbGet(QString path, QString key) {
QString QRCore::sdbGet(QString path, QString key)
{
CORE_LOCK();
Sdb *db = sdb_ns_path(core_->sdb, path.toUtf8().constData(), 0);
if (db) {
if (db)
{
const char *val = sdb_const_get(db, key.toUtf8().constData(), 0);
if (val && *val)
return val;
@ -168,19 +189,22 @@ QString QRCore::sdbGet(QString path, QString key) {
return QString("");
}
bool QRCore::sdbSet(QString path, QString key, QString val) {
bool QRCore::sdbSet(QString path, QString key, QString val)
{
CORE_LOCK();
Sdb *db = sdb_ns_path(core_->sdb, path.toUtf8().constData(), 1);
if (!db) return false;
return sdb_set(db, key.toUtf8().constData(), val.toUtf8().constData(), 0);
}
QRCore::~QRCore() {
QRCore::~QRCore()
{
r_core_free(this->core_);
r_cons_free();
}
QString QRCore::cmd(const QString &str) {
QString QRCore::cmd(const QString &str)
{
CORE_LOCK();
QByteArray cmd = str.toUtf8();
//r_cons_flush();
@ -191,7 +215,8 @@ QString QRCore::cmd(const QString &str) {
return o;
}
bool QRCore::loadFile(QString path, uint64_t loadaddr=0LL, uint64_t mapaddr=0LL, bool rw=false, int va=0, int bits = 0, int idx, bool loadbin) {
bool QRCore::loadFile(QString path, uint64_t loadaddr = 0LL, uint64_t mapaddr = 0LL, bool rw = false, int va = 0, int bits = 0, int idx, bool loadbin)
{
QNOTUSED(loadaddr);
QNOTUSED(idx);
@ -204,49 +229,70 @@ bool QRCore::loadFile(QString path, uint64_t loadaddr=0LL, uint64_t mapaddr=0LL,
// mapaddr = 0LL;
printf("FILE OPEN (%s)\n", path.toUtf8().constData());
f = r_core_file_open(core_, path.toUtf8().constData(), rw ? (R_IO_READ | R_IO_WRITE) : R_IO_READ, mapaddr);
if (!f) {
if (!f)
{
eprintf("r_core_file_open failed\n");
return false;
}
if (loadbin) {
if (va==1) {
if (r_core_bin_load (core_, path.toUtf8().constData(), UT64_MAX)) {
if (loadbin)
{
if (va == 1)
{
if (r_core_bin_load(core_, path.toUtf8().constData(), UT64_MAX))
{
RBinObject *obj = r_bin_get_object(core_->bin);
if (obj) {
if (obj)
{
eprintf("BITS %d\n", obj->info->bits);
}
} else {
}
else
{
eprintf("CANNOT GET RBIN INFO\n");
}
} else {
if (r_core_bin_load (core_, path.toUtf8().constData(), UT64_MAX)) {
}
else
{
if (r_core_bin_load(core_, path.toUtf8().constData(), UT64_MAX))
{
RBinObject *obj = r_bin_get_object(core_->bin);
if (obj) {
if (obj)
{
eprintf("BITS %d\n", obj->info->bits);
} else {
}
else
{
eprintf("Bin load failed\n");
return false;
}
} else {
}
else
{
eprintf("CANNOT GET RBIN INFO\n");
}
}
if (bits != 0) {
if (bits != 0)
{
r_config_set_i(core_->config, "asm.bits", bits);
}
#if HAVE_MULTIPLE_RBIN_FILES_INSIDE_SELECT_WHICH_ONE
if (!r_core_file_open (core, path.toUtf8(), R_IO_READ|rw?R_IO_WRITE:0, mapaddr)) {
if (!r_core_file_open(core, path.toUtf8(), R_IO_READ | rw ? R_IO_WRITE : 0, mapaddr))
{
eprintf("Cannot open file\n");
} else {
}
else
{
// load RBin information
// XXX only for sub-bins
r_core_bin_load(core, path.toUtf8(), loadaddr);
r_bin_select_idx(core_->bin, NULL, idx);
}
#endif
} else {
}
else
{
// Not loading RBin info coz va = false
}
r_core_hash_load(core_, path.toUtf8().constData());
@ -254,7 +300,8 @@ bool QRCore::loadFile(QString path, uint64_t loadaddr=0LL, uint64_t mapaddr=0LL,
return true;
}
void QRCore::analyze(int level) {
void QRCore::analyze(int level)
{
CORE_LOCK();
/*
* Levels
@ -264,38 +311,51 @@ void QRCore::analyze(int level) {
* Nivel 4: aaaa
*/
if (level == 1) {
if (level == 1)
{
r_core_cmd0(core_, "afr@entry0;afr@main");
} else if (level == 2) {
}
else if (level == 2)
{
r_core_cmd0(core_, "aa");
} else if (level == 3) {
}
else if (level == 3)
{
r_core_cmd0(core_, "aaa");
} else if (level == 4) {
}
else if (level == 4)
{
r_core_cmd0(core_, "aaaa");
}
}
void QRCore::renameFunction(QString prev_name, QString new_name) {
void QRCore::renameFunction(QString prev_name, QString new_name)
{
cmd("afn " + new_name + " " + prev_name);
}
void QRCore::setComment(QString addr, QString cmt) {
void QRCore::setComment(QString addr, QString cmt)
{
//r_meta_add (core->anal, 'C', addr, 1, cmt.toUtf8());
cmd("CC " + cmt + " @ " + addr);
}
void QRCore::delComment(ut64 addr) {
void QRCore::delComment(ut64 addr)
{
CORE_LOCK();
r_meta_del(core_->anal, 'C', addr, 1, NULL);
//cmd (QString("CC-@")+addr);
}
QList<QList<QString>> QRCore::getComments() {
QList<QList<QString>> QRCore::getComments()
{
QList<QList<QString>> ret;
QString comments = cmd("CC~CCu");
for (QString line: comments.split ("\n")) {
for (QString line : comments.split("\n"))
{
QStringList fields = line.split("CCu");
if (fields.length() == 2) {
if (fields.length() == 2)
{
QList<QString> tmp = QList<QString>();
tmp << fields[1].split("\"")[1].trimmed();
tmp << fields[0].trimmed();
@ -305,20 +365,26 @@ QList<QList<QString>> QRCore::getComments() {
return ret;
}
QMap<QString, QList<QList<QString>>> QRCore::getNestedComments() {
QMap<QString, QList<QList<QString>>> QRCore::getNestedComments()
{
QMap<QString, QList<QList<QString>>> ret;
QString comments = cmd("CC~CCu");
for (QString line: comments.split ("\n")) {
for (QString line : comments.split("\n"))
{
QStringList fields = line.split("CCu");
if (fields.length() == 2) {
if (fields.length() == 2)
{
QList<QString> tmp = QList<QString>();
tmp << fields[1].split("\"")[1].trimmed();
tmp << fields[0].trimmed();
QString fcn_name = this->cmdFunctionAt(fields[0].trimmed());
if (ret.contains(fcn_name)) {
if (ret.contains(fcn_name))
{
ret[fcn_name].append(tmp);
} else {
}
else
{
ret[fcn_name].append(tmp);
}
}
@ -326,23 +392,27 @@ QMap<QString, QList<QList<QString>>> QRCore::getNestedComments() {
return ret;
}
void QRCore::seek(QString addr) {
void QRCore::seek(QString addr)
{
if (addr.length() > 0)
seek(this->math(addr.toUtf8().constData()));
}
void QRCore::seek(ut64 addr) {
void QRCore::seek(ut64 addr)
{
CORE_LOCK();
r_core_seek(this->core_, addr, true);
}
bool QRCore::tryFile(QString path, bool rw) {
bool QRCore::tryFile(QString path, bool rw)
{
CORE_LOCK();
RCoreFile *cf;
int flags = R_IO_READ;
if (rw) flags |= R_IO_WRITE;
cf = r_core_file_open(this->core_, path.toUtf8().constData(), flags, 0LL);
if (!cf) {
if (!cf)
{
eprintf("QRCore::tryFile: Cannot open file?\n");
return false;
}
@ -358,118 +428,168 @@ bool QRCore::tryFile(QString path, bool rw) {
return true;
}
QList<QString> QRCore::getList(const QString & type, const QString & subtype) {
QList<QString> QRCore::getList(const QString &type, const QString &subtype)
{
CORE_LOCK();
RListIter *it;
QList<QString> ret = QList<QString>();
if (type == "bin") {
if (subtype == "sections") {
if (type == "bin")
{
if (subtype == "sections")
{
QString text = cmd("S*~^S");
for (QString i: text.split ("\n")) {
for (QString i : text.split("\n"))
{
ret << i.mid(2).replace(" ", ",");
}
} else if (subtype == "types") {
}
else if (subtype == "types")
{
ret << "raw";
auto ft = sdb_const_get(DB, "try.filetype", 0);
if (ft && *ft)
ret << ft;
} else if (subtype == "imports") {
}
else if (subtype == "imports")
{
QStringList lines = this->cmd("ii").split("\n");
foreach (QString line, lines) {
foreach (QString line, lines)
{
QStringList tmp = line.split(" ");
if (tmp.length() > 2) {
if (tmp.length() > 2)
{
QString final;
foreach (QString field, tmp) {
foreach (QString field, tmp)
{
QString value = field.split("=")[1];
final.append(value + ",");
}
ret << final;
}
}
} else if (subtype == "entrypoints") {
}
else if (subtype == "entrypoints")
{
if (math("entry0") != 0)
ret << "entry0";
} else if (subtype == "relocs") {
}
else if (subtype == "relocs")
{
RBinReloc *br;
if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) {
QRListForeach (core_->bin->cur->o->relocs, it, RBinReloc, br) {
if (br->import) {
if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o)
{
QRListForeach(core_->bin->cur->o->relocs, it, RBinReloc, br)
{
if (br->import)
{
// TODO: we want the offset too!
QString type = (br->additive ? "ADD_" : "SET_") + QString::number(br->type);
ret << QString("0x%1,%2,%3").arg(QString::number(br->vaddr, 16), type, br->import->name);
} else {
}
else
{
// TODO: we want the offset too!
QString type = (br->additive ? "ADD_" : "SET_") + QString::number(br->type);
ret << QString("0x%1,%2,reloc_%3").arg(QString::number(br->vaddr, 16), type, QString::number(br->vaddr, 16));
}
}
}
} else if (subtype == "symbols") {
}
else if (subtype == "symbols")
{
RBinSymbol *bs;
if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) {
QRListForeach (core_->bin->cur->o->symbols, it, RBinSymbol, bs) {
if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o)
{
QRListForeach(core_->bin->cur->o->symbols, it, RBinSymbol, bs)
{
QString type = QString(bs->bind) + " " + QString(bs->type);
ret << QString("0x%1,%2,%3").arg(QString::number(bs->vaddr, 16), type, bs->name);
}
/* list entrypoints as symbols too */
int n = 0;
RBinAddr *entry;
QRListForeach (core_->bin->cur->o->entries, it, RBinAddr, entry) {
QRListForeach(core_->bin->cur->o->entries, it, RBinAddr, entry)
{
ret << QString("0x%1,%2,%3%4").arg(QString::number(entry->vaddr, 16), "entry", "entry", QString::number(n++));
}
}
} else if (subtype == "strings") {
}
else if (subtype == "strings")
{
RBinString *bs;
if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o) {
QRListForeach (core_->bin->cur->o->strings, it, RBinString, bs) {
if (core_ && core_->bin && core_->bin->cur && core_->bin->cur->o)
{
QRListForeach(core_->bin->cur->o->strings, it, RBinString, bs)
{
ret << QString("0x%1,%2").arg(QString::number(bs->vaddr, 16), bs->string);
}
}
}
} else if (type == "asm") {
if (subtype == "plugins") {
}
else if (type == "asm")
{
if (subtype == "plugins")
{
RAsmPlugin *ap;
QRListForeach (core_->assembler->plugins, it, RAsmPlugin, ap) {
QRListForeach(core_->assembler->plugins, it, RAsmPlugin, ap)
{
ret << ap->name;
}
} else if (subtype == "cpus") {
}
else if (subtype == "cpus")
{
QString funcs = cmd("e asm.cpu=?");
QStringList lines = funcs.split("\n");
for (auto cpu : lines) {
for (auto cpu : lines)
{
ret << cpu;
}
}
} else if (type == "anal") {
if (subtype == "plugins") {
}
else if (type == "anal")
{
if (subtype == "plugins")
{
RAnalPlugin *ap;
QRListForeach (core_->anal->plugins, it, RAnalPlugin, ap) {
QRListForeach(core_->anal->plugins, it, RAnalPlugin, ap)
{
ret << ap->name;
}
} else if (subtype == "functions") {
}
else if (subtype == "functions")
{
QString funcs = cmd("afl");
QStringList lines = funcs.split("\n");
for (auto i : lines) {
if (i != "") {
for (auto i : lines)
{
if (i != "")
{
ret << i.replace(" ", ",").replace(",,", ",").replace(",,", ",").replace(",,", ",");
}
}
}
} else if (type == "flagspaces") {
}
else if (type == "flagspaces")
{
QStringList lines = cmd("fs*").split("\n");
for (auto i : lines) {
for (auto i : lines)
{
QStringList a = i.replace("*", "").split(" ");
if (a.length() > 1)
ret << a[1];
}
} else if (type == "flags") {
}
else if (type == "flags")
{
if (subtype != NULL && subtype != "")
cmd("fs " + subtype);
else cmd("fs *");
QString flags = cmd("f*");
QStringList lines = flags.split("\n");
for (auto i : lines) {
for (auto i : lines)
{
if (i[0] != 0 && i[1] == 's') continue; // skip 'fs ..'
ret << i.mid(2).replace(" ", ",");
}
@ -477,12 +597,14 @@ QList<QString> QRCore::getList(const QString & type, const QString & subtype) {
return ret;
}
ut64 QRCore::math(const QString &expr) {
ut64 QRCore::math(const QString &expr)
{
CORE_LOCK();
return r_num_math(this->core_ ? this->core_->num : NULL, expr.toUtf8().constData());
}
int QRCore::fcnCyclomaticComplexity(ut64 addr) {
int QRCore::fcnCyclomaticComplexity(ut64 addr)
{
CORE_LOCK();
RAnalFunction *fcn = r_anal_get_fcn_at(core_->anal, addr, addr);
if (fcn)
@ -490,24 +612,29 @@ int QRCore::fcnCyclomaticComplexity(ut64 addr) {
return 0;
}
int QRCore::fcnBasicBlockCount(ut64 addr) {
int QRCore::fcnBasicBlockCount(ut64 addr)
{
CORE_LOCK();
//RAnalFunction *fcn = r_anal_get_fcn_at (core_->anal, addr, addr);
RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, addr, 0);
if (fcn) {
if (fcn)
{
return r_list_length(fcn->bbs);
}
return 0;
}
int QRCore::fcnEndBbs(QString addr) {
int QRCore::fcnEndBbs(QString addr)
{
CORE_LOCK();
bool ok;
int offset = addr.toLong(&ok, 16);
RAnalFunction *fcn = r_anal_get_fcn_in(core_->anal, offset, 0);
if (fcn) {
if (fcn)
{
QString tmp = this->cmd("afi @ " + addr + " ~end-bbs").split("\n")[0];
if (tmp.contains(":")) {
if (tmp.contains(":"))
{
QString endbbs = tmp.split(": ")[1];
return endbbs.toInt();
}
@ -516,31 +643,37 @@ int QRCore::fcnEndBbs(QString addr) {
return 0;
}
QString QRCore::itoa(ut64 num, int rdx) {
QString QRCore::itoa(ut64 num, int rdx)
{
return QString::number(num, rdx);
}
QString QRCore::config(const QString &k, const QString &v) {
QString QRCore::config(const QString &k, const QString &v)
{
CORE_LOCK();
QByteArray key = k.toUtf8();
if (v!=NULL) {
if (v != NULL)
{
r_config_set(core_->config, key.constData(), v.toUtf8().constData());
return NULL;
}
return QString(r_config_get(core_->config, key.constData()));
}
int QRCore::config(const QString &k, int v) {
int QRCore::config(const QString &k, int v)
{
CORE_LOCK();
QByteArray key = k.toUtf8();
if (v!=-1) {
if (v != -1)
{
r_config_set_i(core_->config, key.constData(), v);
return 0;
}
return r_config_get_i(core_->config, key.constData());
}
void QRCore::setOptions(QString key) {
void QRCore::setOptions(QString key)
{
QNOTUSED(key);
// va
@ -552,24 +685,28 @@ void QRCore::setOptions(QString key) {
// anal plugin
}
void QRCore::setCPU (QString arch, QString cpu, int bits, bool temporary=false) {
void QRCore::setCPU(QString arch, QString cpu, int bits, bool temporary = false)
{
config("asm.arch", arch);
config("asm.cpu", cpu);
config("asm.bits", bits);
if (!temporary) {
if (!temporary)
{
default_arch = arch;
default_cpu = cpu;
default_bits = bits;
}
}
void QRCore::setDefaultCPU() {
void QRCore::setDefaultCPU()
{
config("asm.arch", default_arch);
config("asm.cpu", default_cpu);
config("asm.bits", QString::number(default_bits));
}
QString QRCore::assemble(const QString &code) {
QString QRCore::assemble(const QString &code)
{
CORE_LOCK();
RAsmCode *ac = r_asm_massemble(core_->assembler, code.toUtf8().constData());
QString hex(ac != nullptr ? ac->buf_hex : "");
@ -577,7 +714,8 @@ QString QRCore::assemble(const QString &code) {
return hex;
}
QString QRCore::disassemble(const QString &hex) {
QString QRCore::disassemble(const QString &hex)
{
CORE_LOCK();
RAsmCode *ac = r_asm_mdisassemble_hexstr(core_->assembler, hex.toUtf8().constData());
QString code = QString(ac != nullptr ? ac->buf_asm : "");
@ -585,13 +723,15 @@ QString QRCore::disassemble(const QString &hex) {
return code;
}
RAnalFunction* QRCore::functionAt(ut64 addr) {
RAnalFunction *QRCore::functionAt(ut64 addr)
{
CORE_LOCK();
//return r_anal_fcn_find (core_->anal, addr, addr);
return r_anal_get_fcn_in(core_->anal, addr, 0);
}
QString QRCore::cmdFunctionAt(QString addr) {
QString QRCore::cmdFunctionAt(QString addr)
{
QString ret;
//afi~name:1[1] @ 0x08048e44
//ret = cmd("afi~name[1] @ " + addr);
@ -619,10 +759,13 @@ QList<QList<QString>> QRCore::get_exec_sections()
QList<QList<QString>> ret;
QString text = cmd("S*~^S");
for (QString line: text.split ("\n")) {
for (QString line : text.split("\n"))
{
QStringList fields = line.split(" ");
if (fields.length() == 7) {
if (fields[6].contains("x")) {
if (fields.length() == 7)
{
if (fields[6].contains("x"))
{
QList<QString> tmp = QList<QString>();
tmp << fields[2];
tmp << fields[3];
@ -634,21 +777,25 @@ QList<QList<QString>> QRCore::get_exec_sections()
return ret;
}
QString QRCore::getOffsetInfo(QString addr) {
QString QRCore::getOffsetInfo(QString addr)
{
return cmd("ao @ " + addr);
}
QString QRCore::getOffsetJump(QString addr) {
QString QRCore::getOffsetJump(QString addr)
{
QString ret = "";
ret = cmd("ao @" + addr + "~jump[1]");
return ret;
}
QString QRCore::getDecompiledCode(QString addr) {
QString QRCore::getDecompiledCode(QString addr)
{
return cmd("pdc @ " + addr);
}
QString QRCore::getFileInfo() {
QString QRCore::getFileInfo()
{
QString info;
info = cmd("ij");
@ -656,7 +803,8 @@ QString QRCore::getFileInfo() {
return info;
}
QStringList QRCore::getStats() {
QStringList QRCore::getStats()
{
QStringList stats;
cmd("fs functions");
stats << cmd("f~?").trimmed();
@ -678,7 +826,8 @@ QStringList QRCore::getStats() {
return stats;
}
QString QRCore::getSimpleGraph(QString function) {
QString QRCore::getSimpleGraph(QString function)
{
// New styles
QString graph = "graph [bgcolor=invis, splines=polyline];";
@ -700,7 +849,8 @@ QString QRCore::getSimpleGraph(QString function) {
return dot;
}
void QRCore::getOpcodes() {
void QRCore::getOpcodes()
{
QString opcodes = cmd("?O");
this->opcodes = opcodes.split("\n");
// Remove the last empty element
@ -710,7 +860,8 @@ void QRCore::getOpcodes() {
this->regs.removeLast();
}
void QRCore::setSettings() {
void QRCore::setSettings()
{
config("scr.color", "false");
config("scr.interactive", "false");
config("asm.lines", "false");

View File

@ -8,7 +8,8 @@ QRDisasm::QRDisasm(QRCore *core)
this->core = core;
}
bool QRDisasm::disassembleAt (ut64 addr, QRDisasmOption opt, QRDisasmRow &dr) {
bool QRDisasm::disassembleAt(ut64 addr, QRDisasmOption opt, QRDisasmRow &dr)
{
QNOTUSED(addr);
QNOTUSED(opt);
QNOTUSED(dr);

View File

@ -3,14 +3,16 @@
#include <qrcore.h>
enum QRDisasmDataType {
enum QRDisasmDataType
{
STRING = 'z',
STRUCT = 's',
DATA = 'd',
};
enum QRDisasmOption {
enum QRDisasmOption
{
DWARF = 1 << 1,
REFS = 1 << 2,
ESIL = 1 << 3,

View File

@ -12,7 +12,8 @@ WebServerThread::WebServerThread(QRCore *core, QObject *parent) :
WebServerThread::~WebServerThread()
{
if (isRunning()) {
if (isRunning())
{
quit();
wait();
}
@ -22,7 +23,8 @@ void WebServerThread::startServer()
{
assert(nullptr != core);
if (!isRunning() && !started) {
if (!isRunning() && !started)
{
QThread::start();
}
}
@ -43,7 +45,8 @@ bool WebServerThread::isStarted() const
return started;
}
void WebServerThread::run() {
void WebServerThread::run()
{
QMutexLocker locker(&mutex);
if (core == nullptr)
@ -63,13 +66,16 @@ void WebServerThread::toggleWebServer()
// "=h*", "", "restart current webserver",
// "=h&", " port", "start http server in background)",
if (started) {
if (started)
{
// after this the only reaction to this commands is:
// sandbox: connect disabled
// and the webserver is still running
// TODO: find out why
core->cmd("=h-");
} else {
}
else
{
core->cmd("=h&");
}

View File

@ -41,14 +41,16 @@ GraphicsBar::GraphicsBar(MainWindow *main, QWidget *parent) :
//addWidget(addsCombo);
}
void GraphicsBar::paintEvent(QPaintEvent *event) {
void GraphicsBar::paintEvent(QPaintEvent *event)
{
QNOTUSED(event);
QPainter painter(this);
this->fillData();
}
void GraphicsBar::fillData() {
void GraphicsBar::fillData()
{
// Prepare the graph scene
int w = this->codeGraphic->width();
@ -67,10 +69,12 @@ void GraphicsBar::fillData() {
QString jsonData = this->main->core->cmd("p-j");
QJsonDocument doc = QJsonDocument::fromJson(jsonData.toUtf8());
if (doc.isNull()) {
if (doc.isNull())
{
qDebug() << "Invalid json in p-j command";
}
else if (doc.isObject()) {
else if (doc.isObject())
{
//get the jsonObject
QJsonObject jObject = doc.object();
@ -82,15 +86,18 @@ void GraphicsBar::fillData() {
int block = mainMap["blocksize"].toInt();
int size = (to - from);
int num = size / block;
if (num < 1) {
if (num < 1)
{
num = 1;
}
int graph_block = w / num;
int counter = 0;
for (auto i : mainMap["blocks"].toList()) {
for (auto i : mainMap["blocks"].toList())
{
QMap<QString, QVariant> map = i.toMap();
if (map.empty()) {
if (map.empty())
{
// Fill empty color
// addRect(qreal x, qreal y, qreal w, qreal h, const QPen &pen = QPen(), const QBrush &brush = QBrush())
//scene->addRect(counter * graph_block, 0, graph_block ,h, QPen(Qt::NoPen), QBrush(QColor(252, 249, 190)));
@ -99,14 +106,19 @@ void GraphicsBar::fillData() {
rect->setBrush(QBrush(QColor(252, 249, 190)));
rect->setToolTip("Data");
scene->addItem(rect);
} else {
}
else
{
// Fill type of color
//scene->addRect(counter * graph_block, 0, graph_block ,h, QPen(Qt::NoPen), QBrush(QColor(69, 104, 229)));
QGraphicsRectItem *rect = new QGraphicsRectItem(counter * graph_block, 0, graph_block, h);
rect->setPen(Qt::NoPen);
if (i.toMap()["functions"].toInt() == 0) {
if (i.toMap()["functions"].toInt() == 0)
{
rect->setBrush(QBrush(QColor(190, 190, 190)));
} else {
}
else
{
rect->setBrush(QBrush(QColor(69, 104, 229)));
}
rect->setToolTip("Offset: 0x" + QString::number(i.toMap()["offset"].toInt(), 16) + "\nFunctions: " + QString::number(i.toMap()["functions"].toInt()) + "\nFlags: " + QString::number(i.toMap()["flags"].toInt()));

View File

@ -48,10 +48,12 @@ void CommentsWidget::on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *it
this->main->seek(offset, name);
}
void CommentsWidget::refreshTree() {
void CommentsWidget::refreshTree()
{
this->commentsTreeWidget->clear();
QList<QList<QString>> comments = this->main->core->getComments();
for (QList<QString> comment: comments) {
for (QList<QString> comment : comments)
{
this->main->add_debug_output(comment[1]);
QString fcn_name = this->main->core->cmdFunctionAt(comment[1]);
this->main->appendRow(this->commentsTreeWidget, comment[1], fcn_name, comment[0].remove('"'));
@ -61,11 +63,13 @@ void CommentsWidget::refreshTree() {
// Add nested comments
this->nestedCommentsTreeWidget->clear();
QMap<QString, QList<QList<QString>>> cmts = this->main->core->getNestedComments();
for(auto cmt : cmts.keys()) {
for (auto cmt : cmts.keys())
{
QTreeWidgetItem *item = new QTreeWidgetItem(this->nestedCommentsTreeWidget);
item->setText(0, cmt);
QList<QList<QString>> meow = cmts.value(cmt);
for (int i = 0; i < meow.size(); ++i) {
for (int i = 0; i < meow.size(); ++i)
{
QList<QString> tmp = meow.at(i);
QTreeWidgetItem *it = new QTreeWidgetItem();
it->setText(0, tmp[1]);
@ -95,10 +99,13 @@ void CommentsWidget::showTitleContextMenu(const QPoint &pt)
menu->addAction(ui->actionHorizontal);
menu->addAction(ui->actionVertical);
if (ui->tabWidget->currentIndex() == 0) {
if (ui->tabWidget->currentIndex() == 0)
{
ui->actionHorizontal->setChecked(true);
ui->actionVertical->setChecked(false);
} else {
}
else
{
ui->actionVertical->setChecked(true);
ui->actionHorizontal->setChecked(false);
}
@ -119,17 +126,23 @@ void CommentsWidget::on_actionVertical_triggered()
ui->tabWidget->setCurrentIndex(1);
}
bool CommentsWidget::eventFilter(QObject *obj, QEvent *event) {
if (this->main->responsive) {
if (event->type() == QEvent::Resize && obj == this && this->isVisible()) {
bool CommentsWidget::eventFilter(QObject *obj, QEvent *event)
{
if (this->main->responsive)
{
if (event->type() == QEvent::Resize && obj == this && this->isVisible())
{
QResizeEvent *resizeEvent = static_cast<QResizeEvent *>(event);
//qDebug("Dock Resized (New Size) - Width: %d Height: %d",
// resizeEvent->size().width(),
// resizeEvent->size().height());
if (resizeEvent->size().width() >= resizeEvent->size().height()) {
if (resizeEvent->size().width() >= resizeEvent->size().height())
{
// Set horizontal view (list)
this->on_actionHorizontal_triggered();
} else {
}
else
{
// Set vertical view (Tree)
this->on_actionVertical_triggered();
}

View File

@ -7,7 +7,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class CommentsWidget;
}

View File

@ -26,7 +26,8 @@ Dashboard::~Dashboard()
delete ui;
}
void Dashboard::updateContents() {
void Dashboard::updateContents()
{
// Parse and add JSON file info
QString info = this->main->core->getFileInfo();
@ -61,47 +62,71 @@ void Dashboard::updateContents() {
this->ui->baddrEdit->setText(QString::number(item2["baddr"].toDouble()));
if ( item2["va"].toBool() == true) {
if (item2["va"].toBool() == true)
{
this->ui->vaEdit->setText("True");
} else {
}
else
{
this->ui->vaEdit->setText("False");
}
if ( item2["canary"].toBool() == true) {
if (item2["canary"].toBool() == true)
{
this->ui->canaryEdit->setText("True");
} else {
}
else
{
this->ui->canaryEdit->setText("False");
this->ui->canaryEdit->setStyleSheet("color: rgb(255, 0, 0);");
}
if ( item2["crypto"].toBool() == true) {
if (item2["crypto"].toBool() == true)
{
this->ui->cryptoEdit->setText("True");
} else {
}
else
{
this->ui->cryptoEdit->setText("False");
}
if ( item2["nx"].toBool() == true) {
if (item2["nx"].toBool() == true)
{
this->ui->nxEdit->setText("True");
} else {
}
else
{
this->ui->nxEdit->setText("False");
this->ui->nxEdit->setStyleSheet("color: rgb(255, 0, 0);");
}
if ( item2["pic"].toBool() == true) {
if (item2["pic"].toBool() == true)
{
this->ui->picEdit->setText("True");
} else {
}
else
{
this->ui->picEdit->setText("False");
this->ui->picEdit->setStyleSheet("color: rgb(255, 0, 0);");
}
if ( item2["static"].toBool() == true) {
if (item2["static"].toBool() == true)
{
this->ui->staticEdit->setText("True");
} else {
}
else
{
this->ui->staticEdit->setText("False");
}
if ( item2["stripped"].toBool() == true) {
if (item2["stripped"].toBool() == true)
{
this->ui->strippedEdit->setText("True");
} else {
}
else
{
this->ui->strippedEdit->setText("False");
}
if ( item2["relocs"].toBool() == true) {
if (item2["relocs"].toBool() == true)
{
this->ui->relocsEdit->setText("True");
} else {
}
else
{
this->ui->relocsEdit->setText("False");
}
@ -113,11 +138,13 @@ void Dashboard::updateContents() {
QString libs = this->main->core->cmd("il");
QStringList lines = libs.split("\n", QString::SkipEmptyParts);
if (! lines.isEmpty()) {
if (! lines.isEmpty())
{
lines.removeFirst();
lines.removeLast();
}
foreach (QString lib, lines) {
foreach (QString lib, lines)
{
QLabel *label = new QLabel(this);
label->setText(lib);
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
@ -135,7 +162,8 @@ void Dashboard::updateContents() {
// Add data to HTML graphs (stats)
QFile html(":/html/stats.html");
if(!html.open(QIODevice::ReadOnly)) {
if (!html.open(QIODevice::ReadOnly))
{
QMessageBox::information(0, "error", html.errorString());
}
QString code = html.readAll();
@ -147,7 +175,8 @@ void Dashboard::updateContents() {
// Add data to polar graph
QFile html2(":/html/radar.html");
if(!html2.open(QIODevice::ReadOnly)) {
if (!html2.open(QIODevice::ReadOnly))
{
QMessageBox::information(0, "error", html2.errorString());
}
QString code2 = html2.readAll();

View File

@ -5,7 +5,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class Dashboard;
}

View File

@ -7,7 +7,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class FlagsWidget;
}

View File

@ -47,15 +47,18 @@ FunctionsWidget::~FunctionsWidget()
delete ui;
}
void FunctionsWidget::fillFunctions() {
void FunctionsWidget::fillFunctions()
{
this->functionsTreeWidget->clear();
ui->nestedFunctionsTree->clear();
for (auto i: this->main->core->getList ("anal", "functions")) {
for (auto i : this->main->core->getList("anal", "functions"))
{
QStringList a = i.split(",");
// off,sz,unk,name
// "0x0804ada3,1,13,,fcn.0804ada3"
// "0x0804ad4a,6,,1,,fcn.0804ad4a"
if (a.length() == 5) {
if (a.length() == 5)
{
// Add list function
this->main->appendRow(this->functionsTreeWidget, a[0], a[1], a[4]);
// Add nested function
@ -68,7 +71,9 @@ void FunctionsWidget::fillFunctions() {
off_it->setText(0, "Size: " + a[1]);
item->addChild(off_it);
ui->nestedFunctionsTree->addTopLevelItem(item);
} else if (a.length() == 6) {
}
else if (a.length() == 6)
{
// Add list function
this->main->appendRow(this->functionsTreeWidget, a[0], a[1], a[5]);
// Add nested function
@ -81,7 +86,9 @@ void FunctionsWidget::fillFunctions() {
off_it->setText(0, "Size: " + a[1]);
item->addChild(off_it);
ui->nestedFunctionsTree->addTopLevelItem(item);
} else {
}
else
{
qDebug() << "fillFunctions()" << a;
}
}
@ -113,25 +120,31 @@ void FunctionsWidget::showFunctionsContextMenu(const QPoint &pt)
menu->addSeparator();
menu->addAction(ui->action_References);
if(ui->tabWidget->currentIndex() == 0) {
if (ui->tabWidget->currentIndex() == 0)
{
this->functionsTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
menu->exec(ui->functionsTreeWidget->mapToGlobal(pt));
} else {
}
else
{
ui->nestedFunctionsTree->setContextMenuPolicy(Qt::CustomContextMenu);
menu->exec(ui->nestedFunctionsTree->mapToGlobal(pt));
}
delete menu;
}
void FunctionsWidget::refreshTree() {
void FunctionsWidget::refreshTree()
{
this->functionsTreeWidget->clear();
ui->nestedFunctionsTree->clear();
for (auto i: this->main->core->getList ("anal", "functions")) {
for (auto i : this->main->core->getList("anal", "functions"))
{
QStringList a = i.split(",");
// off,sz,unk,name
// "0x0804ada3,1,13,,fcn.0804ada3"
// "0x0804ad4a,6,,1,,fcn.0804ad4a"
if (a.length() == 5) {
if (a.length() == 5)
{
// Add list function
this->main->appendRow(this->functionsTreeWidget, a[0], a[1], a[4]);
// Add nested function
@ -144,7 +157,9 @@ void FunctionsWidget::refreshTree() {
off_it->setText(0, "Size: " + a[1]);
item->addChild(off_it);
ui->nestedFunctionsTree->addTopLevelItem(item);
} else if (a.length() == 6) {
}
else if (a.length() == 6)
{
// Add list function
this->main->appendRow(this->functionsTreeWidget, a[0], a[1], a[5]);
// Add nested function
@ -157,7 +172,9 @@ void FunctionsWidget::refreshTree() {
off_it->setText(0, "Size: " + a[1]);
item->addChild(off_it);
ui->nestedFunctionsTree->addTopLevelItem(item);
} else {
}
else
{
qDebug() << "fillFunctions()" << a;
}
}
@ -174,16 +191,20 @@ void FunctionsWidget::on_actionDisasAdd_comment_triggered()
// Create dialog
CommentsDialog *c = new CommentsDialog(this);
// Get selected item in functions tree widget
if(ui->tabWidget->currentIndex() == 0) {
if (ui->tabWidget->currentIndex() == 0)
{
QList<QTreeWidgetItem *> selected_rows = ui->functionsTreeWidget->selectedItems();
// Get selected function name
fcn_name = selected_rows.first()->text(3);
} else {
}
else
{
QList<QTreeWidgetItem *> selected_rows = ui->nestedFunctionsTree->selectedItems();
// Get selected function name
fcn_name = selected_rows.first()->text(0);
}
if (c->exec()) {
if (c->exec())
{
// Get new function name
QString comment = c->getComment();
this->main->add_debug_output("Comment: " + comment + " at: " + fcn_name);
@ -196,7 +217,8 @@ void FunctionsWidget::on_actionDisasAdd_comment_triggered()
this->main->refreshComments();
}
void FunctionsWidget::addTooltips() {
void FunctionsWidget::addTooltips()
{
// Add comments to list functions
QList<QTreeWidgetItem *> clist = this->functionsTreeWidget->findItems("*", Qt::MatchWildcard, 3);
@ -204,7 +226,8 @@ void FunctionsWidget::addTooltips() {
{
QString name = item->text(3);
QList<QString> info = this->main->core->cmd("afi @ " + name).split("\n");
if (info.length() > 2) {
if (info.length() > 2)
{
QString size = info[4].split(" ")[1];
QString complex = info[8].split(" ")[1];
QString bb = info[11].split(" ")[1];
@ -223,7 +246,8 @@ void FunctionsWidget::addTooltips() {
{
QString name = item->text(0);
QList<QString> info = this->main->core->cmd("afi @ " + name).split("\n");
if (info.length() > 2) {
if (info.length() > 2)
{
QString size = info[4].split(" ")[1];
QString complex = info[8].split(" ")[1];
QString bb = info[11].split(" ")[1];
@ -248,7 +272,8 @@ void FunctionsWidget::on_actionFunctionsRename_triggered()
// Set function name in dialog
r->setFunctionName(old_name);
// If user accepted
if (r->exec()) {
if (r->exec())
{
// Get new function name
QString new_name = r->getFunctionName();
// Rename function in r2 core
@ -288,8 +313,10 @@ void FunctionsWidget::on_action_References_triggered()
// refs = calls q hace esa funcion
QList<QString> refs = this->main->core->getFunctionRefs(fcn->addr, 'C');
if (refs.size() > 0) {
for (int i = 0; i < refs.size(); ++i) {
if (refs.size() > 0)
{
for (int i = 0; i < refs.size(); ++i)
{
//this->main->add_debug_output(refs.at(i));
QStringList retlist = refs.at(i).split(",");
QStringList temp;
@ -304,8 +331,10 @@ void FunctionsWidget::on_action_References_triggered()
// xrefs = calls a esa funcion
//qDebug() << this->main->core->getFunctionXrefs(offset.toLong(&ok, 16));
QList<QString> xrefs = this->main->core->getFunctionXrefs(fcn->addr);
if (xrefs.size() > 0) {
for (int i = 0; i < xrefs.size(); ++i) {
if (xrefs.size() > 0)
{
for (int i = 0; i < xrefs.size(); ++i)
{
//this->main->add_debug_output(xrefs.at(i));
QStringList retlist = xrefs.at(i).split(",");
QStringList temp;
@ -328,10 +357,13 @@ void FunctionsWidget::showTitleContextMenu(const QPoint &pt)
menu->addAction(ui->actionHorizontal);
menu->addAction(ui->actionVertical);
if (ui->tabWidget->currentIndex() == 0) {
if (ui->tabWidget->currentIndex() == 0)
{
ui->actionHorizontal->setChecked(true);
ui->actionVertical->setChecked(false);
} else {
}
else
{
ui->actionVertical->setChecked(true);
ui->actionHorizontal->setChecked(false);
}
@ -363,17 +395,23 @@ void FunctionsWidget::on_nestedFunctionsTree_itemDoubleClicked(QTreeWidgetItem *
this->main->memoryDock->raise();
}
bool FunctionsWidget::eventFilter(QObject *obj, QEvent *event) {
if (this->main->responsive) {
if (event->type() == QEvent::Resize && obj == this && this->isVisible() == true) {
bool FunctionsWidget::eventFilter(QObject *obj, QEvent *event)
{
if (this->main->responsive)
{
if (event->type() == QEvent::Resize && obj == this && this->isVisible() == true)
{
QResizeEvent *resizeEvent = static_cast<QResizeEvent *>(event);
//qDebug("Dock Resized (New Size) - Width: %d Height: %d",
// resizeEvent->size().width(),
// resizeEvent->size().height());
if (resizeEvent->size().width() >= resizeEvent->size().height()) {
if (resizeEvent->size().width() >= resizeEvent->size().height())
{
// Set horizontal view (list)
this->on_actionHorizontal_triggered();
} else {
}
else
{
// Set vertical view (Tree)
this->on_actionVertical_triggered();
}

View File

@ -6,7 +6,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class FunctionsWidget;
}

View File

@ -43,9 +43,11 @@ ImportsWidget::ImportsWidget(MainWindow *main, QWidget *parent) :
//ui->importsTreeWidget->setItemDelegate(delegate);
}
void ImportsWidget::fillImports() {
void ImportsWidget::fillImports()
{
this->importsTreeWidget->clear();
for (auto i: this->main->core->getList ("bin", "imports")) {
for (auto i : this->main->core->getList("bin", "imports"))
{
QStringList a = i.split(",");
// ord,plt,name
if (a.length() == 6)
@ -55,7 +57,8 @@ void ImportsWidget::fillImports() {
this->main->adjustColumns(this->importsTreeWidget);
}
void ImportsWidget::highlightUnsafe() {
void ImportsWidget::highlightUnsafe()
{
Banned *ban = new Banned();
QList<QTreeWidgetItem *> clist = this->importsTreeWidget->findItems(ban->banned, Qt::MatchRegExp, 4);
foreach (QTreeWidgetItem *item, clist)
@ -68,9 +71,11 @@ void ImportsWidget::highlightUnsafe() {
//ui->importsTreeWidget->setStyleSheet("QTreeWidget::item { padding-left:10px; padding-top: 1px; padding-bottom: 1px; border-left: 10px; }");
}
void ImportsWidget::adjustColumns(QTreeWidget *tw) {
void ImportsWidget::adjustColumns(QTreeWidget *tw)
{
int count = tw->columnCount();
for (int i = 0; i != count; ++i) {
for (int i = 0; i != count; ++i)
{
ui->importsTreeWidget->resizeColumnToContents(i);
int width = ui->importsTreeWidget->columnWidth(i);
ui->importsTreeWidget->setColumnWidth(i, width + 10);

View File

@ -7,7 +7,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class ImportsWidget;
}

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class MemoryWidget;
}

View File

@ -36,7 +36,8 @@ Notepad::Notepad(MainWindow *main, QWidget *parent) :
this, SLOT(showNotepadContextMenu(const QPoint &)));
}
void Notepad::setText(QString str) {
void Notepad::setText(QString str)
{
ui->notepadTextEdit->setPlainText(str);
}
@ -50,7 +51,8 @@ void Notepad::on_fontButton_clicked()
bool ok = true;
QFont font = QFontDialog::getFont(&ok, ui->notepadTextEdit->font(), this) ;
if (ok) {
if (ok)
{
// the user clicked OK and font is set to the font the user selected
//ui->notepadTextEdit->setFont(font);
//ui->previewTextEdit->setFont(font);
@ -58,7 +60,8 @@ void Notepad::on_fontButton_clicked()
}
}
void Notepad::setFonts(QFont font) {
void Notepad::setFonts(QFont font)
{
ui->notepadTextEdit->setFont(font);
ui->previewTextEdit->setFont(font);
}
@ -66,11 +69,14 @@ void Notepad::setFonts(QFont font) {
void Notepad::on_boldButton_clicked()
{
QTextCursor cursor = ui->notepadTextEdit->textCursor();
if (cursor.hasSelection()) {
if (cursor.hasSelection())
{
QString text = cursor.selectedText();
cursor.removeSelectedText();
cursor.insertText("**" + text + "**");
} else {
}
else
{
cursor.insertText("****");
}
}
@ -78,11 +84,14 @@ void Notepad::on_boldButton_clicked()
void Notepad::on_italicsButton_clicked()
{
QTextCursor cursor = ui->notepadTextEdit->textCursor();
if (cursor.hasSelection()) {
if (cursor.hasSelection())
{
QString text = cursor.selectedText();
cursor.removeSelectedText();
cursor.insertText("*" + text + "*");
} else {
}
else
{
cursor.insertText("**");
}
}
@ -90,11 +99,14 @@ void Notepad::on_italicsButton_clicked()
void Notepad::on_h1Button_clicked()
{
QTextCursor cursor = ui->notepadTextEdit->textCursor();
if (cursor.hasSelection()) {
if (cursor.hasSelection())
{
QString text = cursor.selectedText();
cursor.removeSelectedText();
cursor.insertText("# " + text);
} else {
}
else
{
cursor.insertText("# ");
}
}
@ -102,11 +114,14 @@ void Notepad::on_h1Button_clicked()
void Notepad::on_h2Button_clicked()
{
QTextCursor cursor = ui->notepadTextEdit->textCursor();
if (cursor.hasSelection()) {
if (cursor.hasSelection())
{
QString text = cursor.selectedText();
cursor.removeSelectedText();
cursor.insertText("## " + text);
} else {
}
else
{
cursor.insertText("## ");
}
}
@ -114,11 +129,14 @@ void Notepad::on_h2Button_clicked()
void Notepad::on_h3Button_clicked()
{
QTextCursor cursor = ui->notepadTextEdit->textCursor();
if (cursor.hasSelection()) {
if (cursor.hasSelection())
{
QString text = cursor.selectedText();
cursor.removeSelectedText();
cursor.insertText("### " + text);
} else {
}
else
{
cursor.insertText("### ");
}
}
@ -150,7 +168,8 @@ void Notepad::on_searchEdit_returnPressed()
if (isFirstTime == false)
document->undo();
if (!searchString.isEmpty()) {
if (!searchString.isEmpty())
{
QTextCursor highlightCursor(document);
QTextCursor cursor(document);
@ -161,10 +180,12 @@ void Notepad::on_searchEdit_returnPressed()
QTextCharFormat colorFormat = plainFormat;
colorFormat.setForeground(Qt::red);
while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {
while (!highlightCursor.isNull() && !highlightCursor.atEnd())
{
highlightCursor = document->find(searchString, highlightCursor, QTextDocument::FindWholeWords);
if (!highlightCursor.isNull()) {
if (!highlightCursor.isNull())
{
highlightCursor.movePosition(QTextCursor::WordRight,
QTextCursor::KeepAnchor);
highlightCursor.mergeCharFormat(colorFormat);
@ -186,7 +207,8 @@ void Notepad::on_searchEdit_textEdited(const QString &arg1)
if (isFirstTime == false)
document->undo();
if (!searchString.isEmpty()) {
if (!searchString.isEmpty())
{
QTextCursor highlightCursor(document);
QTextCursor cursor(document);
@ -197,10 +219,12 @@ void Notepad::on_searchEdit_textEdited(const QString &arg1)
QTextCharFormat colorFormat = plainFormat;
colorFormat.setForeground(Qt::red);
while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {
while (!highlightCursor.isNull() && !highlightCursor.atEnd())
{
highlightCursor = document->find(searchString, highlightCursor);
if (!highlightCursor.isNull()) {
if (!highlightCursor.isNull())
{
//highlightCursor.movePosition(QTextCursor::WordRight,
// QTextCursor::KeepAnchor);
highlightCursor.mergeCharFormat(colorFormat);
@ -222,7 +246,8 @@ void Notepad::on_searchEdit_textChanged(const QString &arg1)
if (isFirstTime == false)
document->undo();
if (!searchString.isEmpty()) {
if (!searchString.isEmpty())
{
QTextCursor highlightCursor(document);
QTextCursor cursor(document);
@ -233,10 +258,12 @@ void Notepad::on_searchEdit_textChanged(const QString &arg1)
QTextCharFormat colorFormat = plainFormat;
colorFormat.setForeground(Qt::red);
while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {
while (!highlightCursor.isNull() && !highlightCursor.atEnd())
{
highlightCursor = document->find(searchString, highlightCursor);
if (!highlightCursor.isNull()) {
if (!highlightCursor.isNull())
{
//highlightCursor.movePosition(QTextCursor::WordRight,
// QTextCursor::KeepAnchor);
highlightCursor.mergeCharFormat(colorFormat);
@ -255,11 +282,14 @@ void Notepad::showNotepadContextMenu(const QPoint &pt)
QTextCursor cur = ui->notepadTextEdit->textCursor();
QAction *first = menu->actions().at(0);
if (cur.hasSelection()) {
if (cur.hasSelection())
{
// Get selected text
//this->main->add_debug_output("Selected text: " + cur.selectedText());
this->addr = cur.selectedText();
} else {
}
else
{
// Get word under the cursor
cur.select(QTextCursor::WordUnderCursor);
//this->main->add_debug_output("Word: " + cur.selectedText());

View File

@ -8,7 +8,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class Notepad;
}

View File

@ -44,7 +44,8 @@ Omnibar::Omnibar(MainWindow *main, QWidget *parent) :
clear_shortcut->setContext(Qt::WidgetShortcut);
}
void Omnibar::setupCompleter() {
void Omnibar::setupCompleter()
{
// Set gotoEntry completer for jump history
QStringList flagsList = this->getFlags();
QCompleter *completer = new QCompleter(flagsList, this);
@ -66,7 +67,8 @@ void Omnibar::restoreCompleter()
completer->setFilterMode(Qt::MatchContains);
}
void Omnibar::showCommands() {
void Omnibar::showCommands()
{
this->setFocus();
this->setText(": ");
@ -82,7 +84,8 @@ void Omnibar::showCommands() {
completer->complete();
}
void Omnibar::clearContents() {
void Omnibar::clearContents()
{
this->setText("");
// Necessary hack to make it work properly
this->clearFocus();
@ -92,38 +95,69 @@ void Omnibar::clearContents() {
void Omnibar::on_gotoEntry_returnPressed()
{
QString str = this->text();
if (str.length()>0) {
if (str.contains(": ")) {
if (str.contains("Lock")){
if (str.length() > 0)
{
if (str.contains(": "))
{
if (str.contains("Lock"))
{
this->main->on_actionLock_triggered();
} else if (str.contains("Functions")) {
}
else if (str.contains("Functions"))
{
this->main->on_actionFunctions_triggered();
} else if (str.contains("Flags")) {
}
else if (str.contains("Flags"))
{
this->main->on_actionFlags_triggered();
} else if (str.contains("Sections")) {
}
else if (str.contains("Sections"))
{
this->main->on_actionSections_triggered();
} else if (str.contains("Strings")) {
}
else if (str.contains("Strings"))
{
this->main->on_actionStrings_triggered();
} else if (str.contains("Imports")) {
}
else if (str.contains("Imports"))
{
this->main->on_actionImports_triggered();
} else if (str.contains("Symbols")) {
}
else if (str.contains("Symbols"))
{
this->main->on_actionSymbols_triggered();
} else if (str.contains("Relocs")) {
}
else if (str.contains("Relocs"))
{
this->main->on_actionReloc_triggered();
} else if (str.contains("Comments")) {
}
else if (str.contains("Comments"))
{
this->main->on_actionComents_triggered();
} else if (str.contains("Notepad")) {
}
else if (str.contains("Notepad"))
{
this->main->on_actionNotepad_triggered();
} else if (str.contains("Dashboard")) {
}
else if (str.contains("Dashboard"))
{
this->main->on_actionDashboard_triggered();
} else if (str.contains("Theme")) {
}
else if (str.contains("Theme"))
{
this->main->sideBar->themesButtonToggle();
} else if (str.contains("Script")) {
}
else if (str.contains("Script"))
{
this->main->on_actionRun_Script_triggered();
} else if (str.contains("Tabs")) {
}
else if (str.contains("Tabs"))
{
this->main->on_actionTabs_triggered();
}
} else {
}
else
{
//this->main->seek(this->main->core->cmd("?v " + this->text()), this->text());
QString off = this->main->core->cmd("afo " + this->text());
this->main->seek(off.trimmed(), this->text());
@ -137,14 +171,17 @@ void Omnibar::on_gotoEntry_returnPressed()
this->restoreCompleter();
}
void Omnibar::fillFlags(QString flag) {
void Omnibar::fillFlags(QString flag)
{
this->flags << flag;
}
void Omnibar::clearFlags() {
void Omnibar::clearFlags()
{
this->flags.clear();
}
QStringList Omnibar::getFlags() {
QStringList Omnibar::getFlags()
{
return this->flags;
}

View File

@ -74,12 +74,14 @@ void PieView::dataChanged(const QModelIndex &topLeft,
validItems = 0;
totalValue = 0.0;
for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
for (int row = 0; row < model()->rowCount(rootIndex()); ++row)
{
QModelIndex index = model()->index(row, 1, rootIndex());
double value = model()->data(index).toDouble();
if (value > 0.0) {
if (value > 0.0)
{
totalValue += value;
validItems++;
}
@ -108,7 +110,8 @@ QModelIndex PieView::indexAt(const QPoint &point) const
int wx = point.x() + horizontalScrollBar()->value();
int wy = point.y() + verticalScrollBar()->value();
if (wx < totalSize) {
if (wx < totalSize)
{
double cx = wx - totalSize / 2;
double cy = totalSize / 2 - wy; // positive cy for items above the center
@ -126,12 +129,14 @@ QModelIndex PieView::indexAt(const QPoint &point) const
// Find the relevant slice of the pie.
double startAngle = 0.0;
for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
for (int row = 0; row < model()->rowCount(rootIndex()); ++row)
{
QModelIndex index = model()->index(row, 1, rootIndex());
double value = model()->data(index).toDouble();
if (value > 0.0) {
if (value > 0.0)
{
double sliceAngle = 360 * value / totalValue;
if (angle >= startAngle && angle < (startAngle + sliceAngle))
@ -140,15 +145,19 @@ QModelIndex PieView::indexAt(const QPoint &point) const
startAngle += sliceAngle;
}
}
} else {
}
else
{
double itemHeight = QFontMetrics(viewOptions().font).height();
int listItem = int((wy - margin) / itemHeight);
int validRow = 0;
for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
for (int row = 0; row < model()->rowCount(rootIndex()); ++row)
{
QModelIndex index = model()->index(row, 1, rootIndex());
if (model()->data(index).toDouble() > 0.0) {
if (model()->data(index).toDouble() > 0.0)
{
if (listItem == validRow)
return model()->index(row, 0, rootIndex());
@ -191,14 +200,16 @@ QRect PieView::itemRect(const QModelIndex &index) const
return QRect();
int listItem = 0;
for (int row = index.row()-1; row >= 0; --row) {
for (int row = index.row() - 1; row >= 0; --row)
{
if (model()->data(model()->index(row, 1, rootIndex())).toDouble() > 0.0)
listItem++;
}
double itemHeight;
switch (index.column()) {
switch (index.column())
{
case 0:
itemHeight = QFontMetrics(viewOptions().font).height();
@ -223,15 +234,18 @@ QRegion PieView::itemRegion(const QModelIndex &index) const
return QRegion();
double startAngle = 0.0;
for (int row = 0; row < model()->rowCount(rootIndex()); ++row) {
for (int row = 0; row < model()->rowCount(rootIndex()); ++row)
{
QModelIndex sliceIndex = model()->index(row, 1, rootIndex());
double value = model()->data(sliceIndex).toDouble();
if (value > 0.0) {
if (value > 0.0)
{
double angle = 360 * value / totalValue;
if (sliceIndex == index) {
if (sliceIndex == index)
{
QPainterPath slicePath;
slicePath.moveTo(totalSize / 2, totalSize / 2);
slicePath.arcTo(margin, margin, margin + pieSize, margin + pieSize,
@ -283,7 +297,8 @@ QModelIndex PieView::moveCursor(QAbstractItemView::CursorAction cursorAction,
{
QModelIndex current = currentIndex();
switch (cursorAction) {
switch (cursorAction)
{
case MoveLeft:
case MoveUp:
if (current.row() > 0)
@ -341,11 +356,13 @@ void PieView::paintEvent(QPaintEvent *event)
double startAngle = 0.0;
int row;
for (row = 0; row < model()->rowCount(rootIndex()); ++row) {
for (row = 0; row < model()->rowCount(rootIndex()); ++row)
{
QModelIndex index = model()->index(row, 1, rootIndex());
double value = model()->data(index).toDouble();
if (value > 0.0) {
if (value > 0.0)
{
double angle = 360 * value / totalValue;
QModelIndex colorIndex = model()->index(row, 0, rootIndex());
@ -387,11 +404,13 @@ int PieView::rows(const QModelIndex &index) const
void PieView::rowsInserted(const QModelIndex &parent, int start, int end)
{
for (int row = start; row <= end; ++row) {
for (int row = start; row <= end; ++row)
{
QModelIndex index = model()->index(row, 1, rootIndex());
double value = model()->data(index).toDouble();
if (value > 0.0) {
if (value > 0.0)
{
totalValue += value;
++validItems;
}
@ -402,10 +421,12 @@ void PieView::rowsInserted(const QModelIndex &parent, int start, int end)
void PieView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
{
for (int row = start; row <= end; ++row) {
for (int row = start; row <= end; ++row)
{
QModelIndex index = model()->index(row, 1, rootIndex());
double value = model()->data(index).toDouble();
if (value > 0.0) {
if (value > 0.0)
{
totalValue -= value;
--validItems;
}
@ -424,19 +445,25 @@ void PieView::scrollTo(const QModelIndex &index, ScrollHint)
QRect area = viewport()->rect();
QRect rect = visualRect(index);
if (rect.left() < area.left()) {
if (rect.left() < area.left())
{
horizontalScrollBar()->setValue(
horizontalScrollBar()->value() + rect.left() - area.left());
} else if (rect.right() > area.right()) {
}
else if (rect.right() > area.right())
{
horizontalScrollBar()->setValue(
horizontalScrollBar()->value() + qMin(
rect.right() - area.right(), rect.left() - area.left()));
}
if (rect.top() < area.top()) {
if (rect.top() < area.top())
{
verticalScrollBar()->setValue(
verticalScrollBar()->value() + rect.top() - area.top());
} else if (rect.bottom() > area.bottom()) {
}
else if (rect.bottom() > area.bottom())
{
verticalScrollBar()->setValue(
verticalScrollBar()->value() + qMin(
rect.bottom() - area.bottom(), rect.top() - area.top()));
@ -464,8 +491,10 @@ void PieView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlag
int columns = model()->columnCount(rootIndex());
QModelIndexList indexes;
for (int row = 0; row < rows; ++row) {
for (int column = 0; column < columns; ++column) {
for (int row = 0; row < rows; ++row)
{
for (int column = 0; column < columns; ++column)
{
QModelIndex index = model()->index(row, column, rootIndex());
QRegion region = itemRegion(index);
if (region.intersects(contentsRect))
@ -473,13 +502,15 @@ void PieView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlag
}
}
if (indexes.size() > 0) {
if (indexes.size() > 0)
{
int firstRow = indexes[0].row();
int lastRow = indexes[0].row();
int firstColumn = indexes[0].column();
int lastColumn = indexes[0].column();
for (int i = 1; i < indexes.size(); ++i) {
for (int i = 1; i < indexes.size(); ++i)
{
firstRow = qMin(firstRow, indexes[i].row());
lastRow = qMax(lastRow, indexes[i].row());
firstColumn = qMin(firstColumn, indexes[i].column());
@ -490,7 +521,9 @@ void PieView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlag
model()->index(firstRow, firstColumn, rootIndex()),
model()->index(lastRow, lastColumn, rootIndex()));
selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
} else {
}
else
{
QModelIndex noIndex;
QItemSelection selection(noIndex, noIndex);
selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
@ -543,10 +576,13 @@ QRegion PieView::visualRegionForSelection(const QItemSelection &selection) const
return QRect();
QRegion region;
for (int i = 0; i < ranges; ++i) {
for (int i = 0; i < ranges; ++i)
{
QItemSelectionRange range = selection.at(i);
for (int row = range.top(); row <= range.bottom(); ++row) {
for (int col = range.left(); col <= range.right(); ++col) {
for (int row = range.top(); row <= range.bottom(); ++row)
{
for (int col = range.left(); col <= range.right(); ++col)
{
QModelIndex index = model()->index(row, col, rootIndex());
region += visualRect(index);
}

View File

@ -6,7 +6,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class RelocsWidget;
}

View File

@ -25,7 +25,8 @@ void SdbDock::reload(QString path)
QList<QString> keys;
/* key-values */
keys = main->core->sdbListKeys(path);
foreach (QString key, keys) {
foreach (QString key, keys)
{
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
tempItem->setText(0, key);
tempItem->setText(1, main->core->sdbGet(path, key));
@ -37,7 +38,8 @@ void SdbDock::reload(QString path)
/* namespaces */
keys = main->core->sdbList(path);
keys.append("..");
foreach (QString key, keys) {
foreach (QString key, keys)
{
QTreeWidgetItem *tempItem = new QTreeWidgetItem();
tempItem->setText(0, key + "/");
tempItem->setText(1, "");
@ -52,27 +54,37 @@ void SdbDock::on_treeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
{
QString newpath;
if (column == 0) {
if (item->text(0) == "../") {
if (column == 0)
{
if (item->text(0) == "../")
{
int idx = path.lastIndexOf("/");
if (idx != -1) {
if (idx != -1)
{
newpath = path.mid(0, idx);
} else {
}
else
{
newpath = "";
}
reload(newpath);
} else
if (item->text(0).indexOf("/")!=-1) {
if (path != "") {
}
else if (item->text(0).indexOf("/") != -1)
{
if (path != "")
{
newpath = path + "/" + item->text(0).replace("/", "");
} else {
}
else
{
newpath = path + item->text(0).replace("/", "");
}
// enter directory
reload(newpath);
}
else {
else
{
//__alert ("TODO: change value");
}
}
@ -89,7 +101,9 @@ void SdbDock::on_lockButton_clicked()
{
this->setAllowedAreas(Qt::NoDockWidgetArea);
ui->lockButton->setIcon(QIcon(":/new/prefix1/lock"));
} else {
}
else
{
this->setAllowedAreas(Qt::AllDockWidgetAreas);
ui->lockButton->setIcon(QIcon(":/new/prefix1/unlock"));
}

View File

@ -6,7 +6,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class SdbDock;
}

View File

@ -89,24 +89,32 @@ void SectionsWidget::fillSections(int row, const QString &str, const QString &st
this->tree->insertTopLevelItem(0, tempItem);
}
void SectionsWidget::adjustColumns() {
void SectionsWidget::adjustColumns()
{
int count = 4;
for (int i = 0; i != count; ++i) {
for (int i = 0; i != count; ++i)
{
this->tree->resizeColumnToContents(i);
}
}
bool SectionsWidget::eventFilter(QObject *obj, QEvent *event) {
if (this->main->responsive) {
if (event->type() == QEvent::Resize && obj == this && this->isVisible()) {
bool SectionsWidget::eventFilter(QObject *obj, QEvent *event)
{
if (this->main->responsive)
{
if (event->type() == QEvent::Resize && obj == this && this->isVisible())
{
QResizeEvent *resizeEvent = static_cast<QResizeEvent *>(event);
//qDebug("Dock Resized (New Size) - Width: %d Height: %d",
// resizeEvent->size().width(),
// resizeEvent->size().height());
if (resizeEvent->size().width() >= resizeEvent->size().height()) {
if (resizeEvent->size().width() >= resizeEvent->size().height())
{
// Set horizontal view (list)
this->main->on_actionSectionsHorizontal_triggered();
} else {
}
else
{
// Set vertical view (Tree)
this->main->on_actionSectionsVertical_triggered();
}

View File

@ -14,7 +14,8 @@ class QItemSelectionModel;
QT_END_NAMESPACE
namespace Ui {
namespace Ui
{
class SectionsWidget;
}

View File

@ -14,14 +14,20 @@ SideBar::SideBar(MainWindow *main) :
ui->setupUi(this);
QSettings settings;
if (settings.value("responsive").toBool()) {
if (settings.value("responsive").toBool())
{
ui->respButton->setChecked(true);
} else {
}
else
{
ui->respButton->setChecked(false);
}
if (settings.value("dark").toBool()) {
if (settings.value("dark").toBool())
{
ui->themesButton->setChecked(true);
} else {
}
else
{
ui->themesButton->setChecked(false);
}
}
@ -39,9 +45,12 @@ void SideBar::on_tabsButton_clicked()
void SideBar::on_consoleButton_clicked()
{
this->main->on_actionhide_bottomPannel_triggered();
if (ui->consoleButton->isChecked()) {
if (ui->consoleButton->isChecked())
{
ui->consoleButton->setIcon(QIcon(":/new/prefix1/img/icons/up_white.png"));
} else {
}
else
{
ui->consoleButton->setIcon(QIcon(":/new/prefix1/img/icons/down_white.png"));
}
}
@ -53,25 +62,32 @@ void SideBar::on_webServerButton_clicked()
void SideBar::on_lockButton_clicked()
{
if(ui->lockButton->isChecked()) {
if (ui->lockButton->isChecked())
{
ui->lockButton->setIcon(QIcon(":/new/prefix1/img/icons/unlock_white.png"));
this->main->lockUnlock_Docks(1);
} else {
}
else
{
ui->lockButton->setIcon(QIcon(":/new/prefix1/img/icons/lock_white.png"));
this->main->lockUnlock_Docks(0);
}
}
void SideBar::themesButtonToggle() {
void SideBar::themesButtonToggle()
{
ui->themesButton->click();
}
void SideBar::on_themesButton_clicked()
{
if (ui->themesButton->isChecked() ) {
if (ui->themesButton->isChecked())
{
// Dark theme
this->main->dark();
} else {
}
else
{
// Clear theme
this->main->def_theme();
}

View File

@ -5,7 +5,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class SideBar;
}

View File

@ -6,7 +6,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class StringsWidget;
}

View File

@ -17,9 +17,11 @@ SymbolsWidget::~SymbolsWidget()
delete ui;
}
void SymbolsWidget::fillSymbols() {
void SymbolsWidget::fillSymbols()
{
this->symbolsTreeWidget->clear();
for (auto i: this->main->core->getList ("bin", "symbols")) {
for (auto i : this->main->core->getList("bin", "symbols"))
{
QStringList pieces = i.split(",");
if (pieces.length() == 3)
this->main->appendRow(this->symbolsTreeWidget, pieces[0], pieces[1], pieces[2]);

View File

@ -6,7 +6,8 @@
class MainWindow;
namespace Ui {
namespace Ui
{
class SymbolsWidget;
}