mirror of
https://github.com/LongSoft/UEFITool.git
synced 2025-05-29 14:35:23 -04:00
Big structure update
- files split into common and app-specific ones - messages from parser and finder separated - ffsEngine split into multiple classes to reduce complexity - still no image rebuild
This commit is contained in:
parent
1f0a80d035
commit
2e788a8a1a
64 changed files with 477 additions and 2469 deletions
91
UEFIExtract/ffsdumper.cpp
Normal file
91
UEFIExtract/ffsdumper.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
/* ffsdumper.cpp
|
||||
|
||||
Copyright (c) 2015, 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 "ffsdumper.h"
|
||||
|
||||
FfsDumper::FfsDumper(TreeModel* treeModel, QObject *parent)
|
||||
: model(treeModel), QObject(parent), dumped(false)
|
||||
{
|
||||
}
|
||||
|
||||
FfsDumper::~FfsDumper()
|
||||
{
|
||||
}
|
||||
|
||||
STATUS FfsDumper::dump(const QModelIndex & root, const QString & path)
|
||||
{
|
||||
dumped = false;
|
||||
UINT8 result = recursiveDump(root, path);
|
||||
if (result)
|
||||
return result;
|
||||
else if (!dumped)
|
||||
return ERR_ITEM_NOT_FOUND;
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path)
|
||||
{
|
||||
if (!index.isValid())
|
||||
return ERR_INVALID_PARAMETER;
|
||||
|
||||
QDir dir;
|
||||
|
||||
if (dir.cd(path))
|
||||
return ERR_DIR_ALREADY_EXIST;
|
||||
|
||||
if (!dir.mkpath(path))
|
||||
return ERR_DIR_CREATE;
|
||||
|
||||
QFile file;
|
||||
if (!model->header(index).isEmpty()) {
|
||||
file.setFileName(tr("%1/header.bin").arg(path));
|
||||
if (!file.open(QFile::WriteOnly))
|
||||
return ERR_FILE_OPEN;
|
||||
|
||||
file.write(model->header(index));
|
||||
file.close();
|
||||
}
|
||||
|
||||
if (!model->body(index).isEmpty()) {
|
||||
file.setFileName(tr("%1/body.bin").arg(path));
|
||||
if (!file.open(QFile::WriteOnly))
|
||||
return ERR_FILE_OPEN;
|
||||
|
||||
file.write(model->body(index));
|
||||
file.close();
|
||||
}
|
||||
|
||||
QString info = tr("Type: %1\nSubtype: %2\n%3%4")
|
||||
.arg(itemTypeToQString(model->type(index)))
|
||||
.arg(itemSubtypeToQString(model->type(index), model->subtype(index)))
|
||||
.arg(model->text(index).isEmpty() ? "" : tr("Text: %1\n").arg(model->text(index)))
|
||||
.arg(model->info(index));
|
||||
file.setFileName(tr("%1/info.txt").arg(path));
|
||||
if (!file.open(QFile::Text | QFile::WriteOnly))
|
||||
return ERR_FILE_OPEN;
|
||||
|
||||
file.write(info.toLatin1());
|
||||
file.close();
|
||||
dumped = true;
|
||||
|
||||
UINT8 result;
|
||||
for (int i = 0; i < model->rowCount(index); i++) {
|
||||
QModelIndex childIndex = index.child(i, 0);
|
||||
QString childPath = QString("%1/%2 %3").arg(path).arg(i).arg(model->text(childIndex).isEmpty() ? model->name(childIndex) : model->text(childIndex));
|
||||
result = recursiveDump(childIndex, childPath);
|
||||
if (result)
|
||||
return result;
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
43
UEFIExtract/ffsdumper.h
Normal file
43
UEFIExtract/ffsdumper.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* ffsdumper.h
|
||||
|
||||
Copyright (c) 2015, 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 __FFSDUMPER_H__
|
||||
#define __FFSDUMPER_H__
|
||||
|
||||
#include <QObject>
|
||||
#include <QDir>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QModelIndex>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "..\common\basetypes.h"
|
||||
#include "..\common\treemodel.h"
|
||||
|
||||
class FfsDumper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FfsDumper(TreeModel * treeModel, QObject *parent = 0);
|
||||
~FfsDumper();
|
||||
|
||||
STATUS dump(const QModelIndex & root, const QString & path);
|
||||
|
||||
private:
|
||||
STATUS recursiveDump(const QModelIndex & root, const QString & path);
|
||||
TreeModel* model;
|
||||
bool dumped;
|
||||
};
|
||||
|
||||
#endif
|
37
UEFIExtract/uefiextract.pro
Normal file
37
UEFIExtract/uefiextract.pro
Normal file
|
@ -0,0 +1,37 @@
|
|||
QT += core
|
||||
QT -= gui
|
||||
|
||||
TARGET = UEFIExtract
|
||||
TEMPLATE = app
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
SOURCES += uefiextract_main.cpp \
|
||||
ffsdumper.cpp \
|
||||
../common/types.cpp \
|
||||
../common/descriptor.cpp \
|
||||
../common/ffs.cpp \
|
||||
../common/ffsparser.cpp \
|
||||
../common/peimage.cpp \
|
||||
../common/treeitem.cpp \
|
||||
../common/treemodel.cpp \
|
||||
../common/utility.cpp \
|
||||
../common/LZMA/LzmaDecompress.c \
|
||||
../common/LZMA/SDK/C/LzmaDec.c \
|
||||
../common/Tiano/EfiTianoDecompress.c \
|
||||
|
||||
HEADERS += ffsdumper.h \
|
||||
../common/basetypes.h \
|
||||
../common/descriptor.h \
|
||||
../common/gbe.h \
|
||||
../common/me.h \
|
||||
../common/ffs.h \
|
||||
../common/ffsparser.h \
|
||||
../common/peimage.h \
|
||||
../common/types.h \
|
||||
../common/treeitem.h \
|
||||
../common/treemodel.h \
|
||||
../common/utility.h \
|
||||
../common/LZMA/LzmaDecompress.h \
|
||||
../common/Tiano/EfiTianoDecompress.h
|
||||
|
65
UEFIExtract/uefiextract_main.cpp
Normal file
65
UEFIExtract/uefiextract_main.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
/* uefiextract_main.cpp
|
||||
|
||||
Copyright (c) 2015, 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 <QVector>
|
||||
#include <QPair>
|
||||
#include <QString>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "..\common\ffsparser.h"
|
||||
#include "ffsdumper.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
a.setOrganizationName("CodeRush");
|
||||
a.setOrganizationDomain("coderush.me");
|
||||
a.setApplicationName("UEFIExtract");
|
||||
|
||||
if (a.arguments().length() > 1) {
|
||||
QString path = a.arguments().at(1);
|
||||
QFileInfo fileInfo(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();
|
||||
|
||||
TreeModel model;
|
||||
FfsParser ffsParser(&model);
|
||||
STATUS result = ffsParser.parseImageFile(buffer, model.index(0, 0));
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
QVector<QPair<QString, QModelIndex> > messages = ffsParser.getMessages();
|
||||
QPair<QString, QModelIndex> msg;
|
||||
foreach(msg, messages) {
|
||||
std::cout << msg.first.toLatin1().constData() << std::endl;
|
||||
}
|
||||
|
||||
FfsDumper ffsDumper(&model);
|
||||
return ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"));
|
||||
}
|
||||
else {
|
||||
std::cout << "UEFIExtract 0.10.0" << std::endl << std::endl
|
||||
<< "Usage: uefiextract imagefile" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue