mirror of
https://github.com/LongSoft/UEFITool.git
synced 2025-05-28 05:54:50 -04:00

2) Fixed QHexView misalignment in Windows and macOS. 3) Added some more analysis to raw files and sections: raw files can (or can not) contain sections, raw sections can contain NVAR storage or PE/TE. 4) Improved CPU base address detection and propagation. 5) Improved FIT recognition. 7) ME region not displayed if it is in unknown format, fixed this because we still want to operate with it. 8) Small changes to Flash Descriptor parsing to get more cases for valid "Intel image". To get rid of cases when "Intel image" is already in tree but with parse error because of which "UEFI image" appears. 9) Added parsing of individual UEFI-files (these can be trimmed from UEFI-volume), displaying it as "UEFI volume part". 10) Added possibility to view/save contents of elements "Free volume space", "Free space" and such, because these can be non-empty. 11) Added info about blocks number and block size (with preliminary and stupid validity check) to volume info. 12) Added storage in settings of the following paths: open image file, save image file, open GUIDs file. 13) Added last opened files list. 14) Added permanent opened file name string to the end of the status bar. 15) Added opened file changes tracking: if the file was modified in other program while it is opened in UEFITool, there are 3 ways to act: a) ignore changes (but mark file path displayed in the status bar with italic font); b) ask user to reopen or ignore (if ignore, mark as in a); c) auto reopen changed file in UEFITool. If changes were in some way ignored, file path displayed in the right of the status bar will be marked with italic font and then become clickable: on click request to reopen appears again. 16) Switched to offset/size instead of byte array storing in each tree item. 17) For clarity - added icons to key tree items (compressed and with contents, contents now must be in root item only). 18) For usability - added expanding tree on open image (to depth level 1) and by menu command (expand all).
105 lines
3.3 KiB
C++
Executable file
105 lines
3.3 KiB
C++
Executable file
/* utility.h
|
|
|
|
Copyright (c) 2016, 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 UTILITY_H
|
|
#define UTILITY_H
|
|
|
|
#include <vector>
|
|
|
|
#include "../common/zlib/zlib.h"
|
|
|
|
#include "basetypes.h"
|
|
#include "ustring.h"
|
|
#include "treemodel.h"
|
|
#include "parsingdata.h"
|
|
|
|
// Returns text representation of 4CC value
|
|
UString fourCC(const UINT32 value);
|
|
|
|
// Returns bytes as string when all bytes are ascii visible, hex representation otherwise
|
|
UString visibleAsciiOrHex(UINT8* bytes, UINT32 length);
|
|
|
|
// Returns unique name for tree item
|
|
UString uniqueItemName(const UModelIndex & index);
|
|
|
|
// Makes the name usable as a file name
|
|
void fixFileName(UString &name, bool replaceSpaces);
|
|
|
|
// Converts error code to UString
|
|
UString errorCodeToUString(USTATUS errorCode);
|
|
|
|
// EFI/Tiano/LZMA decompression routine
|
|
USTATUS decompress(const UByteArray & compressed, const UINT8 compressionType, UINT8 & algorithm, UINT32 & dictionarySize, UByteArray & decompressed, UByteArray & efiDecompressed);
|
|
|
|
// GZIP decompression routine
|
|
USTATUS gzipDecompress(const UByteArray & compressed, UByteArray & decompressed);
|
|
|
|
// ZLIB decompression routine
|
|
USTATUS zlibDecompress(const UByteArray& compressed, UByteArray& decompressed);
|
|
|
|
// 8bit sum calculation routine
|
|
UINT8 calculateSum8(const UINT8* buffer, UINT32 bufferSize);
|
|
|
|
// 8bit checksum calculation routine
|
|
UINT8 calculateChecksum8(const UINT8* buffer, UINT32 bufferSize);
|
|
|
|
// 16bit checksum calculation routine
|
|
UINT16 calculateChecksum16(const UINT16* buffer, UINT32 bufferSize);
|
|
|
|
// 32bit checksum calculation routine
|
|
UINT32 calculateChecksum32(const UINT32* buffer, UINT32 bufferSize);
|
|
|
|
// Check if an array is filled in by a single repeated char
|
|
inline signed long checkSingle(const UByteArray& a, signed long defaultRc = -1)
|
|
{
|
|
size_t s = a.size();
|
|
if (!s)
|
|
return defaultRc;
|
|
if (s == 1 || memcmp(a.constData(), a.constData() + 1, s - 1) == 0)
|
|
return (unsigned char)a.at(0);
|
|
return -1;
|
|
}
|
|
|
|
// Get padding type for a given padding
|
|
inline UINT8 getPaddingType(const UByteArray& a)
|
|
{
|
|
size_t s = a.size();
|
|
if (s) {
|
|
if (s == 1 || memcmp(a.constData(), a.constData() + 1, s - 1) == 0) {
|
|
switch (a.at(0)) {
|
|
case 0:
|
|
return Subtypes::ZeroPadding;
|
|
case 0xFF:
|
|
return Subtypes::OnePadding;
|
|
}
|
|
}
|
|
}
|
|
return Subtypes::DataPadding;
|
|
}
|
|
|
|
// Make pattern from a hexstring with an assumption of . being any char
|
|
bool 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);
|
|
|
|
// Safely dereferences misaligned pointers
|
|
template <typename T>
|
|
inline T readUnaligned(const T *v) {
|
|
T tmp = {};
|
|
memcpy(reinterpret_cast<void*>(&tmp), reinterpret_cast<const void*>(v), sizeof(T));
|
|
return tmp;
|
|
}
|
|
|
|
#endif // UTILITY_H
|