Version 0.16.0

- image reconstruction code refactored
- implemented patching of VTF in case of PEI core entry point change
This commit is contained in:
Nikolaj Schlej 2014-01-11 10:20:58 +01:00
parent 9665d0bcff
commit a764f15679
20 changed files with 1116 additions and 768 deletions

View File

@ -1,6 +1,6 @@
/* LZMA Compress Header
Copyright (c) 2012, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at

View File

@ -1,6 +1,6 @@
/* basetypes.h
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef __BASETYPES_H__
#define __BASETYPES_H__
#include <stdarg.h>
#include <stdint.h>
@ -79,6 +80,9 @@ typedef uint16_t CHAR16;
#define ERR_UNKNOWN_IMAGE_TYPE 29
#define ERR_UNKNOWN_PE_OPTIONAL_HEADER_TYPE 30
#define ERR_UNKNOWN_RELOCATION_TYPE 31
#define ERR_GENERIC_CALL_NOT_SUPPORTED 32
#define ERR_VOLUME_BASE_NOT_FOUND 33
#define ERR_PEI_CORE_ENTRY_POINT_NOT_FOUND 34
#define ERR_NOT_IMPLEMENTED 0xFF
// Compression algorithms
@ -120,7 +124,8 @@ enum ActionTypes {
Insert,
Replace,
Remove,
Rebuild
Rebuild,
Rebase
};
// Types
@ -134,6 +139,7 @@ enum ItemTypes {
File,
Section
};
// Subtypes
enum ImageSubtypes{
IntelImage = 70,
@ -145,8 +151,12 @@ enum CapsuleSubtypes {
UefiCapsule
};
enum VolumeSubtypes {
BootVolume = 90
};
enum RegionSubtypes {
DescriptorRegion = 90,
DescriptorRegion = 100,
GbeRegion,
MeRegion,
BiosRegion,

View File

@ -1,6 +1,6 @@
/* descriptor.h
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -167,4 +167,4 @@ extern UINT8* calculateAddress16(UINT8* baseAddress, const UINT16 baseOrLimit);
extern UINT32 calculateRegionOffset(const UINT16 base);
// Calculate size of region using it's base and limit
extern UINT32 calculateRegionSize(const UINT16 base, const UINT16 limit);
#endif
#endif

6
ffs.h
View File

@ -1,6 +1,6 @@
/* ffs.h
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -94,9 +94,13 @@ typedef struct {
// Filesystem GUIDs
const QByteArray EFI_FIRMWARE_FILE_SYSTEM_GUID
("\xD9\x54\x93\x7A\x68\x04\x4A\x44\x81\xCE\x0B\xF6\x17\xD8\x90\xDF", 16);
const QByteArray EFI_APPLE_BOOT_VOLUME_FILE_SYSTEM_GUID
("\xAD\xEE\xAD\x04\xFF\x61\x31\x4D\xB6\xBA\x64\xF8\xBF\x90\x1F\x5A", 16);
const QByteArray EFI_FIRMWARE_FILE_SYSTEM2_GUID
("\x78\xE5\x8C\x8C\x3D\x8A\x1C\x4F\x99\x35\x89\x61\x85\xC3\x2D\xD3", 16);
// Firmware volume signature
const QByteArray EFI_FV_SIGNATURE("_FVH", 4);
#define EFI_FV_SIGNATURE_OFFSET 0x28

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/* ffsengine.h
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -45,7 +45,7 @@ public:
// Firmware image parsing
UINT8 parseInputFile(const QByteArray & buffer);
UINT8 parseIntelImage(const QByteArray & flashImage, QModelIndex & index, const QModelIndex & parent = QModelIndex());
UINT8 parseIntelImage(const QByteArray & intelImage, QModelIndex & index, const QModelIndex & parent = QModelIndex());
UINT8 parseGbeRegion(const QByteArray & gbe, QModelIndex & index, const QModelIndex & parent);
UINT8 parseMeRegion(const QByteArray & me, QModelIndex & index, const QModelIndex & parent);
UINT8 parseBiosRegion(const QByteArray & bios, QModelIndex & index, const QModelIndex & parent);
@ -65,10 +65,15 @@ public:
UINT8 compress(const QByteArray & data, const UINT8 algorithm, QByteArray & compressedData);
// Construction routines
UINT8 reconstructImage(QByteArray & reconstructed);
UINT8 constructPadFile(const UINT32 size, const UINT8 revision, const UINT8 erasePolarity, QByteArray & pad);
UINT8 reconstruct(const QModelIndex & index, QQueue<QByteArray> & queue, const UINT8 revision = 2, const UINT8 erasePolarity = ERASE_POLARITY_UNKNOWN, const UINT32 base = 0);
UINT8 growVolume(QByteArray & header, const UINT32 size, UINT32 & newSize);
UINT8 reconstruct(const QModelIndex &index, QByteArray & reconstructed);
UINT8 reconstructIntelImage(const QModelIndex& index, QByteArray & reconstructed);
UINT8 reconstructRegion(const QModelIndex& index, QByteArray & reconstructed);
UINT8 reconstructBios(const QModelIndex& index, QByteArray & reconstructed);
UINT8 reconstructVolume(const QModelIndex& index, QByteArray & reconstructed);
UINT8 reconstructFile(const QModelIndex& index, const UINT8 revision, const UINT8 erasePolarity, const UINT32 base, QByteArray& reconstructed);
UINT8 reconstructSection(const QModelIndex& index, const UINT32 base, QByteArray & reconstructed);
// Operations on tree items
UINT8 extract(const QModelIndex & index, QByteArray & extracted, const UINT8 mode);
@ -87,11 +92,20 @@ public:
UINT8 findTextPattern(const QString & pattern, const bool unicode, const Qt::CaseSensitivity caseSensitive);
UINT8 findTextPatternIn(const QModelIndex & index, const QString & pattern, const bool unicode, const Qt::CaseSensitivity caseSensitive);
// Rebase routines
UINT8 rebase(QByteArray & executable, const UINT32 base);
private:
TreeModel *model;
// PEI Core entry point
UINT32 oldPeiCoreEntryPoint;
UINT32 newPeiCoreEntryPoint;
// Rebase routines
UINT8 getBase(const QByteArray& file, UINT32& base);
UINT8 getEntryPoint(const QByteArray& file, UINT32 &peiCoreEntryPoint);
UINT8 rebase(QByteArray & executable, const UINT32 base);
// Patch routines
UINT8 patchVtf(QByteArray &vtf);
// Message helper
QQueue<MessageListItem> messageItems;

4
gbe.h
View File

@ -1,6 +1,6 @@
/* gbe.h
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -33,4 +33,4 @@ typedef struct {
// Restore previous packing rules
#pragma pack(pop)
#endif
#endif

View File

@ -1,6 +1,6 @@
/* main.cpp
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -18,12 +18,11 @@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setOrganizationName("CodeRush");
a.setOrganizationDomain("coderush.me");
a.setApplicationName("UEFITool");
UEFITool w;
QCoreApplication::setOrganizationName("CodeRush");
QCoreApplication::setOrganizationDomain("coderush.me");
QCoreApplication::setApplicationName("UEFITool");
if (a.arguments().length() > 1)
w.openImageFile(a.arguments().at(1));
w.show();

4
me.h
View File

@ -1,6 +1,6 @@
/* me.h
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -31,4 +31,4 @@ typedef struct {
// Restore previous packing rules
#pragma pack(pop)
#endif
#endif

View File

@ -1,6 +1,6 @@
/* messagelistitem.h
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at

View File

@ -1,12 +1,4 @@
/** peimage.h
EFI image format for PE32, PE32+ and TE. Please note some data structures are
different for PE32 and PE32+. EFI_IMAGE_NT_HEADERS32 is for PE32 and
EFI_IMAGE_NT_HEADERS64 is for PE32+.
This file is coded to the Visual Studio, Microsoft Portable Executable and
Common Object File Format Specification, Revision 8.0 - May 16, 2006.
This file also includes some definitions in PI Specification, Revision 1.0.
/* peimage.h
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
@ -19,7 +11,7 @@ http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
*/
#ifndef __PE_IMAGE_H__
#define __PE_IMAGE_H__
@ -699,10 +691,10 @@ typedef struct {
//
typedef struct {
UINT16 Signature; // The signature for TE format = "VZ"
UINT16 Machine; // From the original file header
UINT8 NumberOfSections; // From the original file header
UINT16 Machine; // From original file header
UINT8 NumberOfSections; // From original file header
UINT8 Subsystem; // From original optional header
UINT16 StrippedSize; // Number of bytes we removed from the header
UINT16 StrippedSize; // Number of bytes we removed from header
UINT32 AddressOfEntryPoint; // Offset to entry point -- from original optional header
UINT32 BaseOfCode; // From original image -- required for ITP debug
UINT64 ImageBase; // From original file header

View File

@ -1,6 +1,6 @@
/* searchdialog.cpp
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -19,30 +19,9 @@ SearchDialog::SearchDialog(QWidget *parent) :
{
// Create UI
ui->setupUi(this);
// Connect
//connect(ui->dataTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setEditMask()));
//connect(ui->translateFromHexCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setEditMask()));
}
SearchDialog::~SearchDialog()
{
delete ui;
}
/*void SearchDialog::setEditMask()
{
int index = ui->dataTypeComboBox->currentIndex();
QString mask;
if (index == 0) // Hex pattern, max 48 bytes long
mask = "";
else if (index == 1) {
if (ui->translateFromHexCheckBox->isChecked())
mask = "<HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH;_";
else
mask = "<HHHHHHHH-HHHH-HHHH-HHHHHHHHHHHHHHHH;_";
}
else
mask = "";
ui->searchEdit->setInputMask(mask);
}*/

View File

@ -1,6 +1,6 @@
/* searchdialog.h
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -31,4 +31,4 @@ private slots:
};
#endif
#endif

View File

@ -1,6 +1,6 @@
/* treeitem.cpp
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -52,8 +52,12 @@ QString itemSubtypeToQString(const UINT8 type, const UINT8 subtype)
else
return QObject::tr("Unknown");
case Padding:
case Volume:
return "";
case Volume:
if (subtype == BootVolume)
return QObject::tr("Boot");
else
return "";
case Capsule:
if (subtype == AptioCapsule)
return QObject::tr("Aptio extended");
@ -182,6 +186,8 @@ QVariant TreeItem::data(int column) const
return QObject::tr("Remove");
if (itemAction == Rebuild)
return QObject::tr("Rebuild");
if (itemAction == Rebase)
return QObject::tr("Rebase");
return QVariant();
case 2: //Type
return itemTypeName;
@ -297,3 +303,8 @@ void TreeItem::setAction(const UINT8 action)
parentItem->setAction(Rebuild);
}
void TreeItem::setSubtype(const UINT8 subtype)
{
itemSubtype = subtype;
itemSubtypeName = itemSubtypeToQString(itemType, itemSubtype);
}

View File

@ -1,6 +1,6 @@
/* treeitem.h
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -63,6 +63,7 @@ public:
// Some values can be changed after item construction
void setAction(const UINT8 action);
void setSubtype(const UINT8 subtype);
void setTypeName(const QString &text);
void setSubtypeName(const QString &text);
void setName(const QString &text);

View File

@ -1,6 +1,6 @@
/* treemodel.cpp
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -220,6 +220,16 @@ UINT8 TreeModel::compression(const QModelIndex &index) const
return item->compression();
}
void TreeModel::setSubtype(const QModelIndex & index, UINT8 subtype)
{
if(!index.isValid())
return;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
item->setSubtype(subtype);
emit dataChanged(index, index);
}
void TreeModel::setNameString(const QModelIndex &index, const QString &data)
{
if(!index.isValid())

View File

@ -1,6 +1,6 @@
/* treemodel.h
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -53,6 +53,8 @@ public:
void setNameString(const QModelIndex &index, const QString &text);
void setTextString(const QModelIndex &index, const QString &text);
void setSubtype(const QModelIndex & index, UINT8 subtype);
UINT8 type(const QModelIndex &index) const;
UINT8 subtype(const QModelIndex &index) const;
QByteArray header(const QModelIndex &index) const;

View File

@ -1,6 +1,6 @@
/* uefitool.cpp
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -448,7 +448,7 @@ void UEFITool::saveImageFile()
}
QByteArray reconstructed;
UINT8 result = ffsEngine->reconstructImage(reconstructed);
UINT8 result = ffsEngine->reconstruct(ffsEngine->treeModel()->index(0,0), reconstructed);
showMessages();
if (result) {
ui->statusBar->showMessage(tr("Reconstruction failed (%1)").arg(result));
@ -461,13 +461,6 @@ void UEFITool::saveImageFile()
ui->statusBar->showMessage(tr("Reconstructed image written"));
}
/*void UEFITool::resizeTreeViewColumns()
{
int count = ffsEngine->model()->columnCount();
for(int i = 0; i < count; i++)
ui->structureTreeView->resizeColumnToContents(i);
}*/
void UEFITool::openImageFile()
{
QString path = QFileDialog::getOpenFileName(this, tr("Open BIOS image file"),".","BIOS image files (*.rom *.bin *.cap *.bio *.fd *.wph *.efi);;All files (*.*)");
@ -591,7 +584,7 @@ void UEFITool::contextMenuEvent(QContextMenuEvent* event)
void UEFITool::readSettings()
{
QSettings settings("UEFITool.ini", QSettings::IniFormat, this);
QSettings settings(this);
resize(settings.value("mainWindow/size", QSize(800, 600)).toSize());
move(settings.value("mainWindow/position", QPoint(0, 0)).toPoint());
QList<int> horList, vertList;
@ -610,7 +603,7 @@ void UEFITool::readSettings()
void UEFITool::writeSettings()
{
QSettings settings("UEFITool.ini", QSettings::IniFormat, this);
QSettings settings(this);
settings.setValue("mainWindow/size", size());
settings.setValue("mainWindow/position", pos());
settings.setValue("mainWindow/treeWidth", ui->structureGroupBox->width());

View File

@ -1,6 +1,6 @@
/* uefitool.h
Copyright (c) 2013, Nikolaj Schlej. All rights reserved.
Copyright (c) 2014, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at

View File

@ -20,7 +20,7 @@
<bool>true</bool>
</property>
<property name="windowTitle">
<string>UEFITool 0.15.0</string>
<string>UEFITool 0.16.0</string>
</property>
<widget class="QWidget" name="centralWidget">
<property name="sizePolicy">