-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_through.c
180 lines (133 loc) · 4.04 KB
/
write_through.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include "swf_types.h"
#include "swf_tags.h"
#include "swf_parse.h"
#include "swf_movie.h"
#include "swf_serialise.h"
#include "swf_destroy.h"
#include "print_utils.h"
#include <stdio.h>
#define SWF_PARSER_MAX_TAG_ID 48
#define FRAMERATE 15
#define SWF_BUFFER_SIZE 10240
void usage (char * name);
void * init_parser (void);
swf_tagrecord * dummy (swf_parser * context, int * error, SWF_U16 next_id);
swf_tagrecord * extract_tagrecord(swf_parser * context, int * error, SWF_U16 next_id);
int long_tags = 0;
int total_size = 21;
int tags = 0;
int frames = 1;
int longtag = 0;
void
usage (char * name)
{
fprintf (stderr, "Usage: %s <input filename> <output filename>\n", name);
}
swf_tagrecord *
dummy(swf_parser * context, int * error, SWF_U16 next_id)
{
return NULL;
}
swf_tagrecord *
extract_tagrecord(swf_parser * context, int * error, SWF_U16 next_id)
{
swf_tagrecord * temp;
temp = swf_make_tagrecord(error, next_id);
temp->buffer->raw = swf_parse_get_bytes(context, context->cur_tag_len);
temp->buffer->size = context->cur_tag_len;
total_size += context->cur_tag_len + 2;
longtag = 0;
if (context->cur_tag_len >= 0x3f)
{
longtag = 1;
long_tags++;
total_size += 4;
}
temp->serialised = 1;
return temp;
}
void *
init_parser (void) {
void (**parse)();
void (**masked)();
int i;
parse = calloc((1 + SWF_PARSER_MAX_TAG_ID), sizeof(void * ));
masked = calloc((1 + SWF_PARSER_MAX_TAG_ID), sizeof(void * ));
/* Set all the parse functions to dummy, then
* just add the ones we actually want...
*/
for (i=0; i <= SWF_PARSER_MAX_TAG_ID ; i++) {
masked[i] = (void *) extract_tagrecord;
}
free(parse);
return (void *) masked;
}
int main (int argc, char *argv[]) {
swf_movie * movie;
int error = SWF_ENoError;
swf_parser * parser;
swf_header * hdr;
swf_tagrecord * temp;
SWF_U32 next_id = 0;
void* (**parse)();
if (3 != argc) {
usage(argv[0]);
exit(1);
}
/* First, get a parser up */
parser = swf_parse_create(argv[1], &error);
if (parser == NULL) {
fprintf (stderr, "Failed to create SWF context\n");
return -1;
}
printf ("Name of file is '%s'\n", parser->name);
printf("----- Reading the file input header -----\n");
hdr = swf_parse_header(parser, &error);
if (hdr == NULL) {
fprintf (stderr, "Failed to parse headers\n");
exit(1);
}
swf_print_header(hdr, &error);
printf("\n----- Output movie details -----\n");
parse = init_parser();
/* Now generate the output movie */
if ((movie = swf_make_movie(&error)) == NULL) {
fprintf (stderr, "Fail\n");
return 1;
}
/* FIXME: We're copying by reference here, which is a bit crufty... */
movie->header = hdr;
movie->name = (char *) argv[2];
/* FIXME h-h-hack. This should be done in serialisation */
movie->header->rate = movie->header->rate * 256;
do {
tags++;
next_id = swf_parse_nextid(parser, &error);
if (error != SWF_ENoError) {
fprintf (stderr, "ERROR: parsing id : '%s'\n", swf_error_code_to_string(error));
}
printf ("[%d] (%d) %s %s\n", frames, swf_parse_tell(parser), swf_tag_to_string(next_id), (1==longtag)?"*":"");
if (1 == next_id) {
frames++;
// fprintf (stderr, "--------------------[ %d ]-------------------\n", frames++);
}
error = SWF_ENoError;
if (next_id <= SWF_PARSER_MAX_TAG_ID) {
temp = (swf_tagrecord*) (parse[next_id](parser, error, next_id));
if (temp) {
swf_dump_tag(movie, &error, temp);
}
}
if (error != SWF_ENoError) {
fprintf (stderr, "ERROR parsing tag : '%s' : '%s'\n", swf_tag_to_string(next_id), swf_error_code_to_string(error));
}
} while (next_id > 0);
printf("Total movie size is %d\n", total_size);
printf("The number of long tags was %d\n", long_tags);
swf_make_finalise(movie, &error);
/* Kill block */
free(parse);
swf_destroy_movie(movie);
swf_destroy_parser(parser);
return 0;
}