Example #1
0
swf_tag_t *swf_tag_create(bitstream_t *bs) {
    swf_tag_t *tag = NULL;
    unsigned short tag_and_length;
    if (bs == NULL) {
        fprintf(stderr, "swf_tag_create: bs == NULL\n");
        return NULL;
    }
    tag_and_length = bitstream_getbytesLE(bs, 2);
    if (tag_and_length == (unsigned short) -1) {
        fprintf(stderr, "swf_tag_create: tag_and_length(short) == -1\n");
        return NULL;
    }
    tag = calloc(sizeof(*tag), 1);
    tag->code = tag_and_length >> 6;
    tag->length = tag_and_length & 0x3f;
    tag->length_longformat = 0;
    if (tag->length == 0x3f) {
        tag->length = bitstream_getbytesLE(bs, 4);
        if (tag_and_length == (unsigned short) -1) {
	    fprintf(stderr, "swf_tag_create: tag_and_length(long) == -1\n");
            free(tag);
            return NULL;
        }
        tag->length_longformat = 1;
    }
//    printf("XXX: malloc length=%d\n", tag->length);
    tag->data = malloc(tag->length);
    bitstream_getstring(bs, tag->data, tag->length);
    tag->detail = NULL;
    return tag;
}
Example #2
0
int
swf_action_parse(bitstream_t *bs, swf_action_t *act) {
    unsigned long offset;
    bitstream_align(bs);
    act->action_id = bitstream_getbyte(bs);
    if (act->action_id & 0x80) {
        act->action_length = bitstream_getbytesLE(bs, 2);
        offset = bitstream_getbytepos(bs);
        act->action_data = malloc(act->action_length);
        if (act->action_data == NULL) {
            fprintf(stderr, "Can't alloc memory for act->action_data\n");
            return 1;
        }
        bitstream_getstring(bs, act->action_data, act->action_length);
    }
    return 0;
}