Beispiel #1
0
void swf_Render_Delete(RENDERBUF*dest)
{
    renderbuf_internal*i = (renderbuf_internal*)dest->internal;
    int y;
    bitmap_t*b = i->bitmaps;
    
    /* delete canvas */
    rfx_free(i->zbuf);
    rfx_free(i->img);
    
    /* delete line buffers */
    for(y=0;y<i->height2;y++) {
        swf_DeleteTag(0, i->lines[y].points);
        i->lines[y].points = 0;
    }
    
    /* delete bitmaps */
    while(b) {
        bitmap_t*next = b->next;
        free(b->data);b->data=0;
        rfx_free(b);
        b = next;
    }
    
    rfx_free(i->lines); i->lines = 0;
    rfx_free(dest->internal); dest->internal = 0;
}
int main(int argn,char ** argv)
{ 
    srand48(time(0));
    int fi;
    SWF swf;
    TAG* tag;
    char* outfilename = "test.swf";
    char*oldpassword = "******";
    char*newpassword = "******";

    if (argn<1)
    { 
	return 0;
    }
	
    fi = open(argv[1],O_RDONLY|O_BINARY);
	
    if (fi<=0)
    { 
	fprintf(stderr,"Couldn't open %s\n", argv[1]);
    }

    if(swf_ReadSWF(fi,&swf)<0)
    { 
	fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",argv[1]);
	close(fi);
    }

    tag = swf.firstTag;

    while(tag) {
	TAG*next = tag->next;
	//void  swf_SetPassword(TAG * t, const char * password);
	//int   swf_VerifyPassword(TAG * t, const char * password);
	if(tag->id == ST_PROTECT) {
	    int ret;
	    ret = swf_VerifyPassword(tag, oldpassword);
	    if(!ret) printf("Password validation failed\n");
	    else printf("Password ok\n");

	    swf_DeleteTag(&swf, tag);
	}
	tag = next;
    }

    tag = swf_InsertTag(swf.firstTag, ST_PROTECT);
    swf_SetPassword(tag, newpassword);

    fi = open(outfilename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
    if(fi<0) {
	fprintf(stderr, "couldn't create output file %s", outfilename);
    }
    if(swf_WriteSWF(fi, &swf)<0) 
        fprintf(stderr, "WriteSWF() failed.\n");

    close(fi);
    
    return 0;
}
Beispiel #3
0
void removeCommonTags(SWF * swf)
{
    TAG*tag = swf->firstTag;
    while(tag) {
	if(tag->id == ST_SCENEDESCRIPTION ||
	   tag->id == ST_FILEATTRIBUTES ||
	   tag->id == ST_REFLEX) {
	    tag = swf_DeleteTag(swf, tag);
	} else {
	    tag = tag->next;
	}
    }
}
Beispiel #4
0
static void swf_ShapeDrawerClear(drawer_t*draw)
{
    SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
    if(sdraw->tagfree) {
	swf_DeleteTag(0, sdraw->tag);
	sdraw->tag = 0;
    }
    swf_ShapeFree(sdraw->shape);
    sdraw->shape = 0;

    rfx_free(draw->internal);
    draw->internal = 0;
}
Beispiel #5
0
void jpeg_assert(SWF*master, SWF*slave)
{
    /* TODO: if there's a jpegtable found, store it
       and handle it together with the flash file
       headers */

    /* check that master and slave don't have both
       jpegtables (which would be fatal) */
    int pos;
    TAG *mpos=0, *spos=0;
    TAG *mtag,*stag;
    pos = 0;
    mtag = master->firstTag;
    stag = slave->firstTag;
    while(mtag)
    {
	if(mtag->id  == ST_JPEGTABLES)
	    mpos = mtag;
	mtag = mtag->next;
    }
    while(stag)
    {
	if(stag->id == ST_JPEGTABLES)
	    spos = stag;
	stag = stag->next;
    }
    if(mpos && spos)
    {
	if(spos->len == mpos->len &&
	!memcmp(spos->data, mpos->data, mpos->len))
	{
	    // ok, both have jpegtables, but they're identical.
	    // delete one and don't throw an error
	    swf_DeleteTag(slave, spos);
	    spos = 0;
	}
    }
    if(spos && mpos) {
	msg("<error> Master and slave have incompatible JPEGTABLES.");
    }
}
Beispiel #6
0
ActionTAG* swf_ActionCompile(const char* source, int version)
{
    TAG* tag;
    ActionTAG* a = 0;
    void*buffer = 0;
    int len = 0;
    int ret;
    
    tag = swf_InsertTag(NULL, ST_DOACTION);
    ret = compileSWFActionCode(source, version, &buffer, &len);
    if(!ret || buffer==0 || len == 0)
	return 0;

    swf_SetBlock(tag, (U8*)buffer, len);
    swf_SetU8(tag, 0);

    rfx_free(buffer);

    a = swf_ActionGet(tag);
    swf_DeleteTag(0, tag);
    return a;
}
Beispiel #7
0
int catcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
{
    char* depths;
    int t;
    TAG*tag;
    TAG*mtag,*stag;
    if(config.isframe) {
		msg("<fatal> Can't combine --cat and --frame");
		return 101;
    }
    if(config.flashversion)
	master->fileVersion = config.flashversion;
   
    tag = master->firstTag;
    while(tag)
    {
	if(swf_isDefiningTag(tag)) {
	    int defineid = swf_GetDefineID(tag);
	    msg("<debug> tagid %02x defines object %d", tag->id, defineid);
	    masterbitmap[defineid] = 1;
	}
	tag = tag->next;
    }
    
    swf_Relocate(slave, masterbitmap);
    jpeg_assert(master, slave);
    
    memcpy(newswf, master, sizeof(SWF));
    adjustheader(newswf);

    tag = newswf->firstTag = swf_InsertTag(0, ST_REFLEX); // to be removed later

    depths = malloc_safe(65536);
    if(!depths) {
	msg("<fatal> Couldn't allocate %d bytes of memory", 65536);
	return 111;
    }
    memset(depths, 0, 65536);
    mtag = master->firstTag;
    while(mtag && mtag->id!=ST_END)
    {
	int num=1;
	U16 depth;
	msg("<debug> [master] write tag %02x (%d bytes in body)", 
		mtag->id, mtag->len);
	switch(mtag->id) {
	    case ST_PLACEOBJECT2:
		num++;
	    case ST_PLACEOBJECT: {
	       depth = swf_GetDepth(mtag);
	       depths[depth] = 1;
	    }
	    break;
	    case ST_REMOVEOBJECT: {
	       depth = swf_GetDepth(mtag);
	       depths[depth] = 0;
	    }
	    break;
	    case ST_REMOVEOBJECT2: {
	       depth = swf_GetDepth(mtag);
	       depths[depth] = 0;
	    }
	    break;
	}
	tag = swf_InsertTag(tag, mtag->id);
	swf_SetBlock(tag, mtag->data, mtag->len);

	mtag = mtag->next;
    }

    for(t=0;t<65536;t++) 
    if(depths[t])
    {
	char data[16];
	int len;
	tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
	swf_SetU16(tag, t);
    }
    free(depths);

    stag = slave->firstTag;
    while(stag && stag->id!=ST_END)
    {
	msg("<debug> [slave] write tag %02x (%d bytes in body)", 
		stag->id, stag->len);
	tag = swf_InsertTag(tag, stag->id);
	swf_SetBlock(tag, stag->data, stag->len);
	stag = stag->next;
    }
    tag = swf_InsertTag(tag, ST_END);

    swf_DeleteTag(newswf, tag);

	return 0;
}
Beispiel #8
0
int normalcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
{
    int spriteid = -1;
    int replaceddefine = -1;
    int frame = 0;
    char*framelabel;
    TAG * tag = master->firstTag;

    memset(depthbitmap, 0, sizeof(depthbitmap));
    
    // set the idtab
    while(tag)
    {
	int depth = swf_GetDepth(tag);
	if(depth>=0) {
	    depthbitmap[depth] = 1;
	}
	if(swf_isDefiningTag(tag)) {
	    int defineid = swf_GetDefineID(tag);
	    msg("<debug> tagid %02x defines object %d", tag->id, defineid);
	    masterbitmap[defineid] = 1;

	    if (!slavename && defineid==slaveid) {
		if(defineid>=0) {
		  spriteid = defineid;
		  msg("<notice> Slave file attached to object %d.", defineid);
		}
	    }
	} else if(tag->id == ST_EXPORTASSETS) {
	    int t;
	    int num = swf_GetU16(tag);
	    for(t=0;t<num;t++)
	    {
		U16 id = swf_GetU16(tag);
		char*name = swf_GetString(tag);
		if(spriteid<0 && slavename && !strcmp(name,slavename)) {
		    spriteid = id;
		    msg("<notice> Slave file attached to object %d exported as %s.", id, name);
		}
	    }
	} else if(tag->id == ST_SYMBOLCLASS) {
	    /* a symbolclass tag is like a define tag: it defines id 0000 */
	    int num = swf_GetU16(tag);
	    int t;
	    for(t=0;t<num;t++) {
		U16 id = swf_GetU16(tag);
		if(!id) {
		    masterbitmap[id] = 1;
		}
		swf_GetString(tag);
	    }
	} else if(tag->id == ST_PLACEOBJECT2) {
	    char * name = swf_GetName(tag);
	    int id = swf_GetPlaceID(tag);

	    {
		SWFPLACEOBJECT obj;
		swf_GetPlaceObject(tag, &obj);
		swf_PlaceObjectFree(&obj);
		if(obj.clipdepth) {
		    depthbitmap[obj.clipdepth] = 1;
		}
	    }

	    if(name)
	      msg("<verbose> tagid %02x places object %d named \"%s\"", tag->id, id, name);
	    else
	      msg("<verbose> tagid %02x places object %d (no name)", tag->id, id);

	    if (name && slavename && !strcmp(name,slavename)) {
		if(id>=0) {
		  spriteid = id;
		  msg("<notice> Slave file attached to named object %s (%d).", name, id);
		}
	    }
	} else if(tag->id == ST_SHOWFRAME) {
	    if(slaveframe>=0 && frame==slaveframe) {
		msg("<notice> Slave file attached to frame %d.", frame);
	    }
	    frame++;
	} else if(tag->id == ST_FRAMELABEL) {
	    char * name = (char *)tag->data;
	    if(name && slavename && config.isframe && !strcmp(name, slavename)) {
		slaveframe = frame;
		msg("<notice> Slave file attached to frame %d (%s).", frame, name);
	    }
	}
	tag = tag->next;
    };

    if (spriteid<0 && !config.isframe) {
	if(slavename) {
	    if(strcmp(slavename,"!!dummy!!")) {
		msg("<warning> Didn't find anything named %s in file. No substitutions will occur.", slavename);
		if(!strcmp(slavename, "swf")) {
		    msg("<warning> (If you were trying to combine rfxview with a document, try replacing 'swf' with 'viewport'.");
		}
	    }
	}
	else
	    msg("<warning> Didn't find id %d in file. No substitutions will occur.", slaveid);
	spriteid = get_free_id(masterbitmap);
    }

    swf_Relocate (slave, masterbitmap);
    
    if(config.merge)
	swf_RelocateDepth (slave, depthbitmap);
    jpeg_assert(slave, master);
    
    if (config.overlay)
	replaceddefine = get_free_id(masterbitmap);
    
    // write file 

    memcpy(newswf, master, sizeof(SWF));
    adjustheader(newswf);

    newswf->firstTag = tag = swf_InsertTag(0, ST_REFLEX); // to be removed later

    if (config.antistream) {
	if (config.merge) {
	    msg("<fatal> Can't combine --antistream and --merge");
	}
	tag = write_sprite_defines(tag, slave);
	tag = write_sprite(tag, slave, spriteid, replaceddefine);
	tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITEDEFINES);
	tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITENONDEFINES);
    } else {
	if (config.merge)
	    tag = write_master(tag, master, slave, spriteid, replaceddefine, 
		FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES|   FLAGS_WRITESLAVE	);
	else
	    tag = write_master(tag, master, slave, spriteid, replaceddefine, 
		FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES|   FLAGS_WRITESPRITE	);
    }

    swf_DeleteTag(newswf, newswf->firstTag);

	return 0;
}