-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathbitheader.c
81 lines (69 loc) · 2.18 KB
/
bitheader.c
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
/*
* Copyright (C) 2006, 2007 Jean-Baptiste Note <[email protected]>
*
* This file is part of debit.
*
* Debit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Debit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with debit. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glib.h>
#include "bitheader.h"
#include "debitlog.h"
static void
parse_synchro (synchro_option_t *opt) {
guint len = GUINT32_FROM_BE(opt->bitstream_length);
debit_log(L_HEADER, "Synchro option, bitstream length %i", len);
debit_log(L_HEADER, "bitstream data starting @%p", opt->data);
(void) len;
return;
}
static void
parse_option (parsed_header_t *parse,
const header_option_t *opt) {
option_type_t code = opt->code;
gint len = get_option_len(opt);
debit_log(L_HEADER, "Option code %i, length %i", code, len);
debit_log(L_HEADER, "data: %.*s",len,opt->payload);
/* If in range, then record the option */
if (code < LAST_OPTION) {
parse->options[code - FILENAME].len = len;
parse->options[code - FILENAME].data = opt->payload;
}
else {
debit_log(L_HEADER, "Option code unknown, please report");
}
}
int
parse_header(parsed_header_t *parse,
const gchar *buf, const size_t buf_len) {
header_option_t *current;
synchro_option_t *opt;
const gchar *start = buf;
const gchar *end;
/* seek the first option -- I need bitstream examples to
reverse-engeneer the very first option */
while (*buf != FILENAME) {
buf++;
if (buf > start + buf_len)
return -1;
}
current = (void *) buf;
while (current->code != CODE) {
parse_option(parse, current);
current = next_option(current);
}
opt = (void*) current;
parse_synchro(opt);
end = (void *) opt->data;
return (end - start);
}