Rough attempt to deglue UEFIExtract from Qt

This commit is contained in:
vit9696 2018-07-13 00:17:08 +03:00
parent 0a2f115056
commit c9db871c12
9 changed files with 227 additions and 209 deletions

View file

@ -50,6 +50,7 @@ SET(PROJECT_HEADERS
../common/sha256.h
../common/bstrlib/bstrlib.h
../common/bstrlib/bstrwrap.h
../common/filesystem.h
../version.h
)

View file

@ -14,41 +14,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "uefidump.h"
#include "../common/ffs.h"
#include "../common/utility.h"
#include "../common/filesystem.h"
#include <iostream>
#include <fstream>
#include <sstream>
#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)
{

View 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})

View file

@ -13,13 +13,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#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;
counter = 0;
counterHeader = counterBody = counterRaw = counterInfo = 0;
QDir dir;
if (dir.cd(path))
if (changeDirectory(path))
return U_DIR_ALREADY_EXIST;
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;
}
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())
return U_INVALID_PARAMETER;
QDir dir;
if (guid.isEmpty() ||
(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()) == 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;
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 || dumpMode == DUMP_CURRENT || dumpMode == DUMP_HEADER) {
if (!model->header(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
if (counter == 0)
file.setFileName(QObject::tr("%1/header.bin").arg(path));
UString filename;
if (counterHeader == 0)
filename = usprintf("%s/header.bin", (const char *)path.toLocal8Bit());
else
file.setFileName(QObject::tr("%1/header_%2.bin").arg(path).arg(counter));
counter++;
if (!file.open(QFile::WriteOnly))
return U_FILE_OPEN;
file.write(model->header(index));
filename = usprintf("%s/header_%d.bin", (const char *)path.toLocal8Bit(), counterHeader);
counterHeader++;
file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary);
const UByteArray &data = model->header(index);
file.write(data.constData(), data.size());
file.close();
}
}
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_BODY) {
if (!model->body(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
if (counter == 0)
file.setFileName(QObject::tr("%1/body.bin").arg(path));
UString filename;
if (counterBody == 0)
filename = usprintf("%s/body.bin", (const char *)path.toLocal8Bit());
else
file.setFileName(QObject::tr("%1/body_%2.bin").arg(path).arg(counter));
counter++;
if (!file.open(QFile::WriteOnly))
return U_FILE_OPEN;
file.write(model->body(index));
filename = usprintf("%s/body_%d.bin", (const char *)path.toLocal8Bit(), counterBody);
counterBody++;
file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary);
const UByteArray &data = model->body(index);
file.write(data.constData(), data.size());
file.close();
}
}
@ -81,16 +83,19 @@ USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path
UModelIndex fileIndex = model->findParentOfType(index, Types::File);
if (!fileIndex.isValid())
fileIndex = index;
if (counter == 0)
file.setFileName(QObject::tr("%1/file.ffs").arg(path));
UString filename;
if (counterRaw == 0)
filename = usprintf("%s/file.ffs", (const char *)path.toLocal8Bit());
else
file.setFileName(QObject::tr("%1/file_%2.ffs").arg(path).arg(counter));
counter++;
if (!file.open(QFile::WriteOnly))
return U_FILE_OPEN;
file.write(model->header(fileIndex));
file.write(model->body(fileIndex));
file.write(model->tail(fileIndex));
filename = usprintf("%s/file_%d.bin", (const char *)path.toLocal8Bit(), counterRaw);
counterRaw++;
file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary);
const UByteArray &headerData = model->header(index);
const UByteArray &bodyData = model->body(index);
const UByteArray &tailData = model->tail(index);
file.write(headerData.constData(), headerData.size());
file.write(bodyData.constData(), bodyData.size());
file.write(tailData.constData(), tailData.size());
file.close();
}
}
@ -98,20 +103,20 @@ USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path
// Always dump info unless explicitly prohibited
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_INFO)
&& (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
QString info = QObject::tr("Type: %1\nSubtype: %2\n%3%4\n")
.arg(itemTypeToUString(model->type(index)))
.arg(itemSubtypeToUString(model->type(index), model->subtype(index)))
.arg(model->text(index).isEmpty() ? QObject::tr("") : QObject::tr("Text: %1\n").arg(model->text(index)))
.arg(model->info(index));
if (counter == 0)
file.setFileName(QObject::tr("%1/info.txt").arg(path));
UString info = usprintf("Type: %s\nSubtype: %s\n%s%s\n",
(const char *)itemTypeToUString(model->type(index)).toLocal8Bit(),
(const char *)itemSubtypeToUString(model->type(index), model->subtype(index)).toLocal8Bit(),
(const char *)(model->text(index).isEmpty() ? UString("") :
usprintf("Text: %s\n", (const char *)model->text(index).toLocal8Bit())).toLocal8Bit(),
(const char *)model->info(index).toLocal8Bit());
UString filename;
if (counterInfo == 0)
filename = usprintf("%s/info.txt", (const char *)path.toLocal8Bit());
else
file.setFileName(QObject::tr("%1/info_%2.txt").arg(path).arg(counter));
counter++;
if (!file.open(QFile::Text | QFile::WriteOnly))
return U_FILE_OPEN;
file.write(info.toLatin1());
filename = usprintf("%s/info_%d.txt", (const char *)path.toLocal8Bit(), counterInfo);
counterInfo++;
file.open((const char *)filename.toLocal8Bit());
file << (const char *)info.toLocal8Bit();
file.close();
}
@ -120,14 +125,15 @@ USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path
UINT8 result;
for (int i = 0; i < model->rowCount(index); i++) {
QModelIndex childIndex = index.child(i, 0);
UModelIndex childIndex = index.child(i, 0);
bool useText = FALSE;
if (model->type(childIndex) != Types::Volume)
useText = !model->text(childIndex).isEmpty();
QString childPath = path;
UString childPath = path;
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);
if (result)
return result;

View file

@ -14,15 +14,11 @@ 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 "../common/basetypes.h"
#include "../common/ustring.h"
#include "../common/treemodel.h"
#include "../common/ffs.h"
#include "../common/filesystem.h"
class FfsDumper
{
@ -38,15 +34,16 @@ public:
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() {};
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:
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;
bool dumped;
int counter;
int counterHeader, counterBody, counterRaw, counterInfo;
};
#endif // FFSDUMPER_H

View file

@ -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

View file

@ -7,13 +7,16 @@ 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 <QFileInfo>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include "../version.h"
#include "../common/basetypes.h"
#include "../common/ustring.h"
#include "../common/filesystem.h"
#include "../common/ffsparser.h"
#include "../common/ffsreport.h"
#include "ffsdumper.h"
@ -27,26 +30,17 @@ enum ReadType {
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setOrganizationName("LongSoft");
a.setOrganizationDomain("longsoft.me");
a.setApplicationName("UEFIExtract");
if (a.arguments().length() > 1) {
if (argc > 1) {
// Check that input file exists
QString path = a.arguments().at(1);
QFileInfo fileInfo(path);
if (!fileInfo.exists())
UString path = argv[1];
if (!isExistOnFs(path))
return U_FILE_OPEN;
// Open the input file
QFile inputFile;
inputFile.setFileName(path);
if (!inputFile.open(QFile::ReadOnly))
return U_FILE_OPEN;
// Read and close the file
QByteArray buffer = inputFile.readAll();
std::ifstream inputFile;
inputFile.open(argv[1], std::ios::in | std::ios::binary);
std::vector<char> buffer(std::istreambuf_iterator<char>(inputFile),
(std::istreambuf_iterator<char>()));
inputFile.close();
// Create model and ffsParser
@ -58,24 +52,24 @@ int main(int argc, char *argv[])
return result;
// 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++) {
std::cout << messages[i].first.toLatin1().constData() << std::endl;
std::cout << (const char *)messages[i].first.toLocal8Bit() << std::endl;
}
// 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()) {
std::cout << "---------------------------------------------------------------------------" << std::endl;
std::cout << " Address | Size | Ver | CS | Type / Info " << std::endl;
std::cout << "---------------------------------------------------------------------------" << std::endl;
for (size_t i = 0; i < fitTable.size(); i++) {
std::cout << fitTable[i].first[0].toLatin1().constData() << " | "
<< fitTable[i].first[1].toLatin1().constData() << " | "
<< fitTable[i].first[2].toLatin1().constData() << " | "
<< fitTable[i].first[3].toLatin1().constData() << " | "
<< fitTable[i].first[4].toLatin1().constData() << " | "
<< fitTable[i].first[5].toLatin1().constData() << std::endl;
std::cout << (const char *)fitTable[i].first[0].toLocal8Bit() << " | "
<< (const char *)fitTable[i].first[1].toLocal8Bit() << " | "
<< (const char *)fitTable[i].first[2].toLocal8Bit() << " | "
<< (const char *)fitTable[i].first[3].toLocal8Bit() << " | "
<< (const char *)fitTable[i].first[4].toLocal8Bit() << " | "
<< (const char *)fitTable[i].first[5].toLocal8Bit() << std::endl;
}
}
@ -84,27 +78,27 @@ int main(int argc, char *argv[])
FfsDumper ffsDumper(&model);
// Dump only leaf elements, no report
if (a.arguments().length() == 3 && a.arguments().at(2) == QString("dump")) {
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != U_SUCCESS);
if (argc == 3 && !std::strcmp(argv[2], "dump")) {
return (ffsDumper.dump(model.index(0, 0), path + UString(".dump")) != U_SUCCESS);
}
else if (a.arguments().length() > 3 ||
(a.arguments().length() == 3 && a.arguments().at(2) != QString("all") && a.arguments().at(2) != QString("report"))) { // Dump specific files, without report
std::vector<QString> inputs, outputs;
else if (argc > 3 ||
(argc == 3 && std::strcmp(argv[2], "all") != 0 && std::strcmp(argv[2], "report") != 0)) { // Dump specific files, without report
std::vector<UString> inputs, outputs;
std::vector<FfsDumper::DumpMode> modes;
std::vector<UINT8> sectionTypes;
ReadType readType = READ_INPUT;
for (int i = 2; i < a.arguments().length(); i++) {
QString arg = a.arguments().at(i);
if (arg == QString("-i")) {
for (int i = 2; i < argc; i++) {
const char *arg = argv[i];
if (!std::strcmp(arg, "-i")) {
readType = READ_INPUT;
continue;
} else if (arg == QString("-o")) {
} else if (!std::strcmp(arg, "-o")) {
readType = READ_OUTPUT;
continue;
} else if (arg == QString("-m")) {
} else if (!std::strcmp(arg, "-m")) {
readType = READ_MODE;
continue;
} else if (arg == QString("-t")) {
} else if (!std::strcmp(arg, "-t")) {
readType = READ_SECTION;
continue;
}
@ -114,22 +108,22 @@ int main(int argc, char *argv[])
} else if (readType == READ_OUTPUT) {
outputs.push_back(arg);
} else if (readType == READ_MODE) {
if (arg == QString("all"))
if (!std::strcmp(arg, "all"))
modes.push_back(FfsDumper::DUMP_ALL);
else if (arg == QString("body"))
else if (!std::strcmp(arg, "body"))
modes.push_back(FfsDumper::DUMP_BODY);
else if (arg == QString("header"))
else if (!std::strcmp(arg, "header"))
modes.push_back(FfsDumper::DUMP_HEADER);
else if (arg == QString("info"))
else if (!std::strcmp(arg, "info"))
modes.push_back(FfsDumper::DUMP_INFO);
else if (arg == QString("file"))
else if (!std::strcmp(arg, "file"))
modes.push_back(FfsDumper::DUMP_FILE);
else
return U_INVALID_PARAMETER;
} else if (readType == READ_SECTION) {
bool converted;
UINT8 sectionType = (UINT8)arg.toUShort(&converted, 16);
if (!converted)
char *converted = const_cast<char *>(arg);
UINT8 sectionType = (UINT8)std::strtol(arg, &converted, 16);
if (converted == arg)
return U_INVALID_PARAMETER;
sectionTypes.push_back(sectionType);
}
@ -141,12 +135,12 @@ int main(int argc, char *argv[])
USTATUS lastError = U_SUCCESS;
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];
UINT8 type = sectionTypes.empty() ? FfsDumper::IgnoreSectionType : sectionTypes[i];
result = ffsDumper.dump(model.index(0, 0), outPath, mode, type, inputs[i]);
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;
}
}
@ -156,26 +150,22 @@ int main(int argc, char *argv[])
// Create ffsReport
FfsReport ffsReport(&model);
std::vector<QString> report = ffsReport.generate();
std::vector<UString> report = ffsReport.generate();
if (report.size()) {
QFile file;
file.setFileName(fileInfo.fileName().append(".report.txt"));
if (file.open(QFile::Text | QFile::WriteOnly)) {
for (size_t i = 0; i < report.size(); i++) {
file.write(report[i].toLatin1().append('\n'));
}
file.close();
}
std::ofstream file;
file.open((const char *)(path + UString(".report.txt")).toLocal8Bit());
for (size_t i = 0; i < report.size(); i++)
file << (const char *)report[i].toLocal8Bit() << '\n';
}
// Dump all non-leaf elements, with report, default
if (a.arguments().length() == 2) {
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != U_SUCCESS);
if (argc == 2) {
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
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), FfsDumper::DUMP_ALL) != U_SUCCESS);
else if (argc == 3 && !std::strcmp(argv[2], "all")) { // Dump every elementm with report
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;
}
}

51
common/filesystem.h Normal file
View 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

View file

@ -114,7 +114,7 @@ mkdir -p dist || exit 1
build_tool UEFITool "$UEFITOOL_VER" uefitool.pro
build_tool UEFIDump "$UEFITOOL_VER" ""
build_tool UEFIExtract "$UEFITOOL_VER" uefiextract.pro
build_tool UEFIExtract "$UEFITOOL_VER" ""
build_tool UEFIFind "$UEFITOOL_VER" uefifind.pro
exit 0