FireBirdLib - Topfield TMS PVR TAP Programming Library
UncompressedTFDSize.c
Go to the documentation of this file.
1#include "libFireBird.h"
2#include "FBLib_compression.h"
3
4dword UncompressedTFDSize(byte *pSrc)
5{
7
8 word compSize = 0, uncompSize = 0, NrBlocks = 0;
9 dword outSize = 0, i;
10
11 if(!pSrc)
12 {
13 TRACEEXIT();
14 return 0;
15 }
16
17 if(LOAD_WORD(pSrc) != 8)
18 {
19 //Invalid header
20 TRACEEXIT();
21 return 0;
22 }
23
24 if(CRC16 (0, pSrc + 4, 6) != LOAD_WORD(pSrc + 2))
25 {
26 //Invalid header CRC
27 TRACEEXIT();
28 return 0;
29 }
30
31 if(LOAD_WORD(pSrc + 6) != 1)
32 {
33 //Invalid file version
34 TRACEEXIT();
35 return 0;
36 }
37
38 NrBlocks = LOAD_WORD(pSrc + 8);
39
40 pSrc += 10;
41
42 for(i = 0; i < NrBlocks; i++)
43 {
44 compSize = LOAD_WORD(pSrc) - 6;
45 uncompSize = LOAD_WORD(pSrc + 6);
46
47 if(uncompSize > 0x7ffa)
48 {
49 //Uncompressed data block size too large
50 TRACEEXIT();
51
52 return 0;
53 }
54
55 pSrc += compSize + 8;
56 outSize += uncompSize;
57 }
58
59 TRACEEXIT();
60 return outSize;
61}
word CRC16(word StartValue, void *StartAddress, dword Length)
Definition: CRC16.c:23
#define LOAD_WORD(x)
dword UncompressedTFDSize(byte *pSrc)
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243