Exemplo n.º 1
0
int
swf_argb_build(bitstream_t *bs, swf_argb_t *color) {
    bitstream_putbyte(bs, color->alpha);
    bitstream_putbyte(bs, color->red);
    bitstream_putbyte(bs, color->green);
    bitstream_putbyte(bs, color->blue);
    return 0;
}
Exemplo n.º 2
0
int
swf_fill_style_build(bitstream_t *bs, swf_fill_style_t *fill_style,
                     swf_tag_t *tag) {
    if (fill_style == NULL) {
        fprintf(stderr, "swf_fill_style_build: fill_style == NULL\n");
        return 1;
    }
    bitstream_putbyte(bs, fill_style->type);
    switch (fill_style->type) {
      case 0x00: // solid fill
        swf_fill_style_solid_build(bs, &(fill_style->solid), tag);
        break;
      case 0x10: // linear gradient fill
      case 0x11: // radial gradient fill
      case 0x12: // focal  gradient fill
        swf_fill_style_gradient_build(bs, &(fill_style->gradient), tag);
        break;
      case 0x40: // tilled  bitmap fill with smoothed edges
      case 0x41: // clipped bitmap fill with smoothed edges
      case 0x42: // tilled  bitmap fill with hard edges
      case 0x43: // clipped bitmap fill with hard edges
        swf_fill_style_bitmap_build(bs, &(fill_style->bitmap), tag);
        break;
      default:
        fprintf(stderr, "swf_fill_style_build: unknown fill_style->type=%d\n", fill_style->type);
        return 1;
    }
    return 0;
}
Exemplo n.º 3
0
int
swf_button_record_list_build(bitstream_t *bs, swf_button_record_list_t *button_record_list, swf_tag_t *tag) {
    swf_button_record_t *button_record = NULL;
    for (button_record = button_record_list->head ; button_record ; button_record = button_record->next) {
        swf_button_record_build(bs, button_record, tag);
    }
    bitstream_putbyte(bs, 0); //endflag
    return 0;
}
Exemplo n.º 4
0
int
swf_action_list_build(bitstream_t *bs, swf_action_list_t *list) {
    swf_action_t *action;
    for (action=list->head ; action ; action=action->next) {
        if (swf_action_build(bs, action) != 0) {
            fprintf(stderr, "swf_action_list_build: swf_action_build failed\n");
            bitstream_putbyte(bs, 0);
            return 1;
        }
    }
    return 0;
}
Exemplo n.º 5
0
int
swf_fill_style_array_build(bitstream_t *bs,
                           swf_fill_style_array_t *fill_style_array,
                           swf_tag_t *tag) {
    int i;
    int ret;
    if ((tag->code == 2) || // DefineShape
        ((tag->code > 2) && (fill_style_array->count < 255))) {
        bitstream_putbyte(bs, fill_style_array->count);
    } else {
        bitstream_putbyte(bs, 255);
        bitstream_putbytesLE(bs, fill_style_array->count, 2);
    }
    for (i = 0 ; i < fill_style_array->count ; i++) {
        ret = swf_fill_style_build(bs, &(fill_style_array->fill_style[i]), tag);
        if (ret != 0) {
            fprintf(stderr, "swf_fill_style_array_build: swf_fill_style_build failed i=%d/count=%d\n", i, fill_style_array->count);
            return 1;
        }
    }
    return 0;
}
Exemplo n.º 6
0
int
swf_action_build(bitstream_t *bs, swf_action_t *act) {
    bitstream_align(bs);
    bitstream_putbyte(bs, act->action_id);
    if (act->action_id & 0x80) {
        if (act->action_data == NULL) {
            return 1; // error
        }
        bitstream_putbytesLE(bs, act->action_length, 2);
        bitstream_putstring(bs, act->action_data, act->action_length);
    }
    return 0;
}
Exemplo n.º 7
0
int
swf_action_list_replace_strings(swf_action_list_t *action_list,
                                int *modified, y_keyvalue_t *kv) {
    swf_action_t *action;
    if (modified) {
        *modified = 0;
    }
    for (action=action_list->head ; action ; action=action->next) {
        if (action->action_id < 0x80) {
            continue; // skip (no string)
        }
        switch(action->action_id) {
            int type;
            unsigned char *token;
            int token_len;
            bitstream_t *bs;
            char *value;
            int value_len;
            int count;
            int m = 0;
            int i;
        case 0x83: // Get URL
            m = 0;
            bs = bitstream_open();
            token = action->action_data;
            token_len = strlen((char *) token);
            value = y_keyvalue_get(kv, (char *)token, token_len, &value_len);
            if (value) {
                bitstream_putstring(bs, (unsigned char *) value, value_len);
                bitstream_putbyte(bs, '\0');
                m = 1;
            } else {
                bitstream_putstring(bs, (unsigned char *) token, token_len);
                bitstream_putbyte(bs, '\0');
            }
            token +=  token_len + 1;
            token_len = strlen((char *) token);
            value = y_keyvalue_get(kv, (char *)token, token_len, &value_len);
            if (value) {
                bitstream_putstring(bs, (unsigned char *)value, value_len);
                bitstream_putbyte(bs, '\0');
                m = 1;
            } else {
                bitstream_putstring(bs, (unsigned char *)token, token_len);
                bitstream_putbyte(bs, '\0');
            }
            if (m) {
                unsigned long length;
                free(action->action_data);
                action->action_data = bitstream_steal(bs, &length);
                action->action_length = length;
                if (modified) {
                    *modified = 1;
                }
            }
            bitstream_close(bs);
            break;
        case 0x88: // ActionConstantPool
            m = 0;
            count = action->action_data[0] + 0x100 * action->action_data[1];
            token = action->action_data + 2;
            bs = bitstream_open();
            bitstream_putbytesLE(bs, count, 2);
            for (i = 0 ; i < count ; i++) {
                token_len = strlen((char *) token);
                value = y_keyvalue_get(kv, (char *)token, token_len, &value_len);
                if (value) {
                    bitstream_putstring(bs, (unsigned char *)value, value_len);
                    bitstream_putbyte(bs, '\0');
                    m = 1;
                } else {
                    bitstream_putstring(bs, (unsigned char *)token , token_len);
                    bitstream_putbyte(bs, '\0');
                }
                token +=  token_len + 1;
            }
            if (m) {
                unsigned long length;
                free(action->action_data);
                action->action_data = bitstream_steal(bs, &length);
                action->action_length = length;
                if (modified) {
                    *modified = 1;
                }
            }
            bitstream_close(bs);
            break;
        case 0x96: // Push Data
            m = 0;
            token = action->action_data;
            bs = bitstream_open();
            while (token < action->action_data + action->action_length) {
                static const int action_value_type_size[] = {
                    -1, // 0: String
                    4,  // 1: Float
                    0,  // 2: NULL
                    0,  // 3: Undefined
                    1,  // 4: Register
                    1,  // 5: Boolean
                    8,  // 6: Double
                    4,  // 7: Integer
                    1,  // 8: Dictionary Lookup
                    2,  // 9: Large Dictionary Lookup
                };
                type = token[0];
                bitstream_putbyte(bs, type);
                token += 1;
                if (type == 0) { // String
                    token_len = strlen((char *) token);
                    value = y_keyvalue_get(kv, (char *)token, token_len, &value_len);
                    if (value) {
                        bitstream_putstring(bs, (unsigned char *)value, value_len);
                        bitstream_putbyte(bs, '\0');
                        m = 1;
                    } else {
                        bitstream_putstring(bs, (unsigned char *)token , token_len);
                        bitstream_putbyte(bs, '\0');
                    }
                    token +=  token_len + 1;
                } else if (type < 10) { // else String
                    bitstream_putstring(bs, token, action_value_type_size[type]);
                    token += action_value_type_size[type];
                } else {
                    fprintf(stderr, "swf_action_list_replace_strings: illegal type=%d\n", type);
                    bitstream_close(bs);
                    return 1; // FAILURE
                }
            }
            if (m) {
                unsigned long length;
                free(action->action_data);
                action->action_data = bitstream_steal(bs, &length);
                action->action_length = length;
                if (modified) {
                    *modified = 1;
                }
            }
            bitstream_close(bs);
            break;
        }
    }
    return 0;
}