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>
|
|
|
|
|
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"
|
|
|
|
|
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
|
|
|
|
|
|
|
// Decompression routine
|
2016-10-28 00:31:15 +08:00
|
|
|
USTATUS decompress(const UByteArray & compressed, const UINT8 compressionType, UINT8 & algorithm, UByteArray & decompressed, UByteArray & efiDecompressed);
|
2015-03-13 14:48:53 +08:00
|
|
|
|
|
|
|
// Compression routine
|
2018-08-23 13:43:46 +08:00
|
|
|
UINT8 compress(const UByteArray & data, const UINT8 algorithm, UByteArray & compressedData);
|
2016-06-26 11:54:21 +08:00
|
|
|
//USTATUS compress(const UByteArray & decompressed, UByteArray & compressed, const UINT8 & algorithm);
|
2015-03-13 14:48:53 +08:00
|
|
|
|
2015-07-07 21:57:41 +08:00
|
|
|
// CRC32 calculation routine
|
2016-07-09 14:31:08 +08:00
|
|
|
UINT32 crc32(UINT32 initial, const UINT8* buffer, const UINT32 length);
|
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
|
|
|
|
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-08-23 13:43:46 +08:00
|
|
|
// Image base adress
|
|
|
|
USTATUS getBase(const UByteArray& file, UINT32& base);
|
|
|
|
// Entry point
|
|
|
|
USTATUS getEntryPoint(const UByteArray& file, UINT32 &entryPoint);
|
|
|
|
|
|
|
|
USTATUS growVolume(UByteArray & header, const UINT32 size, UINT32 & newSize);
|
|
|
|
|
|
|
|
USTATUS rebase(UByteArray &executable, const UINT32 base);
|
|
|
|
|
2016-04-09 18:47:19 +08:00
|
|
|
#endif // UTILITY_H
|