mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-22 07:58:22 +08:00
Bugfixes for #147
This commit is contained in:
parent
337da5e632
commit
7e1e1ab61e
@ -38,16 +38,15 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
|
|
||||||
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(readMisaligned((const EFI_GUID*)(model->header(index).constData() + sizeof(EFI_COMMON_SECTION_HEADER)))) == guid) ||
|
||||||
guidToUString(*(const EFI_GUID*)model->header(index).constData()) == guid ||
|
guidToUString(readMisaligned((const EFI_GUID*)model->header(index).constData())) == guid ||
|
||||||
guidToUString(*(const EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData()) == guid) {
|
guidToUString(readMisaligned((const EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData())) == guid) {
|
||||||
|
|
||||||
if (!changeDirectory(path) && !makeDirectory(path))
|
if (!changeDirectory(path) && !makeDirectory(path))
|
||||||
return U_DIR_CREATE;
|
return U_DIR_CREATE;
|
||||||
|
|
||||||
counterHeader = counterBody = counterRaw = counterInfo = 0;
|
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)) {
|
||||||
@ -57,10 +56,11 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
else
|
else
|
||||||
filename = usprintf("%s/header_%d.bin", path.toLocal8Bit(), counterHeader);
|
filename = usprintf("%s/header_%d.bin", path.toLocal8Bit(), counterHeader);
|
||||||
counterHeader++;
|
counterHeader++;
|
||||||
file.open(filename.toLocal8Bit(), std::ofstream::binary);
|
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
|
||||||
|
if (!file)
|
||||||
|
return U_FILE_OPEN;
|
||||||
const UByteArray &data = model->header(index);
|
const UByteArray &data = model->header(index);
|
||||||
file.write(data.constData(), data.size());
|
file.write(data.constData(), data.size());
|
||||||
file.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,10 +72,12 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
else
|
else
|
||||||
filename = usprintf("%s/body_%d.bin", path.toLocal8Bit(), counterBody);
|
filename = usprintf("%s/body_%d.bin", path.toLocal8Bit(), counterBody);
|
||||||
counterBody++;
|
counterBody++;
|
||||||
file.open(filename.toLocal8Bit(), std::ofstream::binary);
|
errno = 0;
|
||||||
|
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
|
||||||
|
if (!file)
|
||||||
|
return U_FILE_OPEN;
|
||||||
const UByteArray &data = model->body(index);
|
const UByteArray &data = model->body(index);
|
||||||
file.write(data.constData(), data.size());
|
file.write(data.constData(), data.size());
|
||||||
file.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,14 +91,15 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
else
|
else
|
||||||
filename = usprintf("%s/file_%d.bin", path.toLocal8Bit(), counterRaw);
|
filename = usprintf("%s/file_%d.bin", path.toLocal8Bit(), counterRaw);
|
||||||
counterRaw++;
|
counterRaw++;
|
||||||
file.open(filename.toLocal8Bit(), std::ofstream::binary);
|
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
|
||||||
|
if (!file)
|
||||||
|
return U_FILE_OPEN;
|
||||||
const UByteArray &headerData = model->header(index);
|
const UByteArray &headerData = model->header(index);
|
||||||
const UByteArray &bodyData = model->body(index);
|
const UByteArray &bodyData = model->body(index);
|
||||||
const UByteArray &tailData = model->tail(index);
|
const UByteArray &tailData = model->tail(index);
|
||||||
file.write(headerData.constData(), headerData.size());
|
file.write(headerData.constData(), headerData.size());
|
||||||
file.write(bodyData.constData(), bodyData.size());
|
file.write(bodyData.constData(), bodyData.size());
|
||||||
file.write(tailData.constData(), tailData.size());
|
file.write(tailData.constData(), tailData.size());
|
||||||
file.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,9 +118,10 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
else
|
else
|
||||||
filename = usprintf("%s/info_%d.txt", path.toLocal8Bit(), counterInfo);
|
filename = usprintf("%s/info_%d.txt", path.toLocal8Bit(), counterInfo);
|
||||||
counterInfo++;
|
counterInfo++;
|
||||||
file.open(filename.toLocal8Bit());
|
std::ofstream file(filename.toLocal8Bit());
|
||||||
|
if (!file)
|
||||||
|
return U_FILE_OPEN;
|
||||||
file << info.toLocal8Bit();
|
file << info.toLocal8Bit();
|
||||||
file.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dumped = true;
|
dumped = true;
|
||||||
|
@ -19,6 +19,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
#include "../common/treemodel.h"
|
#include "../common/treemodel.h"
|
||||||
#include "../common/ffs.h"
|
#include "../common/ffs.h"
|
||||||
#include "../common/filesystem.h"
|
#include "../common/filesystem.h"
|
||||||
|
#include "../common/utility.h"
|
||||||
|
|
||||||
class FfsDumper
|
class FfsDumper
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,7 @@ USTATUS UEFIDumper::dump(const UByteArray & buffer, const UString & inPath, cons
|
|||||||
std::vector<std::pair<std::vector<UString>, UModelIndex > > 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].toLocal8Bit() << " | "
|
std::cout << fitTable[i].first[0].toLocal8Bit() << " | "
|
||||||
|
@ -38,7 +38,7 @@ int main(int argc, char *argv[])
|
|||||||
// Check that input file exists
|
// Check that input file exists
|
||||||
USTATUS result;
|
USTATUS result;
|
||||||
UByteArray buffer;
|
UByteArray buffer;
|
||||||
UString path = argv[1];
|
UString path = getAbsPath(argv[1]);
|
||||||
result = readFileIntoBuffer(path, buffer);
|
result = readFileIntoBuffer(path, buffer);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
@ -67,7 +67,7 @@ int main(int argc, char *argv[])
|
|||||||
std::vector<std::pair<std::vector<UString>, UModelIndex > > 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].toLocal8Bit() << " | "
|
std::cout << fitTable[i].first[0].toLocal8Bit() << " | "
|
||||||
@ -112,7 +112,7 @@ int main(int argc, char *argv[])
|
|||||||
if (readType == READ_INPUT) {
|
if (readType == READ_INPUT) {
|
||||||
inputs.push_back(arg);
|
inputs.push_back(arg);
|
||||||
} else if (readType == READ_OUTPUT) {
|
} else if (readType == READ_OUTPUT) {
|
||||||
outputs.push_back(arg);
|
outputs.push_back(getAbsPath(arg));
|
||||||
} else if (readType == READ_MODE) {
|
} else if (readType == READ_MODE) {
|
||||||
if (!std::strcmp(arg, "all"))
|
if (!std::strcmp(arg, "all"))
|
||||||
modes.push_back(FfsDumper::DUMP_ALL);
|
modes.push_back(FfsDumper::DUMP_ALL);
|
||||||
|
@ -67,12 +67,12 @@ USTATUS UEFIFind::find(const UINT8 mode, const bool count, const UString & hexPa
|
|||||||
std::pair<UModelIndex, UModelIndex> indexes = *citer;
|
std::pair<UModelIndex, UModelIndex> indexes = *citer;
|
||||||
if (!model->hasEmptyHeader(indexes.first))
|
if (!model->hasEmptyHeader(indexes.first))
|
||||||
data = model->header(indexes.first).left(16);
|
data = model->header(indexes.first).left(16);
|
||||||
result += guidToUString(*(const EFI_GUID*)data.constData());
|
result += guidToUString(readMisaligned((const EFI_GUID*)data.constData()));
|
||||||
|
|
||||||
// Special case of freeform subtype GUID files
|
// Special case of freeform subtype GUID files
|
||||||
if (indexes.second.isValid() && model->subtype(indexes.second) == EFI_SECTION_FREEFORM_SUBTYPE_GUID) {
|
if (indexes.second.isValid() && model->subtype(indexes.second) == EFI_SECTION_FREEFORM_SUBTYPE_GUID) {
|
||||||
data = model->header(indexes.second);
|
data = model->header(indexes.second);
|
||||||
result += UString(" ") + (guidToUString(*(const EFI_GUID*)(data.constData() + sizeof(EFI_COMMON_SECTION_HEADER))));
|
result += UString(" ") + (guidToUString(readMisaligned((const EFI_GUID*)(data.constData() + sizeof(EFI_COMMON_SECTION_HEADER)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
result += UString("\n");
|
result += UString("\n");
|
||||||
|
@ -361,17 +361,24 @@ struct CBString : public tagbstring {
|
|||||||
int gets (bNgetc getcPtr, void * parm, char terminator = '\n');
|
int gets (bNgetc getcPtr, void * parm, char terminator = '\n');
|
||||||
int read (bNread readPtr, void * parm);
|
int read (bNread readPtr, void * parm);
|
||||||
|
|
||||||
// QString compatibility methods
|
// QString compatibility methods
|
||||||
const char *toLocal8Bit() const { return *this; }
|
const char *toLocal8Bit() const { return *this; }
|
||||||
bool contains(const char *str) { return find(str) >= 0; }
|
bool contains(const char *str) { return find(str) >= 0; }
|
||||||
bool isEmpty() const { return slen == 0; }
|
bool isEmpty() const { return slen == 0; }
|
||||||
void clear() { *this = ""; }
|
void clear() { *this = ""; }
|
||||||
CBString left(int len) const { return midstr(0, len); }
|
CBString left(int len) const { return midstr(0, len); }
|
||||||
CBString mid(int pos, int len) const { return midstr(pos, len); }
|
CBString mid(int pos, int len) const { return midstr(pos, len); }
|
||||||
static CBString fromUtf16(const unsigned short* str) { // Naive implementation assuming that only ASCII part of UCS2 is used
|
static CBString fromUtf16(const unsigned short* str) {
|
||||||
CBString msg; while (*str) { msg += *(char*)str; str++; } return msg;
|
// Naive implementation assuming that only ASCII LE part of UCS2 is used, str may not be aligned.
|
||||||
}
|
CBString msg;
|
||||||
CBString leftJustified(int length) { if (length > slen) { return *this + CBString(' ', length - slen); } return *this; }
|
const char *str8 = reinterpret_cast<const char *>(str);
|
||||||
|
while (str8[0]) {
|
||||||
|
msg += str8[0];
|
||||||
|
str8 += 2;
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
CBString leftJustified(int length) { if (length > slen) { return *this + CBString(' ', length - slen); } return *this; }
|
||||||
};
|
};
|
||||||
extern const CBString operator + (const char *a, const CBString& b);
|
extern const CBString operator + (const char *a, const CBString& b);
|
||||||
extern const CBString operator + (const unsigned char *a, const CBString& b);
|
extern const CBString operator + (const unsigned char *a, const CBString& b);
|
||||||
|
@ -2449,8 +2449,8 @@ USTATUS FfsParser::parseCompressedSectionBody(const UModelIndex & index)
|
|||||||
if (model->hasEmptyParsingData(index) == false) {
|
if (model->hasEmptyParsingData(index) == false) {
|
||||||
UByteArray data = model->parsingData(index);
|
UByteArray data = model->parsingData(index);
|
||||||
const COMPRESSED_SECTION_PARSING_DATA* pdata = (const COMPRESSED_SECTION_PARSING_DATA*)data.constData();
|
const COMPRESSED_SECTION_PARSING_DATA* pdata = (const COMPRESSED_SECTION_PARSING_DATA*)data.constData();
|
||||||
compressionType = pdata->compressionType;
|
compressionType = readMisaligned(pdata).compressionType;
|
||||||
uncompressedSize = pdata->uncompressedSize;
|
uncompressedSize = readMisaligned(pdata).uncompressedSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decompress section
|
// Decompress section
|
||||||
@ -3449,7 +3449,7 @@ USTATUS FfsParser::parseFit(const UModelIndex & index)
|
|||||||
|
|
||||||
// Add FIT header
|
// Add FIT header
|
||||||
std::vector<UString> currentStrings;
|
std::vector<UString> currentStrings;
|
||||||
currentStrings.push_back(UString("_FIT_ "));
|
currentStrings.push_back(UString("_FIT_ "));
|
||||||
currentStrings.push_back(usprintf("%08Xh", fitSize));
|
currentStrings.push_back(usprintf("%08Xh", fitSize));
|
||||||
currentStrings.push_back(usprintf("%04Xh", fitHeader->Version));
|
currentStrings.push_back(usprintf("%04Xh", fitHeader->Version));
|
||||||
currentStrings.push_back(usprintf("%02Xh", fitHeader->Checksum));
|
currentStrings.push_back(usprintf("%02Xh", fitHeader->Checksum));
|
||||||
|
@ -22,6 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
|
#include <stdlib.h>
|
||||||
static inline bool isExistOnFs(const UString & path) {
|
static inline bool isExistOnFs(const UString & path) {
|
||||||
struct _stat buf;
|
struct _stat buf;
|
||||||
return (_stat(path.toLocal8Bit(), &buf) == 0);
|
return (_stat(path.toLocal8Bit(), &buf) == 0);
|
||||||
@ -34,8 +35,16 @@ static inline bool makeDirectory(const UString & dir) {
|
|||||||
static inline bool changeDirectory(const UString & dir) {
|
static inline bool changeDirectory(const UString & dir) {
|
||||||
return (_chdir(dir.toLocal8Bit()) == 0);
|
return (_chdir(dir.toLocal8Bit()) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline UString getAbsPath(const UString * path) {
|
||||||
|
char abs[1024] = {};
|
||||||
|
if (_fullpath(abs, path.toLocal8Bit(), sizeof(abs)))
|
||||||
|
UString(abs);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
static inline bool isExistOnFs(const UString & path) {
|
static inline bool isExistOnFs(const UString & path) {
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
return (stat(path.toLocal8Bit(), &buf) == 0);
|
return (stat(path.toLocal8Bit(), &buf) == 0);
|
||||||
@ -48,6 +57,14 @@ static inline bool makeDirectory(const UString & dir) {
|
|||||||
static inline bool changeDirectory(const UString & dir) {
|
static inline bool changeDirectory(const UString & dir) {
|
||||||
return (chdir(dir.toLocal8Bit()) == 0);
|
return (chdir(dir.toLocal8Bit()) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline UString getAbsPath(const UString & path) {
|
||||||
|
char abs[PATH_MAX] = {};
|
||||||
|
// Last is a non-standard extension for non-existent files.
|
||||||
|
if (realpath(path.toLocal8Bit(), abs) || abs[0] != '\0')
|
||||||
|
return UString(abs);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline USTATUS readFileIntoBuffer(const UString & inPath, UByteArray &buf) {
|
static inline USTATUS readFileIntoBuffer(const UString & inPath, UByteArray &buf) {
|
||||||
|
@ -39,7 +39,7 @@ USTATUS NvramParser::parseNvarStore(const UModelIndex & index)
|
|||||||
if (parentFileIndex.isValid() && model->hasEmptyParsingData(parentFileIndex) == false) {
|
if (parentFileIndex.isValid() && model->hasEmptyParsingData(parentFileIndex) == false) {
|
||||||
UByteArray data = model->parsingData(parentFileIndex);
|
UByteArray data = model->parsingData(parentFileIndex);
|
||||||
const FILE_PARSING_DATA* pdata = (const FILE_PARSING_DATA*)data.constData();
|
const FILE_PARSING_DATA* pdata = (const FILE_PARSING_DATA*)data.constData();
|
||||||
emptyByte = pdata->emptyByte;
|
emptyByte = readMisaligned(pdata).emptyByte;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename parent file
|
// Rename parent file
|
||||||
@ -365,7 +365,7 @@ USTATUS NvramParser::parseNvarStore(const UModelIndex & index)
|
|||||||
|
|
||||||
// Try parsing the entry data as NVAR storage if it begins with NVAR signature
|
// Try parsing the entry data as NVAR storage if it begins with NVAR signature
|
||||||
if ((subtype == Subtypes::DataNvarEntry || subtype == Subtypes::FullNvarEntry)
|
if ((subtype == Subtypes::DataNvarEntry || subtype == Subtypes::FullNvarEntry)
|
||||||
&& body.size() >= 4 && *(const UINT32*)body.constData() == NVRAM_NVAR_ENTRY_SIGNATURE)
|
&& body.size() >= 4 && readMisaligned((const UINT32*)body.constData()) == NVRAM_NVAR_ENTRY_SIGNATURE)
|
||||||
parseNvarStore(varIndex);
|
parseNvarStore(varIndex);
|
||||||
|
|
||||||
// Move to next exntry
|
// Move to next exntry
|
||||||
|
@ -384,7 +384,7 @@ static inline int char2hex(char c) {
|
|||||||
if (c >= '0' && c <= '9')
|
if (c >= '0' && c <= '9')
|
||||||
return c - '0';
|
return c - '0';
|
||||||
if (c >= 'A' && c <= 'F')
|
if (c >= 'A' && c <= 'F')
|
||||||
return c - 'A';
|
return c - 'A' + 10;
|
||||||
if (c == '.')
|
if (c == '.')
|
||||||
return -2;
|
return -2;
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user