2015-03-13 14:48:53 +08:00
|
|
|
/* utility.h
|
|
|
|
|
2016-02-02 09:08:08 +08:00
|
|
|
Copyright (c) 2016, Nikolaj Schlej. All rights reserved.
|
2015-03-13 14:48:53 +08:00
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
2015-04-02 16:04:37 +08:00
|
|
|
|
2016-04-09 18:47:19 +08:00
|
|
|
#ifndef UTILITY_H
|
|
|
|
#define UTILITY_H
|
2015-04-02 16:04:37 +08:00
|
|
|
|
2018-08-02 08:41:11 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2018-11-11 21:33:13 +08:00
|
|
|
#include "../common/zlib/zlib.h"
|
|
|
|
|
2016-10-10 14:05:04 +08:00
|
|
|
#include "basetypes.h"
|
2016-06-26 11:54:21 +08:00
|
|
|
#include "ustring.h"
|
2016-07-07 13:57:45 +08:00
|
|
|
#include "treemodel.h"
|
2015-04-02 16:04:37 +08:00
|
|
|
#include "parsingdata.h"
|
|
|
|
|
2020-11-23 10:01:44 +08:00
|
|
|
// Returns bytes as string when all bytes are ascii visible, hex representation otherwise
|
|
|
|
UString visibleAsciiOrHex(UINT8* bytes, UINT32 length);
|
|
|
|
|
2017-10-12 13:59:23 +08:00
|
|
|
// Returns unique name for tree item
|
2016-07-09 14:31:08 +08:00
|
|
|
UString uniqueItemName(const UModelIndex & index);
|
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
// Converts error code to UString
|
2018-07-13 03:56:51 +08:00
|
|
|
UString errorCodeToUString(USTATUS errorCode);
|
2015-03-13 14:48:53 +08:00
|
|
|
|
2019-01-04 03:53:31 +08:00
|
|
|
// EFI/Tiano/LZMA decompression routine
|
|
|
|
USTATUS decompress(const UByteArray & compressed, const UINT8 compressionType, UINT8 & algorithm, UINT32 & dictionarySize, UByteArray & decompressed, UByteArray & efiDecompressed);
|
2015-03-13 14:48:53 +08:00
|
|
|
|
2018-11-11 21:33:13 +08:00
|
|
|
// GZIP decompression routine
|
|
|
|
USTATUS gzipDecompress(const UByteArray & compressed, UByteArray & decompressed);
|
2015-04-02 16:04:37 +08:00
|
|
|
|
2017-12-11 09:56:00 +08:00
|
|
|
// 8bit sum calculation routine
|
|
|
|
UINT8 calculateSum8(const UINT8* buffer, UINT32 bufferSize);
|
|
|
|
|
2015-07-07 21:57:41 +08:00
|
|
|
// 8bit checksum calculation routine
|
2016-07-09 14:31:08 +08:00
|
|
|
UINT8 calculateChecksum8(const UINT8* buffer, UINT32 bufferSize);
|
2015-07-07 21:57:41 +08:00
|
|
|
|
|
|
|
// 16bit checksum calculation routine
|
2016-07-09 14:31:08 +08:00
|
|
|
UINT16 calculateChecksum16(const UINT16* buffer, UINT32 bufferSize);
|
2015-07-07 21:57:41 +08:00
|
|
|
|
2019-07-25 01:30:59 +08:00
|
|
|
// 32bit checksum calculation routine
|
|
|
|
UINT32 calculateChecksum32(const UINT32* buffer, UINT32 bufferSize);
|
|
|
|
|
2016-10-10 14:05:04 +08:00
|
|
|
// Return padding type from it's contents
|
|
|
|
UINT8 getPaddingType(const UByteArray & padding);
|
|
|
|
|
2018-08-02 08:41:11 +08:00
|
|
|
// 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);
|
|
|
|
|
2018-10-08 17:58:12 +08:00
|
|
|
// Safely dereferences misaligned pointers
|
|
|
|
template <typename T>
|
2018-11-12 14:13:34 +08:00
|
|
|
inline T readUnaligned(const T *v) {
|
2018-10-08 17:58:12 +08:00
|
|
|
T tmp;
|
|
|
|
memcpy(&tmp, v, sizeof(T));
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2016-04-09 18:47:19 +08:00
|
|
|
#endif // UTILITY_H
|