mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-22 07:58:22 +08:00
Remove Qt deps from UEFIFind and fix issues
This commit is contained in:
parent
7d16c1d48d
commit
4d50d581fa
3
.gitignore
vendored
3
.gitignore
vendored
@ -243,3 +243,6 @@ CMakeFiles
|
|||||||
cmake_install.cmake
|
cmake_install.cmake
|
||||||
DerivedData
|
DerivedData
|
||||||
*.xcodeproj
|
*.xcodeproj
|
||||||
|
compile_commands.json
|
||||||
|
CMakeLists.txt
|
||||||
|
CMakeScripts
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
PROJECT(UEFIDump)
|
PROJECT(UEFIDump)
|
||||||
|
|
||||||
SET(PROJECT_SOURCES
|
SET(PROJECT_SOURCES
|
||||||
|
@ -54,12 +54,12 @@ USTATUS UEFIDumper::dump(const UByteArray & buffer, const UString & inPath, cons
|
|||||||
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 << (const char*)fitTable[i].first[0].toLocal8Bit() << " | "
|
std::cout << fitTable[i].first[0].toLocal8Bit() << " | "
|
||||||
<< (const char*)fitTable[i].first[1].toLocal8Bit() << " | "
|
<< fitTable[i].first[1].toLocal8Bit() << " | "
|
||||||
<< (const char*)fitTable[i].first[2].toLocal8Bit() << " | "
|
<< fitTable[i].first[2].toLocal8Bit() << " | "
|
||||||
<< (const char*)fitTable[i].first[3].toLocal8Bit() << " | "
|
<< fitTable[i].first[3].toLocal8Bit() << " | "
|
||||||
<< (const char*)fitTable[i].first[4].toLocal8Bit() << " | "
|
<< fitTable[i].first[4].toLocal8Bit() << " | "
|
||||||
<< (const char*)fitTable[i].first[5].toLocal8Bit() << std::endl;
|
<< fitTable[i].first[5].toLocal8Bit() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,9 +68,9 @@ USTATUS UEFIDumper::dump(const UByteArray & buffer, const UString & inPath, cons
|
|||||||
std::vector<UString> report = ffsReport.generate();
|
std::vector<UString> report = ffsReport.generate();
|
||||||
if (report.size()) {
|
if (report.size()) {
|
||||||
std::ofstream ofs;
|
std::ofstream ofs;
|
||||||
ofs.open((const char*)reportPath, std::ofstream::out);
|
ofs.open(reportPath, std::ofstream::out);
|
||||||
for (size_t i = 0; i < report.size(); i++) {
|
for (size_t i = 0; i < report.size(); i++) {
|
||||||
ofs << (const char*)report[i].toLocal8Bit() << std::endl;
|
ofs << report[i].toLocal8Bit() << std::endl;
|
||||||
}
|
}
|
||||||
ofs.close();
|
ofs.close();
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,9 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
std::ifstream inputFile;
|
std::ifstream inputFile(argv[1], std::ios::in | std::ios::binary);
|
||||||
inputFile.open(argv[1], std::ios::in | std::ios::binary);
|
if (!inputFile)
|
||||||
|
return U_FILE_OPEN;
|
||||||
std::vector<char> buffer(std::istreambuf_iterator<char>(inputFile),
|
std::vector<char> buffer(std::istreambuf_iterator<char>(inputFile),
|
||||||
(std::istreambuf_iterator<char>()));
|
(std::istreambuf_iterator<char>()));
|
||||||
inputFile.close();
|
inputFile.close();
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
PROJECT(UEFIExtract)
|
PROJECT(UEFIExtract)
|
||||||
|
|
||||||
SET(PROJECT_SOURCES
|
SET(PROJECT_SOURCES
|
||||||
|
@ -53,11 +53,11 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
if (!model->header(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
if (!model->header(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
||||||
UString filename;
|
UString filename;
|
||||||
if (counterHeader == 0)
|
if (counterHeader == 0)
|
||||||
filename = usprintf("%s/header.bin", (const char *)path.toLocal8Bit());
|
filename = usprintf("%s/header.bin", path.toLocal8Bit());
|
||||||
else
|
else
|
||||||
filename = usprintf("%s/header_%d.bin", (const char *)path.toLocal8Bit(), counterHeader);
|
filename = usprintf("%s/header_%d.bin", path.toLocal8Bit(), counterHeader);
|
||||||
counterHeader++;
|
counterHeader++;
|
||||||
file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary);
|
file.open(filename.toLocal8Bit(), std::ofstream::binary);
|
||||||
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();
|
file.close();
|
||||||
@ -68,11 +68,11 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
if (!model->body(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
if (!model->body(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
||||||
UString filename;
|
UString filename;
|
||||||
if (counterBody == 0)
|
if (counterBody == 0)
|
||||||
filename = usprintf("%s/body.bin", (const char *)path.toLocal8Bit());
|
filename = usprintf("%s/body.bin", path.toLocal8Bit());
|
||||||
else
|
else
|
||||||
filename = usprintf("%s/body_%d.bin", (const char *)path.toLocal8Bit(), counterBody);
|
filename = usprintf("%s/body_%d.bin", path.toLocal8Bit(), counterBody);
|
||||||
counterBody++;
|
counterBody++;
|
||||||
file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary);
|
file.open(filename.toLocal8Bit(), std::ofstream::binary);
|
||||||
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();
|
file.close();
|
||||||
@ -85,11 +85,11 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
fileIndex = index;
|
fileIndex = index;
|
||||||
UString filename;
|
UString filename;
|
||||||
if (counterRaw == 0)
|
if (counterRaw == 0)
|
||||||
filename = usprintf("%s/file.ffs", (const char *)path.toLocal8Bit());
|
filename = usprintf("%s/file.ffs", path.toLocal8Bit());
|
||||||
else
|
else
|
||||||
filename = usprintf("%s/file_%d.bin", (const char *)path.toLocal8Bit(), counterRaw);
|
filename = usprintf("%s/file_%d.bin", path.toLocal8Bit(), counterRaw);
|
||||||
counterRaw++;
|
counterRaw++;
|
||||||
file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary);
|
file.open(filename.toLocal8Bit(), std::ofstream::binary);
|
||||||
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);
|
||||||
@ -104,19 +104,19 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
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)) {
|
||||||
UString info = usprintf("Type: %s\nSubtype: %s\n%s%s\n",
|
UString info = usprintf("Type: %s\nSubtype: %s\n%s%s\n",
|
||||||
(const char *)itemTypeToUString(model->type(index)).toLocal8Bit(),
|
itemTypeToUString(model->type(index)).toLocal8Bit(),
|
||||||
(const char *)itemSubtypeToUString(model->type(index), model->subtype(index)).toLocal8Bit(),
|
itemSubtypeToUString(model->type(index), model->subtype(index)).toLocal8Bit(),
|
||||||
(const char *)(model->text(index).isEmpty() ? UString("") :
|
(model->text(index).isEmpty() ? UString("") :
|
||||||
usprintf("Text: %s\n", (const char *)model->text(index).toLocal8Bit())).toLocal8Bit(),
|
usprintf("Text: %s\n", model->text(index).toLocal8Bit())).toLocal8Bit(),
|
||||||
(const char *)model->info(index).toLocal8Bit());
|
model->info(index).toLocal8Bit());
|
||||||
UString filename;
|
UString filename;
|
||||||
if (counterInfo == 0)
|
if (counterInfo == 0)
|
||||||
filename = usprintf("%s/info.txt", (const char *)path.toLocal8Bit());
|
filename = usprintf("%s/info.txt", path.toLocal8Bit());
|
||||||
else
|
else
|
||||||
filename = usprintf("%s/info_%d.txt", (const char *)path.toLocal8Bit(), counterInfo);
|
filename = usprintf("%s/info_%d.txt", path.toLocal8Bit(), counterInfo);
|
||||||
counterInfo++;
|
counterInfo++;
|
||||||
file.open((const char *)filename.toLocal8Bit());
|
file.open(filename.toLocal8Bit());
|
||||||
file << (const char *)info.toLocal8Bit();
|
file << info.toLocal8Bit();
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,8 +132,8 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
|
|
||||||
UString childPath = path;
|
UString childPath = path;
|
||||||
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT)
|
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT)
|
||||||
childPath = usprintf("%s/%d %s", (const char *)path.toLocal8Bit(), i,
|
childPath = usprintf("%s/%d %s", path.toLocal8Bit(), i,
|
||||||
(const char *)(useText ? model->text(childIndex) : model->name(childIndex)).toLocal8Bit());
|
(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;
|
||||||
|
@ -37,8 +37,9 @@ int main(int argc, char *argv[])
|
|||||||
return U_FILE_OPEN;
|
return U_FILE_OPEN;
|
||||||
|
|
||||||
// Open the input file
|
// Open the input file
|
||||||
std::ifstream inputFile;
|
std::ifstream inputFile(argv[1], std::ios::in | std::ios::binary);
|
||||||
inputFile.open(argv[1], std::ios::in | std::ios::binary);
|
if (!inputFile)
|
||||||
|
return U_FILE_OPEN;
|
||||||
std::vector<char> buffer(std::istreambuf_iterator<char>(inputFile),
|
std::vector<char> buffer(std::istreambuf_iterator<char>(inputFile),
|
||||||
(std::istreambuf_iterator<char>()));
|
(std::istreambuf_iterator<char>()));
|
||||||
inputFile.close();
|
inputFile.close();
|
||||||
@ -54,7 +55,7 @@ int main(int argc, char *argv[])
|
|||||||
// Show ffsParser's messages
|
// Show ffsParser's messages
|
||||||
std::vector<std::pair<UString, UModelIndex> > 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 << (const char *)messages[i].first.toLocal8Bit() << std::endl;
|
std::cout << messages[i].first.toLocal8Bit() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get last VTF
|
// Get last VTF
|
||||||
@ -64,12 +65,12 @@ int main(int argc, char *argv[])
|
|||||||
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 << (const char *)fitTable[i].first[0].toLocal8Bit() << " | "
|
std::cout << fitTable[i].first[0].toLocal8Bit() << " | "
|
||||||
<< (const char *)fitTable[i].first[1].toLocal8Bit() << " | "
|
<< fitTable[i].first[1].toLocal8Bit() << " | "
|
||||||
<< (const char *)fitTable[i].first[2].toLocal8Bit() << " | "
|
<< fitTable[i].first[2].toLocal8Bit() << " | "
|
||||||
<< (const char *)fitTable[i].first[3].toLocal8Bit() << " | "
|
<< fitTable[i].first[3].toLocal8Bit() << " | "
|
||||||
<< (const char *)fitTable[i].first[4].toLocal8Bit() << " | "
|
<< fitTable[i].first[4].toLocal8Bit() << " | "
|
||||||
<< (const char *)fitTable[i].first[5].toLocal8Bit() << std::endl;
|
<< fitTable[i].first[5].toLocal8Bit() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +141,7 @@ int main(int argc, char *argv[])
|
|||||||
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 " << (const char *)inputs[i].toLocal8Bit() << " failed with " << result << " code!" << std::endl;
|
std::cout << "Guid " << inputs[i].toLocal8Bit() << " failed with " << result << " code!" << std::endl;
|
||||||
lastError = result;
|
lastError = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,9 +154,9 @@ int main(int argc, char *argv[])
|
|||||||
std::vector<UString> report = ffsReport.generate();
|
std::vector<UString> report = ffsReport.generate();
|
||||||
if (report.size()) {
|
if (report.size()) {
|
||||||
std::ofstream file;
|
std::ofstream file;
|
||||||
file.open((const char *)(path + UString(".report.txt")).toLocal8Bit());
|
file.open((path + UString(".report.txt")).toLocal8Bit());
|
||||||
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 << report[i].toLocal8Bit() << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump all non-leaf elements, with report, default
|
// Dump all non-leaf elements, with report, default
|
||||||
|
@ -13,6 +13,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
|
|
||||||
#include "uefifind.h"
|
#include "uefifind.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
UEFIFind::UEFIFind()
|
UEFIFind::UEFIFind()
|
||||||
{
|
{
|
||||||
model = new TreeModel();
|
model = new TreeModel();
|
||||||
@ -27,22 +29,18 @@ UEFIFind::~UEFIFind()
|
|||||||
model = NULL;
|
model = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
USTATUS UEFIFind::init(const QString & path)
|
USTATUS UEFIFind::init(const UString & path)
|
||||||
{
|
{
|
||||||
USTATUS result;
|
USTATUS result;
|
||||||
|
|
||||||
fileInfo = QFileInfo(path);
|
if (!isExistOnFs(path))
|
||||||
|
|
||||||
if (!fileInfo.exists())
|
|
||||||
return U_FILE_OPEN;
|
return U_FILE_OPEN;
|
||||||
|
|
||||||
QFile inputFile;
|
std::ifstream inputFile(path.toLocal8Bit(), std::ios::in | std::ios::binary);
|
||||||
inputFile.setFileName(path);
|
if (!inputFile)
|
||||||
|
|
||||||
if (!inputFile.open(QFile::ReadOnly))
|
|
||||||
return U_FILE_OPEN;
|
return U_FILE_OPEN;
|
||||||
|
std::vector<char> buffer(std::istreambuf_iterator<char>(inputFile),
|
||||||
QByteArray buffer = inputFile.readAll();
|
(std::istreambuf_iterator<char>()));
|
||||||
inputFile.close();
|
inputFile.close();
|
||||||
|
|
||||||
result = ffsParser->parse(buffer);
|
result = ffsParser->parse(buffer);
|
||||||
@ -53,7 +51,7 @@ USTATUS UEFIFind::init(const QString & path)
|
|||||||
return U_SUCCESS;
|
return U_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
USTATUS UEFIFind::find(const UINT8 mode, const bool count, const QString & hexPattern, QString & result)
|
USTATUS UEFIFind::find(const UINT8 mode, const bool count, const UString & hexPattern, UString & result)
|
||||||
{
|
{
|
||||||
UModelIndex root = model->index(0, 0);
|
UModelIndex root = model->index(0, 0);
|
||||||
std::set<std::pair<UModelIndex, UModelIndex> > files;
|
std::set<std::pair<UModelIndex, UModelIndex> > files;
|
||||||
@ -66,29 +64,29 @@ USTATUS UEFIFind::find(const UINT8 mode, const bool count, const QString & hexPa
|
|||||||
|
|
||||||
if (count) {
|
if (count) {
|
||||||
if (!files.empty())
|
if (!files.empty())
|
||||||
result.append(QString("%1\n").arg(files.size()));
|
result += usprintf("%d\n", files.size());
|
||||||
return U_SUCCESS;
|
return U_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::set<std::pair<UModelIndex, UModelIndex> >::const_iterator citer = files.begin(); citer != files.end(); ++citer) {
|
for (std::set<std::pair<UModelIndex, UModelIndex> >::const_iterator citer = files.begin(); citer != files.end(); ++citer) {
|
||||||
QByteArray data(16, '\x00');
|
UByteArray data(16, '\x00');
|
||||||
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.append(guidToUString(*(const EFI_GUID*)data.constData()));
|
result += guidToUString(*(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.append(" ").append(guidToUString(*(const EFI_GUID*)(data.constData() + sizeof(EFI_COMMON_SECTION_HEADER))));
|
result += UString(" ") + (guidToUString(*(const EFI_GUID*)(data.constData() + sizeof(EFI_COMMON_SECTION_HEADER))));
|
||||||
}
|
}
|
||||||
|
|
||||||
result.append("\n");
|
result += UString("\n");
|
||||||
}
|
}
|
||||||
return U_SUCCESS;
|
return U_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
USTATUS UEFIFind::findFileRecursive(const UModelIndex index, const QString & hexPattern, const UINT8 mode, std::set<std::pair<UModelIndex, UModelIndex> > & files)
|
USTATUS UEFIFind::findFileRecursive(const UModelIndex index, const UString & hexPattern, const UINT8 mode, std::set<std::pair<UModelIndex, UModelIndex> > & files)
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return U_SUCCESS;
|
return U_SUCCESS;
|
||||||
@ -96,48 +94,54 @@ USTATUS UEFIFind::findFileRecursive(const UModelIndex index, const QString & hex
|
|||||||
if (hexPattern.isEmpty())
|
if (hexPattern.isEmpty())
|
||||||
return U_INVALID_PARAMETER;
|
return U_INVALID_PARAMETER;
|
||||||
|
|
||||||
|
const char *hexPatternRaw = hexPattern.toLocal8Bit();
|
||||||
|
std::vector<UINT8> pattern, patternMask;
|
||||||
|
if (!makePattern(hexPatternRaw, pattern, patternMask))
|
||||||
|
return U_INVALID_PARAMETER;
|
||||||
|
|
||||||
// Check for "all substrings" pattern
|
// Check for "all substrings" pattern
|
||||||
if (hexPattern.count('.') == hexPattern.length())
|
size_t count = 0;
|
||||||
|
for (size_t i = 0; i < patternMask.size(); i++)
|
||||||
|
if (patternMask[i] == 0)
|
||||||
|
count++;
|
||||||
|
if (count == patternMask.size())
|
||||||
return U_SUCCESS;
|
return U_SUCCESS;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool hasChildren = (model->rowCount(index) > 0);
|
bool hasChildren = (model->rowCount(index) > 0);
|
||||||
for (int i = 0; i < model->rowCount(index); i++) {
|
for (int i = 0; i < model->rowCount(index); i++) {
|
||||||
findFileRecursive(index.child(i, index.column()), hexPattern, mode, files);
|
findFileRecursive(index.child(i, index.column()), hexPattern, mode, files);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray data;
|
UByteArray data;
|
||||||
if (hasChildren) {
|
if (hasChildren) {
|
||||||
if (mode == SEARCH_MODE_HEADER || mode == SEARCH_MODE_ALL)
|
if (mode == SEARCH_MODE_HEADER || mode == SEARCH_MODE_ALL)
|
||||||
data.append(model->header(index));
|
data += model->header(index);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (mode == SEARCH_MODE_HEADER)
|
if (mode == SEARCH_MODE_HEADER)
|
||||||
data.append(model->header(index));
|
data += model->header(index);
|
||||||
else if (mode == SEARCH_MODE_BODY)
|
else if (mode == SEARCH_MODE_BODY)
|
||||||
data.append(model->body(index));
|
data += model->body(index);
|
||||||
else
|
else
|
||||||
data.append(model->header(index)).append(model->body(index));
|
data += model->header(index) + model->body(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString hexBody = QString(data.toHex());
|
const UINT8 *rawData = reinterpret_cast<const UINT8 *>(data.constData());
|
||||||
QRegExp regexp = QRegExp(QString(hexPattern), Qt::CaseInsensitive);
|
INTN offset = findPattern(pattern.data(), patternMask.data(), pattern.size(), rawData, data.size(), 0);
|
||||||
INT32 offset = regexp.indexIn(hexBody);
|
if (offset >= 0) {
|
||||||
while (offset >= 0) {
|
if (model->type(index) != Types::File) {
|
||||||
if (offset % 2 == 0) {
|
UModelIndex ffs = model->findParentOfType(index, Types::File);
|
||||||
if (model->type(index) != Types::File) {
|
if (model->type(index) == Types::Section && model->subtype(index) == EFI_SECTION_FREEFORM_SUBTYPE_GUID)
|
||||||
UModelIndex ffs = model->findParentOfType(index, Types::File);
|
files.insert(std::pair<UModelIndex, UModelIndex>(ffs, index));
|
||||||
if (model->type(index) == Types::Section && model->subtype(index) == EFI_SECTION_FREEFORM_SUBTYPE_GUID)
|
|
||||||
files.insert(std::pair<UModelIndex, UModelIndex>(ffs, index));
|
|
||||||
else
|
|
||||||
files.insert(std::pair<UModelIndex, UModelIndex>(ffs, UModelIndex()));
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
files.insert(std::pair<UModelIndex, UModelIndex>(index, UModelIndex()));
|
files.insert(std::pair<UModelIndex, UModelIndex>(ffs, UModelIndex()));
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
offset = regexp.indexIn(hexBody, offset + 1);
|
else
|
||||||
|
files.insert(std::pair<UModelIndex, UModelIndex>(index, UModelIndex()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return U_SUCCESS;
|
return U_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -17,17 +17,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QByteArray>
|
|
||||||
#include <QString>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QString>
|
|
||||||
#include <QUuid>
|
|
||||||
|
|
||||||
#include "../common/basetypes.h"
|
#include "../common/basetypes.h"
|
||||||
|
#include "../common/ustring.h"
|
||||||
|
#include "../common/filesystem.h"
|
||||||
#include "../common/ffsparser.h"
|
#include "../common/ffsparser.h"
|
||||||
#include "../common/ffs.h"
|
#include "../common/ffs.h"
|
||||||
|
#include "../common/utility.h"
|
||||||
|
|
||||||
class UEFIFind
|
class UEFIFind
|
||||||
{
|
{
|
||||||
@ -35,16 +30,15 @@ public:
|
|||||||
explicit UEFIFind();
|
explicit UEFIFind();
|
||||||
~UEFIFind();
|
~UEFIFind();
|
||||||
|
|
||||||
USTATUS init(const QString & path);
|
USTATUS init(const UString & path);
|
||||||
USTATUS find(const UINT8 mode, const bool count, const QString & hexPattern, QString & result);
|
USTATUS find(const UINT8 mode, const bool count, const UString & hexPattern, UString & result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
USTATUS findFileRecursive(const UModelIndex index, const QString & hexPattern, const UINT8 mode, std::set<std::pair<UModelIndex, UModelIndex> > & files);
|
USTATUS findFileRecursive(const UModelIndex index, const UString & hexPattern, const UINT8 mode, std::set<std::pair<UModelIndex, UModelIndex> > & files);
|
||||||
QString guidToQString(const UINT8* guid);
|
UString guidToQString(const UINT8* guid);
|
||||||
|
|
||||||
FfsParser* ffsParser;
|
FfsParser* ffsParser;
|
||||||
TreeModel* model;
|
TreeModel* model;
|
||||||
QFileInfo fileInfo;
|
|
||||||
bool initDone;
|
bool initDone;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
QT += core
|
|
||||||
QT -= gui
|
|
||||||
|
|
||||||
TARGET = UEFIFind
|
|
||||||
TEMPLATE = app
|
|
||||||
CONFIG += console
|
|
||||||
CONFIG -= app_bundle
|
|
||||||
|
|
||||||
SOURCES += uefifind_main.cpp \
|
|
||||||
uefifind.cpp \
|
|
||||||
../common/guiddatabase.cpp \
|
|
||||||
../common/types.cpp \
|
|
||||||
../common/descriptor.cpp \
|
|
||||||
../common/ffs.cpp \
|
|
||||||
../common/nvram.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 \
|
|
||||||
../common/ustring.cpp \
|
|
||||||
../common/sha256.c
|
|
||||||
|
|
||||||
HEADERS += uefifind.h \
|
|
||||||
../common/guiddatabase.h \
|
|
||||||
../common/basetypes.h \
|
|
||||||
../common/descriptor.h \
|
|
||||||
../common/gbe.h \
|
|
||||||
../common/me.h \
|
|
||||||
../common/ffs.h \
|
|
||||||
../common/nvram.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 \
|
|
||||||
../common/ustring.h \
|
|
||||||
../common/ubytearray.h \
|
|
||||||
../common/bootguard.h \
|
|
||||||
../common/sha256.h \
|
|
||||||
../version.h
|
|
@ -10,44 +10,41 @@ 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 <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "../version.h"
|
#include "../version.h"
|
||||||
#include "uefifind.h"
|
#include "uefifind.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
|
||||||
a.setOrganizationName("LongSoft");
|
|
||||||
a.setOrganizationDomain("longsoft.me");
|
|
||||||
a.setApplicationName("UEFIFind");
|
|
||||||
|
|
||||||
UEFIFind w;
|
UEFIFind w;
|
||||||
UINT8 result;
|
UINT8 result;
|
||||||
|
|
||||||
if (a.arguments().length() == 5) {
|
if (argc == 5) {
|
||||||
QString inputArg = a.arguments().at(1);
|
UString inputArg = argv[1];
|
||||||
QString modeArg = a.arguments().at(2);
|
UString modeArg = argv[2];
|
||||||
QString subModeArg = a.arguments().at(3);
|
UString subModeArg = argv[3];
|
||||||
QString patternArg = a.arguments().at(4);
|
UString patternArg = argv[4];
|
||||||
|
|
||||||
// Get search mode
|
// Get search mode
|
||||||
UINT8 mode;
|
UINT8 mode;
|
||||||
if (modeArg == QString("header"))
|
if (modeArg == UString("header"))
|
||||||
mode = SEARCH_MODE_HEADER;
|
mode = SEARCH_MODE_HEADER;
|
||||||
else if (modeArg == QString("body"))
|
else if (modeArg == UString("body"))
|
||||||
mode = SEARCH_MODE_BODY;
|
mode = SEARCH_MODE_BODY;
|
||||||
else if (modeArg == QString("all"))
|
else if (modeArg == UString("all"))
|
||||||
mode = SEARCH_MODE_ALL;
|
mode = SEARCH_MODE_ALL;
|
||||||
else
|
else
|
||||||
return U_INVALID_PARAMETER;
|
return U_INVALID_PARAMETER;
|
||||||
|
|
||||||
// Get result type
|
// Get result type
|
||||||
bool count;
|
bool count;
|
||||||
if (subModeArg == QString("list"))
|
if (subModeArg == UString("list"))
|
||||||
count = false;
|
count = false;
|
||||||
else if (subModeArg == QString("count"))
|
else if (subModeArg == UString("count"))
|
||||||
count = true;
|
count = true;
|
||||||
else
|
else
|
||||||
return U_INVALID_PARAMETER;
|
return U_INVALID_PARAMETER;
|
||||||
@ -58,7 +55,7 @@ int main(int argc, char *argv[])
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
// Go find the supplied pattern
|
// Go find the supplied pattern
|
||||||
QString found;
|
UString found;
|
||||||
result = w.find(mode, count, patternArg, found);
|
result = w.find(mode, count, patternArg, found);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
@ -68,26 +65,24 @@ int main(int argc, char *argv[])
|
|||||||
return U_ITEM_NOT_FOUND;
|
return U_ITEM_NOT_FOUND;
|
||||||
|
|
||||||
// Print result
|
// Print result
|
||||||
std::cout << found.toStdString();
|
std::cout << found.toLocal8Bit();
|
||||||
return U_SUCCESS;
|
return U_SUCCESS;
|
||||||
}
|
}
|
||||||
else if (a.arguments().length() == 4) {
|
else if (argc == 4) {
|
||||||
QString inputArg = a.arguments().at(1);
|
UString inputArg = argv[1];
|
||||||
QString modeArg = a.arguments().at(2);
|
UString modeArg = argv[2];
|
||||||
QString patternArg = a.arguments().at(3);
|
UString patternArg = argv[3];
|
||||||
|
|
||||||
// Get search mode
|
// Get search mode
|
||||||
if (modeArg != QString("file"))
|
if (modeArg != UString("file"))
|
||||||
return U_INVALID_PARAMETER;
|
return U_INVALID_PARAMETER;
|
||||||
|
|
||||||
// Open patterns file
|
// Open patterns file
|
||||||
QFileInfo fileInfo(patternArg);
|
if (!isExistOnFs(patternArg))
|
||||||
if (!fileInfo.exists())
|
|
||||||
return U_FILE_OPEN;
|
return U_FILE_OPEN;
|
||||||
|
|
||||||
QFile patternsFile;
|
std::ifstream patternsFile(patternArg.toLocal8Bit());
|
||||||
patternsFile.setFileName(patternArg);
|
if (!patternsFile)
|
||||||
if (!patternsFile.open(QFile::ReadOnly))
|
|
||||||
return U_FILE_OPEN;
|
return U_FILE_OPEN;
|
||||||
|
|
||||||
// Parse input file
|
// Parse input file
|
||||||
@ -97,57 +92,66 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Perform searches
|
// Perform searches
|
||||||
bool somethingFound = false;
|
bool somethingFound = false;
|
||||||
while (!patternsFile.atEnd()) {
|
while (!patternsFile.eof()) {
|
||||||
QByteArray line = patternsFile.readLine();
|
std::string line;
|
||||||
|
std::getline(patternsFile, line);
|
||||||
// Use sharp symbol as commentary
|
// Use sharp symbol as commentary
|
||||||
if (line.count() == 0 || line[0] == '#')
|
if (line.size() == 0 || line[0] == '#')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Split the read line
|
// Split the read line
|
||||||
QList<QByteArray> list = line.split(' ');
|
std::vector<UString> list;
|
||||||
if (list.count() < 3) {
|
std::string::size_type prev = 0, curr = 0;
|
||||||
std::cout << line.constData() << "skipped, too few arguments" << std::endl << std::endl;
|
while ((curr = line.find(' ', curr)) != std::string::npos) {
|
||||||
|
std::string substring( line.substr(prev, curr-prev) );
|
||||||
|
list.push_back(UString(substring.c_str()));
|
||||||
|
prev = ++curr;
|
||||||
|
}
|
||||||
|
list.push_back(UString(line.substr(prev, curr-prev).c_str()));
|
||||||
|
|
||||||
|
if (list.size() < 3) {
|
||||||
|
std::cout << line << std::endl << "skipped, too few arguments" << std::endl << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Get search mode
|
// Get search mode
|
||||||
UINT8 mode;
|
UINT8 mode;
|
||||||
if (list.at(0) == QString("header"))
|
if (list.at(0) == UString("header"))
|
||||||
mode = SEARCH_MODE_HEADER;
|
mode = SEARCH_MODE_HEADER;
|
||||||
else if (list.at(0) == QString("body"))
|
else if (list.at(0) == UString("body"))
|
||||||
mode = SEARCH_MODE_BODY;
|
mode = SEARCH_MODE_BODY;
|
||||||
else if (list.at(0) == QString("all"))
|
else if (list.at(0) == UString("all"))
|
||||||
mode = SEARCH_MODE_ALL;
|
mode = SEARCH_MODE_ALL;
|
||||||
else {
|
else {
|
||||||
std::cout << line.constData() << "skipped, invalid search mode" << std::endl << std::endl;
|
std::cout << line << std::endl << "skipped, invalid search mode" << std::endl << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get result type
|
// Get result type
|
||||||
bool count;
|
bool count;
|
||||||
if (list.at(1) == QString("list"))
|
if (list.at(1) == UString("list"))
|
||||||
count = false;
|
count = false;
|
||||||
else if (list.at(1) == QString("count"))
|
else if (list.at(1) == UString("count"))
|
||||||
count = true;
|
count = true;
|
||||||
else {
|
else {
|
||||||
std::cout << line.constData() << "skipped, invalid result type" << std::endl << std::endl;
|
std::cout << line << std::endl << "skipped, invalid result type" << std::endl << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go find the supplied pattern
|
// Go find the supplied pattern
|
||||||
QString found;
|
UString found;
|
||||||
result = w.find(mode, count, list.at(2), found);
|
result = w.find(mode, count, list.at(2), found);
|
||||||
if (result) {
|
if (result) {
|
||||||
std::cout << line.constData() << "skipped, find failed with error " << (UINT32)result << std::endl << std::endl;
|
std::cout << line << std::endl << "skipped, find failed with error " << (UINT32)result << std::endl << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found.isEmpty()) {
|
if (found.isEmpty()) {
|
||||||
// Nothing is found
|
// Nothing is found
|
||||||
std::cout << line.constData() << "nothing found" << std::endl << std::endl;
|
std::cout << line << std::endl << "nothing found" << std::endl << std::endl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Print result
|
// Print result
|
||||||
std::cout << line.constData() << found.toStdString() << std::endl;
|
std::cout << line << std::endl << found.toLocal8Bit() << std::endl;
|
||||||
somethingFound = true;
|
somethingFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,4 +169,3 @@ int main(int argc, char *argv[])
|
|||||||
return U_INVALID_PARAMETER;
|
return U_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -646,13 +646,9 @@ Decode (
|
|||||||
SCRATCH_DATA *Sd
|
SCRATCH_DATA *Sd
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINT16 BytesRemain;
|
UINT16 BytesRemain = (UINT16)(-1);
|
||||||
UINT32 DataIdx;
|
UINT32 DataIdx = 0;
|
||||||
UINT16 CharC;
|
UINT16 CharC = 0;
|
||||||
|
|
||||||
BytesRemain = (UINT16)(-1);
|
|
||||||
|
|
||||||
DataIdx = 0;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
CharC = DecodeC(Sd);
|
CharC = DecodeC(Sd);
|
||||||
|
@ -81,6 +81,7 @@ typedef uint64_t UINT64;
|
|||||||
typedef char CHAR8;
|
typedef char CHAR8;
|
||||||
typedef uint16_t CHAR16;
|
typedef uint16_t CHAR16;
|
||||||
typedef size_t UINTN;
|
typedef size_t UINTN;
|
||||||
|
typedef ptrdiff_t INTN;
|
||||||
|
|
||||||
#define CONST const
|
#define CONST const
|
||||||
#define VOID void
|
#define VOID void
|
||||||
|
@ -2432,7 +2432,7 @@ int i, c, v;
|
|||||||
* NULL is returned, otherwise a bstring with the correct result is returned.
|
* NULL is returned, otherwise a bstring with the correct result is returned.
|
||||||
*/
|
*/
|
||||||
bstring bjoin (const struct bstrList * bl, const_bstring sep) {
|
bstring bjoin (const struct bstrList * bl, const_bstring sep) {
|
||||||
if (sep != NULL && (sep->slen < 0 || sep->data == NULL)) return NULL;
|
if (sep == NULL || (sep->slen < 0 || sep->data == NULL)) return NULL;
|
||||||
return bjoinblk (bl, sep->data, sep->slen);
|
return bjoinblk (bl, sep->data, sep->slen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2458,9 +2458,9 @@ bstring bjoin (const struct bstrList * bl, const_bstring sep) {
|
|||||||
*/
|
*/
|
||||||
int bssplitscb (struct bStream * s, const_bstring splitStr,
|
int bssplitscb (struct bStream * s, const_bstring splitStr,
|
||||||
int (* cb) (void * parm, int ofs, const_bstring entry), void * parm) {
|
int (* cb) (void * parm, int ofs, const_bstring entry), void * parm) {
|
||||||
struct charField chrs;
|
struct charField chrs;
|
||||||
bstring buff;
|
bstring buff;
|
||||||
int i, p, ret;
|
int i = 0, p = 0, ret = 0;
|
||||||
|
|
||||||
if (cb == NULL || s == NULL || s->readFnPtr == NULL ||
|
if (cb == NULL || s == NULL || s->readFnPtr == NULL ||
|
||||||
splitStr == NULL || splitStr->slen < 0) return BSTR_ERR;
|
splitStr == NULL || splitStr->slen < 0) return BSTR_ERR;
|
||||||
@ -2473,7 +2473,6 @@ int i, p, ret;
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
} else {
|
} else {
|
||||||
buildCharField (&chrs, splitStr);
|
buildCharField (&chrs, splitStr);
|
||||||
ret = p = i = 0;
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (i >= buff->slen) {
|
if (i >= buff->slen) {
|
||||||
bsreada (buff, s, BSSSC_BUFF_LEN);
|
bsreada (buff, s, BSSSC_BUFF_LEN);
|
||||||
@ -2525,8 +2524,8 @@ int i, p, ret;
|
|||||||
*/
|
*/
|
||||||
int bssplitstrcb (struct bStream * s, const_bstring splitStr,
|
int bssplitstrcb (struct bStream * s, const_bstring splitStr,
|
||||||
int (* cb) (void * parm, int ofs, const_bstring entry), void * parm) {
|
int (* cb) (void * parm, int ofs, const_bstring entry), void * parm) {
|
||||||
bstring buff;
|
bstring buff;
|
||||||
int i, p, ret;
|
int i = 0, p = 0, ret = 0;
|
||||||
|
|
||||||
if (cb == NULL || s == NULL || s->readFnPtr == NULL
|
if (cb == NULL || s == NULL || s->readFnPtr == NULL
|
||||||
|| splitStr == NULL || splitStr->slen < 0) return BSTR_ERR;
|
|| splitStr == NULL || splitStr->slen < 0) return BSTR_ERR;
|
||||||
@ -2545,8 +2544,7 @@ int i, p, ret;
|
|||||||
}
|
}
|
||||||
return BSTR_OK;
|
return BSTR_OK;
|
||||||
} else {
|
} else {
|
||||||
ret = p = i = 0;
|
for (;;) {
|
||||||
for (i=p=0;;) {
|
|
||||||
if ((ret = binstr (buff, 0, splitStr)) >= 0) {
|
if ((ret = binstr (buff, 0, splitStr)) >= 0) {
|
||||||
struct tagbstring t;
|
struct tagbstring t;
|
||||||
blk2tbstr (t, buff->data, ret);
|
blk2tbstr (t, buff->data, ret);
|
||||||
|
@ -1490,9 +1490,10 @@ int p, i;
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int streamSplitCb (void * parm, int ofs, const_bstring entry) {
|
static int streamSplitCb (void * parm, int ofs, const_bstring entry) {
|
||||||
CBStringList * r = (CBStringList *) parm;
|
CBStringList * r = (CBStringList *) parm;
|
||||||
|
//FIXME: this is broken!
|
||||||
ofs = ofs;
|
// ofs = ofs;
|
||||||
|
(void)ofs;
|
||||||
r->push_back (CBString (*entry));
|
r->push_back (CBString (*entry));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,7 @@ struct CBString : public tagbstring {
|
|||||||
int read (bNread readPtr, void * parm);
|
int read (bNread readPtr, void * parm);
|
||||||
|
|
||||||
// QString compatibility methods
|
// QString compatibility methods
|
||||||
CBString toLocal8Bit() const { return *this; }
|
const char *toLocal8Bit() const { return *this; }
|
||||||
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); }
|
||||||
|
@ -22,29 +22,29 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
static inline bool isExistOnFs(const UString & path) {
|
static inline bool isExistOnFs(const UString & path) {
|
||||||
struct _stat buf;
|
struct _stat buf;
|
||||||
return (_stat((const char*)path.toLocal8Bit(), &buf) == 0);
|
return (_stat(path.toLocal8Bit(), &buf) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool makeDirectory(const UString & dir) {
|
static inline bool makeDirectory(const UString & dir) {
|
||||||
return (_mkdir((const char*)dir.toLocal8Bit()) == 0);
|
return (_mkdir(dir.toLocal8Bit()) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool changeDirectory(const UString & dir) {
|
static inline bool changeDirectory(const UString & dir) {
|
||||||
return (_chdir((const char*)dir.toLocal8Bit()) == 0);
|
return (_chdir(dir.toLocal8Bit()) == 0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
static inline bool isExistOnFs(const UString & path) {
|
static inline bool isExistOnFs(const UString & path) {
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
return (stat((const char*)path.toLocal8Bit(), &buf) == 0);
|
return (stat(path.toLocal8Bit(), &buf) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool makeDirectory(const UString & dir) {
|
static inline bool makeDirectory(const UString & dir) {
|
||||||
return (mkdir((const char*)dir.toLocal8Bit(), ACCESSPERMS) == 0);
|
return (mkdir(dir.toLocal8Bit(), ACCESSPERMS) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool changeDirectory(const UString & dir) {
|
static inline bool changeDirectory(const UString & dir) {
|
||||||
return (chdir((const char*)dir.toLocal8Bit()) == 0);
|
return (chdir(dir.toLocal8Bit()) == 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -501,12 +501,26 @@ USTATUS NvramParser::parseNvramVolumeBody(const UModelIndex & index)
|
|||||||
for (int i = 0; i < model->rowCount(index); i++) {
|
for (int i = 0; i < model->rowCount(index); i++) {
|
||||||
UModelIndex current = index.child(i, 0);
|
UModelIndex current = index.child(i, 0);
|
||||||
switch (model->type(current)) {
|
switch (model->type(current)) {
|
||||||
case Types::FdcStore: return parseFdcStoreBody(current);
|
case Types::FdcStore:
|
||||||
case Types::VssStore: return parseVssStoreBody(current, 0);
|
parseFdcStoreBody(current);
|
||||||
case Types::Vss2Store: return parseVssStoreBody(current, 4);
|
break;
|
||||||
case Types::FsysStore: return parseFsysStoreBody(current);
|
case Types::VssStore:
|
||||||
case Types::EvsaStore: return parseEvsaStoreBody(current);
|
parseVssStoreBody(current, 0);
|
||||||
case Types::FlashMapStore: return parseFlashMapBody(current);
|
break;
|
||||||
|
case Types::Vss2Store:
|
||||||
|
parseVssStoreBody(current, 4);
|
||||||
|
break;
|
||||||
|
case Types::FsysStore:
|
||||||
|
parseFsysStoreBody(current);
|
||||||
|
break;
|
||||||
|
case Types::EvsaStore:
|
||||||
|
parseEvsaStoreBody(current);
|
||||||
|
break;
|
||||||
|
case Types::FlashMapStore:
|
||||||
|
parseFlashMapBody(current);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Ignore unknown!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1197,8 +1211,8 @@ USTATUS NvramParser::parseSlicMarkerHeader(const UByteArray & store, const UINT3
|
|||||||
markerHeader->Size, markerHeader->Size,
|
markerHeader->Size, markerHeader->Size,
|
||||||
header.size(), header.size(),
|
header.size(), header.size(),
|
||||||
markerHeader->Version,
|
markerHeader->Version,
|
||||||
(const char*)UString((const char*)&(markerHeader->OemId)).left(6).toLocal8Bit(),
|
UString((const char*)&(markerHeader->OemId)).left(6).toLocal8Bit(),
|
||||||
(const char*)UString((const char*)&(markerHeader->OemTableId)).left(8).toLocal8Bit(),
|
UString((const char*)&(markerHeader->OemTableId)).left(8).toLocal8Bit(),
|
||||||
markerHeader->SlicVersion);
|
markerHeader->SlicVersion);
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ QVariant TreeModel::data(const UModelIndex &index, int role) const
|
|||||||
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
|
||||||
|
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
return (const char*)item->data(index.column()).toLocal8Bit();
|
return item->data(index.column()).toLocal8Bit();
|
||||||
}
|
}
|
||||||
#if defined (QT_GUI_LIB)
|
#if defined (QT_GUI_LIB)
|
||||||
else if (role == Qt::BackgroundRole) {
|
else if (role == Qt::BackgroundRole) {
|
||||||
@ -34,7 +34,7 @@ QVariant TreeModel::data(const UModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (role == Qt::UserRole) {
|
else if (role == Qt::UserRole) {
|
||||||
return (const char*)item->info().toLocal8Bit();
|
return item->info().toLocal8Bit();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@ -556,4 +556,4 @@ goDeeper:
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (parentIndex == index(0, 0) ? UModelIndex() : parentIndex);
|
return (parentIndex == index(0, 0) ? UModelIndex() : parentIndex);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
#include "treemodel.h"
|
#include "treemodel.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
#include "ffs.h"
|
#include "ffs.h"
|
||||||
@ -375,3 +378,68 @@ UINT8 getPaddingType(const UByteArray & padding)
|
|||||||
return Subtypes::OnePadding;
|
return Subtypes::OnePadding;
|
||||||
return Subtypes::DataPadding;
|
return Subtypes::DataPadding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int char2hex(char c) {
|
||||||
|
if (c >= '0' && c <= '9')
|
||||||
|
return c - '0';
|
||||||
|
if (c >= 'A' && c <= 'F')
|
||||||
|
return c - 'A';
|
||||||
|
if (c == '.')
|
||||||
|
return -2;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
INTN findPattern(const UINT8 *pattern, const UINT8 *patternMask, UINTN patternSize,
|
||||||
|
const UINT8 *data, UINTN dataSize, UINTN dataOff) {
|
||||||
|
if (patternSize == 0 || dataSize == 0 || dataOff >= dataSize || dataSize - dataOff < patternSize)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
while (dataOff + patternSize < dataSize) {
|
||||||
|
BOOLEAN matches = TRUE;
|
||||||
|
for (UINTN i = 0; i < patternSize; i++) {
|
||||||
|
if ((data[dataOff + i] & patternMask[i]) != pattern[i]) {
|
||||||
|
matches = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matches)
|
||||||
|
return static_cast<INTN>(dataOff);
|
||||||
|
|
||||||
|
dataOff++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOLEAN makePattern(const CHAR8 *textPattern, std::vector<UINT8> &pattern, std::vector<UINT8> &patternMask) {
|
||||||
|
UINTN len = std::strlen(textPattern);
|
||||||
|
|
||||||
|
if (len == 0 || len % 2 != 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
len /= 2;
|
||||||
|
|
||||||
|
pattern.resize(len);
|
||||||
|
patternMask.resize(len);
|
||||||
|
|
||||||
|
for (UINTN i = 0; i < len; i++) {
|
||||||
|
int v1 = char2hex(std::toupper(textPattern[i * 2]));
|
||||||
|
int v2 = char2hex(std::toupper(textPattern[i * 2 + 1]));
|
||||||
|
|
||||||
|
if (v1 == -1 || v2 == -1)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (v1 != -2) {
|
||||||
|
patternMask[i] = 0xF0;
|
||||||
|
pattern[i] = static_cast<UINT8>(v1) << 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v2 != -2) {
|
||||||
|
patternMask[i] |= 0x0F;
|
||||||
|
pattern[i] |= static_cast<UINT8>(v2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
@ -14,6 +14,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||||||
#ifndef UTILITY_H
|
#ifndef UTILITY_H
|
||||||
#define UTILITY_H
|
#define UTILITY_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "basetypes.h"
|
#include "basetypes.h"
|
||||||
#include "ustring.h"
|
#include "ustring.h"
|
||||||
#include "treemodel.h"
|
#include "treemodel.h"
|
||||||
@ -46,4 +48,11 @@ UINT16 calculateChecksum16(const UINT16* buffer, UINT32 bufferSize);
|
|||||||
// Return padding type from it's contents
|
// Return padding type from it's contents
|
||||||
UINT8 getPaddingType(const UByteArray & padding);
|
UINT8 getPaddingType(const UByteArray & padding);
|
||||||
|
|
||||||
|
// Make pattern from a hexstring with an assumption of . being any char
|
||||||
|
BOOLEAN makePattern(const CHAR8 *textPattern, std::vector<UINT8> &pattern, std::vector<UINT8> &patternMask);
|
||||||
|
|
||||||
|
// Find pattern in a binary blob
|
||||||
|
INTN findPattern(const UINT8 *pattern, const UINT8 *patternMask, UINTN patternSize,
|
||||||
|
const UINT8 *data, UINTN dataSize, UINTN dataOff);
|
||||||
|
|
||||||
#endif // UTILITY_H
|
#endif // UTILITY_H
|
||||||
|
Loading…
Reference in New Issue
Block a user