mirror of
https://github.com/markdavidlong/AppleSAWS.git
synced 2024-12-30 03:29:42 +00:00
Continued work on assembler metadata dialog
This commit is contained in:
parent
a5382655a3
commit
0badceb216
@ -60,7 +60,10 @@ SOURCES += \
|
||||
src/ui/widgets/HiresScreenWidget.cpp \
|
||||
src/ui/widgets/DisassemblerMetadataDialog.cpp \
|
||||
src/binaryfile/EntryPointModel.cpp \
|
||||
src/ui/widgets/LocationInfoDialog.cpp
|
||||
src/ui/widgets/LocationInfoDialog.cpp \
|
||||
src/binaryfile/EntryPoints.cpp \
|
||||
src/binaryfile/AssemblerSymbols.cpp \
|
||||
src/binaryfile/AssemblerSymbolModel.cpp
|
||||
|
||||
|
||||
HEADERS += \
|
||||
@ -103,7 +106,10 @@ HEADERS += \
|
||||
src/ui/widgets/HiresScreenWidget.h \
|
||||
src/ui/widgets/DisassemblerMetadataDialog.h \
|
||||
src/binaryfile/EntryPointModel.h \
|
||||
src/ui/widgets/LocationInfoDialog.h
|
||||
src/ui/widgets/LocationInfoDialog.h \
|
||||
src/binaryfile/EntryPoints.h \
|
||||
src/binaryfile/AssemblerSymbols.h \
|
||||
src/binaryfile/AssemblerSymbolModel.h
|
||||
|
||||
FORMS += \
|
||||
src/ui/catalogwidget.ui \
|
||||
|
121
src/binaryfile/AssemblerSymbolModel.cpp
Normal file
121
src/binaryfile/AssemblerSymbolModel.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
#include "AssemblerSymbolModel.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
AssemblerSymbolModel::AssemblerSymbolModel(QObject *parent, AssemblerSymbols *symbols)
|
||||
:QAbstractTableModel(parent)
|
||||
{
|
||||
setAssemblerSymbolsData(symbols);
|
||||
}
|
||||
|
||||
void AssemblerSymbolModel::setAssemblerSymbolsData(AssemblerSymbols *symbols)
|
||||
{
|
||||
assemblerSymbols = symbols;
|
||||
|
||||
if (assemblerSymbols)
|
||||
{
|
||||
connect(assemblerSymbols,SIGNAL(symbolAddedAt(int)),SLOT(handleSymbolAddition(int)));
|
||||
connect(assemblerSymbols,SIGNAL(symbolChangedAt(int)),SLOT(handleSymbolChange(int)));
|
||||
connect(assemblerSymbols,SIGNAL(symbolRemovedAt(int)),SLOT(handleSymbolRemoval(int)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QVariant AssemblerSymbolModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (!assemblerSymbols) return QVariant();
|
||||
|
||||
if (orientation == Qt::Horizontal)
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
if (section == 0)
|
||||
return "";
|
||||
|
||||
}
|
||||
}
|
||||
else // Orientation == Qt::Vertical
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
return "0x"+uint16ToHex(assemblerSymbols->at(section).address);
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
int AssemblerSymbolModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
if (!assemblerSymbols) return 0;
|
||||
|
||||
return assemblerSymbols->numAssemblerSymbols();
|
||||
}
|
||||
|
||||
int AssemblerSymbolModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant AssemblerSymbolModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!assemblerSymbols) return QVariant();
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
if (index.column() == 0)
|
||||
{
|
||||
return assemblerSymbols->at(index.row()).name;
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool AssemblerSymbolModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!assemblerSymbols) return false;
|
||||
|
||||
if (data(index, role) != value) {
|
||||
if (index.column() == 0)
|
||||
{
|
||||
assemblerSymbols->symbolRefAt(index.row()).name = value.toString();
|
||||
}
|
||||
emit dataChanged(index, index, QVector<int>() << role);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::ItemFlags AssemblerSymbolModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
if (index.column() == 0)
|
||||
return Qt::ItemIsEditable | QAbstractTableModel::flags(index);
|
||||
else
|
||||
return QAbstractTableModel::flags(index);
|
||||
}
|
||||
|
||||
bool AssemblerSymbolModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
beginInsertRows(parent, row, row + count - 1);
|
||||
endInsertRows();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AssemblerSymbolModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
if (!assemblerSymbols) return false;
|
||||
|
||||
beginRemoveRows(parent, row, row + count - 1);
|
||||
for (int idx = 0; idx < count; idx++)
|
||||
{
|
||||
assemblerSymbols->removeSymbolAt(row);
|
||||
}
|
||||
endRemoveRows();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
60
src/binaryfile/AssemblerSymbolModel.h
Normal file
60
src/binaryfile/AssemblerSymbolModel.h
Normal file
@ -0,0 +1,60 @@
|
||||
#ifndef ASSEMBLERSYMBOLMODEL_H
|
||||
#define ASSEMBLERSYMBOLMODEL_H
|
||||
|
||||
|
||||
#include "AssemblerSymbols.h"
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
|
||||
|
||||
|
||||
class AssemblerSymbolModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AssemblerSymbolModel(QObject *parent = 0, AssemblerSymbols *symbols = Q_NULLPTR);
|
||||
void setAssemblerSymbolsData(AssemblerSymbols *symbols);
|
||||
|
||||
// Header:
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;//DONE
|
||||
|
||||
// Basic functionality:
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
// Editable:
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
|
||||
// Add data:
|
||||
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
|
||||
// Remove data:
|
||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
|
||||
void doTestData();
|
||||
|
||||
|
||||
protected slots:
|
||||
void handleSymbolAddition(int location) { insertRows(location,1); }
|
||||
void handleSymbolRemoval(int location) { removeRows(location, 1); }
|
||||
void handleSymbolChange(int location)
|
||||
{
|
||||
QModelIndex ind = createIndex(location,0);
|
||||
emit dataChanged(ind,ind,QVector<int>() << Qt::DisplayRole);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
AssemblerSymbols *assemblerSymbols;
|
||||
};
|
||||
|
||||
|
||||
#endif // ASSEMBLERSYMBOLMODEL_H
|
124
src/binaryfile/AssemblerSymbols.cpp
Normal file
124
src/binaryfile/AssemblerSymbols.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include "AssemblerSymbols.h"
|
||||
|
||||
AssemblerSymbols::AssemblerSymbols(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool AssemblerSymbols::hasAssemSymbolAtAddress(quint16 address)
|
||||
{
|
||||
// Assume list m_assemblerSymbols is sorted by address (it should be)
|
||||
QListIterator<AssemSymbol> it(m_assemblerSymbols);
|
||||
while (it.hasNext())
|
||||
{
|
||||
AssemSymbol ep = it.next();
|
||||
if (ep.address == address) return true;
|
||||
if (ep.address > address) return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AssemblerSymbols::editSymbol(int location, AssemSymbol newSymbol)
|
||||
{
|
||||
|
||||
if (m_assemblerSymbols.at(location).address == newSymbol.address)
|
||||
{
|
||||
m_assemblerSymbols[location].name = newSymbol.name;
|
||||
emit symbolChangedAt(location);
|
||||
}
|
||||
else
|
||||
{
|
||||
removeSymbolAt(location);
|
||||
addSymbol(newSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
void AssemblerSymbols::addSymbol(AssemSymbol ep)
|
||||
{
|
||||
if (hasAssemSymbolAtAddress(ep.address)) return;
|
||||
|
||||
int idx = 0;
|
||||
for (; idx < m_assemblerSymbols.count(); idx++)
|
||||
{
|
||||
if (ep.address < m_assemblerSymbols[idx].address)
|
||||
break;
|
||||
}
|
||||
m_assemblerSymbols.insert(idx,ep);
|
||||
emit symbolAddedAt(idx);
|
||||
emit symbolAdded(ep,idx);
|
||||
}
|
||||
|
||||
void AssemblerSymbols::removeSymbolAt(int location)
|
||||
{
|
||||
m_assemblerSymbols.removeAt(location);
|
||||
emit symbolRemovedAt(location);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// STREAMING OPERATORS
|
||||
|
||||
QDataStream &AssemblerSymbols::read(QDataStream &dataStream)
|
||||
{
|
||||
quint8 version;
|
||||
dataStream >> version;
|
||||
if (version == 0)
|
||||
{
|
||||
dataStream >> m_assemblerSymbols;
|
||||
}
|
||||
else qWarning("Unhandled version of AssemSymbolModel (%d) found in QDataStream",version);
|
||||
|
||||
return dataStream;
|
||||
}
|
||||
|
||||
QDataStream &AssemblerSymbols::write(QDataStream &dataStream) const
|
||||
{
|
||||
quint8 version = 0; // Increment this and update read() if new items are added
|
||||
dataStream << version;
|
||||
dataStream << m_assemblerSymbols;
|
||||
return dataStream;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const AssemblerSymbols &model)
|
||||
{
|
||||
return model.write(out);
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, AssemblerSymbols&model)
|
||||
{
|
||||
return model.read(in);
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const AssemSymbol &model)
|
||||
{
|
||||
out << model.address;
|
||||
out << model.name;
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, AssemSymbol &model)
|
||||
{
|
||||
in >> model.address;
|
||||
in >> model.name;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// TESTING
|
||||
|
||||
void AssemblerSymbols::doTestData()
|
||||
{
|
||||
AssemSymbol ep;
|
||||
ep.address = 0x0010;
|
||||
ep.name = "Test Entry Symbol 1";
|
||||
addSymbol(ep);
|
||||
ep.address = 0x0020;
|
||||
ep.name = "Test Entry Symbol 2";
|
||||
addSymbol(ep);
|
||||
ep.address = 0x0030;
|
||||
ep.name = "Test Entry Symbol 3";
|
||||
addSymbol(ep);
|
||||
|
||||
}
|
||||
|
||||
|
51
src/binaryfile/AssemblerSymbols.h
Normal file
51
src/binaryfile/AssemblerSymbols.h
Normal file
@ -0,0 +1,51 @@
|
||||
#ifndef ASSEMBLERSYMBOLS_H
|
||||
#define ASSEMBLERSYMBOLS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDataStream>
|
||||
|
||||
struct AssemSymbol {
|
||||
quint16 address;
|
||||
QString name;
|
||||
};
|
||||
|
||||
class AssemblerSymbols : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AssemblerSymbols(QObject *parent = 0);
|
||||
|
||||
bool hasAssemSymbolAtAddress(quint16 address);
|
||||
|
||||
const AssemSymbol &at(int location) const { return m_assemblerSymbols.at(location); }
|
||||
AssemSymbol &symbolRefAt(int location) { return m_assemblerSymbols[location]; }
|
||||
AssemSymbol &operator[](int location) { return m_assemblerSymbols[location]; }
|
||||
|
||||
void editSymbol(int at, AssemSymbol newSymbol);
|
||||
|
||||
QDataStream &read(QDataStream &dataStream);
|
||||
QDataStream &write(QDataStream &dataStream) const;
|
||||
|
||||
int numAssemblerSymbols() const { return m_assemblerSymbols.count(); }
|
||||
|
||||
void doTestData();
|
||||
|
||||
signals:
|
||||
void symbolAdded(AssemSymbol &AssemSymbol, int location);
|
||||
void symbolAddedAt(int location);
|
||||
void symbolRemovedAt(int location);
|
||||
void symbolChangedAt(int location);
|
||||
|
||||
public slots:
|
||||
void addSymbol(AssemSymbol ep);
|
||||
void removeSymbolAt(int location);
|
||||
|
||||
protected:
|
||||
QList<AssemSymbol> m_assemblerSymbols;
|
||||
};
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const AssemblerSymbols &model);
|
||||
QDataStream &operator>>(QDataStream &in, AssemblerSymbols &model);
|
||||
|
||||
|
||||
#endif // ASSEMBLERSYMBOLS_H
|
@ -3,13 +3,32 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
EntryPointModel::EntryPointModel(QObject *parent)
|
||||
|
||||
|
||||
EntryPointModel::EntryPointModel(QObject *parent, EntryPoints *points)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
setEntryPointsData(points);
|
||||
}
|
||||
|
||||
void EntryPointModel::setEntryPointsData(EntryPoints *points)
|
||||
{
|
||||
entryPoints = points;
|
||||
|
||||
if (entryPoints)
|
||||
{
|
||||
connect(entryPoints,SIGNAL(pointAddedAt(int)),SLOT(handlePointAddition(int)));
|
||||
connect(entryPoints,SIGNAL(pointChangedAt(int)),SLOT(handlePointChange(int)));
|
||||
connect(entryPoints,SIGNAL(pointRemovedAt(int)),SLOT(handlePointRemoval(int)));
|
||||
// insertRows(0,entryPoints->numEntryPoints());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QVariant EntryPointModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (!entryPoints) return QVariant();
|
||||
|
||||
if (orientation == Qt::Horizontal)
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
@ -23,7 +42,7 @@ QVariant EntryPointModel::headerData(int section, Qt::Orientation orientation, i
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
return "0x"+uint16ToHex(m_entryPoints[section].address);
|
||||
return "0x"+uint16ToHex(entryPoints->at(section).address);
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
@ -33,44 +52,40 @@ QVariant EntryPointModel::headerData(int section, Qt::Orientation orientation, i
|
||||
int EntryPointModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
// if (parent.isValid())
|
||||
return m_entryPoints.count();
|
||||
// else
|
||||
// return 0;
|
||||
if (!entryPoints) return 0;
|
||||
|
||||
return entryPoints->numEntryPoints();
|
||||
}
|
||||
|
||||
int EntryPointModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
//if (parent.isValid())
|
||||
return 1;
|
||||
// else
|
||||
// return 0;
|
||||
}
|
||||
|
||||
QVariant EntryPointModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!entryPoints) return QVariant();
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
EntryPoint ep = m_entryPoints[index.row()];
|
||||
if (index.column() == 0)
|
||||
{
|
||||
return ep.note;
|
||||
return entryPoints->at(index.row()).note;
|
||||
}
|
||||
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool EntryPointModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!entryPoints) return false;
|
||||
|
||||
if (data(index, role) != value) {
|
||||
if (index.column() == 0)
|
||||
{
|
||||
m_entryPoints[index.row()].note = value.toString();
|
||||
entryPoints->pointRefAt(index.row()).note = value.toString();
|
||||
}
|
||||
|
||||
emit dataChanged(index, index, QVector<int>() << role);
|
||||
return true;
|
||||
}
|
||||
@ -89,67 +104,21 @@ Qt::ItemFlags EntryPointModel::flags(const QModelIndex &index) const
|
||||
bool EntryPointModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
beginInsertRows(parent, row, row + count - 1);
|
||||
// FIXME: Implement me!
|
||||
endInsertRows();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EntryPointModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
if (!entryPoints) return false;
|
||||
|
||||
beginRemoveRows(parent, row, row + count - 1);
|
||||
for (int idx = 0; idx < count; idx++)
|
||||
{
|
||||
m_entryPoints.removeAt(row);
|
||||
entryPoints->removePointAt(row);
|
||||
}
|
||||
endRemoveRows();
|
||||
return false;
|
||||
}
|
||||
|
||||
void EntryPointModel::doTestData()
|
||||
{
|
||||
EntryPoint ep;
|
||||
ep.address = 0x0010;
|
||||
ep.note = "Test Entry Point 1";
|
||||
addEntryPoint(ep);
|
||||
ep.address = 0x0020;
|
||||
ep.note = "Test Entry Point 2";
|
||||
addEntryPoint(ep);
|
||||
ep.address = 0x0030;
|
||||
ep.note = "Test Entry Point 3";
|
||||
addEntryPoint(ep);
|
||||
|
||||
}
|
||||
|
||||
void EntryPointModel::addEntryPoint(EntryPoint ep)
|
||||
{
|
||||
if (!m_entryPoints.count())
|
||||
{
|
||||
m_entryPoints.append(ep);
|
||||
insertRows(m_entryPoints.count(),1);
|
||||
}
|
||||
else
|
||||
{
|
||||
int idx = 0;
|
||||
for (; idx < m_entryPoints.count(); idx++)
|
||||
{
|
||||
if (ep.address < m_entryPoints[idx].address)
|
||||
break;
|
||||
}
|
||||
m_entryPoints.insert(idx,ep);
|
||||
insertRows(idx,1);
|
||||
}
|
||||
}
|
||||
|
||||
void EntryPointModel::removeSelection(QModelIndexList selection)
|
||||
{
|
||||
if (selection.count() > 1)
|
||||
{
|
||||
qWarning() << "Unexpected number of items to remove. Only removing the first.";
|
||||
}
|
||||
if (selection.count())
|
||||
{
|
||||
removeRow(selection[1].row());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,28 +1,30 @@
|
||||
#ifndef ENTRYPOINTMODEL_H
|
||||
#define ENTRYPOINTMODEL_H
|
||||
|
||||
#include "EntryPoints.h"
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
struct EntryPoint {
|
||||
quint16 address;
|
||||
QString note;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class EntryPointModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EntryPointModel(QObject *parent = 0);
|
||||
explicit EntryPointModel(QObject *parent = 0, EntryPoints *points = Q_NULLPTR);
|
||||
void setEntryPointsData(EntryPoints *points);
|
||||
|
||||
// Header:
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;//DONE
|
||||
|
||||
// Basic functionality:
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override; //DONE
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;//DONE
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;//DONE
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
// Editable:
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
@ -38,13 +40,22 @@ public:
|
||||
|
||||
void doTestData();
|
||||
|
||||
void addEntryPoint(EntryPoint ep);
|
||||
|
||||
void removeSelection(QModelIndexList selection);
|
||||
protected slots:
|
||||
void handlePointAddition(int location) { insertRows(location,1); }
|
||||
void handlePointRemoval(int location) { removeRows(location, 1); }
|
||||
void handlePointChange(int location)
|
||||
{
|
||||
QModelIndex ind = createIndex(location,0);
|
||||
emit dataChanged(ind,ind,QVector<int>() << Qt::DisplayRole);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
QList<EntryPoint> m_entryPoints;
|
||||
|
||||
EntryPoints *entryPoints;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // ENTRYPOINTMODEL_H
|
||||
|
124
src/binaryfile/EntryPoints.cpp
Normal file
124
src/binaryfile/EntryPoints.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include "EntryPoints.h"
|
||||
|
||||
EntryPoints::EntryPoints(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool EntryPoints::hasEntryPointAtAddress(quint16 address)
|
||||
{
|
||||
// Assume list m_entryPoints is sorted by address (it should be)
|
||||
QListIterator<EntryPoint> it(m_entryPoints);
|
||||
while (it.hasNext())
|
||||
{
|
||||
EntryPoint ep = it.next();
|
||||
if (ep.address == address) return true;
|
||||
if (ep.address > address) return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void EntryPoints::editPoint(int location, EntryPoint newPoint)
|
||||
{
|
||||
|
||||
if (m_entryPoints.at(location).address == newPoint.address)
|
||||
{
|
||||
m_entryPoints[location].note = newPoint.note;
|
||||
emit pointChangedAt(location);
|
||||
}
|
||||
else
|
||||
{
|
||||
removePointAt(location);
|
||||
addPoint(newPoint);
|
||||
}
|
||||
}
|
||||
|
||||
void EntryPoints::addPoint(EntryPoint ep)
|
||||
{
|
||||
if (hasEntryPointAtAddress(ep.address)) return;
|
||||
|
||||
int idx = 0;
|
||||
for (; idx < m_entryPoints.count(); idx++)
|
||||
{
|
||||
if (ep.address < m_entryPoints[idx].address)
|
||||
break;
|
||||
}
|
||||
m_entryPoints.insert(idx,ep);
|
||||
emit pointAddedAt(idx);
|
||||
emit pointAdded(ep,idx);
|
||||
}
|
||||
|
||||
void EntryPoints::removePointAt(int location)
|
||||
{
|
||||
m_entryPoints.removeAt(location);
|
||||
emit pointRemovedAt(location);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// STREAMING OPERATORS
|
||||
|
||||
QDataStream &EntryPoints::read(QDataStream &dataStream)
|
||||
{
|
||||
quint8 version;
|
||||
dataStream >> version;
|
||||
if (version == 0)
|
||||
{
|
||||
dataStream >> m_entryPoints;
|
||||
}
|
||||
else qWarning("Unhandled version of EntryPointModel (%d) found in QDataStream",version);
|
||||
|
||||
return dataStream;
|
||||
}
|
||||
|
||||
QDataStream &EntryPoints::write(QDataStream &dataStream) const
|
||||
{
|
||||
quint8 version = 0; // Increment this and update read() if new items are added
|
||||
dataStream << version;
|
||||
dataStream << m_entryPoints;
|
||||
return dataStream;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const EntryPoints &model)
|
||||
{
|
||||
return model.write(out);
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, EntryPoints&model)
|
||||
{
|
||||
return model.read(in);
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const EntryPoint &model)
|
||||
{
|
||||
out << model.address;
|
||||
out << model.note;
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, EntryPoint &model)
|
||||
{
|
||||
in >> model.address;
|
||||
in >> model.note;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// TESTING
|
||||
|
||||
void EntryPoints::doTestData()
|
||||
{
|
||||
EntryPoint ep;
|
||||
ep.address = 0x0010;
|
||||
ep.note = "Test Entry Point 1";
|
||||
addPoint(ep);
|
||||
ep.address = 0x0020;
|
||||
ep.note = "Test Entry Point 2";
|
||||
addPoint(ep);
|
||||
ep.address = 0x0030;
|
||||
ep.note = "Test Entry Point 3";
|
||||
addPoint(ep);
|
||||
|
||||
}
|
||||
|
||||
|
50
src/binaryfile/EntryPoints.h
Normal file
50
src/binaryfile/EntryPoints.h
Normal file
@ -0,0 +1,50 @@
|
||||
#ifndef ENTRYPOINTS_H
|
||||
#define ENTRYPOINTS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDataStream>
|
||||
|
||||
struct EntryPoint {
|
||||
quint16 address;
|
||||
QString note;
|
||||
};
|
||||
|
||||
class EntryPoints : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit EntryPoints(QObject *parent = 0);
|
||||
|
||||
bool hasEntryPointAtAddress(quint16 address);
|
||||
|
||||
const EntryPoint &at(int location) const { return m_entryPoints.at(location); }
|
||||
EntryPoint &pointRefAt(int location) { return m_entryPoints[location]; }
|
||||
EntryPoint &operator[](int location) { return m_entryPoints[location]; }
|
||||
|
||||
void editPoint(int at, EntryPoint newPoint);
|
||||
|
||||
QDataStream &read(QDataStream &dataStream);
|
||||
QDataStream &write(QDataStream &dataStream) const;
|
||||
|
||||
int numEntryPoints() const { return m_entryPoints.count(); }
|
||||
|
||||
void doTestData();
|
||||
|
||||
signals:
|
||||
void pointAdded(EntryPoint &entryPoint, int location);
|
||||
void pointAddedAt(int location);
|
||||
void pointRemovedAt(int location);
|
||||
void pointChangedAt(int location);
|
||||
|
||||
public slots:
|
||||
void addPoint(EntryPoint ep);
|
||||
void removePointAt(int location);
|
||||
|
||||
protected:
|
||||
QList<EntryPoint> m_entryPoints;
|
||||
};
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const EntryPoints &model);
|
||||
QDataStream &operator>>(QDataStream &in, EntryPoints &model);
|
||||
|
||||
#endif // ENTRYPOINTS_H
|
@ -34,8 +34,8 @@ BinaryFileMetadata::BinaryFileMetadata(QString filename)
|
||||
|
||||
bool BinaryFileMetadata::load()
|
||||
{
|
||||
setSymbol(0x0000,"Test Symbol 1");
|
||||
setSymbol(0x0006,"Test Symbol 2");
|
||||
// setSymbol(0x0000,"Test Symbol 1");
|
||||
// setSymbol(0x0006,"Test Symbol 2");
|
||||
// setEntryPoint(0x0010,"Test Entry Point 1");
|
||||
// setEntryPoint(0x0020,"Test Entry Point 2");
|
||||
return true;
|
||||
@ -46,39 +46,39 @@ bool BinaryFileMetadata::save()
|
||||
return false;
|
||||
}
|
||||
|
||||
void BinaryFileMetadata::setSymbol(quint16 address, QString name)
|
||||
{
|
||||
AssemSymbol symbol;
|
||||
symbol.address = address;
|
||||
symbol.name = name;
|
||||
setSymbol(symbol);
|
||||
}
|
||||
//void BinaryFileMetadata::setSymbol(quint16 address, QString name)
|
||||
//{
|
||||
// AssemSymbol Symbol;
|
||||
// Symbol.address = address;
|
||||
// Symbol.name = name;
|
||||
// setSymbol(Symbol);
|
||||
//}
|
||||
|
||||
void BinaryFileMetadata::setSymbol(AssemSymbol symbol)
|
||||
{
|
||||
m_symbols.insert(symbol.address, symbol);
|
||||
}
|
||||
//void BinaryFileMetadata::setSymbol(AssemSymbol Symbol)
|
||||
//{
|
||||
// m_Symbols.insert(Symbol.address, Symbol);
|
||||
//}
|
||||
|
||||
AssemSymbol BinaryFileMetadata::getSymbolAtAddress(quint16 address)
|
||||
{
|
||||
if (hasSymbolAtAddress(address))
|
||||
{
|
||||
return m_symbols[address];
|
||||
}
|
||||
return AssemSymbol();
|
||||
}
|
||||
//AssemSymbol BinaryFileMetadata::getSymbolAtAddress(quint16 address)
|
||||
//{
|
||||
// if (hasSymbolAtAddress(address))
|
||||
// {
|
||||
// return m_Symbols[address];
|
||||
// }
|
||||
// return AssemSymbol();
|
||||
//}
|
||||
|
||||
void BinaryFileMetadata::removeSymbol(AssemSymbol symbol)
|
||||
{
|
||||
removeSymbol(symbol.address);
|
||||
}
|
||||
//void BinaryFileMetadata::removeSymbol(AssemSymbol Symbol)
|
||||
//{
|
||||
// removeSymbol(Symbol.address);
|
||||
//}
|
||||
|
||||
void BinaryFileMetadata::removeSymbol(quint16 address)
|
||||
{
|
||||
if (hasSymbolAtAddress(address))
|
||||
{
|
||||
m_symbols.remove(address);
|
||||
}
|
||||
}
|
||||
//void BinaryFileMetadata::removeSymbol(quint16 address)
|
||||
//{
|
||||
// if (hasSymbolAtAddress(address))
|
||||
// {
|
||||
// m_Symbols.remove(address);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
@ -7,10 +7,6 @@
|
||||
|
||||
|
||||
|
||||
struct AssemSymbol {
|
||||
quint16 address;
|
||||
QString name;
|
||||
};
|
||||
|
||||
class BinaryFileMetadata
|
||||
{
|
||||
@ -35,20 +31,20 @@ public:
|
||||
// QList<EntryPoint> getEntryPointList() const { return m_entryPoints.values(); }
|
||||
// QMap<quint16,EntryPoint> getEntryPointMap() const { return m_entryPoints; }
|
||||
|
||||
void setSymbol(quint16 address, QString name);
|
||||
void setSymbol(AssemSymbol symbol);
|
||||
bool hasSymbol(AssemSymbol symbol) const { return hasSymbolAtAddress(symbol.address); }
|
||||
bool hasSymbolAtAddress(quint16 address) const { return m_symbols.contains(address); }
|
||||
AssemSymbol getSymbolAtAddress(quint16 address);
|
||||
void removeSymbol(AssemSymbol symbol);
|
||||
void removeSymbol(quint16 address);
|
||||
// void setSymbol(quint16 address, QString name);
|
||||
// void setSymbol(AssemSymbol Symbol);
|
||||
// bool hasSymbol(AssemSymbol Symbol) const { return hasSymbolAtAddress(Symbol.address); }
|
||||
// bool hasSymbolAtAddress(quint16 address) const { return m_Symbols.contains(address); }
|
||||
// AssemSymbol getSymbolAtAddress(quint16 address);
|
||||
// void removeSymbol(AssemSymbol Symbol);
|
||||
// void removeSymbol(quint16 address);
|
||||
|
||||
QList<AssemSymbol> getSymbolList() const { return m_symbols.values(); }
|
||||
QMap<quint16, AssemSymbol> getSymbolMap() const { return m_symbols; }
|
||||
// QList<AssemSymbol> getSymbolList() const { return m_Symbols.values(); }
|
||||
// QMap<quint16, AssemSymbol> getSymbolMap() const { return m_Symbols; }
|
||||
|
||||
private:
|
||||
|
||||
QMap<quint16,AssemSymbol> m_symbols;
|
||||
// QMap<quint16,AssemSymbol> m_Symbols;
|
||||
QString m_filename;
|
||||
};
|
||||
|
||||
|
@ -14,13 +14,17 @@ DisassemblerMetadataDialog::DisassemblerMetadataDialog(QWidget *parent) :
|
||||
m_bfm = new BinaryFileMetadata("Test");
|
||||
m_bfm->load();
|
||||
|
||||
m_epmodel = new EntryPointModel(this);
|
||||
|
||||
m_eps = new EntryPoints(this);
|
||||
m_as = new AssemblerSymbols(this);
|
||||
|
||||
processEntryPoints();
|
||||
processSymbols();
|
||||
|
||||
m_epmodel = new EntryPointModel(this,m_eps);
|
||||
m_asmodel = new AssemblerSymbolModel(this,m_as);
|
||||
|
||||
ui->entryTable->setModel(m_epmodel);
|
||||
ui->symbolTable->setModel(m_asmodel);
|
||||
|
||||
connect(ui->cancelButton, SIGNAL(clicked(bool)), SLOT(handleCancelButton()));
|
||||
connect(ui->exitButton,SIGNAL(clicked(bool)), SLOT(handleExitButton()));
|
||||
@ -36,6 +40,10 @@ DisassemblerMetadataDialog::~DisassemblerMetadataDialog()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DisassemblerMetadataDialog::showEvent(QShowEvent *){
|
||||
ui->entryTable->resizeRowsToContents();
|
||||
}
|
||||
|
||||
void DisassemblerMetadataDialog::setRelocatable(bool relocatable)
|
||||
{
|
||||
ui->reloAddrLabel->setVisible(relocatable);
|
||||
@ -67,7 +75,8 @@ void DisassemblerMetadataDialog::handleAddEntryPointButton()
|
||||
EntryPoint ep;
|
||||
ep.address = lid.getAddress();
|
||||
ep.note = lid.getInfo();
|
||||
m_epmodel->addEntryPoint(ep);
|
||||
m_eps->addPoint(ep);
|
||||
ui->entryTable->resizeRowsToContents();
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,13 +93,16 @@ void DisassemblerMetadataDialog::handleRemoveEntryPointButton()
|
||||
void DisassemblerMetadataDialog::handleAddSymbolButton()
|
||||
{
|
||||
LocationInfoDialog lid(this);
|
||||
lid.setInfoLabelString("Symbol");
|
||||
lid.setInfoLabelString("Symbol Name");
|
||||
lid.setWindowTitle("Add Symbol");
|
||||
if (lid.exec() == Accepted)
|
||||
{
|
||||
qDebug() << "Accepted";
|
||||
AssemSymbol as;
|
||||
as.address = lid.getAddress();
|
||||
as.name = lid.getInfo();
|
||||
m_as->addSymbol(as);
|
||||
ui->symbolTable->resizeRowsToContents();
|
||||
}
|
||||
else qDebug()<<"Rejected";
|
||||
}
|
||||
|
||||
void DisassemblerMetadataDialog::handleRemoveSymbolButton()
|
||||
@ -106,5 +118,5 @@ void DisassemblerMetadataDialog::processSymbols()
|
||||
|
||||
void DisassemblerMetadataDialog::processEntryPoints()
|
||||
{
|
||||
m_epmodel->doTestData();
|
||||
m_eps->doTestData();
|
||||
}
|
||||
|
@ -2,7 +2,10 @@
|
||||
#define DISASSEMBLERMETADATADIALOG_H
|
||||
|
||||
#include "binaryfilemetadata.h"
|
||||
#include "EntryPoints.h"
|
||||
#include "EntryPointModel.h"
|
||||
#include "AssemblerSymbolModel.h"
|
||||
#include "AssemblerSymbols.h"
|
||||
#include "LocationInfoDialog.h"
|
||||
|
||||
#include <QDialog>
|
||||
@ -24,6 +27,9 @@ public:
|
||||
void processSymbols();
|
||||
void processEntryPoints();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
|
||||
protected slots:
|
||||
void handleCancelButton();
|
||||
void handleExitButton();
|
||||
@ -41,8 +47,12 @@ private:
|
||||
|
||||
BinaryFileMetadata *m_bfm;
|
||||
|
||||
EntryPoints *m_eps;
|
||||
EntryPointModel *m_epmodel;
|
||||
|
||||
AssemblerSymbols *m_as;
|
||||
AssemblerSymbolModel *m_asmodel;
|
||||
|
||||
bool m_isRelocatable;
|
||||
};
|
||||
|
||||
|
@ -114,7 +114,23 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<widget class="QTableView" name="symbolTable"/>
|
||||
<widget class="QTableView" name="symbolTable">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
Loading…
Reference in New Issue
Block a user