Version 0.17.1

This commit is contained in:
Nikolaj Schlej 2014-02-02 13:26:33 +01:00
parent 66dc4bb6e3
commit dfb307b4aa
15 changed files with 103 additions and 86 deletions

View File

@ -1,5 +1,5 @@
/* LzFind.c -- Match finder for LZ algorithms
2009-04-22 : Igor Pavlov : Public doma*/
2009-04-22 : Igor Pavlov : Public domain */
#include <string.h>

View File

@ -1,5 +1,5 @@
/* LzmaDec.c -- LZMA Decoder
2009-09-20 : Igor Pavlov : Public doma*/
2009-09-20 : Igor Pavlov : Public domain*/
#include "LzmaDec.h"
@ -116,7 +116,7 @@ StopCompilingDueBUG
#define LZMA_DIC_MIN (1 << 12)
/* First LZMA-symbol is always decoded.
And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is withlast normalization
And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is with last normalization
Out:
Result:
SZ_OK - OK

View File

@ -1,5 +1,5 @@
/* LzmaEnc.c -- LZMA Encoder
2010-04-16 : Igor Pavlov : Public doma*/
2010-04-16 : Igor Pavlov : Public domain*/
#include <string.h>

View File

@ -339,7 +339,7 @@ Returns:
}
//
// Fillcompressed size and original size
// Fill compressed size and original size
//
mDst = DstBuffer;
PutDword(mCompSize+1);
@ -368,11 +368,11 @@ PutDword(
Routine Description:
Put a dword to output stream
Put a DWORD to output stream
Arguments:
Data - the dword to put
Data - the DWORD to put
Returns: (VOID)
@ -402,9 +402,9 @@ AllocateMemory ()
Routine Description:
Allocate memory spaces for data structures usedcompression process
Allocate memory spaces for data structures used in compression process
Argements: (VOID)
Arguments: (VOID)
Returns:
@ -656,7 +656,7 @@ Returns: (VOID)
//
// We have just got a long match, the target tree
// can be located by MatchPos + 1. Travese the tree
// can be located by MatchPos + 1. Traverse the tree
// from bottom up to get to a proper starting point.
// The usage of PERC_FLAG ensures proper node deletion
//DeleteNode() later.
@ -830,7 +830,7 @@ GetNextMatch ()
Routine Description:
Advance the current position (readnew data if needed).
Advance the current position (read new data if needed).
Delete outdated string info. Find a match string for current position.
Arguments: (VOID)
@ -1285,7 +1285,7 @@ Routine Description:
Outputs rightmost n bits of x
Argments:
Arguments:
n - the rightmost n bits of the data is used
x - the data
@ -1331,7 +1331,7 @@ FreadCrc (
Routine Description:
Readsource data
Read source data
Arguments:

View File

@ -178,7 +178,7 @@ Creates Huffman Code mapping table according to code length array.
Arguments:
Sd - The global scratch data
NumOfChar - Number of symbolsthe symbol set
NumOfChar - Number of symbols in the symbol set
BitLen - Code length array
TableBits - The width of the mapping table
Table - The table
@ -681,7 +681,7 @@ ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
@ -729,7 +729,7 @@ Version 2 for Tiano de/compression algorithm.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_SUCCESS - Decompression is successful
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
@ -853,7 +853,7 @@ ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_SUCCESS - Decompression is successful
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
@ -900,7 +900,7 @@ ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_SUCCESS - Decompression is successful
EFI_INVALID_PARAMETER - The source data is corrupted
--*/

View File

@ -59,7 +59,7 @@ ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successull retrieved.
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
@ -93,7 +93,7 @@ ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_SUCCESS - Decompression is successful
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
@ -127,7 +127,7 @@ ScratchSize - The size of scratch buffer.
Returns:
EFI_SUCCESS - Decompression is successfull
EFI_SUCCESS - Decompression is successful
EFI_INVALID_PARAMETER - The source data is corrupted
--*/

View File

@ -374,11 +374,11 @@ STATIC
Routine Description:
Put a dword to output stream
Put a DWORD to output stream
Arguments:
Data - the dword to put
Data - the DWORD to put
Returns: (VOID)
@ -412,7 +412,7 @@ STATIC
Allocate memory spaces for data structures used compression process
Argements:
Arguments:
VOID
Returns:
@ -681,7 +681,7 @@ STATIC
if (mMatchLen >= 4) {
//
// We have just got a long match, the target tree
// can be located by MatchPos + 1. Travese the tree
// can be located by MatchPos + 1. Traverse the tree
// from bottom up to get to a proper starting point.
// The usage of PERC_FLAG ensures proper node deletion
// DeleteNode() later.
@ -922,7 +922,7 @@ STATIC
Routine Description:
The macontrolling routine for compression process.
The mac controlling routine for compression process.
Arguments: (VOID)
@ -1314,7 +1314,7 @@ STATIC
if ((mOutputMask >>= 1) == 0) {
mOutputMask = 1U << (UINT8_BIT - 1);
//
// Check the buffer overflow per outputing UINT8_BIT symbols
// Check the buffer overflow per outputting UINT8_BIT symbols
// which is an Original Character or a Pointer. The biggest
// symbol is a Pointer which occupies 5 bytes.
//

View File

@ -152,8 +152,10 @@ enum CapsuleSubtypes {
};
enum VolumeSubtypes {
BootVolume = 90,
UnknownVolume
NormalVolume = 90,
BootVolume,
UnknownVolume,
NvramVolume
};
enum RegionSubtypes {
@ -165,7 +167,7 @@ enum RegionSubtypes {
};
// EFI GUID
typedef struct{
typedef struct {
UINT8 Data[16];
} EFI_GUID;

View File

@ -76,7 +76,7 @@ typedef struct {
#define FLASH_DENSITY_8MB 0x04
#define FLASH_DENSITY_16MB 0x05
// Flash frequences
// Flash frequencies
#define FLASH_FREQUENCY_20MHZ 0x00
#define FLASH_FREQUENCY_33MHZ 0x01
#define FLASH_FREQUENCY_50MHZ 0x04

7
ffs.h
View File

@ -55,7 +55,7 @@ typedef struct {
EFI_CAPSULE_HEADER CapsuleHeader;
UINT16 RomImageOffset; // offset in bytes from the beginning of the capsule header to the start of
// the capsule volume
//!TODO: Enable certificate and rom layout reading
//!TODO: Enable certificate and ROM layout reading
//UINT16 RomLayoutOffset; // offset to the table of the module descriptors in the capsule's volume
// that are included in the signature calculation
//FW_CERTIFICATE FWCert;
@ -91,7 +91,7 @@ typedef struct {
//EFI_FV_BLOCK_MAP_ENTRY FvBlockMap[1];
} EFI_FIRMWARE_VOLUME_HEADER;
// Filesystem GUIDs
// File system GUIDs
const QByteArray EFI_FIRMWARE_FILE_SYSTEM_GUID
("\xD9\x54\x93\x7A\x68\x04\x4A\x44\x81\xCE\x0B\xF6\x17\xD8\x90\xDF", 16);
const QByteArray EFI_APPLE_BOOT_VOLUME_FILE_SYSTEM_GUID
@ -214,6 +214,9 @@ typedef struct {
//UINT8 Data[];
} EFI_FIRMWARE_VOLUME_EXT_ENTRY_GUID_TYPE;
// NVRAM volume signature
const QByteArray EFI_FIRMWARE_VOLUME_NVRAM_SIGNATURE("$VSS", 4);
// Volume header 16bit checksum calculation routine
extern UINT16 calculateChecksum16(UINT16* buffer, UINT32 bufferSize);

View File

@ -78,7 +78,7 @@ UINT8 FfsEngine::parseImageFile(const QByteArray & buffer)
QModelIndex index;
QByteArray flashImage;
// Check buffer size to be more then or equal to sizeof(EFI_CAPSULE_HEADER)
// Check buffer size to be more then or equal to size of EFI_CAPSULE_HEADER
if ((UINT32) buffer.size() <= sizeof(EFI_CAPSULE_HEADER))
{
msg(tr("parseImageFile: Image file is smaller then minimum size of %1 bytes").arg(sizeof(EFI_CAPSULE_HEADER)));
@ -627,7 +627,7 @@ UINT8 FfsEngine::findNextVolume(const QByteArray & bios, UINT32 volumeOffset, UI
return ERR_SUCCESS;
}
UINT8 FfsEngine::getVolumeSize(const QByteArray & bios, UINT32 volumeOffset, UINT32 & volumeSize)
UINT8 FfsEngine::getVolumeSize(const QByteArray & bios, UINT32 volumeOffset, UINT32 & volumeSize, bool fromHeader)
{
// Populate volume header
EFI_FIRMWARE_VOLUME_HEADER* volumeHeader = (EFI_FIRMWARE_VOLUME_HEADER*) (bios.constData() + volumeOffset);
@ -636,16 +636,22 @@ UINT8 FfsEngine::getVolumeSize(const QByteArray & bios, UINT32 volumeOffset, UIN
if (QByteArray((const char*) &volumeHeader->Signature, sizeof(volumeHeader->Signature)) != EFI_FV_SIGNATURE)
return ERR_INVALID_VOLUME;
// Use BlockMap to determine volume size
EFI_FV_BLOCK_MAP_ENTRY* entry = (EFI_FV_BLOCK_MAP_ENTRY*) (bios.constData() + volumeOffset + sizeof(EFI_FIRMWARE_VOLUME_HEADER));
if (fromHeader) {
// Use header field
volumeSize = volumeHeader->FvLength;
}
else {
// Use BlockMap
EFI_FV_BLOCK_MAP_ENTRY* entry = (EFI_FV_BLOCK_MAP_ENTRY*)(bios.constData() + volumeOffset + sizeof(EFI_FIRMWARE_VOLUME_HEADER));
volumeSize = 0;
while(entry->NumBlocks != 0 && entry->Length != 0) {
if ((void*) entry > bios.constData() + bios.size())
while (entry->NumBlocks != 0 && entry->Length != 0) {
if ((void*)entry > bios.constData() + bios.size())
return ERR_INVALID_VOLUME;
volumeSize += entry->NumBlocks * entry->Length;
entry += 1;
}
}
return ERR_SUCCESS;
}
@ -655,9 +661,19 @@ UINT8 FfsEngine::parseVolume(const QByteArray & volume, QModelIndex & index, co
// Populate volume header
EFI_FIRMWARE_VOLUME_HEADER* volumeHeader = (EFI_FIRMWARE_VOLUME_HEADER*) (volume.constData());
// Check filesystem GUID to be known
// Do not parse volume with unknown FFS, because parsing will fail
bool parseCurrentVolume = true;
// Calculate volume header size
UINT32 headerSize;
if (volumeHeader->Revision > 1 && volumeHeader->ExtHeaderOffset) {
EFI_FIRMWARE_VOLUME_EXT_HEADER* extendedHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)((UINT8*)volumeHeader + volumeHeader->ExtHeaderOffset);
headerSize = volumeHeader->ExtHeaderOffset + extendedHeader->ExtHeaderSize;
}
else {
headerSize = volumeHeader->HeaderLength;
}
// Check for volume structure to be known
// Default volume subtype is "normal"
UINT8 subtype = NormalVolume;
// FFS GUID v1
if (QByteArray((const char*) &volumeHeader->FileSystemGuid, sizeof(EFI_GUID)) == EFI_FIRMWARE_FILE_SYSTEM_GUID) {
// Code can be added here
@ -670,35 +686,25 @@ UINT8 FfsEngine::parseVolume(const QByteArray & volume, QModelIndex & index, co
else if (QByteArray((const char*) &volumeHeader->FileSystemGuid, sizeof(EFI_GUID)) == EFI_FIRMWARE_FILE_SYSTEM2_GUID) {
// Code can be added here
}
// NVRAM volume
else if (QByteArray((const char*)volumeHeader + headerSize, EFI_FIRMWARE_VOLUME_NVRAM_SIGNATURE.length()) == EFI_FIRMWARE_VOLUME_NVRAM_SIGNATURE) {
subtype = NvramVolume;
}
// Other GUID
else {
msg(tr("parseVolume: Unknown file system (%1)").arg(guidToQString(volumeHeader->FileSystemGuid)), parent);
parseCurrentVolume = false;
subtype = UnknownVolume;
}
// Check attributes
// Determine value of empty byte
char empty = volumeHeader->Attributes & EFI_FVB_ERASE_POLARITY ? '\xFF' : '\x00';
// Check header checksum by recalculating it
if (calculateChecksum16((UINT16*) volumeHeader, volumeHeader->HeaderLength)) {
msg(tr("parseVolume: Volume header checksum is invalid"), parent);
}
// Check for presence of extended header, only if header revision is greater then 1
UINT32 headerSize;
if (volumeHeader->Revision > 1 && volumeHeader->ExtHeaderOffset) {
EFI_FIRMWARE_VOLUME_EXT_HEADER* extendedHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER*) ((UINT8*) volumeHeader + volumeHeader->ExtHeaderOffset);
headerSize = volumeHeader->ExtHeaderOffset + extendedHeader->ExtHeaderSize;
} else {
headerSize = volumeHeader->HeaderLength;
}
// Get volume size
UINT8 result;
UINT32 volumeSize;
result = getVolumeSize(volume, 0, volumeSize);
result = getVolumeSize(volume, 0, volumeSize, false);
if (result)
return result;
@ -709,6 +715,14 @@ UINT8 FfsEngine::parseVolume(const QByteArray & volume, QModelIndex & index, co
.arg(volumeHeader->FvLength, 8, 16, QChar('0'))
.arg(volumeSize, 8, 16, QChar('0')), parent);
}
// Trust header size
else
volumeSize = volumeHeader->FvLength;
// Check header checksum by recalculating it
if (subtype == NormalVolume && calculateChecksum16((UINT16*)volumeHeader, volumeHeader->HeaderLength)) {
msg(tr("parseVolume: Volume header checksum is invalid"), parent);
}
// Get info
QString name = guidToQString(volumeHeader->FileSystemGuid);
@ -721,15 +735,11 @@ UINT8 FfsEngine::parseVolume(const QByteArray & volume, QModelIndex & index, co
// Add tree item
QByteArray header = volume.left(headerSize);
QByteArray body = volume.mid(headerSize, volumeSize - headerSize);
index = model->addItem(Volume, subtype, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, QByteArray(), parent, mode);
// Do not parse volumes with unknown FS
if (!parseCurrentVolume) {
index = model->addItem(Volume, UnknownVolume, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, QByteArray(), parent, mode);
// Do not parse the contents of volumes other then normal
if (subtype != NormalVolume)
return ERR_SUCCESS;
}
else
index = model->addItem(Volume, 0, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, QByteArray(), parent, mode);
// Search for and parse all files
UINT32 fileOffset = headerSize;
@ -741,7 +751,7 @@ UINT8 FfsEngine::parseVolume(const QByteArray & volume, QModelIndex & index, co
if (result)
return result;
// Check file size to be at least sizeof(EFI_FFS_FILE_HEADER)
// Check file size to be at least size of EFI_FFS_FILE_HEADER
if (fileSize < sizeof(EFI_FFS_FILE_HEADER)) {
msg(tr("parseVolume: File with invalid size"), index);
return ERR_INVALID_FILE;
@ -939,7 +949,7 @@ UINT8 FfsEngine::parseFile(const QByteArray & file, QModelIndex & index, const U
.arg(fileHeader->State, 2, 16, QChar('0'));
// Add tree item
index = model->addItem( File, fileHeader->Type, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, tail, parent, mode);
index = model->addItem(File, fileHeader->Type, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, tail, parent, mode);
if (!parseCurrentFile)
return ERR_SUCCESS;
@ -2158,7 +2168,7 @@ out:
// File will be unaligned if added as is, so we must add pad file before it
// Determine pad file size
UINT32 size = alignment - (alignmentBase % alignment);
// Required padding is smaler then minimal pad file size
// Required padding is smaller then minimal pad file size
while (size < sizeof(EFI_FFS_FILE_HEADER)) {
size += alignment;
}
@ -2235,7 +2245,7 @@ out:
// Root volume can't be grown yet
UINT8 parentType = model->type(index.parent());
if(parentType != File && parentType != Section) {
msg(tr("reconstructVolume: %1: can't grow root volume").arg(guidToQString(volumeHeader->FileSystemGuid)), index);
msg(tr("reconstructVolume: %1: root volume can't be grown").arg(guidToQString(volumeHeader->FileSystemGuid)), index);
return ERR_INVALID_VOLUME;
}
@ -2517,7 +2527,7 @@ UINT8 FfsEngine::reconstructSection(const QModelIndex& index, const UINT32 base,
result = compress(reconstructed, model->compression(index), compressed);
if (result)
return result;
// Check for auth status valid attribute
// Check for authentication status valid attribute
if (guidDefinedHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) {
msg(tr("reconstructSection: %1: GUID defined section signature can now become invalid")
.arg(guidToQString(guidDefinedHeader->SectionDefinitionGuid)), index);
@ -2890,11 +2900,11 @@ UINT8 FfsEngine::rebase(QByteArray &executable, const UINT32 base)
return ERR_UNKNOWN_RELOCATION_TYPE;
}
// Next reloc record
// Next relocation record
Reloc += 1;
}
// Next reloc block
// Next relocation block
RelocBase = (EFI_IMAGE_BASE_RELOCATION*)RelocEnd;
}
@ -2913,7 +2923,7 @@ UINT8 FfsEngine::patchVtf(QByteArray &vtf)
// No need to patch anything
return ERR_SUCCESS;
// Replace last occurence of oldPeiCoreEntryPoint with newPeiCoreEntryPoint
// Replace last occurrence of oldPeiCoreEntryPoint with newPeiCoreEntryPoint
QByteArray old((char*) &oldPeiCoreEntryPoint, sizeof(oldPeiCoreEntryPoint));
int i = vtf.lastIndexOf(old);
if (i == -1) {

View File

@ -93,7 +93,7 @@ private:
// Parsing helpers
UINT8 findNextVolume(const QByteArray & bios, const UINT32 volumeOffset, UINT32 & nextVolumeOffset);
UINT8 getVolumeSize(const QByteArray & bios, const UINT32 volumeOffset, UINT32 & volumeSize);
UINT8 getVolumeSize(const QByteArray & bios, const UINT32 volumeOffset, UINT32 & volumeSize, bool fromHeader = true);
UINT8 getFileSize(const QByteArray & volume, const UINT32 fileOffset, UINT32 & fileSize);
UINT8 getSectionSize(const QByteArray & file, const UINT32 sectionOffset, UINT32 & sectionSize);

View File

@ -66,7 +66,7 @@ typedef struct {
UINT16 e_oemid; // OEM identifier (for e_oeminfo)
UINT16 e_oeminfo; // OEM information; e_oemid specific
UINT16 e_res2[10]; // Reserved words
UINT32 e_lfanew; // File address of new exe header
UINT32 e_lfanew; // File address of new header
} EFI_IMAGE_DOS_HEADER;
//
@ -91,8 +91,8 @@ typedef struct {
// Characteristics
//
#define EFI_IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file
#define EFI_IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved externel references)
#define EFI_IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line nunbers stripped from file
#define EFI_IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved external references)
#define EFI_IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line numbers stripped from file
#define EFI_IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file
#define EFI_IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed
#define EFI_IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine
@ -478,7 +478,7 @@ typedef struct {
//
typedef struct {
union {
UINT32 SymbolTableIndex; // Symbol table index of function name if Linenumber is 0
UINT32 SymbolTableIndex; // Symbol table index of function name if line number is 0
UINT32 VirtualAddress; // Virtual address of line number
} Type;
UINT16 Linenumber; // Line number
@ -622,7 +622,7 @@ typedef struct {
//
// Debug Data Structure defined by Apple Mach-O to Coff utility.
// Debug Data Structure defined by Apple Mach-O to COFF utility.
//
#define CODEVIEW_SIGNATURE_MTOC 0x434F544D // MTOC
typedef struct {

View File

@ -58,6 +58,8 @@ QString itemSubtypeToQString(const UINT8 type, const UINT8 subtype)
return QObject::tr("Boot");
else if (subtype == UnknownVolume)
return QObject::tr("Unknown");
else if (subtype == NvramVolume)
return QObject::tr("NVRAM");
else
return "";
case Capsule:

View File

@ -20,7 +20,7 @@
<bool>true</bool>
</property>
<property name="windowTitle">
<string>UEFITool 0.17.0</string>
<string>UEFITool 0.17.1</string>
</property>
<widget class="QWidget" name="centralWidget">
<property name="sizePolicy">