UEFITool 0.18.4 / UEFIExtract 0.2.2

- added new FFS GUID found new in Apple EFI images
- added PDR region parsing as BIOS space (Apple feature again)
- changed default directory for saving to the directory containing opened file
- focus and cursor position are now set properly for GUID tab in search dialog
- search dialog resized to fit the whole GUID
- codebase cleaned form unnecessary spaces
This commit is contained in:
Nikolaj Schlej 2014-07-24 16:59:51 -07:00
parent 6e1f226aa0
commit 534f01fcd5
35 changed files with 3589 additions and 3656 deletions

View file

@ -31,26 +31,26 @@ SRes OnProgress(void *p, UInt64 inSize, UInt64 outSize)
static ICompressProgress g_ProgressCallback = { &OnProgress };
STATIC
UINT64
EFIAPI
RShiftU64 (
UINT64 Operand,
UINT32 Count
)
UINT64
EFIAPI
RShiftU64(
UINT64 Operand,
UINT32 Count
)
{
return Operand >> Count;
}
VOID
SetEncodedSizeOfBuf(
UINT64 EncodedSize,
UINT8 *EncodedData
)
SetEncodedSizeOfBuf(
UINT64 EncodedSize,
UINT8 *EncodedData
)
{
INT32 Index;
EncodedData[LZMA_PROPS_SIZE] = EncodedSize & 0xFF;
for (Index = LZMA_PROPS_SIZE+1; Index <= LZMA_PROPS_SIZE + 7; Index++)
for (Index = LZMA_PROPS_SIZE + 1; Index <= LZMA_PROPS_SIZE + 7; Index++)
{
EncodedSize = RShiftU64(EncodedSize, 8);
EncodedData[Index] = EncodedSize & 0xFF;
@ -58,13 +58,13 @@ VOID
}
INT32
EFIAPI
LzmaCompress (
CONST UINT8 *Source,
UINT32 SourceSize,
UINT8 *Destination,
UINT32 *DestinationSize
)
EFIAPI
LzmaCompress(
CONST UINT8 *Source,
UINT32 SourceSize,
UINT8 *Destination,
UINT32 *DestinationSize
)
{
SRes LzmaResult;
CLzmaEncProps props;
@ -101,10 +101,8 @@ INT32
if (LzmaResult == SZ_OK) {
return ERR_SUCCESS;
} else {
}
else {
return ERR_INVALID_PARAMETER;
}
}

View file

@ -9,7 +9,7 @@
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
*/
#ifndef __LZMACOMPRESS_H__
#define __LZMACOMPRESS_H__
@ -24,9 +24,9 @@ extern "C" {
#define LZMA_DICTIONARY_SIZE 0x800000
#define _LZMA_SIZE_OPT
INT32
EFIAPI
LzmaCompress (
INT32
EFIAPI
LzmaCompress(
const UINT8 *Source,
UINT32 SourceSize,
UINT8 *Destination,

View file

@ -18,11 +18,11 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <stdlib.h>
UINT64
EFIAPI
LShiftU64 (
UINT64 Operand,
UINT32 Count
)
EFIAPI
LShiftU64(
UINT64 Operand,
UINT32 Count
)
{
return Operand << Count;
}
@ -39,9 +39,9 @@ Get the size of the uncompressed buffer by parsing EncodeData header.
@return The size of the uncompressed buffer.
*/
UINT64
GetDecodedSizeOfBuf(
UINT8 *EncodedData
)
GetDecodedSizeOfBuf(
UINT8 *EncodedData
)
{
UINT64 DecodedSize;
INT32 Index;
@ -86,12 +86,12 @@ buffer was returned ScratchSize.
*/
INT32
EFIAPI
LzmaGetInfo (
CONST VOID *Source,
UINT32 SourceSize,
UINT32 *DestinationSize
)
EFIAPI
LzmaGetInfo(
CONST VOID *Source,
UINT32 SourceSize,
UINT32 *DestinationSize
)
{
UInt64 DecodedSize;
@ -123,12 +123,12 @@ The source buffer specified by Source is corrupted
(not a valid compressed format).
*/
INT32
EFIAPI
LzmaDecompress (
CONST VOID *Source,
UINT32 SourceSize,
VOID *Destination
)
EFIAPI
LzmaDecompress(
CONST VOID *Source,
UINT32 SourceSize,
VOID *Destination
)
{
SRes LzmaResult;
ELzmaStatus Status;
@ -136,10 +136,10 @@ INT32
SizeT EncodedDataSize;
DecodedBufSize = (SizeT)GetDecodedSizeOfBuf((UINT8*)Source);
EncodedDataSize = (SizeT) (SourceSize - LZMA_HEADER_SIZE);
EncodedDataSize = (SizeT)(SourceSize - LZMA_HEADER_SIZE);
LzmaResult = LzmaDecode(
(Byte*) Destination,
(Byte*)Destination,
&DecodedBufSize,
(Byte*)((UINT8*)Source + LZMA_HEADER_SIZE),
&EncodedDataSize,
@ -152,8 +152,8 @@ INT32
if (LzmaResult == SZ_OK) {
return ERR_SUCCESS;
} else {
}
else {
return ERR_INVALID_PARAMETER;
}
}

View file

@ -9,7 +9,7 @@
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
*/
#ifndef __LZMADECOMPRESS_H__
#define __LZMADECOMPRESS_H__
@ -23,14 +23,14 @@ extern "C" {
#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
UINT64
EFIAPI
LShiftU64 (
UINT64
EFIAPI
LShiftU64(
UINT64 Operand,
UINT32 Count
);
/*
/*
Given a Lzma compressed source buffer, this function retrieves the size of
the uncompressed buffer and the size of the scratch buffer required
to decompress the compressed source buffer.
@ -56,16 +56,16 @@ LShiftU64 (
DestinationSize and the size of the scratch
buffer was returned ScratchSize.
*/
INT32
EFIAPI
LzmaGetInfo (
*/
INT32
EFIAPI
LzmaGetInfo(
const VOID *Source,
UINT32 SourceSize,
UINT32 *DestinationSize
);
/*
/*
Decompresses a Lzma compressed source buffer.
Extracts decompressed data to its original form.
@ -83,10 +83,10 @@ LzmaGetInfo (
@retval EFI_INVALID_PARAMETER
The source buffer specified by Source is corrupted
(not a valid compressed format).
*/
INT32
EFIAPI
LzmaDecompress (
*/
INT32
EFIAPI
LzmaDecompress(
const VOID *Source,
UINT32 SourceSize,
VOID *Destination
@ -96,4 +96,3 @@ LzmaDecompress (
}
#endif
#endif

View file

@ -516,7 +516,6 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
p->hash[hash2Value] =
p->hash[kFix3HashSize + hashValue] = p->pos;
maxLen = 2;
offset = 0;
if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
@ -543,11 +542,11 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
HASH4_CALC;
delta2 = p->pos - p->hash[ hash2Value];
delta2 = p->pos - p->hash[hash2Value];
delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
curMatch = p->hash[kFix4HashSize + hashValue];
p->hash[ hash2Value] =
p->hash[hash2Value] =
p->hash[kFix3HashSize + hash3Value] =
p->hash[kFix4HashSize + hashValue] = p->pos;
@ -590,11 +589,11 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
HASH4_CALC;
delta2 = p->pos - p->hash[ hash2Value];
delta2 = p->pos - p->hash[hash2Value];
delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
curMatch = p->hash[kFix4HashSize + hashValue];
p->hash[ hash2Value] =
p->hash[hash2Value] =
p->hash[kFix3HashSize + hash3Value] =
p->hash[kFix4HashSize + hashValue] = p->pos;
@ -653,8 +652,7 @@ static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
curMatch = p->hash[hashValue];
p->hash[hashValue] = p->pos;
SKIP_FOOTER
}
while (--num != 0);
} while (--num != 0);
}
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
@ -666,8 +664,7 @@ void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
curMatch = p->hash[hashValue];
p->hash[hashValue] = p->pos;
SKIP_FOOTER
}
while (--num != 0);
} while (--num != 0);
}
static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
@ -681,8 +678,7 @@ static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
p->hash[hash2Value] =
p->hash[kFix3HashSize + hashValue] = p->pos;
SKIP_FOOTER
}
while (--num != 0);
} while (--num != 0);
}
static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
@ -693,12 +689,11 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
SKIP_HEADER(4)
HASH4_CALC;
curMatch = p->hash[kFix4HashSize + hashValue];
p->hash[ hash2Value] =
p->hash[hash2Value] =
p->hash[kFix3HashSize + hash3Value] = p->pos;
p->hash[kFix4HashSize + hashValue] = p->pos;
SKIP_FOOTER
}
while (--num != 0);
} while (--num != 0);
}
static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
@ -709,13 +704,12 @@ static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
SKIP_HEADER(4)
HASH4_CALC;
curMatch = p->hash[kFix4HashSize + hashValue];
p->hash[ hash2Value] =
p->hash[hash2Value] =
p->hash[kFix3HashSize + hash3Value] =
p->hash[kFix4HashSize + hashValue] = p->pos;
p->son[p->cyclicBufferPos] = curMatch;
MOVE_POS
}
while (--num != 0);
} while (--num != 0);
}
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
@ -728,8 +722,7 @@ void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
p->hash[hashValue] = p->pos;
p->son[p->cyclicBufferPos] = curMatch;
MOVE_POS
}
while (--num != 0);
} while (--num != 0);
}
void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)

View file

@ -56,7 +56,6 @@
#define TREE_DECODE_CHECK(probs, limit, i) \
{ i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }
#define kNumPosBitsMax 4
#define kNumPosStatesMax (1 << kNumPosBitsMax)
@ -74,7 +73,6 @@
#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
#define kNumStates 12
#define kNumLitStates 7
@ -118,14 +116,14 @@ StopCompilingDueBUG
/* First LZMA-symbol is always decoded.
And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is with last normalization
Out:
Result:
SZ_OK - OK
SZ_ERROR_DATA - Error
p->remainLen:
< kMatchSpecLenStart : normal remain
= kMatchSpecLenStart : finished
= kMatchSpecLenStart + 1 : Flush marker
= kMatchSpecLenStart + 2 : State Init Marker
Result:
SZ_OK - OK
SZ_ERROR_DATA - Error
p->remainLen:
< kMatchSpecLenStart : normal remain
= kMatchSpecLenStart : finished
= kMatchSpecLenStart + 1 : Flush marker
= kMatchSpecLenStart + 2 : State Init Marker
*/
static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
@ -187,15 +185,14 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
bit = (matchByte & offs);
probLit = prob + offs + bit + symbol;
GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)
}
while (symbol < 0x100);
} while (symbol < 0x100);
}
dic[dicPos++] = (Byte)symbol;
processedPos++;
continue;
}
else
{
else
{
UPDATE_1(prob);
prob = probs + IsRep + state;
IF_BIT_0(prob)
@ -204,8 +201,8 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
state += kNumStates;
prob = probs + LenCoder;
}
else
{
else
{
UPDATE_1(prob);
if (checkDicSize == 0 && processedPos == 0)
return SZ_ERROR_DATA;
@ -257,7 +254,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
}
state = state < kNumLitStates ? 8 : 11;
prob = probs + RepLenCoder;
}
}
{
unsigned limit, offset;
CLzmaProb *probLen = prob + LenChoice;
@ -291,8 +288,8 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
len += offset;
}
if (state >= kNumStates)
{
if (state >= kNumStates)
{
UInt32 distance;
prob = probs + PosSlot +
((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
@ -311,10 +308,9 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
unsigned i = 1;
do
{
GET_BIT2(prob + i, i, ; , distance |= mask);
GET_BIT2(prob + i, i, ;, distance |= mask);
mask <<= 1;
}
while (--numDirectBits != 0);
} while (--numDirectBits != 0);
}
}
else
@ -340,16 +336,15 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
distance |= 1;
}
*/
}
while (--numDirectBits != 0);
} while (--numDirectBits != 0);
prob = probs + Align;
distance <<= kNumAlignBits;
{
unsigned i = 1;
GET_BIT2(prob + i, i, ; , distance |= 1);
GET_BIT2(prob + i, i, ; , distance |= 2);
GET_BIT2(prob + i, i, ; , distance |= 4);
GET_BIT2(prob + i, i, ; , distance |= 8);
GET_BIT2(prob + i, i, ;, distance |= 1);
GET_BIT2(prob + i, i, ;, distance |= 2);
GET_BIT2(prob + i, i, ;, distance |= 4);
GET_BIT2(prob + i, i, ;, distance |= 8);
}
if (distance == (UInt32)0xFFFFFFFF)
{
@ -371,13 +366,13 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
else if (distance >= checkDicSize)
return SZ_ERROR_DATA;
state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
}
}
len += kMatchMinLen;
len += kMatchMinLen;
if (limit == dicPos)
return SZ_ERROR_DATA;
{
if (limit == dicPos)
return SZ_ERROR_DATA;
{
SizeT rem = limit - dicPos;
unsigned curLen = ((rem < len) ? (unsigned)rem : len);
SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);
@ -402,13 +397,11 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
dic[dicPos++] = dic[pos];
if (++pos == dicBufSize)
pos = 0;
} while (--curLen != 0);
}
while (--curLen != 0);
}
}
}
}
while (dicPos < limit && buf < bufLimit);
}
}
} while (dicPos < limit && buf < bufLimit);
NORMALIZE;
p->buf = buf;
p->range = range;
@ -466,8 +459,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte
if (p->processedPos >= p->prop.dicSize)
p->checkDicSize = p->prop.dicSize;
LzmaDec_WriteRem(p, limit);
}
while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
} while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
if (p->remainLen > kMatchSpecLenStart)
{
@ -531,13 +523,12 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
bit = (matchByte & offs);
probLit = prob + offs + bit + symbol;
GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
}
while (symbol < 0x100);
} while (symbol < 0x100);
}
res = DUMMY_LIT;
}
else
{
else
{
unsigned len;
UPDATE_1_CHECK;
@ -549,8 +540,8 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
prob = probs + LenCoder;
res = DUMMY_MATCH;
}
else
{
else
{
UPDATE_1_CHECK;
res = DUMMY_REP;
prob = probs + IsRepG0 + state;
@ -593,7 +584,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
}
state = kNumStates;
prob = probs + RepLenCoder;
}
}
{
unsigned limit, offset;
CLzmaProb *probLen = prob + LenChoice;
@ -627,8 +618,8 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
len += offset;
}
if (state < 4)
{
if (state < 4)
{
unsigned posSlot;
prob = probs + PosSlot +
((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
@ -653,8 +644,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
range >>= 1;
code -= range & (((code - range) >> 31) - 1);
/* if (code >= range) code -= range; */
}
while (--numDirectBits != 0);
} while (--numDirectBits != 0);
prob = probs + Align;
numDirectBits = kNumAlignBits;
}
@ -663,18 +653,16 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
do
{
GET_BIT_CHECK(prob + i, i);
}
while (--numDirectBits != 0);
}
}
} while (--numDirectBits != 0);
}
}
}
}
}
NORMALIZE_CHECK;
return res;
}
static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
{
p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);

View file

@ -66,11 +66,11 @@ void LzmaEncProps_Normalize(CLzmaEncProps *p)
if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);
if (p->numThreads < 0)
p->numThreads =
#ifndef _7ZIP_ST
#ifndef _7ZIP_ST
((p->btMode && p->algo) ? 2 : 1);
#else
#else
1;
#endif
#endif
}
UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
@ -83,7 +83,6 @@ UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
/* #define LZMA_LOG_BSR */
/* Define it for Intel's CPU */
#ifdef LZMA_LOG_BSR
#define kDicLogSizeMaxCompress 30
@ -126,7 +125,7 @@ void LzmaEnc_FastPosInit(Byte *g_FastPos)
#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \
p->g_FastPos[pos >> 6] + 12 : \
p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }
*/
*/
#define GetPosSlot1(pos) p->g_FastPos[pos]
#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
@ -134,7 +133,6 @@ void LzmaEnc_FastPosInit(Byte *g_FastPos)
#endif
#define LZMA_NUM_REPS 4
typedef unsigned CState;
@ -163,7 +161,6 @@ typedef struct
#define kDicLogSizeMax 32
#define kDistTableSizeMax (kDicLogSizeMax * 2)
#define kNumAlignBits 4
#define kAlignTableSize (1 << kNumAlignBits)
#define kAlignMask (kAlignTableSize - 1)
@ -186,7 +183,6 @@ typedef struct
#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)
#define kLenNumLowBits 3
#define kLenNumLowSymbols (1 << kLenNumLowBits)
#define kLenNumMidBits 3
@ -259,16 +255,16 @@ typedef struct
IMatchFinder matchFinder;
void *matchFinderObj;
#ifndef _7ZIP_ST
#ifndef _7ZIP_ST
Bool mtMode;
CMatchFinderMt matchFinderMt;
#endif
#endif
CMatchFinder matchFinderBase;
#ifndef _7ZIP_ST
#ifndef _7ZIP_ST
Byte pad[128];
#endif
#endif
UInt32 optimumEndIndex;
UInt32 optimumCurrentIndex;
@ -278,9 +274,9 @@ typedef struct
UInt32 numAvail;
COptimal opt[kNumOpts];
#ifndef LZMA_LOG_BSR
#ifndef LZMA_LOG_BSR
Byte g_FastPos[1 << kNumLogBits];
#endif
#endif
UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];
@ -428,7 +424,7 @@ SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
p->writeEndMark = props.writeEndMark;
#ifndef _7ZIP_ST
#ifndef _7ZIP_ST
/*
if (newMultiThread != _multiThread)
{
@ -437,15 +433,15 @@ SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
}
*/
p->multiThread = (props.numThreads > 1);
#endif
#endif
return SZ_OK;
}
static const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
static const int kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
static const int kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
static const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
static const int kLiteralNextStates[kNumStates] = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
static const int kMatchNextStates[kNumStates] = { 7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10 };
static const int kRepNextStates[kNumStates] = { 8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11 };
static const int kShortRepNextStates[kNumStates] = { 9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11 };
#define IsCharState(s) ((s) < 7)
@ -519,8 +515,7 @@ static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
if (buf == p->bufLim)
RangeEnc_FlushStream(p);
temp = 0xFF;
}
while (--p->cacheSize != 0);
} while (--p->cacheSize != 0);
p->cache = (Byte)((UInt32)p->low >> 24);
}
p->cacheSize++;
@ -545,8 +540,7 @@ static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)
p->range <<= 8;
RangeEnc_ShiftLow(p);
}
}
while (numBits != 0);
} while (numBits != 0);
}
static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)
@ -579,8 +573,7 @@ static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)
{
RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);
symbol <<= 1;
}
while (symbol < 0x10000);
} while (symbol < 0x10000);
}
static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)
@ -593,8 +586,7 @@ static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol,
RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);
symbol <<= 1;
offs &= ~(matchByte ^ symbol);
}
while (symbol < 0x10000);
} while (symbol < 0x10000);
}
void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
@ -620,7 +612,6 @@ void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
}
}
#define GET_PRICE(prob, symbol) \
p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
@ -641,8 +632,7 @@ static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *Pro
{
price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);
symbol <<= 1;
}
while (symbol < 0x10000);
} while (symbol < 0x10000);
return price;
}
@ -657,12 +647,10 @@ static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt
price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);
symbol <<= 1;
offs &= ~(matchByte ^ symbol);
}
while (symbol < 0x10000);
} while (symbol < 0x10000);
return price;
}
static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
{
UInt32 m = 1;
@ -717,7 +705,6 @@ static UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, U
return price;
}
static void LenEnc_Init(CLenEnc *p)
{
unsigned i;
@ -797,15 +784,12 @@ static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32
LenPriceEnc_UpdateTable(p, posState, ProbPrices);
}
static void MovePos(CLzmaEnc *p, UInt32 num)
{
#ifdef SHOW_STAT
#ifdef SHOW_STAT
ttt += num;
printf("\n MovePos %d", num);
#endif
#endif
if (num != 0)
{
p->additionalOffset += num;
@ -818,7 +802,7 @@ static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
UInt32 lenRes = 0, numPairs;
p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);
#ifdef SHOW_STAT
#ifdef SHOW_STAT
printf("\n i = %d numPairs = %d ", ttt, numPairs / 2);
ttt++;
{
@ -826,7 +810,7 @@ static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
for (i = 0; i < numPairs; i += 2)
printf("%2d %6d | ", p->matches[i], p->matches[i + 1]);
}
#endif
#endif
if (numPairs > 0)
{
lenRes = p->matches[numPairs - 2];
@ -848,7 +832,6 @@ static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
return lenRes;
}
#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;
#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;
#define IsShortRep(p) ((p)->backPrev == 0)
@ -917,8 +900,7 @@ static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)
p->opt[posPrev].posPrev = cur;
cur = posPrev;
}
}
while (cur != 0);
} while (cur != 0);
*backRes = p->opt[0].backPrev;
p->optimumCurrentIndex = p->opt[0].posPrev;
return p->optimumCurrentIndex;
@ -1065,8 +1047,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
opt->backPrev = i;
opt->prev1IsChar = False;
}
}
while (--repLen >= 2);
} while (--repLen >= 2);
}
normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);
@ -1077,7 +1058,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
UInt32 offs = 0;
while (len > matches[offs])
offs += 2;
for (; ; len++)
for (;; len++)
{
COptimal *opt;
UInt32 distance = matches[offs + 1];
@ -1111,7 +1092,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
cur = 0;
#ifdef SHOW_STAT2
#ifdef SHOW_STAT2
if (position >= 0)
{
unsigned i;
@ -1119,7 +1100,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
for (i = cur; i <= lenEnd; i++)
printf("\nprice[%4X] = %d", position - cur + i, p->opt[i].price);
}
#endif
#endif
for (;;)
{
@ -1331,8 +1312,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
opt->backPrev = repIndex;
opt->prev1IsChar = False;
}
}
while (--lenTest >= 2);
} while (--lenTest >= 2);
lenTest = lenTestTemp;
if (repIndex == 0)
@ -1407,7 +1387,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
offs += 2;
curBack = matches[offs + 1];
GetPosSlot2(curBack, posSlot);
for (lenTest = /*2*/ startLen; ; lenTest++)
for (lenTest = /*2*/ startLen;; lenTest++)
{
UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];
UInt32 lenToPosState = GetLenToPosState(lenTest);
@ -1677,10 +1657,10 @@ void LzmaEnc_Construct(CLzmaEnc *p)
{
RangeEnc_Construct(&p->rc);
MatchFinder_Construct(&p->matchFinderBase);
#ifndef _7ZIP_ST
#ifndef _7ZIP_ST
MatchFinderMt_Construct(&p->matchFinderMt);
p->matchFinderMt.MatchFinder = &p->matchFinderBase;
#endif
#endif
{
CLzmaEncProps props;
@ -1688,9 +1668,9 @@ void LzmaEnc_Construct(CLzmaEnc *p)
LzmaEnc_SetProps(p, &props);
}
#ifndef LZMA_LOG_BSR
#ifndef LZMA_LOG_BSR
LzmaEnc_FastPosInit(p->g_FastPos);
#endif
#endif
LzmaEnc_InitPriceTables(p->ProbPrices);
p->litProbs = 0;
@ -1716,9 +1696,9 @@ void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
{
#ifndef _7ZIP_ST
#ifndef _7ZIP_ST
MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
#endif
#endif
MatchFinder_Free(&p->matchFinderBase, allocBig);
LzmaEnc_FreeLits(p, alloc);
RangeEnc_Free(&p->rc, alloc);
@ -1771,9 +1751,9 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize
else
len = GetOptimum(p, nowPos32, &pos);
#ifdef SHOW_STAT2
#ifdef SHOW_STAT2
printf("\n pos = %4X, len = %d pos = %d", nowPos32, len, pos);
#endif
#endif
posState = nowPos32 & p->pbMask;
if (len == 1 && pos == (UInt32)-1)
@ -1901,9 +1881,9 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, I
if (!RangeEnc_Alloc(&p->rc, alloc))
return SZ_ERROR_MEM;
btMode = (p->matchFinderBase.btMode != 0);
#ifndef _7ZIP_ST
#ifndef _7ZIP_ST
p->mtMode = (p->multiThread && !p->fastMode && btMode);
#endif
#endif
{
unsigned lclp = p->lc + p->lp;
@ -1926,7 +1906,7 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, I
if (beforeSize + p->dictSize < keepWindowSize)
beforeSize = keepWindowSize - p->dictSize;
#ifndef _7ZIP_ST
#ifndef _7ZIP_ST
if (p->mtMode)
{
RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));
@ -1934,7 +1914,7 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, I
MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
}
else
#endif
#endif
{
if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))
return SZ_ERROR_MEM;
@ -1948,12 +1928,11 @@ void LzmaEnc_Init(CLzmaEnc *p)
{
UInt32 i;
p->state = 0;
for (i = 0 ; i < LZMA_NUM_REPS; i++)
for (i = 0; i < LZMA_NUM_REPS; i++)
p->reps[i] = 0;
RangeEnc_Init(&p->rc);
for (i = 0; i < kNumStates; i++)
{
UInt32 j;
@ -2073,13 +2052,13 @@ SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
void LzmaEnc_Finish(CLzmaEncHandle pp)
{
#ifndef _7ZIP_ST
#ifndef _7ZIP_ST
CLzmaEnc *p = (CLzmaEnc *)pp;
if (p->mtMode)
MatchFinderMt_ReleaseStream(&p->matchFinderMt);
#else
#else
//pp = pp;
#endif
#endif
}
typedef struct
@ -2104,7 +2083,6 @@ static size_t MyWrite(void *pp, const void *data, size_t size)
return size;
}
UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
{
const CLzmaEnc *p = (CLzmaEnc *)pp;
@ -2155,12 +2133,12 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
{
SRes res = SZ_OK;
#ifndef _7ZIP_ST
#ifndef _7ZIP_ST
Byte allocaDummy[0x300];
int i = 0;
for (i = 0; i < 16; i++)
allocaDummy[i] = (Byte)i;
#endif
#endif
for (;;)
{

View file

@ -500,7 +500,6 @@ VOID
// Special usage of 'next'
//
mNext[LoopVar4] = mPos;
}
/**
@ -914,7 +913,6 @@ IN UINT32 x
mSubBitBuf |= x << (mBitCount -= LoopVar8);
}
else {
Temp = (UINT8)(mSubBitBuf | (x >> (LoopVar8 -= mBitCount)));
if (mDst < mDstUpperLimit) {
*mDst++ = Temp;
@ -925,7 +923,6 @@ IN UINT32 x
mSubBitBuf = x << (mBitCount = UINT8_BIT - LoopVar8);
}
else {
Temp = (UINT8)(x >> (LoopVar8 - UINT8_BIT));
if (mDst < mDstUpperLimit) {
*mDst++ = Temp;
@ -1031,7 +1028,7 @@ VOID
}
}
else {
ASSERT((LoopVar3 + 2)<(2 * NT - 1));
ASSERT((LoopVar3 + 2) < (2 * NT - 1));
mTFreq[LoopVar3 + 2]++;
}
}
@ -1135,7 +1132,7 @@ VOID
}
}
else {
ASSERT((LoopVar3 + 2)<NPT);
ASSERT((LoopVar3 + 2) < NPT);
PutBits(mPTLen[LoopVar3 + 2], mPTCode[LoopVar3 + 2]);
}
}
@ -1456,7 +1453,6 @@ IN OUT UINT64 *DstSize
*DstSize = mCompSize + 1 + 8;
return EFI_SUCCESS;
}
}
UINT8 EfiCompress(CONST VOID* SrcBuffer, CONST UINT64 SrcSize, VOID* DstBuffer, UINT64* DstSize)

View file

@ -12,11 +12,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
TianoCompress.h
TianoCompress.h
Abstract:
Header file for compression routine.
Header file for compression routine.
*/
@ -32,13 +32,13 @@ Abstract:
extern "C" {
#endif
/*++
/*++
Routine Description:
Routine Description:
Tiano compression routine.
Arguments:
Arguments:
SrcBuffer - The buffer storing the source data
SrcSize - The size of source data
@ -46,7 +46,7 @@ Arguments:
DstSize - On input, the size of DstBuffer; On output,
the size of the actual compressed data.
Returns:
Returns:
EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. this case,
DstSize contains the size needed.
@ -54,23 +54,23 @@ Returns:
EFI_OUT_OF_RESOURCES - No resource to complete function.
EFI_INVALID_PARAMETER - Parameter supplied is wrong.
--*/
UINT8
TianoCompress (
--*/
UINT8
TianoCompress(
CONST VOID *SrcBuffer,
CONST UINT64 SrcSize,
VOID *DstBuffer,
UINT64 *DstSize
)
;
;
/*++
/*++
Routine Description:
Routine Description:
EFI 1.1 compression routine.
Arguments:
Arguments:
SrcBuffer - The buffer storing the source data
SrcSize - The size of source data
@ -78,7 +78,7 @@ Arguments:
DstSize - On input, the size of DstBuffer; On output,
the size of the actual compressed data.
Returns:
Returns:
EFI_BUFFER_TOO_SMALL - The DstBuffer is too small. this case,
DstSize contains the size needed.
@ -86,15 +86,15 @@ Returns:
EFI_OUT_OF_RESOURCES - No resource to complete function.
EFI_INVALID_PARAMETER - Parameter supplied is wrong.
--*/
UINT8
EfiCompress (
--*/
UINT8
EfiCompress(
CONST VOID *SrcBuffer,
CONST UINT64 SrcSize,
VOID *DstBuffer,
UINT64 *DstSize
)
;
;
#ifdef __cplusplus
}

View file

@ -103,7 +103,6 @@ Returns: (VOID)
Sd->mBitBuf = (UINT32)(Sd->mBitBuf << NumOfBits);
while (NumOfBits > Sd->mBitCount) {
Sd->mBitBuf |= (UINT32)(Sd->mSubBitBuf << (NumOfBits = (UINT16)(NumOfBits - Sd->mBitCount)));
if (Sd->mCompSize > 0) {
@ -114,7 +113,6 @@ Returns: (VOID)
Sd->mSubBitBuf = 0;
Sd->mSubBitBuf = Sd->mSrcBase[Sd->mInBuf++];
Sd->mBitCount = 8;
}
else {
//
@ -122,7 +120,6 @@ Returns: (VOID)
//
Sd->mSubBitBuf = 0;
Sd->mBitCount = 8;
}
}
@ -270,7 +267,6 @@ BAD_TABLE - The table is corrupted.
Mask = (UINT16)(1U << (15 - TableBits));
for (Char = 0; Char < NumOfChar; Char++) {
Len = BitLen[Char];
if (Len == 0 || Len >= 17) {
continue;
@ -279,17 +275,14 @@ BAD_TABLE - The table is corrupted.
NextCode = (UINT16)(Start[Len] + Weight[Len]);
if (Len <= TableBits) {
for (Index = Start[Len]; Index < NextCode; Index++) {
// Check to prevent possible heap corruption
if (Index >= (UINT16)(1U << TableBits))
return (UINT16)BAD_TABLE;
Table[Index] = Char;
}
}
else {
Index3 = Start[Len];
Pointer = &Table[Index3 >> JuBits];
Index = (UINT16)(Len - TableBits);
@ -318,7 +311,6 @@ BAD_TABLE - The table is corrupted.
}
*Pointer = Char;
}
Start[Len] = NextCode;
@ -360,7 +352,6 @@ The position value decoded.
Mask = 1U << (BITBUFSIZ - 1 - 8);
do {
if (Sd->mBitBuf & Mask) {
Val = Sd->mRight[Val];
}
@ -443,7 +434,6 @@ BAD_TABLE - Table is corrupted.
Index = 0;
while (Index < Number) {
CharC = (UINT16)(Sd->mBitBuf >> (BITBUFSIZ - 3));
if (CharC == 7) {
@ -521,13 +511,11 @@ Returns: (VOID)
Index = 0;
while (Index < Number) {
CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];
if (CharC >= NT) {
Mask = 1U << (BITBUFSIZ - 1 - 8);
do {
if (Mask & Sd->mBitBuf) {
CharC = Sd->mRight[CharC];
}
@ -536,7 +524,6 @@ Returns: (VOID)
}
Mask >>= 1;
} while (CharC >= NT);
}
//
@ -545,7 +532,6 @@ Returns: (VOID)
FillBuf(Sd, Sd->mPTLen[CharC]);
if (CharC <= 2) {
if (CharC == 0) {
CharC = 1;
}
@ -559,12 +545,9 @@ Returns: (VOID)
while ((INT16)(--CharC) >= 0) {
Sd->mCLen[Index++] = 0;
}
}
else {
Sd->mCLen[Index++] = (UINT8)(CharC - 2);
}
}
@ -687,7 +670,6 @@ Returns: (VOID)
else {
Sd->mDstBase[Sd->mOutBuf++] = (UINT8)CharC;
}
}
else {
//

View file

@ -12,12 +12,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Decompress.h
Decompress.h
Abstract:
Header file for decompression routine.
Providing both EFI and Tiano decompress algorithms.
Header file for decompression routine.
Providing both EFI and Tiano decompress algorithms.
--*/
@ -32,108 +32,108 @@ Abstract:
extern "C" {
#endif
typedef struct {
typedef struct {
UINT32 CompSize;
UINT32 OrigSize;
} EFI_TIANO_HEADER;
} EFI_TIANO_HEADER;
EFI_STATUS
EFIAPI
EfiTianoGetInfo (
VOID *Source,
UINT32 SrcSize,
UINT32 *DstSize,
UINT32 *ScratchSize
)
/*++
EFI_STATUS
EFIAPI
EfiTianoGetInfo(
VOID *Source,
UINT32 SrcSize,
UINT32 *DstSize,
UINT32 *ScratchSize
)
/*++
Routine Description:
Routine Description:
The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.GetInfo().
The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.GetInfo().
Arguments:
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
DstSize - The size of destination buffer.
ScratchSize - The size of scratch buffer.
Returns:
Returns:
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
EFI_SUCCESS - The size of destination buffer and the size of scratch buffer are successfully retrieved.
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
;
--*/
;
EFI_STATUS
EFIAPI
EfiDecompress (
VOID *Source,
UINT32 SrcSize,
VOID *Destination,
UINT32 DstSize,
VOID *Scratch,
UINT32 ScratchSize
)
/*++
EFI_STATUS
EFIAPI
EfiDecompress(
VOID *Source,
UINT32 SrcSize,
VOID *Destination,
UINT32 DstSize,
VOID *Scratch,
UINT32 ScratchSize
)
/*++
Routine Description:
Routine Description:
The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.Decompress().
The implementation is same as that of EFI_DECOMPRESS_PROTOCOL.Decompress().
Arguments:
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
Returns:
EFI_SUCCESS - Decompression is successful
EFI_INVALID_PARAMETER - The source data is corrupted
EFI_SUCCESS - Decompression is successful
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
;
--*/
;
EFI_STATUS
EFIAPI
TianoDecompress (
VOID *Source,
UINT32 SrcSize,
VOID *Destination,
UINT32 DstSize,
VOID *Scratch,
UINT32 ScratchSize
)
/*++
EFI_STATUS
EFIAPI
TianoDecompress(
VOID *Source,
UINT32 SrcSize,
VOID *Destination,
UINT32 DstSize,
VOID *Scratch,
UINT32 ScratchSize
)
/*++
Routine Description:
Routine Description:
The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.Decompress().
The implementation is same as that of EFI_TIANO_DECOMPRESS_PROTOCOL.Decompress().
Arguments:
Arguments:
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
This - The protocol instance pointer
Source - The source buffer containing the compressed data.
SrcSize - The size of source buffer
Destination - The destination buffer to store the decompressed data
DstSize - The size of destination buffer.
Scratch - The buffer used internally by the decompress routine. This buffer is needed to store intermediate data.
ScratchSize - The size of scratch buffer.
Returns:
Returns:
EFI_SUCCESS - Decompression is successful
EFI_INVALID_PARAMETER - The source data is corrupted
EFI_SUCCESS - Decompression is successful
EFI_INVALID_PARAMETER - The source data is corrupted
--*/
;
--*/
;
#ifdef __cplusplus
}

View file

@ -41,7 +41,7 @@ int main(int argc, char *argv[])
}
else {
result = ERR_INVALID_PARAMETER;
std::cout << "UEFIExtract 0.2.1" << std::endl << std::endl <<
std::cout << "UEFIExtract 0.2.2" << std::endl << std::endl <<
"Usage: uefiextract imagefile\n" << std::endl;
}

View file

@ -41,10 +41,6 @@ typedef uint16_t CHAR16;
#define FALSE ((BOOLEAN)(0==1))
#endif
#ifndef NULL
#define NULL ((VOID *) 0)
#endif
#define ERR_SUCCESS 0
#define ERR_INVALID_PARAMETER 1
#define ERR_BUFFER_TOO_SMALL 2

View file

@ -51,7 +51,6 @@ typedef struct {
UINT16 ReservedZero; // Still unknown, zeros in all descriptors I have seen
} FLASH_DESCRIPTOR_MAP;
// Component section
// Flash parameters DWORD structure
typedef struct {

22
ffs.cpp
View file

@ -14,24 +14,24 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "ffs.h"
const UINT8 ffsAlignmentTable[] =
{0, 4, 7, 9, 10, 12, 15, 16};
{ 0, 4, 7, 9, 10, 12, 15, 16 };
UINT8 calculateChecksum8(UINT8* buffer, UINT32 bufferSize)
{
if(!buffer)
if (!buffer)
return 0;
UINT8 counter = 0;
while(bufferSize--)
while (bufferSize--)
counter += buffer[bufferSize];
return (UINT8) 0x100 - counter;
return (UINT8)0x100 - counter;
}
UINT16 calculateChecksum16(UINT16* buffer, UINT32 bufferSize)
{
if(!buffer)
if (!buffer)
return 0;
UINT16 counter = 0;
@ -40,17 +40,17 @@ UINT16 calculateChecksum16(UINT16* buffer, UINT32 bufferSize)
bufferSize /= sizeof(UINT16);
for (; index < bufferSize; index++) {
counter = (UINT16) (counter + buffer[index]);
counter = (UINT16)(counter + buffer[index]);
}
return (UINT16) 0x10000 - counter;
return (UINT16)0x10000 - counter;
}
VOID uint32ToUint24(UINT32 size, UINT8* ffsSize)
{
ffsSize[2] = (UINT8) ((size) >> 16);
ffsSize[1] = (UINT8) ((size) >> 8);
ffsSize[0] = (UINT8) ((size) );
ffsSize[2] = (UINT8)((size) >> 16);
ffsSize[1] = (UINT8)((size) >> 8);
ffsSize[0] = (UINT8)((size));
}
UINT32 uint24ToUint32(UINT8* ffsSize)
@ -62,7 +62,7 @@ UINT32 uint24ToUint32(UINT8* ffsSize)
QString guidToQString(const EFI_GUID& guid)
{
QByteArray baGuid = QByteArray::fromRawData((const char*) guid.Data, sizeof(EFI_GUID));
QByteArray baGuid = QByteArray::fromRawData((const char*)guid.Data, sizeof(EFI_GUID));
UINT32 i32 = *(UINT32*)baGuid.left(4).constData();
UINT16 i16_0 = *(UINT16*)baGuid.mid(4, 2).constData();
UINT16 i16_1 = *(UINT16*)baGuid.mid(6, 2).constData();

2
ffs.h
View file

@ -97,6 +97,8 @@ 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
("\xAD\xEE\xAD\x04\xFF\x61\x31\x4D\xB6\xBA\x64\xF8\xBF\x90\x1F\x5A", 16);
const QByteArray EFI_APPLE_BOOT_VOLUME_FILE_SYSTEM2_GUID
("\x8C\x1B\x00\xBD\x71\x6A\x7B\x48\xA1\x4F\x0C\x2A\x2D\xCF\x7A\x5D", 16);
const QByteArray EFI_FIRMWARE_FILE_SYSTEM2_GUID
("\x78\xE5\x8C\x8C\x3D\x8A\x1C\x4F\x99\x35\x89\x61\x85\xC3\x2D\xD3", 16);

View file

@ -171,7 +171,7 @@ QString errorMessage(UINT8 errorCode)
}
FfsEngine::FfsEngine(QObject *parent)
: QObject(parent)
: QObject(parent)
{
model = new TreeModel();
oldPeiCoreEntryPoint = 0;
@ -606,6 +606,11 @@ UINT8 FfsEngine::parsePdrRegion(const QByteArray & pdr, QModelIndex & index, con
// Add tree item
index = model->addItem(Types::Region, Subtypes::PdrRegion, COMPRESSION_ALGORITHM_NONE, name, "", info, QByteArray(), pdr, QByteArray(), parent, mode);
// Parse PDR region as BIOS space
UINT8 result = parseBios(pdr, index);
if (result && result != ERR_VOLUMES_NOT_FOUND)
return result;
return ERR_SUCCESS;
}
@ -737,7 +742,6 @@ UINT8 FfsEngine::parseBios(const QByteArray & bios, const QModelIndex & parent)
}
break;
}
}
return ERR_SUCCESS;
@ -817,6 +821,10 @@ UINT8 FfsEngine::parseVolume(const QByteArray & volume, QModelIndex & index, co
else if (QByteArray((const char*)&volumeHeader->FileSystemGuid, sizeof(EFI_GUID)) == EFI_APPLE_BOOT_VOLUME_FILE_SYSTEM_GUID) {
// Code can be added here
}
// Apple Boot Volume FFS GUID
else if (QByteArray((const char*)&volumeHeader->FileSystemGuid, sizeof(EFI_GUID)) == EFI_APPLE_BOOT_VOLUME_FILE_SYSTEM2_GUID) {
// Code can be added here
}
// FFS GUID v2
else if (QByteArray((const char*)&volumeHeader->FileSystemGuid, sizeof(EFI_GUID)) == EFI_FIRMWARE_FILE_SYSTEM2_GUID) {
// Code can be added here
@ -976,7 +984,7 @@ UINT8 FfsEngine::parseFile(const QByteArray & file, QModelIndex & index, const U
EFI_FFS_FILE_HEADER* tempFileHeader = (EFI_FFS_FILE_HEADER*)(tempHeader.data());
tempFileHeader->IntegrityCheck.Checksum.Header = 0;
tempFileHeader->IntegrityCheck.Checksum.File = 0;
UINT8 calculated = calculateChecksum8((UINT8*)tempFileHeader, sizeof(EFI_FFS_FILE_HEADER)-1);
UINT8 calculated = calculateChecksum8((UINT8*)tempFileHeader, sizeof(EFI_FFS_FILE_HEADER) - 1);
if (fileHeader->IntegrityCheck.Checksum.Header != calculated)
{
msg(tr("parseFile: %1, stored header checksum %2 differs from calculated %3")
@ -1504,12 +1512,12 @@ UINT8 FfsEngine::create(const QModelIndex & index, const UINT8 type, const QByte
// Correct file size
UINT8 tailSize = fileHeader->Attributes & FFS_ATTRIB_TAIL_PRESENT ? sizeof(UINT16) : 0;
uint32ToUint24(sizeof(EFI_FFS_FILE_HEADER)+body.size() + tailSize, fileHeader->Size);
uint32ToUint24(sizeof(EFI_FFS_FILE_HEADER) + body.size() + tailSize, fileHeader->Size);
// Recalculate header checksum
fileHeader->IntegrityCheck.Checksum.Header = 0;
fileHeader->IntegrityCheck.Checksum.File = 0;
fileHeader->IntegrityCheck.Checksum.Header = calculateChecksum8((UINT8*)fileHeader, sizeof(EFI_FFS_FILE_HEADER)-1);
fileHeader->IntegrityCheck.Checksum.Header = calculateChecksum8((UINT8*)fileHeader, sizeof(EFI_FFS_FILE_HEADER) - 1);
// Recalculate data checksum, if needed
if (fileHeader->Attributes & FFS_ATTRIB_CHECKSUM)
@ -1760,7 +1768,6 @@ UINT8 FfsEngine::replace(const QModelIndex & index, const QByteArray & object, c
return ERR_SUCCESS;
}
UINT8 FfsEngine::extract(const QModelIndex & index, QByteArray & extracted, const UINT8 mode)
{
if (!index.isValid())
@ -2085,7 +2092,7 @@ UINT8 FfsEngine::constructPadFile(const QByteArray &guid, const UINT32 size, con
// Calculate header checksum
header->IntegrityCheck.Checksum.Header = 0;
header->IntegrityCheck.Checksum.File = 0;
header->IntegrityCheck.Checksum.Header = calculateChecksum8((UINT8*)header, sizeof(EFI_FFS_FILE_HEADER)-1);
header->IntegrityCheck.Checksum.Header = calculateChecksum8((UINT8*)header, sizeof(EFI_FFS_FILE_HEADER) - 1);
// Set data checksum
if (revision == 1)
@ -2136,7 +2143,7 @@ UINT8 FfsEngine::reconstructIntelImage(const QModelIndex& index, QByteArray& rec
UINT32 offset = descriptor.size();
// Reconstruct other regions
char empty = '\xFF'; //!TODO: determine empty char using one of reserved descriptor fields
char empty = '\xFF';
for (int i = 1; i < model->rowCount(index); i++) {
QByteArray region;
result = reconstructRegion(index.child(i, 0), region);
@ -2280,7 +2287,6 @@ UINT8 FfsEngine::reconstructVolume(const QModelIndex & index, QByteArray & recon
}
else if (model->action(index) == Actions::Rebuild) {
//!TODO: add check for weak aligned volume
//!TODO: better return codes
QByteArray header = model->header(index);
EFI_FIRMWARE_VOLUME_HEADER* volumeHeader = (EFI_FIRMWARE_VOLUME_HEADER*)header.data();
@ -2311,7 +2317,7 @@ UINT8 FfsEngine::reconstructVolume(const QModelIndex & index, QByteArray & recon
// VTF found
if (file.left(sizeof(EFI_GUID)) == EFI_FFS_VOLUME_TOP_FILE_GUID) {
baseFound = true;
volumeBase = (UINT32) (0x100000000 - volumeSize);
volumeBase = (UINT32)(0x100000000 - volumeSize);
break;
}
}
@ -2631,7 +2637,7 @@ UINT8 FfsEngine::reconstructFile(const QModelIndex& index, const UINT8 revision,
}
// Calculate section base
UINT32 sectionBase = base ? base + sizeof(EFI_FFS_FILE_HEADER)+offset : 0;
UINT32 sectionBase = base ? base + sizeof(EFI_FFS_FILE_HEADER) + offset : 0;
// Reconstruct section
QByteArray section;
@ -2654,13 +2660,12 @@ UINT8 FfsEngine::reconstructFile(const QModelIndex& index, const UINT8 revision,
// Correct file size
UINT8 tailSize = (fileHeader->Attributes & FFS_ATTRIB_TAIL_PRESENT) ? sizeof(UINT16) : 0;
uint32ToUint24(sizeof(EFI_FFS_FILE_HEADER)+reconstructed.size() + tailSize, fileHeader->Size);
uint32ToUint24(sizeof(EFI_FFS_FILE_HEADER) + reconstructed.size() + tailSize, fileHeader->Size);
// Recalculate header checksum
fileHeader->IntegrityCheck.Checksum.Header = 0;
fileHeader->IntegrityCheck.Checksum.File = 0;
fileHeader->IntegrityCheck.Checksum.Header = calculateChecksum8((UINT8*)fileHeader, sizeof(EFI_FFS_FILE_HEADER)-1);
fileHeader->IntegrityCheck.Checksum.Header = calculateChecksum8((UINT8*)fileHeader, sizeof(EFI_FFS_FILE_HEADER) - 1);
}
// Use current file body
else
@ -2818,7 +2823,6 @@ UINT8 FfsEngine::reconstructSection(const QModelIndex& index, const UINT32 base,
(model->subtype(index.parent()) == EFI_FV_FILETYPE_PEI_CORE ||
model->subtype(index.parent()) == EFI_FV_FILETYPE_PEIM ||
model->subtype(index.parent()) == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER)) {
if (base) {
result = rebase(reconstructed, base + header.size());
if (result) {
@ -2929,7 +2933,6 @@ UINT8 FfsEngine::growVolume(QByteArray & header, const UINT32 size, UINT32 & new
return ERR_INVALID_VOLUME;
// Case of complex blockMap
//!TODO: implement this case
if (blockMapCount > 2)
return ERR_COMPLEX_BLOCK_MAP;
@ -3002,7 +3005,7 @@ UINT8 FfsEngine::findHexPattern(const QModelIndex & index, const QByteArray & he
.arg(hexBody.mid(offset, hexPattern.length()))
.arg(model->nameString(index))
.arg(mode == SEARCH_MODE_BODY ? tr("body") : tr("header"))
.arg(offset/2, 8, 16, QChar('0')),
.arg(offset / 2, 8, 16, QChar('0')),
index);
}
offset = regexp.indexIn(hexBody, offset + 1);
@ -3574,7 +3577,7 @@ UINT8 FfsEngine::patchViaPattern(QByteArray & data, const QByteArray & hexFindPa
INT32 offset = regexp.indexIn(hexBody);
while (offset >= 0) {
if (offset % 2 == 0) {
UINT8 result = patchViaOffset(body, offset/2, hexReplacePattern);
UINT8 result = patchViaOffset(body, offset / 2, hexReplacePattern);
if (result)
return result;
}

4
gbe.h
View file

@ -26,8 +26,8 @@ typedef struct {
#define GBE_VERSION_OFFSET 10
typedef struct {
UINT8 id: 4;
UINT8 minor: 4;
UINT8 id : 4;
UINT8 minor : 4;
UINT8 major;
} GBE_VERSION;

View file

@ -9,7 +9,7 @@
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
*/
#include "messagelistitem.h"
@ -33,7 +33,6 @@ MessageListItem::MessageListItem(const QIcon & icon, const QString & text, QList
MessageListItem::~MessageListItem()
{
}
QModelIndex MessageListItem::index() const

View file

@ -9,7 +9,7 @@
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 __MESSAGELISTITEM_H__
#define __MESSAGELISTITEM_H__

View file

@ -27,7 +27,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
//
// PE32+ Machine type for EFI images
//
@ -517,7 +516,6 @@ typedef struct {
//
#define EFI_IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
//
// DLL Support
//
@ -573,7 +571,6 @@ typedef struct {
EFI_IMAGE_THUNK_DATA *FirstThunk;
} EFI_IMAGE_IMPORT_DESCRIPTOR;
//
// Debug Directory Format
//
@ -620,7 +617,6 @@ typedef struct {
//
} EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY;
//
// Debug Data Structure defined by Apple Mach-O to COFF utility.
//
@ -654,16 +650,16 @@ typedef struct {
typedef struct {
union {
struct {
UINT32 NameOffset:31;
UINT32 NameIsString:1;
UINT32 NameOffset : 31;
UINT32 NameIsString : 1;
} s;
UINT32 Id;
} u1;
union {
UINT32 OffsetToData;
struct {
UINT32 OffsetToDirectory:31;
UINT32 DataIsDirectory:1;
UINT32 OffsetToDirectory : 31;
UINT32 DataIsDirectory : 1;
} s;
} u2;
} EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY;

View file

@ -9,15 +9,15 @@
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
*/
#include "searchdialog.h"
SearchDialog::SearchDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SearchDialog),
hexValidator(QRegExp("([0-9a-fA-F\\.])*")),
guidValidator(QRegExp("[0-9a-fA-F\\.]{8}-[0-9a-fA-F\\.]{4}-[0-9a-fA-F\\.]{4}-[0-9a-fA-F\\.]{4}-[0-9a-fA-F\\.]{12}"))
QDialog(parent),
ui(new Ui::SearchDialog),
hexValidator(QRegExp("([0-9a-fA-F\\.])*")),
guidValidator(QRegExp("[0-9a-fA-F\\.]{8}-[0-9a-fA-F\\.]{4}-[0-9a-fA-F\\.]{4}-[0-9a-fA-F\\.]{4}-[0-9a-fA-F\\.]{12}"))
{
// Create UI
ui->setupUi(this);
@ -40,9 +40,10 @@ void SearchDialog::setEditFocus(int index)
{
if (index == 0) // Hex pattern
ui->hexEdit->setFocus();
else if (index == 1) // GUID
else if (index == 1) { // GUID
ui->guidEdit->setFocus();
ui->guidEdit->setCursorPosition(0);
}
else if (index == 2) // Text
ui->textEdit->setFocus();
}

View file

@ -9,7 +9,7 @@
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 SEARCHDIALOG_H
#define SEARCHDIALOG_H

View file

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>340</width>
<width>400</width>
<height>214</height>
</rect>
</property>

View file

@ -15,9 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "treeitem.h"
#include "types.h"
TreeItem::TreeItem(const UINT8 type, const UINT8 subtype, const UINT8 compression,
const QString & name, const QString & text, const QString & info,
const QByteArray & header, const QByteArray & body, const QByteArray & tail,
@ -95,7 +92,7 @@ int TreeItem::columnCount() const
QVariant TreeItem::data(int column) const
{
switch(column)
switch (column)
{
case 0: //Name
return itemName;
@ -206,7 +203,7 @@ void TreeItem::setAction(const UINT8 action)
// On insert action, set insert action for children
if (action == Actions::Insert)
for(int i = 0; i < childCount(); i++)
for (int i = 0; i < childCount(); i++)
child(i)->setAction(Actions::Insert);
// Set rebuild action for parent, if it has no action now

View file

@ -61,7 +61,7 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch(section)
switch (section)
{
case 0:
return tr("Name");
@ -132,7 +132,7 @@ int TreeModel::rowCount(const QModelIndex &parent) const
UINT8 TreeModel::type(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return 0;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->type();
@ -140,7 +140,7 @@ UINT8 TreeModel::type(const QModelIndex &index) const
UINT8 TreeModel::subtype(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return 0;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->subtype();
@ -148,7 +148,7 @@ UINT8 TreeModel::subtype(const QModelIndex &index) const
QByteArray TreeModel::header(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return QByteArray();
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->header();
@ -156,7 +156,7 @@ QByteArray TreeModel::header(const QModelIndex &index) const
bool TreeModel::hasEmptyHeader(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return true;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->hasEmptyHeader();
@ -164,7 +164,7 @@ bool TreeModel::hasEmptyHeader(const QModelIndex &index) const
QByteArray TreeModel::body(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return QByteArray();
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->body();
@ -172,7 +172,7 @@ QByteArray TreeModel::body(const QModelIndex &index) const
bool TreeModel::hasEmptyBody(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return true;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->hasEmptyBody();
@ -180,7 +180,7 @@ bool TreeModel::hasEmptyBody(const QModelIndex &index) const
QByteArray TreeModel::tail(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return QByteArray();
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->tail();
@ -188,7 +188,7 @@ QByteArray TreeModel::tail(const QModelIndex &index) const
bool TreeModel::hasEmptyTail(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return true;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->hasEmptyTail();
@ -196,7 +196,7 @@ bool TreeModel::hasEmptyTail(const QModelIndex &index) const
QString TreeModel::info(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return QString();
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->info();
@ -204,7 +204,7 @@ QString TreeModel::info(const QModelIndex &index) const
UINT8 TreeModel::action(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return Actions::NoAction;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->action();
@ -212,7 +212,7 @@ UINT8 TreeModel::action(const QModelIndex &index) const
UINT8 TreeModel::compression(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return COMPRESSION_ALGORITHM_UNKNOWN;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->compression();
@ -220,7 +220,7 @@ UINT8 TreeModel::compression(const QModelIndex &index) const
void TreeModel::setSubtype(const QModelIndex & index, UINT8 subtype)
{
if(!index.isValid())
if (!index.isValid())
return;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
@ -230,7 +230,7 @@ void TreeModel::setSubtype(const QModelIndex & index, UINT8 subtype)
void TreeModel::setNameString(const QModelIndex &index, const QString &data)
{
if(!index.isValid())
if (!index.isValid())
return;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
@ -240,7 +240,7 @@ void TreeModel::setNameString(const QModelIndex &index, const QString &data)
void TreeModel::setTypeString(const QModelIndex &index, const QString &data)
{
if(!index.isValid())
if (!index.isValid())
return;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
@ -250,7 +250,7 @@ void TreeModel::setTypeString(const QModelIndex &index, const QString &data)
void TreeModel::setSubtypeString(const QModelIndex &index, const QString &data)
{
if(!index.isValid())
if (!index.isValid())
return;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
@ -260,7 +260,7 @@ void TreeModel::setSubtypeString(const QModelIndex &index, const QString &data)
void TreeModel::setTextString(const QModelIndex &index, const QString &data)
{
if(!index.isValid())
if (!index.isValid())
return;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
@ -270,7 +270,7 @@ void TreeModel::setTextString(const QModelIndex &index, const QString &data)
QString TreeModel::nameString(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return QString();
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
@ -279,15 +279,16 @@ QString TreeModel::nameString(const QModelIndex &index) const
QString TreeModel::actionString(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return QString();
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->data(1).toString();}
return item->data(1).toString();
}
QString TreeModel::typeString(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return QString();
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
@ -296,7 +297,7 @@ QString TreeModel::typeString(const QModelIndex &index) const
QString TreeModel::subtypeString(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return QString();
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
@ -305,22 +306,21 @@ QString TreeModel::subtypeString(const QModelIndex &index) const
QString TreeModel::textString(const QModelIndex &index) const
{
if(!index.isValid())
if (!index.isValid())
return QString();
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->data(4).toString();
}
void TreeModel::setAction(const QModelIndex &index, const UINT8 action)
{
if(!index.isValid())
if (!index.isValid())
return;
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
item->setAction(action);
emit dataChanged(this->index(0,0), index);
emit dataChanged(this->index(0, 0), index);
}
QModelIndex TreeModel::addItem(const UINT8 type, const UINT8 subtype, const UINT8 compression,
@ -376,13 +376,13 @@ QModelIndex TreeModel::addItem(const UINT8 type, const UINT8 subtype, const UINT
QModelIndex TreeModel::findParentOfType(const QModelIndex& index, UINT8 type) const
{
if(!index.isValid())
if (!index.isValid())
return QModelIndex();
TreeItem *item;
QModelIndex parent = index;
for(item = static_cast<TreeItem*>(parent.internalPointer());
for (item = static_cast<TreeItem*>(parent.internalPointer());
item != NULL && item != rootItem && item->type() != type;
item = static_cast<TreeItem*>(parent.internalPointer()))
parent = parent.parent();

View file

@ -116,7 +116,6 @@ QString compressionTypeToQString(UINT8 algorithm)
}
}
QString actionTypeToQString(UINT8 action)
{
switch (action) {
@ -138,4 +137,3 @@ QString actionTypeToQString(UINT8 action)
return QObject::tr("Unknown");
}
}

View file

@ -9,14 +9,14 @@
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
*/
#include "uefitool.h"
#include "ui_uefitool.h"
UEFITool::UEFITool(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::UEFITool)
QMainWindow(parent),
ui(new Ui::UEFITool)
{
clipboard = QApplication::clipboard();
@ -48,6 +48,9 @@ UEFITool::UEFITool(QWidget *parent) :
// Enable Drag-and-Drop actions
this->setAcceptDrops(true);
// Set current directory
currentDir = ".";
// Initialize non-persistent data
init();
@ -152,6 +155,7 @@ void UEFITool::search()
}
else if (index == 1) { // GUID
searchDialog->ui->guidEdit->setFocus();
searchDialog->ui->guidEdit->setCursorPosition(0);
QByteArray pattern = searchDialog->ui->guidEdit->text().toLatin1();
if (pattern.isEmpty())
return;
@ -217,11 +221,11 @@ void UEFITool::insert(const UINT8 mode)
QString path;
switch (type) {
case Types::Volume:
path = QFileDialog::getOpenFileName(this, tr("Select FFS file to insert"),".","FFS files (*.ffs *.bin);;All files (*.*)");
path = QFileDialog::getOpenFileName(this, tr("Select FFS file to insert"), currentDir, "FFS files (*.ffs *.bin);;All files (*.*)");
break;
case Types::File:
case Types::Section:
path = QFileDialog::getOpenFileName(this, tr("Select section file to insert"),".","Section files (*.sct *.bin);;All files (*.*)");
path = QFileDialog::getOpenFileName(this, tr("Select section file to insert"), currentDir, "Section files (*.sct *.bin);;All files (*.*)");
break;
default:
return;
@ -290,39 +294,39 @@ void UEFITool::replace(const UINT8 mode)
QString path;
if (model->type(index) == Types::Region) {
if (mode == REPLACE_MODE_AS_IS) {
path = QFileDialog::getOpenFileName(this, tr("Select region file to replace selected object"), ".", "Region files (*.rgn *.bin);;All files (*.*)");
path = QFileDialog::getOpenFileName(this, tr("Select region file to replace selected object"), currentDir, "Region files (*.rgn *.bin);;All files (*.*)");
}
else
return;
}
else if (model->type(index) == Types::File) {
if (mode == REPLACE_MODE_AS_IS) {
path = QFileDialog::getOpenFileName(this, tr("Select FFS file to replace selected object"),".","FFS files (*.ffs *.bin);;All files (*.*)");
path = QFileDialog::getOpenFileName(this, tr("Select FFS file to replace selected object"), currentDir, "FFS files (*.ffs *.bin);;All files (*.*)");
}
else if (mode == REPLACE_MODE_BODY) {
if (model->subtype(index) == EFI_FV_FILETYPE_ALL || model->subtype(index) == EFI_FV_FILETYPE_RAW)
path = QFileDialog::getOpenFileName(this, tr("Select raw file to replace body"),".","Raw files (*.raw *.bin);;All files (*.*)");
path = QFileDialog::getOpenFileName(this, tr("Select raw file to replace body"), currentDir, "Raw files (*.raw *.bin);;All files (*.*)");
else if (model->subtype(index) == EFI_FV_FILETYPE_PAD) // Pad file body can't be replaced
return;
else
path = QFileDialog::getOpenFileName(this, tr("Select FFS file body to replace body"),".","FFS file body files (*.fbd *.bin);;All files (*.*)");
path = QFileDialog::getOpenFileName(this, tr("Select FFS file body to replace body"), currentDir, "FFS file body files (*.fbd *.bin);;All files (*.*)");
}
else
return;
}
else if (model->type(index) == Types::Section) {
if (mode == REPLACE_MODE_AS_IS) {
path = QFileDialog::getOpenFileName(this, tr("Select section file to replace selected object"),".","Section files (*.sec *.bin);;All files (*.*)");
path = QFileDialog::getOpenFileName(this, tr("Select section file to replace selected object"), currentDir, "Section files (*.sec *.bin);;All files (*.*)");
}
else if (mode == REPLACE_MODE_BODY) {
if (model->subtype(index) == EFI_SECTION_COMPRESSION || model->subtype(index) == EFI_SECTION_GUID_DEFINED || model->subtype(index) == EFI_SECTION_DISPOSABLE)
path = QFileDialog::getOpenFileName(this, tr("Select FFS file body file to replace body"),".","FFS file body files (*.fbd *.bin);;All files (*.*)");
path = QFileDialog::getOpenFileName(this, tr("Select FFS file body file to replace body"), currentDir, "FFS file body files (*.fbd *.bin);;All files (*.*)");
else if (model->subtype(index) == EFI_SECTION_FIRMWARE_VOLUME_IMAGE)
path = QFileDialog::getOpenFileName(this, tr("Select volume file to replace body"),".","Volume files (*.vol *.bin);;All files (*.*)");
path = QFileDialog::getOpenFileName(this, tr("Select volume file to replace body"), currentDir, "Volume files (*.vol *.bin);;All files (*.*)");
else if (model->subtype(index) == EFI_SECTION_RAW)
path = QFileDialog::getOpenFileName(this, tr("Select raw file to replace body"),".","Raw files (*.raw *.bin);;All files (*.*)");
path = QFileDialog::getOpenFileName(this, tr("Select raw file to replace body"), currentDir, "Raw files (*.raw *.bin);;All files (*.*)");
else
path = QFileDialog::getOpenFileName(this, tr("Select file to replace body"),".","Binary files (*.bin);;All files (*.*)");
path = QFileDialog::getOpenFileName(this, tr("Select file to replace body"), currentDir, "Binary files (*.bin);;All files (*.*)");
}
else
return;
@ -381,59 +385,59 @@ void UEFITool::extract(const UINT8 mode)
if (mode == EXTRACT_MODE_AS_IS) {
switch (type) {
case Types::Capsule:
path = QFileDialog::getSaveFileName(this, tr("Save capsule to file"),".","Capsule files (*.cap *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save capsule to file"), currentDir, "Capsule files (*.cap *.bin);;All files (*.*)");
break;
case Types::Image:
path = QFileDialog::getSaveFileName(this, tr("Save image to file"),".","Image files (*.rom *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save image to file"), currentDir, "Image files (*.rom *.bin);;All files (*.*)");
break;
case Types::Region:
path = QFileDialog::getSaveFileName(this, tr("Save region to file"),".","Region files (*.rgn *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save region to file"), currentDir, "Region files (*.rgn *.bin);;All files (*.*)");
break;
case Types::Padding:
path = QFileDialog::getSaveFileName(this, tr("Save padding to file"),".","Padding files (*.pad *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save padding to file"), currentDir, "Padding files (*.pad *.bin);;All files (*.*)");
break;
case Types::Volume:
path = QFileDialog::getSaveFileName(this, tr("Save volume to file"),".","Volume files (*.vol *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save volume to file"), currentDir, "Volume files (*.vol *.bin);;All files (*.*)");
break;
case Types::File:
path = QFileDialog::getSaveFileName(this, tr("Save FFS file to file"),".","FFS files (*.ffs *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save FFS file to file"), currentDir, "FFS files (*.ffs *.bin);;All files (*.*)");
break;
case Types::Section:
path = QFileDialog::getSaveFileName(this, tr("Save section file to file"),".","Section files (*.sct *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save section file to file"), currentDir, "Section files (*.sct *.bin);;All files (*.*)");
break;
default:
path = QFileDialog::getSaveFileName(this, tr("Save object to file"),".","Binary files (*.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save object to file"), currentDir, "Binary files (*.bin);;All files (*.*)");
}
}
else if (mode == EXTRACT_MODE_BODY) {
switch (type) {
case Types::Capsule:
path = QFileDialog::getSaveFileName(this, tr("Save capsule body to image file"),".","Image files (*.rom *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save capsule body to image file"), currentDir, "Image files (*.rom *.bin);;All files (*.*)");
break;
case Types::File: {
if (model->subtype(index) == EFI_FV_FILETYPE_ALL || model->subtype(index) == EFI_FV_FILETYPE_RAW)
path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to raw file"),".","Raw files (*.raw *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to raw file"), currentDir, "Raw files (*.raw *.bin);;All files (*.*)");
else
path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to file"),".","FFS file body files (*.fbd *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to file"), currentDir, "FFS file body files (*.fbd *.bin);;All files (*.*)");
}
break;
case Types::Section: {
if (model->subtype(index) == EFI_SECTION_COMPRESSION || model->subtype(index) == EFI_SECTION_GUID_DEFINED || model->subtype(index) == EFI_SECTION_DISPOSABLE)
path = QFileDialog::getSaveFileName(this, tr("Save encapsulation section body to FFS body file"),".","FFS file body files (*.fbd *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save encapsulation section body to FFS body file"), currentDir, "FFS file body files (*.fbd *.bin);;All files (*.*)");
else if (model->subtype(index) == EFI_SECTION_FIRMWARE_VOLUME_IMAGE)
path = QFileDialog::getSaveFileName(this, tr("Save section body to volume file"),".","Volume files (*.vol *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save section body to volume file"), currentDir, "Volume files (*.vol *.bin);;All files (*.*)");
else if (model->subtype(index) == EFI_SECTION_RAW)
path = QFileDialog::getSaveFileName(this, tr("Save section body to raw file"),".","Raw files (*.raw *.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save section body to raw file"), currentDir, "Raw files (*.raw *.bin);;All files (*.*)");
else
path = QFileDialog::getSaveFileName(this, tr("Save section body to file"),".","Binary files (*.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save section body to file"), currentDir, "Binary files (*.bin);;All files (*.*)");
}
break;
default:
path = QFileDialog::getSaveFileName(this, tr("Save object to file"),".","Binary files (*.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save object to file"), currentDir, "Binary files (*.bin);;All files (*.*)");
}
}
else
path = QFileDialog::getSaveFileName(this, tr("Save object to file"),".","Binary files (*.bin);;All files (*.*)");
path = QFileDialog::getSaveFileName(this, tr("Save object to file"), currentDir, "Binary files (*.bin);;All files (*.*)");
if (path.trimmed().isEmpty())
return;
@ -480,7 +484,7 @@ void UEFITool::exit()
void UEFITool::saveImageFile()
{
QString path = QFileDialog::getSaveFileName(this, tr("Save BIOS image file"),".","BIOS image files (*.rom *.bin *.cap *.bio *.fd *.wph *.efi);;All files (*.*)");
QString path = QFileDialog::getSaveFileName(this, tr("Save BIOS image file"), currentDir, "BIOS image files (*.rom *.bin *.cap *.bio *.fd *.wph *.efi);;All files (*.*)");
if (path.isEmpty())
return;
@ -510,7 +514,7 @@ void UEFITool::saveImageFile()
void UEFITool::openImageFile()
{
QString path = QFileDialog::getOpenFileName(this, tr("Open BIOS image file"),".","BIOS image files (*.rom *.bin *.cap *.bio *.fd *.wph *.efi);;All files (*.*)");
QString path = QFileDialog::getOpenFileName(this, tr("Open BIOS image file"), currentDir, "BIOS image files (*.rom *.bin *.cap *.bio *.fd *.wph *.efi);;All files (*.*)");
openImageFile(path);
}
@ -547,6 +551,9 @@ void UEFITool::openImageFile(QString path)
// Enable search
ui->actionSearch->setEnabled(true);
// Set current directory
currentDir = fileInfo.absolutePath();
}
void UEFITool::copyMessage()
@ -610,16 +617,16 @@ void UEFITool::contextMenuEvent(QContextMenuEvent* event)
return;
}
if(!ui->structureTreeView->underMouse())
if (!ui->structureTreeView->underMouse())
return;
QPoint pt = event->pos();
QModelIndex index = ui->structureTreeView->indexAt(ui->structureTreeView->viewport()->mapFrom(this, pt));
if(!index.isValid())
if (!index.isValid())
return;
TreeModel* model = ffsEngine->treeModel();
switch(model->type(index))
switch (model->type(index))
{
case Types::Capsule:
ui->menuCapsuleActions->exec(event->globalPos());

View file

@ -9,7 +9,7 @@
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 __UEFITOOL_H__
#define __UEFITOOL_H__
@ -39,7 +39,7 @@
#include "searchdialog.h"
namespace Ui {
class UEFITool;
class UEFITool;
}
class UEFITool : public QMainWindow
@ -52,7 +52,7 @@ public:
void openImageFile(QString path);
private slots:
private slots:
void init();
void populateUi(const QModelIndex &current);
void scrollTreeView(QListWidgetItem* item);
@ -93,6 +93,7 @@ private:
FfsEngine* ffsEngine;
SearchDialog* searchDialog;
QClipboard* clipboard;
QString currentDir;
QQueue<MessageListItem> messageItems;
void showMessages();

View file

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

View file

@ -9,7 +9,7 @@
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
*/
#include <QApplication>
#include <QString>