Fixed RelocatableFile viewer

This commit is contained in:
Mark Long
2025-09-30 17:46:05 -05:00
parent 46a021ecba
commit 438cb82817
4 changed files with 71 additions and 44 deletions
+3 -1
View File
@@ -7,7 +7,9 @@
BinaryFileMetadata::BinaryFileMetadata(GenericFile &file, quint16 defaultAddress, QObject *parent)
: QObject(parent), m_file(file), m_defaultAddress(defaultAddress)
{
load();
EntryPoint p {defaultAddress, "Start"};
m_eps.addPoint(p);
//load();
}
void BinaryFileMetadata::load()
+1 -1
View File
@@ -7,7 +7,7 @@
#include <QDataStream>
struct EntryPoint {
quint16 address;
quint16 address{0};
QString note;
};
+63 -39
View File
@@ -1,45 +1,57 @@
#include "RelocatableFile.h"
#include <QDebug>
RelocatableFile::RelocatableFile(const QByteArray& data) noexcept
RelocatableFile::RelocatableFile(const QByteArray &data) noexcept
: GenericFile(data)
{
if (!data.isEmpty()) {
if (!data.isEmpty())
{
setData(data);
}
qDebug() << this->filename();
dump();
}
void RelocatableFile::setData(const QByteArray& data)
void RelocatableFile::setData(const QByteArray &data)
{
// qDebug() << "setData()";
if (data.length() >= 6) {
m_starting_ram_address = makeWord(m_data[0],m_data[1]);
m_ram_image_length = makeWord(m_data[2],m_data[3]);
m_code_image_length = makeWord(m_data[4],m_data[5]);
// qDebug() << "setData()";
if (data.length() >= 6)
{
m_starting_ram_address = makeWord(m_data[0], m_data[1]);
m_address = m_starting_ram_address;
m_ram_image_length = makeWord(m_data[2], m_data[3]);
m_code_image_length = makeWord(m_data[4], m_data[5]);
m_data = m_data.mid(6);
int offset = 0;
for (int idx = 6; idx < m_code_image_length+6; idx++) {
for (int idx = 0; idx < m_code_image_length; idx++)
{
quint8 val = m_data[idx];
m_binary_code_image.append(val);
}
for (int N = 0; N < (m_code_image_length/4); N++) {
offset = m_code_image_length+ 6 +(N*4);
for (int N = 0; N < (m_code_image_length); N += 4)
{
// qDebug() << "N: " << N << uint8ToHex(m_data[offset])
// << uint8ToHex(m_data[offset+1])
// << uint8ToHex(m_data[offset+2])
// << uint8ToHex(m_data[offset+3]);
offset = m_code_image_length + N;
RelocatableDictItem rdi = RelocatableDictItem(m_data[offset],m_data[offset+1],
m_data[offset+2],m_data[offset+3]);
// qDebug() << "N: " << N << uint8ToHex(m_data[offset])
// << uint8ToHex(m_data[offset+1])
// << uint8ToHex(m_data[offset+2])
// << uint8ToHex(m_data[offset+3]);
RelocatableDictItem rdi = RelocatableDictItem(m_data[offset], m_data[offset + 1],
m_data[offset + 2], m_data[offset + 3]);
if (rdi.isEndOfRLD())
{
break;
}
m_relocatable_dict.append(rdi);
if (rdi.isEndOfRLD()) { break; }
}
// m_data = m_binary_code_image;
}
}
@@ -51,15 +63,21 @@ void RelocatableFile::dump()
qDebug() << "Length of Code Image: " << m_code_image_length << uint16ToHex(m_code_image_length);
int itemIdx = 0;
for (const auto& item : m_relocatable_dict) {
for (const auto &item : m_relocatable_dict)
{
const auto b4rt = item.getByte4();
QString typestr;
if (b4rt.first == RelocatableTypes::Byte4Type::ESDSymbol) {
typestr = QStringLiteral("ESDSymbol");
} else if (b4rt.first == RelocatableTypes::Byte4Type::ByteHi) {
typestr = QStringLiteral("Hi Byte");
} else {
typestr = QStringLiteral("Lo Byte");
if (b4rt.first == RelocatableTypes::Byte4Type::ESDSymbol)
{
typestr = QStringLiteral("ESDSymbol");
}
else if (b4rt.first == RelocatableTypes::Byte4Type::ByteHi)
{
typestr = QStringLiteral("Hi Byte");
}
else
{
typestr = QStringLiteral("Lo Byte");
}
const quint16 fo = item.getFieldOffset();
qDebug() << " Item #" << itemIdx++
@@ -75,24 +93,30 @@ QStringList RelocatableFile::decodeRelocatableDict() const
{
QStringList retval;
int idx = 0;
for (const auto& item : m_relocatable_dict) {
for (const auto &item : m_relocatable_dict)
{
const auto b4rt = item.getByte4();
QString typestr;
if (b4rt.first == RelocatableTypes::Byte4Type::ESDSymbol) {
typestr = QStringLiteral("ESDSymbol");
} else if (b4rt.first == RelocatableTypes::Byte4Type::ByteHi) {
typestr = QStringLiteral("Hi Byte");
} else {
typestr = QStringLiteral("Lo Byte");
if (b4rt.first == RelocatableTypes::Byte4Type::ESDSymbol)
{
typestr = QStringLiteral("ESDSymbol");
}
else if (b4rt.first == RelocatableTypes::Byte4Type::ByteHi)
{
typestr = QStringLiteral("Hi Byte");
}
else
{
typestr = QStringLiteral("Lo Byte");
}
const quint16 fo = item.getFieldOffset();
retval.append(QStringLiteral("Item %1, Offset %2, @ %3, %4 Field, %5")
.arg(idx++)
.arg(uint16ToHex(fo))
.arg(uint16ToHex(fo + address() + 6))
.arg((item.getFieldSize() == RelocatableTypes::FieldSize::TwoByte) ? "2-Byte" : "1-Byte")
.arg((item.isExtern()) ? "Extern" : "Not Extern"));
.arg(idx++)
.arg(uint16ToHex(fo))
.arg(uint16ToHex(fo + address() + 6))
.arg((item.getFieldSize() == RelocatableTypes::FieldSize::TwoByte) ? "2-Byte" : "1-Byte")
.arg((item.isExtern()) ? "Extern" : "Not Extern"));
}
return retval;
+4 -3
View File
@@ -104,7 +104,7 @@ void DisassemblerViewer::setFile(RelocatableFile *file) {
setCursor(Qt::WaitCursor);
m_bfm = new BinaryFileMetadata(*m_file, file->address() + 6, this);
m_bfm = new BinaryFileMetadata(*m_file, file->address(), this);
connect(m_bfm, &BinaryFileMetadata::doDisassemble,
this, &DisassemblerViewer::handleDisassembleRequest);
@@ -112,8 +112,9 @@ void DisassemblerViewer::setFile(RelocatableFile *file) {
QString title = QString("Disassembler Viewer: %1 (Relocatable)").arg(m_file->filename());
setWindowTitle(title);
quint16 address = file->address() + 6 ; // Handle offset for relocatable metadata
m_mem.addFile(m_file->data(), address);
quint16 address = file->address(); // Handle offset for relocatable metadata
m_mem.addFile(file->data(), address);
qDebug("Added %d bytes at $%s", file->data().length(), uint16ToHex(address).toStdString().c_str());
QList<quint16> addresses = m_bfm->entryPoints().getEntryPointAddresses();
if (!addresses.count()) { addresses.append(address); }