forked from wmcbrine/tivodecode-ng
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtivo_parse.hxx
93 lines (72 loc) · 2.54 KB
/
tivo_parse.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef TIVO_PARSE_HXX_
#define TIVO_PARSE_HXX_
#ifdef HAVE_CONFIG_H
#include "tdconfig.h"
#endif
#include "happyfile.hxx"
#include "Turing.hxx"
#include "turing_stream.hxx"
extern uint16_t portable_ntohs(uint8_t *pVal);
extern uint32_t portable_ntohl(uint8_t *pVal);
#define static_strlen(str) (sizeof(str) - 1)
extern int o_verbose;
extern bool o_pkt_dump;
#define IS_VERBOSE ( (o_pkt_dump) || (o_verbose >= 1) )
#define IS_VVERBOSE ( (o_pkt_dump) || (o_verbose >= 2) )
#define IS_VVVERBOSE ( (o_pkt_dump) || (o_verbose >= 3) )
#define VERBOSE(...) if (IS_VERBOSE) { std::fprintf(stderr, __VA_ARGS__); }
#define VVERBOSE(...) if (IS_VVERBOSE) { std::fprintf(stderr, __VA_ARGS__); }
#define VVVERBOSE(...) if (IS_VVVERBOSE) { std::fprintf(stderr, __VA_ARGS__); }
/*
* Initial header formats lifted from ezrec's posting:
* http://www.dealdatabase.com/forum/showthread.php?t=41132
*/
typedef enum
{
TIVO_FORMAT_NONE = 0,
TIVO_FORMAT_PS,
TIVO_FORMAT_TS,
TIVO_FORMAT_MAX
}
TiVoFormatType;
typedef enum
{
TIVO_CHUNK_PLAINTEXT_XML = 0,
TIVO_CHUNK_ENCRYPTED_XML = 1
}
TiVoChunkType;
/* All elements are in big-endian format and are packed */
class TiVoStreamHeader
{
public:
char fileType[4]; /* the string 'TiVo' */
uint16_t dummy_0004;
uint16_t dummy_0006;
uint16_t dummy_0008;
uint32_t mpeg_offset; /* 0-based offset of MPEG stream */
uint16_t chunks; /* Number of metadata chunks */
TiVoFormatType getFormatType();
bool read(HappyFile *file);
void dump(uint8_t dbgLevel=0);
uint16_t size() { return sizeof(TiVoStreamHeader); };
TiVoStreamHeader();
} __attribute__((packed));
class TiVoStreamChunk
{
public:
uint32_t chunkSize; /* Size of chunk */
uint32_t dataSize; /* Length of the payload */
uint16_t id; /* Chunk ID */
uint16_t type; /* Subtype */
uint8_t *pData; /* Variable length data */
bool read(HappyFile *file);
bool write(HappyFile *file);
void dump(uint8_t dbgLevel=0);
uint16_t size() { return sizeof(TiVoStreamChunk) - sizeof(uint8_t*); };
void setupTuringKey(TuringState *pTuring, uint8_t *pMAK);
void setupMetadataKey(TuringState *pTuring, uint8_t *pMAK);
void decryptMetadata(TuringState *pTuring, uint16_t offsetVal);
TiVoStreamChunk();
~TiVoStreamChunk();
} __attribute__((packed));
#endif /* TIVO_PARSE_HXX_ */