Implementing an indicator of the trust level

This commit is contained in:
Anonymus Raccoon
2020-03-28 16:06:33 +01:00
parent 8102a49f87
commit 4a8a4a98f3
5 changed files with 44 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="resources">
<file>icons/continue.svg</file>
<file>icons/step.svg</file>
<file>Logo.png</file>
<file>icons/play.svg</file>

View File

@@ -0,0 +1 @@
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="level-down-alt" class="svg-inline--fa fa-level-down-alt fa-w-10" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path fill="currentColor" d="M313.553 392.331L209.587 504.334c-9.485 10.214-25.676 10.229-35.174 0L70.438 392.331C56.232 377.031 67.062 352 88.025 352H152V80H68.024a11.996 11.996 0 0 1-8.485-3.515l-56-56C-4.021 12.926 1.333 0 12.024 0H208c13.255 0 24 10.745 24 24v328h63.966c20.878 0 31.851 24.969 17.587 40.331z"></path></svg>

After

Width:  |  Height:  |  Size: 531 B

View File

@@ -183,6 +183,7 @@ namespace ComSquare::Debugger
while (pc < endAddr) {
DisassembledInstruction instruction = this->_parseInstruction(pc, ctx);
instruction.level = ctx.level;
map.push_back(instruction);
pc += instruction.size;
if (instruction.addressingMode == ImmediateForA && !ctx.mFlag)
@@ -214,10 +215,10 @@ namespace ComSquare::Debugger
ctx.mFlag = true;
ctx.xFlag = true;
} else
ctx.compromised = true;
ctx.level = Compromised;
}
if (instruction.opcode == 0xFB) {// XCE
ctx.compromised = true;
ctx.level = Unsafe;
ctx.isEmulationMode = false; // The most common use of the XCE is to enable native mode at the start of the ROM so we guess that it has done that.
}
}
@@ -332,7 +333,7 @@ DisassemblyModel::DisassemblyModel(ComSquare::Debugger::CPUDebug &cpu) : QAbstra
int DisassemblyModel::columnCount(const QModelIndex &) const
{
return 3;
return 4;
}
int DisassemblyModel::rowCount(const QModelIndex &) const
@@ -342,9 +343,16 @@ int DisassemblyModel::rowCount(const QModelIndex &) const
QVariant DisassemblyModel::data(const QModelIndex &index, int role) const
{
if (role != Qt::DisplayRole)
if (role != Qt::DisplayRole && role != Qt::DecorationRole)
return QVariant();
ComSquare::Debugger::DisassembledInstruction instruction = this->_cpu.disassembledInstructions[index.row()];
if (role == Qt::DecorationRole) {
if (index.column() == 3 && instruction.level == ComSquare::Debugger::TrustLevel::Unsafe)
return QColor(Qt::yellow);
if (index.column() == 3 && instruction.level == ComSquare::Debugger::TrustLevel::Compromised)
return QColor(Qt::red);
return QVariant();
}
switch (index.column()) {
case 0:
return QString(instruction.name.c_str());

View File

@@ -56,6 +56,12 @@ protected:
namespace ComSquare::Debugger
{
enum TrustLevel {
Safe,
Unsafe,
Compromised
};
//! @brief Struct used to emulate the state of the processor during the disassembly since instructions take a different amount of space depending on some flags.
struct DisassemblyContext {
//! @brief The accumulator and Memory width flag (in native mode only) - 0 = 16 bits mode, 1 = 8 bits mode.
@@ -67,14 +73,19 @@ namespace ComSquare::Debugger
//! @brief Is the CPU emulating a 6502? If yes, some instructions don't change flags the same way.
bool isEmulationMode = true;
//! @brief Sometimes, the flags can't be tracked correctly after an instruction so the next instructions may not be correctly disassembled.
bool compromised = false;
TrustLevel level = Safe;
};
//! @brief Struct representing an instruction in an human readable way (created by disassembling the rom).
struct DisassembledInstruction : public CPU::Instruction {
//! @brief The address of the instruction
uint24_t address;
//! @brief A string representing the argument with the right addressing mode.
std::string argument;
//! @brief The opcode of the instruction
uint8_t opcode;
//! @brief Are we sure that this instruction has been correctly disassembled?
TrustLevel level;
DisassembledInstruction(const CPU::Instruction &instruction, uint24_t address, std::string argument, uint8_t opcode);
DisassembledInstruction(const DisassembledInstruction &) = default;

View File

@@ -220,6 +220,7 @@
<bool>false</bool>
</attribute>
<addaction name="actionPause"/>
<addaction name="actionNext"/>
<addaction name="actionStep"/>
</widget>
<action name="actionPause">
@@ -228,13 +229,13 @@
<normaloff>:/resources/icons/play.svg</normaloff>:/resources/icons/play.svg</iconset>
</property>
<property name="text">
<string>Resume</string>
<string>Continue</string>
</property>
<property name="toolTip">
<string>Pause or Resume instruction execution.</string>
</property>
<property name="shortcut">
<string>P</string>
<string>C</string>
</property>
</action>
<action name="actionStep">
@@ -252,6 +253,21 @@
<string>S</string>
</property>
</action>
<action name="actionNext">
<property name="icon">
<iconset resource="../resources/appResources.qrc">
<normaloff>:/resources/icons/continue.svg</normaloff>:/resources/icons/continue.svg</iconset>
</property>
<property name="text">
<string>Next</string>
</property>
<property name="toolTip">
<string>Continue execution to the next line.</string>
</property>
<property name="shortcut">
<string>N</string>
</property>
</action>
</widget>
<resources>
<include location="../resources/appResources.qrc"/>