X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Frfxswf.c;h=d601a1550849d7fe508943bf6fdfa71c96a7b33c;hb=ebb61a567502ebe4b3d3c4b3284964600fecd90b;hp=93f5db5d2d287b3faa34083ed9093c271b1caa9d;hpb=8d26cc0baf8f7d05e72bc7b8e5f1a6f7caa9f158;p=swftools.git diff --git a/lib/rfxswf.c b/lib/rfxswf.c index 93f5db5..d601a15 100644 --- a/lib/rfxswf.c +++ b/lib/rfxswf.c @@ -204,17 +204,22 @@ U32 swf_GetBits(TAG * t,int nbits) if (!t->readBit) t->readBit = 0x80; while (nbits) { res<<=1; +#ifdef DEBUG_RFXSWF + if (t->pos>=t->len) + { fprintf(stderr,"GetBits() out of bounds: TagID = %i, pos=%d, len=%d\n",t->id, t->pos, t->len); + int i,m=t->len>10?10:t->len; + for(i=-1;idata[i]); + } + fprintf(stderr, "\n"); + return res; + } +#endif if (t->data[t->pos]&t->readBit) res|=1; t->readBit>>=1; nbits--; if (!t->readBit) { if (nbits) t->readBit = 0x80; - #ifdef DEBUG_RFXSWF - if (t->pos>=t->len) - { fprintf(stderr,"GetBits() out of bounds: TagID = %i\n",t->id); - return res; - } - #endif t->pos++; } } @@ -368,7 +373,12 @@ int swf_GetS30(TAG*tag) while(1) { U8 b = swf_GetU8(tag); nr++; - s|=(b&127)<len>10?10:t->len; + for(i=0;idata[i]); + } + fprintf(stderr, "\n"); + s|=(b&127)<=32) { if(b&64) { @@ -1460,6 +1470,7 @@ int swf_ReadSWF2(reader_t*reader, SWF * swf) // Reads SWF to memory (malloc'ed swf->frameCount = SWAP16(swf->frameCount); /* read tags and connect to list */ + t1.next = 0; t = &t1; while (t) { t = swf_ReadTag(reader,t); @@ -1469,7 +1480,8 @@ int swf_ReadSWF2(reader_t*reader, SWF * swf) // Reads SWF to memory (malloc'ed } } swf->firstTag = t1.next; - t1.next->prev = NULL; + if(t1.next) + t1.next->prev = NULL; } return reader->pos; @@ -1549,8 +1561,19 @@ int WriteExtraTags(SWF*swf, writer_t*writer) } swf_DeleteTag(0, fileattrib); } else { - if(swf_WriteTag2(writer, has_fileattributes)<0) - return -1; + if(swf->fileAttributes) { + /* if we're writing a file out again where we might have possible + modified the fileattributes in the header, adjust the tag data */ + TAG*tt = swf_CopyTag(0,has_fileattributes); + U32 flags = swf_GetU32(tt) | swf->fileAttributes; + swf_ResetTag(tt, tt->id); + swf_SetU32(tt, flags); + if(swf_WriteTag2(writer, has_fileattributes)<0) return -1; + swf_DeleteTag(0, tt); + } else { + if(swf_WriteTag2(writer, has_fileattributes)<0) + return -1; + } } if(0 && !has_scenedescription) { TAG*scene = swf_InsertTag(0, ST_SCENEDESCRIPTION); @@ -1699,6 +1722,21 @@ int swf_WriteSWF2(writer_t*writer, SWF * swf) // Writes SWF to file, return } } +int swf_SaveSWF(SWF * swf, char*filename) +{ + int fi = open(filename, O_BINARY|O_RDWR|O_TRUNC|O_CREAT, 0777); + if(fi<0) { + perror(filename); + return 0; + } + if(swf_WriteSWF(fi, swf)<0) { + fprintf(stderr, "Unable to write output file: %s\n", filename); + return 0; + } + close(fi); + return 1; +} + int swf_WriteSWF(int handle, SWF * swf) // Writes SWF to file, returns length or <0 if fails { writer_t writer;