mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-22 16:08:23 +08:00
Version 0.17.10.4
- commited all file of UEFIExtract project
This commit is contained in:
parent
7f81296e48
commit
e1c641ca08
53
UEFIExtract/uefiextract.cpp
Normal file
53
UEFIExtract/uefiextract.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/* uefiextract.cpp
|
||||||
|
|
||||||
|
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
|
||||||
|
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.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "uefiextract.h"
|
||||||
|
|
||||||
|
UEFIExtract::UEFIExtract(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
ffsEngine = new FfsEngine(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
UEFIExtract::~UEFIExtract()
|
||||||
|
{
|
||||||
|
delete ffsEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT8 UEFIExtract::extractAll(QString path)
|
||||||
|
{
|
||||||
|
QFileInfo fileInfo = QFileInfo(path);
|
||||||
|
|
||||||
|
if (!fileInfo.exists())
|
||||||
|
return ERR_FILE_OPEN;
|
||||||
|
|
||||||
|
QFile inputFile;
|
||||||
|
inputFile.setFileName(path);
|
||||||
|
|
||||||
|
if (!inputFile.open(QFile::ReadOnly))
|
||||||
|
return ERR_FILE_OPEN;
|
||||||
|
|
||||||
|
QByteArray buffer = inputFile.readAll();
|
||||||
|
inputFile.close();
|
||||||
|
|
||||||
|
UINT8 result = ffsEngine->parseImageFile(buffer);
|
||||||
|
if (result)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
QModelIndex rootIndex = ffsEngine->treeModel()->index(0, 0);
|
||||||
|
result = ffsEngine->dump(rootIndex, fileInfo.fileName().append(".dump"));
|
||||||
|
if (result)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return ERR_SUCCESS;
|
||||||
|
}
|
40
UEFIExtract/uefiextract.h
Normal file
40
UEFIExtract/uefiextract.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/* uefiextract.h
|
||||||
|
|
||||||
|
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
|
||||||
|
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 __UEFIEXTRACT_H__
|
||||||
|
#define __UEFIEXTRACT_H__
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QString>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
|
#include "../basetypes.h"
|
||||||
|
#include "../ffsengine.h"
|
||||||
|
|
||||||
|
class UEFIExtract : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit UEFIExtract(QObject *parent = 0);
|
||||||
|
~UEFIExtract();
|
||||||
|
|
||||||
|
UINT8 extractAll(QString path);
|
||||||
|
|
||||||
|
private:
|
||||||
|
FfsEngine* ffsEngine;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
49
UEFIExtract/uefiextract_main.cpp
Normal file
49
UEFIExtract/uefiextract_main.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/* uefiextract_main.cpp
|
||||||
|
|
||||||
|
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
|
||||||
|
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.
|
||||||
|
|
||||||
|
*/
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <iostream>
|
||||||
|
#include "uefiextract.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
a.setOrganizationName("CodeRush");
|
||||||
|
a.setOrganizationDomain("coderush.me");
|
||||||
|
a.setApplicationName("UEFIExtract");
|
||||||
|
|
||||||
|
UEFIExtract w;
|
||||||
|
UINT8 result = ERR_SUCCESS;
|
||||||
|
if (a.arguments().length() > 1) {
|
||||||
|
result = w.extractAll(a.arguments().at(1));
|
||||||
|
switch (result) {
|
||||||
|
case ERR_DIR_ALREADY_EXIST:
|
||||||
|
std::cout << "Dump directory already exist, please remove it" << std::endl;
|
||||||
|
break;
|
||||||
|
case ERR_DIR_CREATE:
|
||||||
|
std::cout << "Can't create directory" << std::endl;
|
||||||
|
break;
|
||||||
|
case ERR_FILE_OPEN:
|
||||||
|
std::cout << "Can't create file" << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = ERR_INVALID_PARAMETER;
|
||||||
|
std::cout << "UEFIExtract 0.1.0" << std::endl << std::endl <<
|
||||||
|
"Usage: uefiextract imagefile\n" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
3199
ffsengine.cpp
Normal file
3199
ffsengine.cpp
Normal file
File diff suppressed because it is too large
Load Diff
133
ffsengine.h
Normal file
133
ffsengine.h
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/* ffsengine.h
|
||||||
|
|
||||||
|
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
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __FFSENGINE_H__
|
||||||
|
#define __FFSENGINE_H__
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QModelIndex>
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QQueue>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
#include "basetypes.h"
|
||||||
|
#include "treemodel.h"
|
||||||
|
#include "peimage.h"
|
||||||
|
|
||||||
|
#ifndef _CONSOLE
|
||||||
|
#include "messagelistitem.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class TreeModel;
|
||||||
|
|
||||||
|
class FfsEngine : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Default constructor and destructor
|
||||||
|
FfsEngine(QObject *parent = 0);
|
||||||
|
~FfsEngine(void);
|
||||||
|
|
||||||
|
// Returns model for Qt view classes
|
||||||
|
TreeModel* treeModel() const;
|
||||||
|
|
||||||
|
#ifndef _CONSOLE
|
||||||
|
// Returns message items queue
|
||||||
|
QQueue<MessageListItem> messages() const;
|
||||||
|
// Clears message items queue
|
||||||
|
void clearMessages();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Firmware image parsing
|
||||||
|
UINT8 parseImageFile(const QByteArray & buffer);
|
||||||
|
UINT8 parseIntelImage(const QByteArray & intelImage, QModelIndex & index, const QModelIndex & parent = QModelIndex());
|
||||||
|
UINT8 parseGbeRegion(const QByteArray & gbe, QModelIndex & index, const QModelIndex & parent, const UINT8 mode = CREATE_MODE_APPEND);
|
||||||
|
UINT8 parseMeRegion(const QByteArray & me, QModelIndex & index, const QModelIndex & parent, const UINT8 mode = CREATE_MODE_APPEND);
|
||||||
|
UINT8 parseBiosRegion(const QByteArray & bios, QModelIndex & index, const QModelIndex & parent, const UINT8 mode = CREATE_MODE_APPEND);
|
||||||
|
UINT8 parsePdrRegion(const QByteArray & pdr, QModelIndex & index, const QModelIndex & parent, const UINT8 mode = CREATE_MODE_APPEND);
|
||||||
|
UINT8 parseBios(const QByteArray & bios, const QModelIndex & parent = QModelIndex());
|
||||||
|
UINT8 parseVolume(const QByteArray & volume, QModelIndex & index, const QModelIndex & parent = QModelIndex(), const UINT8 mode = CREATE_MODE_APPEND);
|
||||||
|
UINT8 parseFile(const QByteArray & file, QModelIndex & index, const UINT8 erasePolarity = ERASE_POLARITY_UNKNOWN, const QModelIndex & parent = QModelIndex(), const UINT8 mode = CREATE_MODE_APPEND);
|
||||||
|
UINT8 parseSections(const QByteArray & body, const QModelIndex & parent = QModelIndex());
|
||||||
|
UINT8 parseSection(const QByteArray & section, QModelIndex & index, const QModelIndex & parent = QModelIndex(), const UINT8 mode = CREATE_MODE_APPEND);
|
||||||
|
|
||||||
|
// Compression routines
|
||||||
|
UINT8 decompress(const QByteArray & compressed, const UINT8 compressionType, QByteArray & decompressedData, UINT8 * algorithm = NULL);
|
||||||
|
UINT8 compress(const QByteArray & data, const UINT8 algorithm, QByteArray & compressedData);
|
||||||
|
|
||||||
|
// Construction routines
|
||||||
|
UINT8 reconstructImageFile(QByteArray &reconstructed);
|
||||||
|
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);
|
||||||
|
UINT8 create(const QModelIndex & index, const UINT8 type, const QByteArray & header, const QByteArray & body, const UINT8 mode, const UINT8 action, const UINT8 algorithm = COMPRESSION_ALGORITHM_NONE);
|
||||||
|
UINT8 insert(const QModelIndex & index, const QByteArray & object, const UINT8 mode);
|
||||||
|
UINT8 replace(const QModelIndex & index, const QByteArray & object, const UINT8 mode);
|
||||||
|
UINT8 remove(const QModelIndex & index);
|
||||||
|
UINT8 rebuild(const QModelIndex & index);
|
||||||
|
UINT8 dump(const QModelIndex & index, const QString path);
|
||||||
|
|
||||||
|
// Search routines
|
||||||
|
UINT8 findHexPattern(const QByteArray & pattern, const UINT8 mode);
|
||||||
|
UINT8 findHexPatternIn(const QModelIndex & index, const QByteArray & pattern, const UINT8 mode);
|
||||||
|
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);
|
||||||
|
|
||||||
|
private:
|
||||||
|
TreeModel *model;
|
||||||
|
|
||||||
|
// PEI Core entry point
|
||||||
|
UINT32 oldPeiCoreEntryPoint;
|
||||||
|
UINT32 newPeiCoreEntryPoint;
|
||||||
|
|
||||||
|
// Parsing helpers
|
||||||
|
UINT8 findNextVolume(const QByteArray & bios, const UINT32 volumeOffset, UINT32 & nextVolumeOffset);
|
||||||
|
UINT8 getVolumeSize(const QByteArray & bios, const UINT32 volumeOffset, UINT32 & volumeSize);
|
||||||
|
UINT8 getFileSize(const QByteArray & volume, const UINT32 fileOffset, UINT32 & fileSize);
|
||||||
|
UINT8 getSectionSize(const QByteArray & file, const UINT32 sectionOffset, UINT32 & sectionSize);
|
||||||
|
|
||||||
|
// Reconstruction helpers
|
||||||
|
UINT8 constructPadFile(const QByteArray &guid, const UINT32 size, const UINT8 revision, const UINT8 erasePolarity, QByteArray & pad);
|
||||||
|
UINT8 growVolume(QByteArray & header, const UINT32 size, UINT32 & newSize);
|
||||||
|
|
||||||
|
// Rebase routines
|
||||||
|
UINT8 getBase(const QByteArray& file, UINT32& base);
|
||||||
|
UINT8 getEntryPoint(const QByteArray& file, UINT32 &entryPoint);
|
||||||
|
UINT8 rebase(QByteArray & executable, const UINT32 base);
|
||||||
|
void rebasePeiFiles(const QModelIndex & index);
|
||||||
|
|
||||||
|
// Patch routines
|
||||||
|
UINT8 patchVtf(QByteArray &vtf);
|
||||||
|
|
||||||
|
#ifndef _CONSOLE
|
||||||
|
QQueue<MessageListItem> messageItems;
|
||||||
|
#endif
|
||||||
|
// Message helper
|
||||||
|
void msg(const QString & message, const QModelIndex &index = QModelIndex());
|
||||||
|
|
||||||
|
// Internal operations
|
||||||
|
bool hasIntersection(const UINT32 begin1, const UINT32 end1, const UINT32 begin2, const UINT32 end2);
|
||||||
|
UINT32 crc32(UINT32 initial, const UINT8* buffer, UINT32 length);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user