mirror of
https://github.com/LongSoft/UEFITool.git
synced 2025-05-14 23:24:49 -04:00
Multiple improvements and bugfixes
1. Fixes #158, UEFITool and UEFIFind failed to lookup pattern crossing header/body boundary 2. Fixes #159, filter out more symbols in fileanems, which are prohibited by different filesystems 3. Add more known file GUIDs 4. Add basic support for FMP images 5. Fix unaligned read in uint24ToUint32 6. Fix compilation with latest cmake requiring directory path
This commit is contained in:
parent
40b77a713f
commit
1ac6e6a4f0
13 changed files with 266 additions and 82 deletions
|
@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
*/
|
||||
|
||||
#include "uefifind.h"
|
||||
#include "../common/ffsutils.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
@ -52,7 +53,7 @@ USTATUS UEFIFind::find(const UINT8 mode, const bool count, const UString & hexPa
|
|||
|
||||
result.clear();
|
||||
|
||||
USTATUS returned = findFileRecursive(root, hexPattern, mode, files);
|
||||
USTATUS returned = FfsUtils::findFileRecursive(model, root, hexPattern, mode, files);
|
||||
if (returned)
|
||||
return returned;
|
||||
|
||||
|
@ -79,63 +80,3 @@ USTATUS UEFIFind::find(const UINT8 mode, const bool count, const UString & hexPa
|
|||
}
|
||||
return U_SUCCESS;
|
||||
}
|
||||
|
||||
USTATUS UEFIFind::findFileRecursive(const UModelIndex index, const UString & hexPattern, const UINT8 mode, std::set<std::pair<UModelIndex, UModelIndex> > & files)
|
||||
{
|
||||
if (!index.isValid())
|
||||
return U_SUCCESS;
|
||||
|
||||
if (hexPattern.isEmpty())
|
||||
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
|
||||
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;
|
||||
|
||||
|
||||
|
||||
bool hasChildren = (model->rowCount(index) > 0);
|
||||
for (int i = 0; i < model->rowCount(index); i++) {
|
||||
findFileRecursive(index.child(i, index.column()), hexPattern, mode, files);
|
||||
}
|
||||
|
||||
UByteArray data;
|
||||
if (hasChildren) {
|
||||
if (mode == SEARCH_MODE_HEADER || mode == SEARCH_MODE_ALL)
|
||||
data += model->header(index);
|
||||
}
|
||||
else {
|
||||
if (mode == SEARCH_MODE_HEADER)
|
||||
data += model->header(index);
|
||||
else if (mode == SEARCH_MODE_BODY)
|
||||
data += model->body(index);
|
||||
else
|
||||
data += model->header(index) + model->body(index);
|
||||
}
|
||||
|
||||
const UINT8 *rawData = reinterpret_cast<const UINT8 *>(data.constData());
|
||||
INTN offset = findPattern(pattern.data(), patternMask.data(), pattern.size(), rawData, data.size(), 0);
|
||||
if (offset >= 0) {
|
||||
if (model->type(index) != Types::File) {
|
||||
UModelIndex ffs = model->findParentOfType(index, Types::File);
|
||||
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
|
||||
files.insert(std::pair<UModelIndex, UModelIndex>(index, UModelIndex()));
|
||||
|
||||
}
|
||||
|
||||
return U_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue