NE Alpha 41

This commit is contained in:
Cr4sh 2017-07-08 22:31:57 +03:00
parent c0f1a8eadf
commit 227be5480e
12 changed files with 8145 additions and 37 deletions

View File

@ -0,0 +1,23 @@
#ifndef GOTOADDRESSDIALOG_H
#define GOTOADDRESSDIALOG_H
#include <QObject>
#include <QDialog>
#include "ui_gotoaddressdialog.h"
class GoToAddressDialog : public QDialog
{
Q_OBJECT
public:
GoToAddressDialog(QWidget* parent = NULL) :
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint),
ui(new Ui::GoToAddressDialog) {
ui->setupUi(this);
}
~GoToAddressDialog() { delete ui; }
Ui::GoToAddressDialog* ui;
};
#endif // GOTOADDRESSDIALOG_H

View File

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GoToAddressDialog</class>
<widget class="QDialog" name="GoToAddressDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>270</width>
<height>70</height>
</rect>
</property>
<property name="windowTitle">
<string>Go to address</string>
</property>
<property name="modal">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Select tree item at address:</string>
</property>
</widget>
</item>
<item>
<widget class="HexSpinBox" name="hexSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>HexSpinBox</class>
<extends>QSpinBox</extends>
<header>hexspinbox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>GoToAddressDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>182</x>
<y>185</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>194</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>GoToAddressDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>182</x>
<y>185</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>194</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>204</width>
<width>270</width>
<height>70</height>
</rect>
</property>
@ -56,7 +56,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Select tree item at:</string>
<string>Select tree item at offset:</string>
</property>
</widget>
</item>

View File

@ -17,7 +17,7 @@
HexSpinBox::HexSpinBox(QWidget *parent) :
QSpinBox(parent), validator(QRegExp("0x([0-9a-fA-F]){1,8}"))
{
this->setRange(0, INT_MAX);
this->setRange(INT_MIN, INT_MAX);
this->setPrefix("0x");
}
@ -28,10 +28,10 @@ QValidator::State HexSpinBox::validate(QString &text, int &pos) const
QString HexSpinBox::textFromValue(int val) const
{
return QString::number(val, 16).toUpper();
return QString::number((uint)val, 16).toUpper();
}
int HexSpinBox::valueFromText(const QString &text) const
{
return text.toInt(NULL, 16);
return (int)text.toUInt(NULL, 16);
}

7914
UEFITool/qrc_uefitool.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@
UEFITool::UEFITool(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::UEFITool),
version(tr("NE alpha 40"))
version(tr("NE alpha 41"))
{
clipboard = QApplication::clipboard();
@ -26,6 +26,7 @@ version(tr("NE alpha 40"))
searchDialog = new SearchDialog(this);
hexViewDialog = new HexViewDialog(this);
goToOffsetDialog = new GoToOffsetDialog(this);
goToAddressDialog = new GoToAddressDialog(this);
model = NULL;
ffsParser = NULL;
ffsFinder = NULL;
@ -57,8 +58,8 @@ version(tr("NE alpha 40"))
connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(exit()));
connect(ui->actionGoToData, SIGNAL(triggered()), this, SLOT(goToData()));
connect(ui->actionGoToOffset, SIGNAL(triggered()), this, SLOT(goToOffset()));
connect(ui->actionGoToAddress, SIGNAL(triggered()), this, SLOT(goToAddress()));
connect(ui->actionLoadGuidDatabase, SIGNAL(triggered()), this, SLOT(loadGuidDatabase()));
connect(ui->actionGoToOffset, SIGNAL(triggered()), this, SLOT(goToOffset()));
connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(writeSettings()));
// Enable Drag-and-Drop actions
@ -84,6 +85,7 @@ version(tr("NE alpha 40"))
searchDialog->ui->hexEdit->setFont(font);
hexViewDialog->setFont(font);
goToOffsetDialog->ui->hexSpinBox->setFont(font);
goToAddressDialog->ui->hexSpinBox->setFont(font);
// Load built-in GUID database
initGuidDatabase(":/guids.csv");
@ -124,6 +126,7 @@ void UEFITool::init()
// Disable menus
ui->actionSearch->setEnabled(false);
ui->actionGoToOffset->setEnabled(false);
ui->actionGoToAddress->setEnabled(false);
ui->menuCapsuleActions->setEnabled(false);
ui->menuImageActions->setEnabled(false);
ui->menuRegionActions->setEnabled(false);
@ -344,6 +347,21 @@ void UEFITool::goToOffset()
}
}
void UEFITool::goToAddress()
{
goToAddressDialog->ui->hexSpinBox->setFocus();
goToAddressDialog->ui->hexSpinBox->selectAll();
if (goToAddressDialog->exec() != QDialog::Accepted)
return;
UINT32 address = (UINT32)goToAddressDialog->ui->hexSpinBox->value();
QModelIndex index = model->findByOffset(address - ffsParser->getAddressDiff());
if (index.isValid()) {
ui->structureTreeView->scrollTo(index, QAbstractItemView::PositionAtCenter);
ui->structureTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows | QItemSelectionModel::Clear);
}
}
void UEFITool::goToData()
{
QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex();
@ -820,8 +838,10 @@ void UEFITool::openImageFile(QString path)
delete ffsOps;
ffsOps = new FfsOperations(model);
// Enable goToOffset
// Enable goToOffset and goToAddress
ui->actionGoToOffset->setEnabled(true);
if (ffsParser->getAddressDiff() < 0xFFFFFFFFUL)
ui->actionGoToAddress->setEnabled(true);
// Set current directory
currentDir = fileInfo.absolutePath();
@ -1107,4 +1127,4 @@ void UEFITool::loadGuidDatabase()
if (!currentPath.isEmpty() && QMessageBox::Yes == QMessageBox::information(this, tr("New GUID database loaded"), tr("Apply new GUID database on the opened file?\nUnsaved changes and tree position will be lost."), QMessageBox::Yes, QMessageBox::No))
openImageFile(currentPath);
}
}
}

View File

@ -45,6 +45,7 @@
#include "searchdialog.h"
#include "gotooffsetdialog.h"
#include "gotoaddressdialog.h"
#include "hexviewdialog.h"
#include "ffsfinder.h"
@ -74,9 +75,9 @@ private slots:
void openImageFileInNewWindow();
void saveImageFile();
void search();
void goToOffset();
void goToAddress();
void hexView();
void bodyHexView();
@ -125,6 +126,7 @@ private:
SearchDialog* searchDialog;
HexViewDialog* hexViewDialog;
GoToOffsetDialog* goToOffsetDialog;
GoToAddressDialog* goToAddressDialog;
QClipboard* clipboard;
QString currentDir;
QString currentPath;
@ -141,7 +143,6 @@ private:
void showFinderMessages();
void showFitTable();
void showBuilderMessages();
};
#endif // UEFITOOL_H

View File

@ -10,6 +10,7 @@ HEADERS += uefitool.h \
searchdialog.h \
hexviewdialog.h \
gotooffsetdialog.h \
gotoaddressdialog.h \
guidlineedit.h \
ffsfinder.h \
hexspinbox.h \
@ -78,7 +79,8 @@ SOURCES += uefitool_main.cpp \
FORMS += uefitool.ui \
searchdialog.ui \
hexviewdialog.ui \
gotooffsetdialog.ui
gotooffsetdialog.ui \
gotoaddressdialog.ui
RESOURCES += uefitool.qrc
RC_FILE = uefitool.rc

View File

@ -272,8 +272,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>850</width>
<height>22</height>
<width>851</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -478,6 +478,7 @@
<addaction name="actionReplaceBody"/>
</widget>
<addaction name="actionGoToOffset"/>
<addaction name="actionGoToAddress"/>
<addaction name="actionSearch"/>
<addaction name="separator"/>
<addaction name="menuCapsuleActions"/>
@ -799,6 +800,17 @@
<string>Ctrl+Alt+G</string>
</property>
</action>
<action name="actionGoToAddress">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Go to &amp;address...</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+G</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>

View File

@ -2818,13 +2818,13 @@ USTATUS FfsParser::performSecondPass(const UModelIndex & index)
// Calculate address difference
const UINT32 vtfSize = model->header(lastVtf).size() + model->body(lastVtf).size() + model->tail(lastVtf).size();
const UINT32 diff = 0xFFFFFFFFUL - model->offset(lastVtf) - vtfSize + 1;
addressDiff = 0xFFFFFFFFUL - model->offset(lastVtf) - vtfSize + 1;
// Find and parse FIT
parseFit(index, diff);
parseFit(index);
// Apply address information to index and all it's child items
addMemoryAddressesRecursive(index, diff);
addMemoryAddressesRecursive(index);
// Add fixed and compressed
addFixedAndCompressedRecursive(index);
@ -2849,7 +2849,7 @@ USTATUS FfsParser::addFixedAndCompressedRecursive(const UModelIndex & index) {
return U_SUCCESS;
}
USTATUS FfsParser::parseFit(const UModelIndex & index, const UINT32 diff)
USTATUS FfsParser::parseFit(const UModelIndex & index)
{
// Check sanity
if (!index.isValid())
@ -2858,7 +2858,7 @@ USTATUS FfsParser::parseFit(const UModelIndex & index, const UINT32 diff)
// Search for FIT
UModelIndex fitIndex;
UINT32 fitOffset;
USTATUS result = findFitRecursive(index, diff, fitIndex, fitOffset);
USTATUS result = findFitRecursive(index, fitIndex, fitOffset);
if (result)
return result;
@ -2922,8 +2922,8 @@ USTATUS FfsParser::parseFit(const UModelIndex & index, const UINT32 diff)
case FIT_TYPE_MICROCODE: {
//TODO: refactor into function with error reporting
if (currentEntry->Address > diff && currentEntry->Address < 0xFFFFFFFFUL) {
UINT32 offset = (UINT32)currentEntry->Address - diff;
if (currentEntry->Address > addressDiff && currentEntry->Address < 0xFFFFFFFFUL) {
UINT32 offset = (UINT32)currentEntry->Address - addressDiff;
UModelIndex mcIndex = model->findByOffset(offset);
UByteArray mcFile = model->header(mcIndex) + model->body(mcIndex) + model->tail(mcIndex);
@ -2962,8 +2962,8 @@ USTATUS FfsParser::parseFit(const UModelIndex & index, const UINT32 diff)
case FIT_TYPE_AC_KEY_MANIFEST:
case FIT_TYPE_AC_BOOT_POLICY:
default:
if (currentEntry->Address > diff && currentEntry->Address < 0xFFFFFFFFUL) {
UINT32 offset = (UINT32)currentEntry->Address - diff;
if (currentEntry->Address > addressDiff && currentEntry->Address < 0xFFFFFFFFUL) {
UINT32 offset = (UINT32)currentEntry->Address - addressDiff;
itemIndex = model->findByOffset(offset);
}
@ -2987,7 +2987,7 @@ USTATUS FfsParser::parseFit(const UModelIndex & index, const UINT32 diff)
return U_SUCCESS;
}
USTATUS FfsParser::findFitRecursive(const UModelIndex & index, const UINT32 diff, UModelIndex & found, UINT32 & fitOffset)
USTATUS FfsParser::findFitRecursive(const UModelIndex & index, UModelIndex & found, UINT32 & fitOffset)
{
// Sanity check
if (!index.isValid())
@ -2995,7 +2995,7 @@ USTATUS FfsParser::findFitRecursive(const UModelIndex & index, const UINT32 diff
// Process child items
for (int i = 0; i < model->rowCount(index); i++) {
findFitRecursive(index.child(i, 0), diff, found, fitOffset);
findFitRecursive(index.child(i, 0), found, fitOffset);
if (found.isValid())
return U_SUCCESS;
}
@ -3007,7 +3007,7 @@ USTATUS FfsParser::findFitRecursive(const UModelIndex & index, const UINT32 diff
offset >= 0;
offset = model->body(index).indexOf(FIT_SIGNATURE, offset + 1)) {
// FIT candidate found, calculate it's physical address
UINT32 fitAddress = model->offset(index) + diff + model->header(index).size() + (UINT32)offset;
UINT32 fitAddress = model->offset(index) + addressDiff + model->header(index).size() + (UINT32)offset;
// Check FIT address to be stored in the last VTF
if (fitAddress == storedFitAddress) {
@ -3023,7 +3023,7 @@ USTATUS FfsParser::findFitRecursive(const UModelIndex & index, const UINT32 diff
return U_SUCCESS;
}
USTATUS FfsParser::addMemoryAddressesRecursive(const UModelIndex & index, const UINT32 diff)
USTATUS FfsParser::addMemoryAddressesRecursive(const UModelIndex & index)
{
// Sanity check
if (!index.isValid())
@ -3032,7 +3032,7 @@ USTATUS FfsParser::addMemoryAddressesRecursive(const UModelIndex & index, const
// Set address value for non-compressed data
if (!model->compressed(index)) {
// Check address sanity
UINT64 address = (const UINT64)diff + model->offset(index);
UINT64 address = (const UINT64)addressDiff + model->offset(index);
if (address <= 0xFFFFFFFFUL) {
// Update info
UINT32 headerSize = model->header(index).size();
@ -3098,7 +3098,7 @@ USTATUS FfsParser::addMemoryAddressesRecursive(const UModelIndex & index, const
// Process child items
for (int i = 0; i < model->rowCount(index); i++) {
addMemoryAddressesRecursive(index.child(i, 0), diff);
addMemoryAddressesRecursive(index.child(i, 0));
}
return U_SUCCESS;

View File

@ -26,10 +26,10 @@ class FfsParser
{
public:
// Default constructor and destructor
FfsParser(TreeModel* treeModel) : model(treeModel), nvramParser(treeModel), meParser(treeModel), capsuleOffsetFixup(0) {}
FfsParser(TreeModel* treeModel) : model(treeModel), nvramParser(treeModel), meParser(treeModel), capsuleOffsetFixup(0), addressDiff(0x100000000ULL) {}
~FfsParser() {}
// Returns messages
// Obtain parser messages
std::vector<std::pair<UString, UModelIndex> > getMessages() const {
std::vector<std::pair<UString, UModelIndex> > meVector = meParser.getMessages();
std::vector<std::pair<UString, UModelIndex> > nvramVector = nvramParser.getMessages();
@ -39,15 +39,18 @@ public:
return resultVector;
}
// Clears messages
// Clear messages
void clearMessages() { messagesVector.clear(); }
// Firmware image parsing
// Parse firmware image
USTATUS parse(const UByteArray &buffer);
// Obtain parsed FIT table
std::vector<std::pair<std::vector<UString>, UModelIndex> > getFitTable() const { return fitTable; }
// Obtain offset/address difference
UINT64 getAddressDiff() { return addressDiff; }
private:
TreeModel *model;
std::vector<std::pair<UString, UModelIndex> > messagesVector;
@ -60,6 +63,7 @@ private:
UModelIndex lastVtf;
UINT32 capsuleOffsetFixup;
UINT64 addressDiff;
std::vector<std::pair<std::vector<UString>, UModelIndex> > fitTable;
// First pass
@ -109,10 +113,10 @@ private:
// Second pass
USTATUS performSecondPass(const UModelIndex & index);
USTATUS addOffsetsRecursive(const UModelIndex & index);
USTATUS addMemoryAddressesRecursive(const UModelIndex & index, const UINT32 diff);
USTATUS addMemoryAddressesRecursive(const UModelIndex & index);
USTATUS addFixedAndCompressedRecursive(const UModelIndex & index);
USTATUS parseFit(const UModelIndex & index, const UINT32 diff);
USTATUS findFitRecursive(const UModelIndex & index, const UINT32 diff, UModelIndex & found, UINT32 & fitOffset);
USTATUS parseFit(const UModelIndex & index);
USTATUS findFitRecursive(const UModelIndex & index, UModelIndex & found, UINT32 & fitOffset);
};
#endif // FFSPARSER_H

View File

@ -124,7 +124,6 @@ public:
UModelIndex createIndex(int row, int column, void *data) const { return UModelIndex(row, column, data, this); }
#endif
~TreeModel() {
delete rootItem;
}