MCPcopy Create free account
hub / github.com/LongSoft/UEFITool / decompress

Method decompress

ffsengine.cpp:2757–2886  ·  view source on GitHub ↗

Compression routines

Source from the content-addressed store, hash-verified

2755
2756// Compression routines
2757UINT8 FfsEngine::decompress(const QByteArray & compressedData, const UINT8 compressionType, QByteArray & decompressedData, UINT8 * algorithm)
2758{
2759 const UINT8* data;
2760 UINT32 dataSize;
2761 UINT8* decompressed;
2762 UINT32 decompressedSize = 0;
2763 UINT8* scratch;
2764 UINT32 scratchSize = 0;
2765 const EFI_TIANO_HEADER* header;
2766
2767 switch (compressionType)
2768 {
2769 case EFI_NOT_COMPRESSED:
2770 decompressedData = compressedData;
2771 if (algorithm)
2772 *algorithm = COMPRESSION_ALGORITHM_NONE;
2773 return ERR_SUCCESS;
2774 case EFI_STANDARD_COMPRESSION:
2775 // Get buffer sizes
2776 data = (UINT8*)compressedData.data();
2777 dataSize = compressedData.size();
2778
2779 // Check header to be valid
2780 header = (const EFI_TIANO_HEADER*)data;
2781 if (header->CompSize + sizeof(EFI_TIANO_HEADER) != dataSize)
2782 return ERR_STANDARD_DECOMPRESSION_FAILED;
2783
2784 // Get info function is the same for both algorithms
2785 if (ERR_SUCCESS != EfiTianoGetInfo(data, dataSize, &decompressedSize, &scratchSize))
2786 return ERR_STANDARD_DECOMPRESSION_FAILED;
2787
2788 // Allocate memory
2789 decompressed = new UINT8[decompressedSize];
2790 scratch = new UINT8[scratchSize];
2791
2792 // Decompress section data
2793
2794 //TODO: separate EFI1.1 from Tiano another way
2795 // Try Tiano decompression first
2796 if (ERR_SUCCESS != TianoDecompress(data, dataSize, decompressed, decompressedSize, scratch, scratchSize)) {
2797 // Not Tiano, try EFI 1.1
2798 if (ERR_SUCCESS != EfiDecompress(data, dataSize, decompressed, decompressedSize, scratch, scratchSize)) {
2799 if (algorithm)
2800 *algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
2801
2802 delete[] decompressed;
2803 delete[] scratch;
2804 return ERR_STANDARD_DECOMPRESSION_FAILED;
2805 }
2806 else if (algorithm)
2807 *algorithm = COMPRESSION_ALGORITHM_EFI11;
2808 }
2809 else if (algorithm)
2810 *algorithm = COMPRESSION_ALGORITHM_TIANO;
2811
2812 if (decompressedSize > INT32_MAX) {
2813 delete[] decompressed;
2814 delete[] scratch;

Callers

nothing calls this directly

Calls 7

EfiTianoGetInfoFunction · 0.85
TianoDecompressFunction · 0.85
EfiDecompressFunction · 0.85
LzmaGetInfoFunction · 0.85
LzmaDecompressFunction · 0.85
sizeOfSectionHeaderFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected