X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fswfextract.c;h=47bcbe778b8cecdcb8d14f89519da2f6af68bfc8;hb=4e518c7853f14ef0333975c2f6775884f44cf28d;hp=79ebf058868ac868d8d973a6522eb7170bfd5c7e;hpb=dbf0152b6dec49f34a4b57c31eaac449294dee00;p=swftools.git diff --git a/src/swfextract.c b/src/swfextract.c index 79ebf05..47bcbe7 100644 --- a/src/swfextract.c +++ b/src/swfextract.c @@ -25,6 +25,8 @@ #include "../lib/rfxswf.h" #include "../lib/args.h" #include "../lib/log.h" +#include "../lib/jpeg.h" +#include "../lib/png.h" #ifdef HAVE_ZLIB_H #ifdef HAVE_LIBZ #include "zlib.h" @@ -682,13 +684,23 @@ int handlejpeg(TAG*tag) char name[80]; char*filename = name; FILE*fi; - - prepare_name(name, sizeof(name), "pic", "jpg", GET16(tag->data)); - if(numextracts==1) { - filename = destfilename; - if(!strcmp(filename,"output.swf")) - filename = "output.jpg"; + + if(tag->id != ST_DEFINEBITSJPEG3) { + prepare_name(name, sizeof(name), "pic", "jpg", GET16(tag->data)); + if(numextracts==1) { + filename = destfilename; + if(!strcmp(filename,"output.swf")) + filename = "output.jpg"; + } + } else { + prepare_name(name, sizeof(name), "pic", "png", GET16(tag->data)); + if(numextracts==1) { + filename = destfilename; + if(!strcmp(filename,"output.swf")) + filename = "output.png"; + } } + /* swf jpeg images have two streams, which both start with ff d8 and end with ff d9. The following code handles sorting the middle bytes out, so that one stream remains */ @@ -719,18 +731,34 @@ int handlejpeg(TAG*tag) } else if(tag->id == ST_DEFINEBITSJPEG3 && tag->len>6) { U32 end = GET32(&tag->data[2])+6; - int pos = findjpegboundary(&tag->data[6], tag->len-6); - if(pos<0) { - fi = save_fopen(filename, "wb"); - fwrite(&tag->data[6], end-6, 1, fi); - fclose(fi); - } else { - pos+=6; - fi = save_fopen(filename, "wb"); - fwrite(&tag->data[6], pos-6, 1, fi); - fwrite(&tag->data[pos+4], end-(pos+4), 1, fi); - fclose(fi); - } + int pos = findjpegboundary(&tag->data[6], end); + if(end >= tag->len) { + msg(" zlib data out of bounds in definebitsjpeg3"); + return 0; + } + if(pos) { + /* TODO: do we actually need this? */ + memmove(&tag->data[pos], &tag->data[pos+4], end-(pos+4)); + } + unsigned char*image; + int width=0, height=0; + jpeg_load_from_mem(&tag->data[6], end-6, &image, &width, &height); + + uLongf datalen = width*height; + Bytef *data = malloc(datalen); + + int error = uncompress(data, &datalen, &tag->data[end], (uLong)(tag->len - end)); + if(error != Z_OK) { + fprintf(stderr, "Zlib error %d\n", error); + return 0; + } + int t, size = width*height; + for(t=0;tdata); @@ -771,7 +799,7 @@ static inline void png_write_byte(FILE*fi, U8 byte) static void png_start_chunk(FILE*fi, char*type, int len) { U8 mytype[4]={0,0,0,0}; - U32 mylen = REVERSESWAP32(len); + U32 mylen = BE_32_TO_NATIVE(len); memcpy(mytype,type,strlen(type)); fwrite(&mylen, 4, 1, fi); mycrc32=0xffffffff; @@ -795,7 +823,7 @@ static void png_write_dword(FILE*fi, U32 dword) } static void png_end_chunk(FILE*fi) { - U32 tmp = REVERSESWAP32((mycrc32^0xffffffff)); + U32 tmp = BE_32_TO_NATIVE((mycrc32^0xffffffff)); fwrite(&tmp,4,1,fi); }