1
0
Fork 0

PROJECT: more formatting (please use install.bat for pre-commit formatting hook)

This commit is contained in:
mrexodia 2015-12-19 04:20:42 +01:00
parent a004fdd19d
commit 5b57e2a6c9
4 changed files with 346 additions and 346 deletions

View File

@ -1,90 +1,90 @@
#include "commandline.h"
#include "threading.h"
#include "memory.h"
#include "debugger.h"
#include "debugger_commands.h"
char commandLine[MAX_COMMAND_LINE_SIZE];
bool isCmdLineEmpty()
{
return !strlen(commandLine);
}
char* getCommandLineArgs()
{
char* commandLineArguments = NULL;
char* extensionPtr = strchr(commandLine, '.');
if (!extensionPtr)
return NULL;
commandLineArguments = strchr(extensionPtr, ' ');
if (!commandLineArguments)
return NULL;
return (commandLineArguments + 1);
}
void CmdLineCacheSave(JSON Root)
{
EXCLUSIVE_ACQUIRE(LockCmdLine);
// return if command line is empty
if (!strlen(commandLine))
return;
// Create a JSON array to store each sub-object with a breakpoint
const JSON jsonCmdLine = json_object();
json_object_set_new(jsonCmdLine, "cmdLine", json_string(commandLine));
json_object_set(Root, "commandLine", jsonCmdLine);
// Notify garbage collector
json_decref(jsonCmdLine);
}
void CmdLineCacheLoad(JSON Root)
{
EXCLUSIVE_ACQUIRE(LockCmdLine);
// Clear command line
memset(commandLine, 0, MAX_COMMAND_LINE_SIZE);
// Get a handle to the root object -> commandLine
const JSON jsonCmdLine = json_object_get(Root, "commandLine");
// Return if there was nothing to load
if (!jsonCmdLine)
return;
const char *cmdLine = json_string_value(json_object_get(jsonCmdLine, "cmdLine"));
strcpy_s(commandLine, cmdLine);
json_decref(jsonCmdLine);
}
void copyCommandLine(const char* cmdLine)
{
strcpy_s(commandLine, cmdLine);
}
CMDRESULT SetCommandLine()
{
cmdline_error_t cmdline_error = { (cmdline_error_type_t)0, 0 };
if (!dbgsetcmdline(commandLine, &cmdline_error))
{
showcommandlineerror(&cmdline_error);
return STATUS_ERROR;
}
//update the memory map
MemUpdateMap();
GuiUpdateMemoryView();
return STATUS_CONTINUE;
}
#include "commandline.h"
#include "threading.h"
#include "memory.h"
#include "debugger.h"
#include "debugger_commands.h"
char commandLine[MAX_COMMAND_LINE_SIZE];
bool isCmdLineEmpty()
{
return !strlen(commandLine);
}
char* getCommandLineArgs()
{
char* commandLineArguments = NULL;
char* extensionPtr = strchr(commandLine, '.');
if (!extensionPtr)
return NULL;
commandLineArguments = strchr(extensionPtr, ' ');
if (!commandLineArguments)
return NULL;
return (commandLineArguments + 1);
}
void CmdLineCacheSave(JSON Root)
{
EXCLUSIVE_ACQUIRE(LockCmdLine);
// return if command line is empty
if (!strlen(commandLine))
return;
// Create a JSON array to store each sub-object with a breakpoint
const JSON jsonCmdLine = json_object();
json_object_set_new(jsonCmdLine, "cmdLine", json_string(commandLine));
json_object_set(Root, "commandLine", jsonCmdLine);
// Notify garbage collector
json_decref(jsonCmdLine);
}
void CmdLineCacheLoad(JSON Root)
{
EXCLUSIVE_ACQUIRE(LockCmdLine);
// Clear command line
memset(commandLine, 0, MAX_COMMAND_LINE_SIZE);
// Get a handle to the root object -> commandLine
const JSON jsonCmdLine = json_object_get(Root, "commandLine");
// Return if there was nothing to load
if (!jsonCmdLine)
return;
const char *cmdLine = json_string_value(json_object_get(jsonCmdLine, "cmdLine"));
strcpy_s(commandLine, cmdLine);
json_decref(jsonCmdLine);
}
void copyCommandLine(const char* cmdLine)
{
strcpy_s(commandLine, cmdLine);
}
CMDRESULT SetCommandLine()
{
cmdline_error_t cmdline_error = { (cmdline_error_type_t)0, 0 };
if (!dbgsetcmdline(commandLine, &cmdline_error))
{
showcommandlineerror(&cmdline_error);
return STATUS_ERROR;
}
//update the memory map
MemUpdateMap();
GuiUpdateMemoryView();
return STATUS_CONTINUE;
}

View File

@ -1,11 +1,11 @@
#pragma once
#include "_global.h"
#include "command.h"
bool isCmdLineEmpty();
char* getCommandLineArgs();
void CmdLineCacheSave(JSON Root);
void CmdLineCacheLoad(JSON Root);
void copyCommandLine(const char* cmdLine);
#pragma once
#include "_global.h"
#include "command.h"
bool isCmdLineEmpty();
char* getCommandLineArgs();
void CmdLineCacheSave(JSON Root);
void CmdLineCacheLoad(JSON Root);
void copyCommandLine(const char* cmdLine);
CMDRESULT setCommandLine();

View File

@ -1,193 +1,193 @@
#include "AssembleDialog.h"
#include "ui_AssembleDialog.h"
#include <QMessageBox>
bool AssembleDialog::bWarningShowedOnce = false;
AssembleDialog::AssembleDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AssembleDialog)
{
ui->setupUi(this);
setModal(true);
setFixedSize(this->size()); //fixed size
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
#endif
mSelectedInstrVa = 0;
bKeepSizeChecked = false;
bFillWithNopsChecked = false;
mValidateThread = new ValidateExpressionThread(this);
mValidateThread->setOnExpressionChangedCallback(std::bind(&AssembleDialog::validateInstruction, this, std::placeholders::_1));
connect(ui->lineEdit, SIGNAL(textEdited(QString)), this, SLOT(textChangedSlot(QString)));
connect(mValidateThread, SIGNAL(instructionChanged(dsint,QString)), this, SLOT(instructionChangedSlot(dsint, QString)));
}
AssembleDialog::~AssembleDialog()
{
delete ui;
}
void AssembleDialog::setTextEditValue(const QString &text)
{
ui->lineEdit->setText(text);
}
void AssembleDialog::setKeepSizeChecked(bool checked)
{
ui->checkBoxKeepSize->setChecked(checked);
bKeepSizeChecked = checked;
}
void AssembleDialog::setKeepSizeLabel(const QString &text)
{
ui->labelKeepSize->setText(text);
}
void AssembleDialog::setFillWithNopsChecked(bool checked)
{
ui->checkBoxFillWithNops->setChecked(checked);
bFillWithNopsChecked = checked;
}
void AssembleDialog::setFillWithNopsLabel(const QString &text)
{
ui->labelFillWithNops->setText(text);
}
void AssembleDialog::setSelectedInstrVa(const duint va)
{
this->mSelectedInstrVa = va;
}
void AssembleDialog::setOkButtonEnabled(bool enabled)
{
ui->pushButtonOk->setEnabled(enabled);
}
void AssembleDialog::validateInstruction(QString expression)
{
//void instructionChanged(bool validInstruction, dsint sizeDifference, QString error)
dsint sizeDifference = 0;
int typedInstructionSize = 0;
int selectedInstructionSize = 0;
bool validInstruction = false;
QByteArray error(MAX_ERROR_SIZE, 0);
BASIC_INSTRUCTION_INFO basicInstrInfo;
// Get selected instruction info (size here)
DbgDisasmFastAt(mSelectedInstrVa, &basicInstrInfo);
selectedInstructionSize = basicInstrInfo.size;
// Get typed in instruction size
if(!DbgFunctions()->Assemble(this->mSelectedInstrVa, NULL, &typedInstructionSize, editText.toUtf8().constData(), error.data()) || selectedInstructionSize == 0)
{
emit mValidateThread->emitInstructionChanged(0, QString(error));
return;
}
// Valid instruction
validInstruction = true;
sizeDifference = typedInstructionSize - selectedInstructionSize;
emit mValidateThread->emitInstructionChanged(sizeDifference, "");
}
void AssembleDialog::hideEvent(QHideEvent *event)
{
Q_UNUSED(event);
mValidateThread->stop();
mValidateThread->wait();
}
void AssembleDialog::textChangedSlot(QString text)
{
if(ui->checkBoxKeepSize->isChecked())
mValidateThread->textChanged(text);
}
void AssembleDialog::instructionChangedSlot(dsint sizeDifference, QString error)
{
if(ui->checkBoxKeepSize->isChecked())
{
// If there was an error
if(error.length())
{
this->setKeepSizeLabel("<font color='orange'><b>Instruction decoding error : " + error + "</b></font>");
return;
}
// No error
else
{
// SizeDifference > 0 <=> Typed instruction is bigger
if(sizeDifference > 0)
{
QString message = "<font color='red'><b>Instruction bigger by " + QString::number(sizeDifference);
if(sizeDifference == 1)
message += QString(" byte</b></font>");
else
message += QString(" bytes</b></font>");
this->setKeepSizeLabel(message);
this->setOkButtonEnabled(false);
}
// SizeDifference < 0 <=> Typed instruction is smaller
else if(sizeDifference < 0)
{
QString message = "<font color='#00cc00'><b>Instruction smaller by " + QString::number(sizeDifference);
if(sizeDifference == -1)
message += QString(" byte</b></font>");
else
message += QString(" bytes</b></font>");
this->setKeepSizeLabel(message);
this->setOkButtonEnabled(true);
}
// SizeDifference == 0 <=> Both instruction have same size
else
{
QString message = "<font color='#00cc00'><b>Instruction is same size</b></font>";
this->setKeepSizeLabel(message);
this->setOkButtonEnabled(true);
}
}
}
}
void AssembleDialog::on_lineEdit_textChanged(const QString &arg1)
{
editText = arg1;
if(ui->checkBoxKeepSize->isChecked() && editText.size())
mValidateThread->start(editText);
}
void AssembleDialog::on_checkBoxKeepSize_clicked(bool checked)
{
if(checked && editText.size())
{
mValidateThread->start();
mValidateThread->textChanged(ui->lineEdit->text()); // Have to add this or textChanged isn't called inside start()
}
else
{
mValidateThread->stop();
mValidateThread->wait();
ui->labelKeepSize->setText("");
ui->pushButtonOk->setEnabled(true);
}
bKeepSizeChecked = checked;
}
void AssembleDialog::on_checkBoxFillWithNops_clicked(bool checked)
{
bFillWithNopsChecked = checked;
}
#include "AssembleDialog.h"
#include "ui_AssembleDialog.h"
#include <QMessageBox>
bool AssembleDialog::bWarningShowedOnce = false;
AssembleDialog::AssembleDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AssembleDialog)
{
ui->setupUi(this);
setModal(true);
setFixedSize(this->size()); //fixed size
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
#endif
mSelectedInstrVa = 0;
bKeepSizeChecked = false;
bFillWithNopsChecked = false;
mValidateThread = new ValidateExpressionThread(this);
mValidateThread->setOnExpressionChangedCallback(std::bind(&AssembleDialog::validateInstruction, this, std::placeholders::_1));
connect(ui->lineEdit, SIGNAL(textEdited(QString)), this, SLOT(textChangedSlot(QString)));
connect(mValidateThread, SIGNAL(instructionChanged(dsint,QString)), this, SLOT(instructionChangedSlot(dsint, QString)));
}
AssembleDialog::~AssembleDialog()
{
delete ui;
}
void AssembleDialog::setTextEditValue(const QString &text)
{
ui->lineEdit->setText(text);
}
void AssembleDialog::setKeepSizeChecked(bool checked)
{
ui->checkBoxKeepSize->setChecked(checked);
bKeepSizeChecked = checked;
}
void AssembleDialog::setKeepSizeLabel(const QString &text)
{
ui->labelKeepSize->setText(text);
}
void AssembleDialog::setFillWithNopsChecked(bool checked)
{
ui->checkBoxFillWithNops->setChecked(checked);
bFillWithNopsChecked = checked;
}
void AssembleDialog::setFillWithNopsLabel(const QString &text)
{
ui->labelFillWithNops->setText(text);
}
void AssembleDialog::setSelectedInstrVa(const duint va)
{
this->mSelectedInstrVa = va;
}
void AssembleDialog::setOkButtonEnabled(bool enabled)
{
ui->pushButtonOk->setEnabled(enabled);
}
void AssembleDialog::validateInstruction(QString expression)
{
//void instructionChanged(bool validInstruction, dsint sizeDifference, QString error)
dsint sizeDifference = 0;
int typedInstructionSize = 0;
int selectedInstructionSize = 0;
bool validInstruction = false;
QByteArray error(MAX_ERROR_SIZE, 0);
BASIC_INSTRUCTION_INFO basicInstrInfo;
// Get selected instruction info (size here)
DbgDisasmFastAt(mSelectedInstrVa, &basicInstrInfo);
selectedInstructionSize = basicInstrInfo.size;
// Get typed in instruction size
if(!DbgFunctions()->Assemble(this->mSelectedInstrVa, NULL, &typedInstructionSize, editText.toUtf8().constData(), error.data()) || selectedInstructionSize == 0)
{
emit mValidateThread->emitInstructionChanged(0, QString(error));
return;
}
// Valid instruction
validInstruction = true;
sizeDifference = typedInstructionSize - selectedInstructionSize;
emit mValidateThread->emitInstructionChanged(sizeDifference, "");
}
void AssembleDialog::hideEvent(QHideEvent *event)
{
Q_UNUSED(event);
mValidateThread->stop();
mValidateThread->wait();
}
void AssembleDialog::textChangedSlot(QString text)
{
if(ui->checkBoxKeepSize->isChecked())
mValidateThread->textChanged(text);
}
void AssembleDialog::instructionChangedSlot(dsint sizeDifference, QString error)
{
if(ui->checkBoxKeepSize->isChecked())
{
// If there was an error
if(error.length())
{
this->setKeepSizeLabel("<font color='orange'><b>Instruction decoding error : " + error + "</b></font>");
return;
}
// No error
else
{
// SizeDifference > 0 <=> Typed instruction is bigger
if(sizeDifference > 0)
{
QString message = "<font color='red'><b>Instruction bigger by " + QString::number(sizeDifference);
if(sizeDifference == 1)
message += QString(" byte</b></font>");
else
message += QString(" bytes</b></font>");
this->setKeepSizeLabel(message);
this->setOkButtonEnabled(false);
}
// SizeDifference < 0 <=> Typed instruction is smaller
else if(sizeDifference < 0)
{
QString message = "<font color='#00cc00'><b>Instruction smaller by " + QString::number(sizeDifference);
if(sizeDifference == -1)
message += QString(" byte</b></font>");
else
message += QString(" bytes</b></font>");
this->setKeepSizeLabel(message);
this->setOkButtonEnabled(true);
}
// SizeDifference == 0 <=> Both instruction have same size
else
{
QString message = "<font color='#00cc00'><b>Instruction is same size</b></font>";
this->setKeepSizeLabel(message);
this->setOkButtonEnabled(true);
}
}
}
}
void AssembleDialog::on_lineEdit_textChanged(const QString &arg1)
{
editText = arg1;
if(ui->checkBoxKeepSize->isChecked() && editText.size())
mValidateThread->start(editText);
}
void AssembleDialog::on_checkBoxKeepSize_clicked(bool checked)
{
if(checked && editText.size())
{
mValidateThread->start();
mValidateThread->textChanged(ui->lineEdit->text()); // Have to add this or textChanged isn't called inside start()
}
else
{
mValidateThread->stop();
mValidateThread->wait();
ui->labelKeepSize->setText("");
ui->pushButtonOk->setEnabled(true);
}
bKeepSizeChecked = checked;
}
void AssembleDialog::on_checkBoxFillWithNops_clicked(bool checked)
{
bFillWithNopsChecked = checked;
}

View File

@ -1,53 +1,53 @@
#ifndef ASSEMBLEDIALOG_H
#define ASSEMBLEDIALOG_H
#include <QDialog>
#include <functional>
#include "Bridge.h"
#include "ValidateExpressionThread.h"
namespace Ui
{
class AssembleDialog;
}
class AssembleDialog : public QDialog
{
Q_OBJECT
public:
explicit AssembleDialog(QWidget *parent = 0);
~AssembleDialog();
QString editText;
static bool bWarningShowedOnce;
void setTextEditValue(const QString & text);
bool bKeepSizeChecked;
void setKeepSizeChecked(bool checked);
void setKeepSizeLabel(const QString & text);
bool bFillWithNopsChecked;
void setFillWithNopsChecked(bool checked);
void setFillWithNopsLabel(const QString & text);
void setSelectedInstrVa(const duint va);
void setOkButtonEnabled(bool enabled);
void validateInstruction(QString expression);
void hideEvent(QHideEvent *event);
private slots:
void textChangedSlot(QString text);
void instructionChangedSlot(dsint sizeDifference, QString error);
void on_lineEdit_textChanged(const QString &arg1);
void on_checkBoxKeepSize_clicked(bool checked);
void on_checkBoxFillWithNops_clicked(bool checked);
private:
Ui::AssembleDialog *ui;
duint mSelectedInstrVa;
ValidateExpressionThread *mValidateThread;
};
#endif // ASSEMBLEDIALOG_H
#ifndef ASSEMBLEDIALOG_H
#define ASSEMBLEDIALOG_H
#include <QDialog>
#include <functional>
#include "Bridge.h"
#include "ValidateExpressionThread.h"
namespace Ui
{
class AssembleDialog;
}
class AssembleDialog : public QDialog
{
Q_OBJECT
public:
explicit AssembleDialog(QWidget *parent = 0);
~AssembleDialog();
QString editText;
static bool bWarningShowedOnce;
void setTextEditValue(const QString & text);
bool bKeepSizeChecked;
void setKeepSizeChecked(bool checked);
void setKeepSizeLabel(const QString & text);
bool bFillWithNopsChecked;
void setFillWithNopsChecked(bool checked);
void setFillWithNopsLabel(const QString & text);
void setSelectedInstrVa(const duint va);
void setOkButtonEnabled(bool enabled);
void validateInstruction(QString expression);
void hideEvent(QHideEvent *event);
private slots:
void textChangedSlot(QString text);
void instructionChangedSlot(dsint sizeDifference, QString error);
void on_lineEdit_textChanged(const QString &arg1);
void on_checkBoxKeepSize_clicked(bool checked);
void on_checkBoxFillWithNops_clicked(bool checked);
private:
Ui::AssembleDialog *ui;
duint mSelectedInstrVa;
ValidateExpressionThread *mValidateThread;
};
#endif // ASSEMBLEDIALOG_H