mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-25 17:38:22 +08:00
Rough attempt to deglue UEFIExtract from Qt
This commit is contained in:
parent
0a2f115056
commit
c9db871c12
@ -50,6 +50,7 @@ SET(PROJECT_HEADERS
|
|||||||
../common/sha256.h
|
../common/sha256.h
|
||||||
../common/bstrlib/bstrlib.h
|
../common/bstrlib/bstrlib.h
|
||||||
../common/bstrlib/bstrwrap.h
|
../common/bstrlib/bstrwrap.h
|
||||||
|
../common/filesystem.h
|
||||||
../version.h
|
../version.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,41 +14,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
#include "uefidump.h"
|
#include "uefidump.h"
|
||||||
#include "../common/ffs.h"
|
#include "../common/ffs.h"
|
||||||
#include "../common/utility.h"
|
#include "../common/utility.h"
|
||||||
|
#include "../common/filesystem.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <direct.h>
|
|
||||||
bool isExistOnFs(const UString & path) {
|
|
||||||
struct _stat buf;
|
|
||||||
return (_stat((const char*)path.toLocal8Bit(), &buf) == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool makeDirectory(const UString & dir) {
|
|
||||||
return (_mkdir((const char*)dir.toLocal8Bit()) == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool changeDirectory(const UString & dir) {
|
|
||||||
return (_chdir((const char*)dir.toLocal8Bit()) == 0);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#include <unistd.h>
|
|
||||||
bool isExistOnFs(const UString & path) {
|
|
||||||
struct stat buf;
|
|
||||||
return (stat((const char*)path.toLocal8Bit(), &buf) == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool makeDirectory(const UString & dir) {
|
|
||||||
return (mkdir((const char*)dir.toLocal8Bit(), ACCESSPERMS) == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool changeDirectory(const UString & dir) {
|
|
||||||
return (chdir((const char*)dir.toLocal8Bit()) == 0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
USTATUS UEFIDumper::dump(const UByteArray & buffer, const UString & inPath, const UString & guid)
|
USTATUS UEFIDumper::dump(const UByteArray & buffer, const UString & inPath, const UString & guid)
|
||||||
{
|
{
|
||||||
|
58
UEFIExtract/CMakeLists.txt
Normal file
58
UEFIExtract/CMakeLists.txt
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
PROJECT(UEFIExtract)
|
||||||
|
|
||||||
|
SET(PROJECT_SOURCES
|
||||||
|
uefiextract_main.cpp
|
||||||
|
ffsdumper.cpp
|
||||||
|
../common/guiddatabase.cpp
|
||||||
|
../common/types.cpp
|
||||||
|
../common/descriptor.cpp
|
||||||
|
../common/ffs.cpp
|
||||||
|
../common/nvram.cpp
|
||||||
|
../common/nvramparser.cpp
|
||||||
|
../common/ffsparser.cpp
|
||||||
|
../common/ffsreport.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
|
||||||
|
../common/ustring.cpp
|
||||||
|
../common/sha256.c
|
||||||
|
../common/bstrlib/bstrlib.c
|
||||||
|
../common/bstrlib/bstrwrap.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
SET(PROJECT_HEADERS
|
||||||
|
ffsdumper.h
|
||||||
|
../common/guiddatabase.h
|
||||||
|
../common/basetypes.h
|
||||||
|
../common/descriptor.h
|
||||||
|
../common/gbe.h
|
||||||
|
../common/me.h
|
||||||
|
../common/ffs.h
|
||||||
|
../common/nvram.h
|
||||||
|
../common/nvramparser.h
|
||||||
|
../common/ffsparser.h
|
||||||
|
../common/ffsreport.h
|
||||||
|
../common/peimage.h
|
||||||
|
../common/types.h
|
||||||
|
../common/treeitem.h
|
||||||
|
../common/treemodel.h
|
||||||
|
../common/utility.h
|
||||||
|
../common/LZMA/LzmaDecompress.h
|
||||||
|
../common/Tiano/EfiTianoDecompress.h
|
||||||
|
../common/ubytearray.h
|
||||||
|
../common/ustring.h
|
||||||
|
../common/bootguard.h
|
||||||
|
../common/sha256.h
|
||||||
|
../common/filesystem.h
|
||||||
|
../common/bstrlib/bstrlib.h
|
||||||
|
../common/bstrlib/bstrwrap.h
|
||||||
|
../version.h
|
||||||
|
)
|
||||||
|
|
||||||
|
ADD_DEFINITIONS(-DU_ENABLE_NVRAM_PARSING_SUPPORT)
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(UEFIExtract ${PROJECT_SOURCES} ${PROJECT_HEADERS})
|
@ -13,13 +13,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
|
|
||||||
#include "ffsdumper.h"
|
#include "ffsdumper.h"
|
||||||
|
|
||||||
USTATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const DumpMode dumpMode, const UINT8 sectionType, const QString & guid)
|
#include <fstream>
|
||||||
|
|
||||||
|
USTATUS FfsDumper::dump(const UModelIndex & root, const UString & path, const DumpMode dumpMode, const UINT8 sectionType, const UString & guid)
|
||||||
{
|
{
|
||||||
dumped = false;
|
dumped = false;
|
||||||
counter = 0;
|
counterHeader = counterBody = counterRaw = counterInfo = 0;
|
||||||
|
|
||||||
QDir dir;
|
if (changeDirectory(path))
|
||||||
if (dir.cd(path))
|
|
||||||
return U_DIR_ALREADY_EXIST;
|
return U_DIR_ALREADY_EXIST;
|
||||||
|
|
||||||
UINT8 result = recursiveDump(root, path, dumpMode, sectionType, guid);
|
UINT8 result = recursiveDump(root, path, dumpMode, sectionType, guid);
|
||||||
@ -30,49 +31,50 @@ USTATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const Du
|
|||||||
return U_SUCCESS;
|
return U_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path, const DumpMode dumpMode, const UINT8 sectionType, const QString & guid)
|
USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path, const DumpMode dumpMode, const UINT8 sectionType, const UString & guid)
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return U_INVALID_PARAMETER;
|
return U_INVALID_PARAMETER;
|
||||||
|
|
||||||
QDir dir;
|
|
||||||
if (guid.isEmpty() ||
|
if (guid.isEmpty() ||
|
||||||
(model->subtype(index) == EFI_SECTION_FREEFORM_SUBTYPE_GUID &&
|
(model->subtype(index) == EFI_SECTION_FREEFORM_SUBTYPE_GUID &&
|
||||||
guidToUString(*(const EFI_GUID*)(model->header(index).constData() + sizeof(EFI_COMMON_SECTION_HEADER))) == guid) ||
|
guidToUString(*(const EFI_GUID*)(model->header(index).constData() + sizeof(EFI_COMMON_SECTION_HEADER))) == guid) ||
|
||||||
guidToUString(*(const EFI_GUID*)model->header(index).constData()) == guid ||
|
guidToUString(*(const EFI_GUID*)model->header(index).constData()) == guid ||
|
||||||
guidToUString(*(const EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData()) == guid) {
|
guidToUString(*(const EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData()) == guid) {
|
||||||
|
|
||||||
if (!dir.cd(path) && !dir.mkpath(path))
|
if (!changeDirectory(path) && !makeDirectory(path))
|
||||||
return U_DIR_CREATE;
|
return U_DIR_CREATE;
|
||||||
|
|
||||||
QFile file;
|
counterHeader = counterBody = counterRaw = counterInfo = 0;
|
||||||
|
|
||||||
|
std::ofstream file;
|
||||||
if (dumpMode == DUMP_ALL || model->rowCount(index) == 0) { // Dump if leaf item or dumpAll is true
|
if (dumpMode == DUMP_ALL || model->rowCount(index) == 0) { // Dump if leaf item or dumpAll is true
|
||||||
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_HEADER) {
|
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_HEADER) {
|
||||||
if (!model->header(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
if (!model->header(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
||||||
if (counter == 0)
|
UString filename;
|
||||||
file.setFileName(QObject::tr("%1/header.bin").arg(path));
|
if (counterHeader == 0)
|
||||||
|
filename = usprintf("%s/header.bin", (const char *)path.toLocal8Bit());
|
||||||
else
|
else
|
||||||
file.setFileName(QObject::tr("%1/header_%2.bin").arg(path).arg(counter));
|
filename = usprintf("%s/header_%d.bin", (const char *)path.toLocal8Bit(), counterHeader);
|
||||||
counter++;
|
counterHeader++;
|
||||||
if (!file.open(QFile::WriteOnly))
|
file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary);
|
||||||
return U_FILE_OPEN;
|
const UByteArray &data = model->header(index);
|
||||||
|
file.write(data.constData(), data.size());
|
||||||
file.write(model->header(index));
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_BODY) {
|
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_BODY) {
|
||||||
if (!model->body(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
if (!model->body(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
||||||
if (counter == 0)
|
UString filename;
|
||||||
file.setFileName(QObject::tr("%1/body.bin").arg(path));
|
if (counterBody == 0)
|
||||||
|
filename = usprintf("%s/body.bin", (const char *)path.toLocal8Bit());
|
||||||
else
|
else
|
||||||
file.setFileName(QObject::tr("%1/body_%2.bin").arg(path).arg(counter));
|
filename = usprintf("%s/body_%d.bin", (const char *)path.toLocal8Bit(), counterBody);
|
||||||
counter++;
|
counterBody++;
|
||||||
if (!file.open(QFile::WriteOnly))
|
file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary);
|
||||||
return U_FILE_OPEN;
|
const UByteArray &data = model->body(index);
|
||||||
|
file.write(data.constData(), data.size());
|
||||||
file.write(model->body(index));
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,16 +83,19 @@ USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path
|
|||||||
UModelIndex fileIndex = model->findParentOfType(index, Types::File);
|
UModelIndex fileIndex = model->findParentOfType(index, Types::File);
|
||||||
if (!fileIndex.isValid())
|
if (!fileIndex.isValid())
|
||||||
fileIndex = index;
|
fileIndex = index;
|
||||||
if (counter == 0)
|
UString filename;
|
||||||
file.setFileName(QObject::tr("%1/file.ffs").arg(path));
|
if (counterRaw == 0)
|
||||||
|
filename = usprintf("%s/file.ffs", (const char *)path.toLocal8Bit());
|
||||||
else
|
else
|
||||||
file.setFileName(QObject::tr("%1/file_%2.ffs").arg(path).arg(counter));
|
filename = usprintf("%s/file_%d.bin", (const char *)path.toLocal8Bit(), counterRaw);
|
||||||
counter++;
|
counterRaw++;
|
||||||
if (!file.open(QFile::WriteOnly))
|
file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary);
|
||||||
return U_FILE_OPEN;
|
const UByteArray &headerData = model->header(index);
|
||||||
file.write(model->header(fileIndex));
|
const UByteArray &bodyData = model->body(index);
|
||||||
file.write(model->body(fileIndex));
|
const UByteArray &tailData = model->tail(index);
|
||||||
file.write(model->tail(fileIndex));
|
file.write(headerData.constData(), headerData.size());
|
||||||
|
file.write(bodyData.constData(), bodyData.size());
|
||||||
|
file.write(tailData.constData(), tailData.size());
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,20 +103,20 @@ USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path
|
|||||||
// Always dump info unless explicitly prohibited
|
// Always dump info unless explicitly prohibited
|
||||||
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_INFO)
|
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_INFO)
|
||||||
&& (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
&& (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
||||||
QString info = QObject::tr("Type: %1\nSubtype: %2\n%3%4\n")
|
UString info = usprintf("Type: %s\nSubtype: %s\n%s%s\n",
|
||||||
.arg(itemTypeToUString(model->type(index)))
|
(const char *)itemTypeToUString(model->type(index)).toLocal8Bit(),
|
||||||
.arg(itemSubtypeToUString(model->type(index), model->subtype(index)))
|
(const char *)itemSubtypeToUString(model->type(index), model->subtype(index)).toLocal8Bit(),
|
||||||
.arg(model->text(index).isEmpty() ? QObject::tr("") : QObject::tr("Text: %1\n").arg(model->text(index)))
|
(const char *)(model->text(index).isEmpty() ? UString("") :
|
||||||
.arg(model->info(index));
|
usprintf("Text: %s\n", (const char *)model->text(index).toLocal8Bit())).toLocal8Bit(),
|
||||||
if (counter == 0)
|
(const char *)model->info(index).toLocal8Bit());
|
||||||
file.setFileName(QObject::tr("%1/info.txt").arg(path));
|
UString filename;
|
||||||
|
if (counterInfo == 0)
|
||||||
|
filename = usprintf("%s/info.txt", (const char *)path.toLocal8Bit());
|
||||||
else
|
else
|
||||||
file.setFileName(QObject::tr("%1/info_%2.txt").arg(path).arg(counter));
|
filename = usprintf("%s/info_%d.txt", (const char *)path.toLocal8Bit(), counterInfo);
|
||||||
counter++;
|
counterInfo++;
|
||||||
if (!file.open(QFile::Text | QFile::WriteOnly))
|
file.open((const char *)filename.toLocal8Bit());
|
||||||
return U_FILE_OPEN;
|
file << (const char *)info.toLocal8Bit();
|
||||||
|
|
||||||
file.write(info.toLatin1());
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,14 +125,15 @@ USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path
|
|||||||
|
|
||||||
UINT8 result;
|
UINT8 result;
|
||||||
for (int i = 0; i < model->rowCount(index); i++) {
|
for (int i = 0; i < model->rowCount(index); i++) {
|
||||||
QModelIndex childIndex = index.child(i, 0);
|
UModelIndex childIndex = index.child(i, 0);
|
||||||
bool useText = FALSE;
|
bool useText = FALSE;
|
||||||
if (model->type(childIndex) != Types::Volume)
|
if (model->type(childIndex) != Types::Volume)
|
||||||
useText = !model->text(childIndex).isEmpty();
|
useText = !model->text(childIndex).isEmpty();
|
||||||
|
|
||||||
QString childPath = path;
|
UString childPath = path;
|
||||||
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT)
|
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT)
|
||||||
childPath = QString("%1/%2 %3").arg(path).arg(i).arg(useText ? model->text(childIndex) : model->name(childIndex));
|
childPath = usprintf("%s/%d %s", (const char *)path.toLocal8Bit(), i,
|
||||||
|
(const char *)(useText ? model->text(childIndex) : model->name(childIndex)).toLocal8Bit());
|
||||||
result = recursiveDump(childIndex, childPath, dumpMode, sectionType, guid);
|
result = recursiveDump(childIndex, childPath, dumpMode, sectionType, guid);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
|
@ -14,15 +14,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
#ifndef FFSDUMPER_H
|
#ifndef FFSDUMPER_H
|
||||||
#define FFSDUMPER_H
|
#define FFSDUMPER_H
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QByteArray>
|
|
||||||
#include <QString>
|
|
||||||
#include <QModelIndex>
|
|
||||||
|
|
||||||
#include "../common/basetypes.h"
|
#include "../common/basetypes.h"
|
||||||
|
#include "../common/ustring.h"
|
||||||
#include "../common/treemodel.h"
|
#include "../common/treemodel.h"
|
||||||
#include "../common/ffs.h"
|
#include "../common/ffs.h"
|
||||||
|
#include "../common/filesystem.h"
|
||||||
|
|
||||||
class FfsDumper
|
class FfsDumper
|
||||||
{
|
{
|
||||||
@ -38,15 +34,16 @@ public:
|
|||||||
|
|
||||||
static const UINT8 IgnoreSectionType = 0xFF;
|
static const UINT8 IgnoreSectionType = 0xFF;
|
||||||
|
|
||||||
explicit FfsDumper(TreeModel * treeModel) : model(treeModel), dumped(false), counter(0) {}
|
explicit FfsDumper(TreeModel * treeModel) : model(treeModel), dumped(false),
|
||||||
|
counterHeader(0), counterBody(0), counterRaw(0), counterInfo(0) {}
|
||||||
~FfsDumper() {};
|
~FfsDumper() {};
|
||||||
|
|
||||||
USTATUS dump(const QModelIndex & root, const QString & path, const DumpMode dumpMode = DUMP_CURRENT, const UINT8 sectionType = IgnoreSectionType, const QString & guid = QString());
|
USTATUS dump(const UModelIndex & root, const UString & path, const DumpMode dumpMode = DUMP_CURRENT, const UINT8 sectionType = IgnoreSectionType, const UString & guid = UString());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
USTATUS recursiveDump(const QModelIndex & root, const QString & path, const DumpMode dumpMode, const UINT8 sectionType, const QString & guid);
|
USTATUS recursiveDump(const UModelIndex & root, const UString & path, const DumpMode dumpMode, const UINT8 sectionType, const UString & guid);
|
||||||
TreeModel* model;
|
TreeModel* model;
|
||||||
bool dumped;
|
bool dumped;
|
||||||
int counter;
|
int counterHeader, counterBody, counterRaw, counterInfo;
|
||||||
};
|
};
|
||||||
#endif // FFSDUMPER_H
|
#endif // FFSDUMPER_H
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
QT += core
|
|
||||||
QT -= gui
|
|
||||||
|
|
||||||
TARGET = UEFIExtract
|
|
||||||
TEMPLATE = app
|
|
||||||
CONFIG += console
|
|
||||||
CONFIG -= app_bundle
|
|
||||||
DEFINES += "U_ENABLE_NVRAM_PARSING_SUPPORT"
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
uefiextract_main.cpp \
|
|
||||||
ffsdumper.cpp \
|
|
||||||
../common/guiddatabase.cpp \
|
|
||||||
../common/types.cpp \
|
|
||||||
../common/descriptor.cpp \
|
|
||||||
../common/ffs.cpp \
|
|
||||||
../common/nvram.cpp \
|
|
||||||
../common/nvramparser.cpp \
|
|
||||||
../common/ffsparser.cpp \
|
|
||||||
../common/ffsreport.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 \
|
|
||||||
../common/ustring.cpp \
|
|
||||||
../common/sha256.c
|
|
||||||
|
|
||||||
HEADERS += \
|
|
||||||
ffsdumper.h \
|
|
||||||
../common/guiddatabase.h \
|
|
||||||
../common/basetypes.h \
|
|
||||||
../common/descriptor.h \
|
|
||||||
../common/gbe.h \
|
|
||||||
../common/me.h \
|
|
||||||
../common/ffs.h \
|
|
||||||
../common/nvram.h \
|
|
||||||
../common/nvramparser.h \
|
|
||||||
../common/ffsparser.h \
|
|
||||||
../common/ffsreport.h \
|
|
||||||
../common/peimage.h \
|
|
||||||
../common/types.h \
|
|
||||||
../common/treeitem.h \
|
|
||||||
../common/treemodel.h \
|
|
||||||
../common/utility.h \
|
|
||||||
../common/LZMA/LzmaDecompress.h \
|
|
||||||
../common/Tiano/EfiTianoDecompress.h \
|
|
||||||
../common/ubytearray.h \
|
|
||||||
../common/ustring.h \
|
|
||||||
../common/bootguard.h \
|
|
||||||
../common/sha256.h \
|
|
||||||
../version.h
|
|
||||||
|
|
@ -7,13 +7,16 @@ http://opensource.org/licenses/bsd-license.php
|
|||||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
*/
|
*/
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QString>
|
|
||||||
#include <QFileInfo>
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
#include "../version.h"
|
#include "../version.h"
|
||||||
|
#include "../common/basetypes.h"
|
||||||
|
#include "../common/ustring.h"
|
||||||
|
#include "../common/filesystem.h"
|
||||||
#include "../common/ffsparser.h"
|
#include "../common/ffsparser.h"
|
||||||
#include "../common/ffsreport.h"
|
#include "../common/ffsreport.h"
|
||||||
#include "ffsdumper.h"
|
#include "ffsdumper.h"
|
||||||
@ -27,26 +30,17 @@ enum ReadType {
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
if (argc > 1) {
|
||||||
a.setOrganizationName("LongSoft");
|
|
||||||
a.setOrganizationDomain("longsoft.me");
|
|
||||||
a.setApplicationName("UEFIExtract");
|
|
||||||
|
|
||||||
if (a.arguments().length() > 1) {
|
|
||||||
// Check that input file exists
|
// Check that input file exists
|
||||||
QString path = a.arguments().at(1);
|
UString path = argv[1];
|
||||||
QFileInfo fileInfo(path);
|
if (!isExistOnFs(path))
|
||||||
if (!fileInfo.exists())
|
|
||||||
return U_FILE_OPEN;
|
return U_FILE_OPEN;
|
||||||
|
|
||||||
// Open the input file
|
// Open the input file
|
||||||
QFile inputFile;
|
std::ifstream inputFile;
|
||||||
inputFile.setFileName(path);
|
inputFile.open(argv[1], std::ios::in | std::ios::binary);
|
||||||
if (!inputFile.open(QFile::ReadOnly))
|
std::vector<char> buffer(std::istreambuf_iterator<char>(inputFile),
|
||||||
return U_FILE_OPEN;
|
(std::istreambuf_iterator<char>()));
|
||||||
|
|
||||||
// Read and close the file
|
|
||||||
QByteArray buffer = inputFile.readAll();
|
|
||||||
inputFile.close();
|
inputFile.close();
|
||||||
|
|
||||||
// Create model and ffsParser
|
// Create model and ffsParser
|
||||||
@ -58,24 +52,24 @@ int main(int argc, char *argv[])
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
// Show ffsParser's messages
|
// Show ffsParser's messages
|
||||||
std::vector<std::pair<QString, QModelIndex> > messages = ffsParser.getMessages();
|
std::vector<std::pair<UString, UModelIndex> > messages = ffsParser.getMessages();
|
||||||
for (size_t i = 0; i < messages.size(); i++) {
|
for (size_t i = 0; i < messages.size(); i++) {
|
||||||
std::cout << messages[i].first.toLatin1().constData() << std::endl;
|
std::cout << (const char *)messages[i].first.toLocal8Bit() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get last VTF
|
// Get last VTF
|
||||||
std::vector<std::pair<std::vector<QString>, QModelIndex > > fitTable = ffsParser.getFitTable();
|
std::vector<std::pair<std::vector<UString>, UModelIndex > > fitTable = ffsParser.getFitTable();
|
||||||
if (fitTable.size()) {
|
if (fitTable.size()) {
|
||||||
std::cout << "---------------------------------------------------------------------------" << std::endl;
|
std::cout << "---------------------------------------------------------------------------" << std::endl;
|
||||||
std::cout << " Address | Size | Ver | CS | Type / Info " << std::endl;
|
std::cout << " Address | Size | Ver | CS | Type / Info " << std::endl;
|
||||||
std::cout << "---------------------------------------------------------------------------" << std::endl;
|
std::cout << "---------------------------------------------------------------------------" << std::endl;
|
||||||
for (size_t i = 0; i < fitTable.size(); i++) {
|
for (size_t i = 0; i < fitTable.size(); i++) {
|
||||||
std::cout << fitTable[i].first[0].toLatin1().constData() << " | "
|
std::cout << (const char *)fitTable[i].first[0].toLocal8Bit() << " | "
|
||||||
<< fitTable[i].first[1].toLatin1().constData() << " | "
|
<< (const char *)fitTable[i].first[1].toLocal8Bit() << " | "
|
||||||
<< fitTable[i].first[2].toLatin1().constData() << " | "
|
<< (const char *)fitTable[i].first[2].toLocal8Bit() << " | "
|
||||||
<< fitTable[i].first[3].toLatin1().constData() << " | "
|
<< (const char *)fitTable[i].first[3].toLocal8Bit() << " | "
|
||||||
<< fitTable[i].first[4].toLatin1().constData() << " | "
|
<< (const char *)fitTable[i].first[4].toLocal8Bit() << " | "
|
||||||
<< fitTable[i].first[5].toLatin1().constData() << std::endl;
|
<< (const char *)fitTable[i].first[5].toLocal8Bit() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,27 +78,27 @@ int main(int argc, char *argv[])
|
|||||||
FfsDumper ffsDumper(&model);
|
FfsDumper ffsDumper(&model);
|
||||||
|
|
||||||
// Dump only leaf elements, no report
|
// Dump only leaf elements, no report
|
||||||
if (a.arguments().length() == 3 && a.arguments().at(2) == QString("dump")) {
|
if (argc == 3 && !std::strcmp(argv[2], "dump")) {
|
||||||
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != U_SUCCESS);
|
return (ffsDumper.dump(model.index(0, 0), path + UString(".dump")) != U_SUCCESS);
|
||||||
}
|
}
|
||||||
else if (a.arguments().length() > 3 ||
|
else if (argc > 3 ||
|
||||||
(a.arguments().length() == 3 && a.arguments().at(2) != QString("all") && a.arguments().at(2) != QString("report"))) { // Dump specific files, without report
|
(argc == 3 && std::strcmp(argv[2], "all") != 0 && std::strcmp(argv[2], "report") != 0)) { // Dump specific files, without report
|
||||||
std::vector<QString> inputs, outputs;
|
std::vector<UString> inputs, outputs;
|
||||||
std::vector<FfsDumper::DumpMode> modes;
|
std::vector<FfsDumper::DumpMode> modes;
|
||||||
std::vector<UINT8> sectionTypes;
|
std::vector<UINT8> sectionTypes;
|
||||||
ReadType readType = READ_INPUT;
|
ReadType readType = READ_INPUT;
|
||||||
for (int i = 2; i < a.arguments().length(); i++) {
|
for (int i = 2; i < argc; i++) {
|
||||||
QString arg = a.arguments().at(i);
|
const char *arg = argv[i];
|
||||||
if (arg == QString("-i")) {
|
if (!std::strcmp(arg, "-i")) {
|
||||||
readType = READ_INPUT;
|
readType = READ_INPUT;
|
||||||
continue;
|
continue;
|
||||||
} else if (arg == QString("-o")) {
|
} else if (!std::strcmp(arg, "-o")) {
|
||||||
readType = READ_OUTPUT;
|
readType = READ_OUTPUT;
|
||||||
continue;
|
continue;
|
||||||
} else if (arg == QString("-m")) {
|
} else if (!std::strcmp(arg, "-m")) {
|
||||||
readType = READ_MODE;
|
readType = READ_MODE;
|
||||||
continue;
|
continue;
|
||||||
} else if (arg == QString("-t")) {
|
} else if (!std::strcmp(arg, "-t")) {
|
||||||
readType = READ_SECTION;
|
readType = READ_SECTION;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -114,22 +108,22 @@ int main(int argc, char *argv[])
|
|||||||
} else if (readType == READ_OUTPUT) {
|
} else if (readType == READ_OUTPUT) {
|
||||||
outputs.push_back(arg);
|
outputs.push_back(arg);
|
||||||
} else if (readType == READ_MODE) {
|
} else if (readType == READ_MODE) {
|
||||||
if (arg == QString("all"))
|
if (!std::strcmp(arg, "all"))
|
||||||
modes.push_back(FfsDumper::DUMP_ALL);
|
modes.push_back(FfsDumper::DUMP_ALL);
|
||||||
else if (arg == QString("body"))
|
else if (!std::strcmp(arg, "body"))
|
||||||
modes.push_back(FfsDumper::DUMP_BODY);
|
modes.push_back(FfsDumper::DUMP_BODY);
|
||||||
else if (arg == QString("header"))
|
else if (!std::strcmp(arg, "header"))
|
||||||
modes.push_back(FfsDumper::DUMP_HEADER);
|
modes.push_back(FfsDumper::DUMP_HEADER);
|
||||||
else if (arg == QString("info"))
|
else if (!std::strcmp(arg, "info"))
|
||||||
modes.push_back(FfsDumper::DUMP_INFO);
|
modes.push_back(FfsDumper::DUMP_INFO);
|
||||||
else if (arg == QString("file"))
|
else if (!std::strcmp(arg, "file"))
|
||||||
modes.push_back(FfsDumper::DUMP_FILE);
|
modes.push_back(FfsDumper::DUMP_FILE);
|
||||||
else
|
else
|
||||||
return U_INVALID_PARAMETER;
|
return U_INVALID_PARAMETER;
|
||||||
} else if (readType == READ_SECTION) {
|
} else if (readType == READ_SECTION) {
|
||||||
bool converted;
|
char *converted = const_cast<char *>(arg);
|
||||||
UINT8 sectionType = (UINT8)arg.toUShort(&converted, 16);
|
UINT8 sectionType = (UINT8)std::strtol(arg, &converted, 16);
|
||||||
if (!converted)
|
if (converted == arg)
|
||||||
return U_INVALID_PARAMETER;
|
return U_INVALID_PARAMETER;
|
||||||
sectionTypes.push_back(sectionType);
|
sectionTypes.push_back(sectionType);
|
||||||
}
|
}
|
||||||
@ -141,12 +135,12 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
USTATUS lastError = U_SUCCESS;
|
USTATUS lastError = U_SUCCESS;
|
||||||
for (size_t i = 0; i < inputs.size(); i++) {
|
for (size_t i = 0; i < inputs.size(); i++) {
|
||||||
QString outPath = outputs.empty() ? fileInfo.fileName().append(".dump") : outputs[i];
|
UString outPath = outputs.empty() ? path + UString(".dump") : outputs[i];
|
||||||
FfsDumper::DumpMode mode = modes.empty() ? FfsDumper::DUMP_ALL : modes[i];
|
FfsDumper::DumpMode mode = modes.empty() ? FfsDumper::DUMP_ALL : modes[i];
|
||||||
UINT8 type = sectionTypes.empty() ? FfsDumper::IgnoreSectionType : sectionTypes[i];
|
UINT8 type = sectionTypes.empty() ? FfsDumper::IgnoreSectionType : sectionTypes[i];
|
||||||
result = ffsDumper.dump(model.index(0, 0), outPath, mode, type, inputs[i]);
|
result = ffsDumper.dump(model.index(0, 0), outPath, mode, type, inputs[i]);
|
||||||
if (result) {
|
if (result) {
|
||||||
std::cout << "Guid " << inputs[i].toStdString() << " failed with " << result << " code!" << std::endl;
|
std::cout << "Guid " << (const char *)inputs[i].toLocal8Bit() << " failed with " << result << " code!" << std::endl;
|
||||||
lastError = result;
|
lastError = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,26 +150,22 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Create ffsReport
|
// Create ffsReport
|
||||||
FfsReport ffsReport(&model);
|
FfsReport ffsReport(&model);
|
||||||
std::vector<QString> report = ffsReport.generate();
|
std::vector<UString> report = ffsReport.generate();
|
||||||
if (report.size()) {
|
if (report.size()) {
|
||||||
QFile file;
|
std::ofstream file;
|
||||||
file.setFileName(fileInfo.fileName().append(".report.txt"));
|
file.open((const char *)(path + UString(".report.txt")).toLocal8Bit());
|
||||||
if (file.open(QFile::Text | QFile::WriteOnly)) {
|
for (size_t i = 0; i < report.size(); i++)
|
||||||
for (size_t i = 0; i < report.size(); i++) {
|
file << (const char *)report[i].toLocal8Bit() << '\n';
|
||||||
file.write(report[i].toLatin1().append('\n'));
|
|
||||||
}
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump all non-leaf elements, with report, default
|
// Dump all non-leaf elements, with report, default
|
||||||
if (a.arguments().length() == 2) {
|
if (argc == 2) {
|
||||||
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != U_SUCCESS);
|
return (ffsDumper.dump(model.index(0, 0), path + UString(".dump")) != U_SUCCESS);
|
||||||
}
|
}
|
||||||
else if (a.arguments().length() == 3 && a.arguments().at(2) == QString("all")) { // Dump every elementm with report
|
else if (argc == 3 && !std::strcmp(argv[2], "all")) { // Dump every elementm with report
|
||||||
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), FfsDumper::DUMP_ALL) != U_SUCCESS);
|
return (ffsDumper.dump(model.index(0, 0), path + UString(".dump"), FfsDumper::DUMP_ALL) != U_SUCCESS);
|
||||||
}
|
}
|
||||||
else if (a.arguments().length() == 3 && a.arguments().at(2) == QString("report")) { // Skip dumping
|
else if (argc == 3 && !std::strcmp(argv[2], "report")) { // Skip dumping
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
51
common/filesystem.h
Normal file
51
common/filesystem.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* filesystem.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 FILESYSTEM_H
|
||||||
|
#define FILESYSTEM_H
|
||||||
|
|
||||||
|
#include "basetypes.h"
|
||||||
|
#include "ustring.h"
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <direct.h>
|
||||||
|
static inline bool isExistOnFs(const UString & path) {
|
||||||
|
struct _stat buf;
|
||||||
|
return (_stat((const char*)path.toLocal8Bit(), &buf) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool makeDirectory(const UString & dir) {
|
||||||
|
return (_mkdir((const char*)dir.toLocal8Bit()) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool changeDirectory(const UString & dir) {
|
||||||
|
return (_chdir((const char*)dir.toLocal8Bit()) == 0);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
static inline bool isExistOnFs(const UString & path) {
|
||||||
|
struct stat buf;
|
||||||
|
return (stat((const char*)path.toLocal8Bit(), &buf) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool makeDirectory(const UString & dir) {
|
||||||
|
return (mkdir((const char*)dir.toLocal8Bit(), ACCESSPERMS) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool changeDirectory(const UString & dir) {
|
||||||
|
return (chdir((const char*)dir.toLocal8Bit()) == 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -114,7 +114,7 @@ mkdir -p dist || exit 1
|
|||||||
|
|
||||||
build_tool UEFITool "$UEFITOOL_VER" uefitool.pro
|
build_tool UEFITool "$UEFITOOL_VER" uefitool.pro
|
||||||
build_tool UEFIDump "$UEFITOOL_VER" ""
|
build_tool UEFIDump "$UEFITOOL_VER" ""
|
||||||
build_tool UEFIExtract "$UEFITOOL_VER" uefiextract.pro
|
build_tool UEFIExtract "$UEFITOOL_VER" ""
|
||||||
build_tool UEFIFind "$UEFITOOL_VER" uefifind.pro
|
build_tool UEFIFind "$UEFITOOL_VER" uefifind.pro
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user