void gfxpoly_fail(char*expr, char*file, int line, const char*function) { if(!current_polygon) { fprintf(stderr, "assert(%s) failed in %s in line %d: %s\n", expr, file, line, function); exit(1); } void*md5 = init_md5(); int s,t; gfxpolystroke_t*stroke = current_polygon->strokes; for(;stroke;stroke=stroke->next) { for(t=0;t<stroke->num_points;t++) { update_md5(md5, (unsigned char*)&stroke->points[t].x, sizeof(stroke->points[t].x)); update_md5(md5, (unsigned char*)&stroke->points[t].y, sizeof(stroke->points[t].y)); } } unsigned char h[16]; char filename[32+4+1]; finish_md5(md5, h); sprintf(filename, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x.ps", h[0],h[1],h[2],h[3],h[4],h[5],h[6],h[7],h[8],h[9],h[10],h[11],h[12],h[13],h[14],h[15]); fprintf(stderr, "assert(%s) failed in %s in line %d: %s\n", expr, file, line, function); fprintf(stderr, "I'm saving a debug file \"%s\" to the current directory.\n", filename); gfxpoly_save(current_polygon, filename); exit(1); }
int generate_zync_state(FILE *in_file, struct zync_state *zs, zync_block_size_t block_size) { if (block_size <= 0) { fprintf(stderr, "block_size <= 0"); return -1; } if (fseek(in_file, 0, SEEK_SET) != 0) { return -1; } zync_file_size_t in_filelen = 0; zync_block_index_t block_id = 0; unsigned char *zync_checksum = safe_malloc(sizeof(unsigned char) * 16); //zync_checksum+1 if (zync_checksum == NULL) { return -1; } CC_MD5_CTX *zync_ctx = init_md5(); //zync_ctx+1 while (block_id < MAX_BLOCKS) { unsigned char *in_file_buf = safe_malloc(sizeof(unsigned char) * block_size); //in_file_buf+1 if (in_file_buf == NULL) { free(zync_checksum); //zync_checksum-1 free(zync_ctx); //zync_ctx-1 return -1; } size_t in_file_read = safe_fread(in_file_buf, block_size, in_file); if (in_file_read == -1) { free(zync_checksum); //zync_checksum-1 free(zync_ctx); //zync_ctx-1 free(in_file_buf); //in_file_buf-1 return -1; } zync_rsum_t adler = (zync_rsum_t) calc_adler32(in_file_buf, block_size); unsigned char *md5_buf = safe_malloc(sizeof(unsigned char) * 16); //md5_buf+1 if (md5_buf == NULL) { free(zync_checksum); //zync_checksum-1 free(zync_ctx); //zync_ctx-1 free(in_file_buf); //in_file_buf-1 return -1; } calc_md5((void *) in_file_buf, block_size, md5_buf); add_zync_block(zs, block_id++, 0, 0, adler, md5_buf); free(md5_buf); //md5_buf-1 update_md5(zync_ctx, (void *) in_file_buf, block_size); in_filelen += in_file_read; free(in_file_buf); //in_file_buf-1 if (feof(in_file)) { break; } } finalize_md5(zync_ctx, zync_checksum); //zync_ctx-1 for (int i = 0; i < 16; i++) { zs->checksum[i] = zync_checksum[i]; } free(zync_checksum); //zync_checksum-1 zs->filelen = in_filelen; zs->block_size = block_size; zs->block_fill_count = 0; return 0; }
void swf_AddButtonLinks(SWF*swf, char stop_each_frame, char events) { int num_frames = 0; int has_buttons = 0; TAG*tag=swf->firstTag; void*md5 = initialize_md5(); while(tag) { if(tag->id == ST_SHOWFRAME) num_frames++; if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) has_buttons = 1; update_md5(md5, tag->data, tag->len); tag = tag->next; } int t = time(0); update_md5(md5, (unsigned char*)&t, sizeof(t)); unsigned char h[16]; unsigned char file_signature[33]; finish_md5(md5, h); sprintf((char*)file_signature, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", h[0],h[1],h[2],h[3], h[4],h[5],h[6],h[7], h[8],h[9],h[10],h[11], h[12],h[13],h[14],h[15]); char scenename1[80], scenename2[80]; sprintf(scenename1, "rfx.MainTimeline_%s", file_signature); sprintf(scenename2, "rfx::MainTimeline_%s", file_signature); abc_file_t*file = abc_file_new(); abc_method_body_t*c = 0; abc_class_t*cls = abc_class_new2(file, scenename2, "flash.display::MovieClip"); TAG*abctag = swf_InsertTagBefore(swf, swf->firstTag, ST_DOABC); tag = swf_InsertTag(abctag, ST_SYMBOLCLASS); swf_SetU16(tag, 1); swf_SetU16(tag, 0); swf_SetString(tag, scenename1); c = abc_class_getstaticconstructor(cls, 0)->body; c->old.max_stack = 1; c->old.local_count = 1; c->old.init_scope_depth = 9; c->old.max_scope_depth = 10; __ getlocal_0(c); __ pushscope(c); __ returnvoid(c); c = abc_class_getconstructor(cls, 0)->body; c->old.max_stack = 3; c->old.local_count = 1; c->old.init_scope_depth = 10; c->old.max_scope_depth = 11; debugfile(c, "constructor.as"); __ getlocal_0(c); __ pushscope(c); __ getlocal_0(c); __ constructsuper(c,0); __ getlex(c, "[package]flash.system::Security"); __ pushstring(c, "*"); __ callpropvoid(c, "[package]::allowDomain", 1); if(stop_each_frame || has_buttons) { int frame = 0; tag = swf->firstTag; abc_method_body_t*f = 0; //frame script while(tag && tag->id!=ST_END) { char framename[80]; char needs_framescript=0; char buttonname[80]; char functionname[80]; sprintf(framename, "[packageinternal]rfx::frame%d_%s", frame, file_signature); if(!f && (tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2 || stop_each_frame)) { /* make the contructor add a frame script */ __ findpropstrict(c,"[package]::addFrameScript"); __ pushuint(c,frame); __ getlex(c,framename); __ callpropvoid(c,"[package]::addFrameScript",2); f = abc_class_method(cls, 0, multiname_fromstring(framename))->body; f->old.max_stack = 3; f->old.local_count = 1; f->old.init_scope_depth = 10; f->old.max_scope_depth = 11; __ debugfile(f, "framescript.as"); __ debugline(f, 1); __ getlocal_0(f); __ pushscope(f); if(stop_each_frame) { __ findpropstrict(f, "[package]::stop"); __ callpropvoid(f, "[package]::stop", 0); } } if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) { U16 id = swf_GetDefineID(tag); sprintf(buttonname, "::button%d", swf_GetDefineID(tag)); __ getlex(f,buttonname); __ getlex(f,"flash.events::MouseEvent"); __ getproperty(f, "::CLICK"); sprintf(functionname, "::clickbutton%d_%s", swf_GetDefineID(tag), file_signature); __ getlex(f,functionname); __ callpropvoid(f, "::addEventListener" ,2); needs_framescript = 1; abc_method_body_t*h = abc_class_method(cls, 0, multiname_fromstring(functionname))->body; list_append(h->method->parameters, multiname_fromstring("flash.events::MouseEvent")); h->old.max_stack = 6; h->old.local_count = 2; h->old.init_scope_depth = 10; h->old.max_scope_depth = 11; __ getlocal_0(h); __ pushscope(h); ActionTAG*oldaction = swf_ButtonGetAction(tag); if(oldaction && oldaction->op == ACTION__GOTOFRAME) { int framenr = GET16(oldaction->data); if(!events) { __ findpropstrict(h,"[package]::gotoAndStop"); __ pushuint(h,framenr+1); __ callpropvoid(h,"[package]::gotoAndStop", 1); } else { char framename[80]; sprintf(framename, "frame%d_%s", framenr, file_signature); __ getlocal_0(h); //this __ findpropstrict(h, "[package]flash.events::TextEvent"); __ pushstring(h, "link"); __ pushtrue(h); __ pushtrue(h); __ pushstring(h, framename); __ constructprop(h,"[package]flash.events::TextEvent", 4); __ callpropvoid(h,"[package]::dispatchEvent", 1); } } else if(oldaction && oldaction->op == ACTION__GETURL) { if(!events) { __ findpropstrict(h,"flash.net::navigateToURL"); __ findpropstrict(h,"flash.net::URLRequest"); // TODO: target _blank __ pushstring(h,(char*)oldaction->data); //url __ constructprop(h,"flash.net::URLRequest", 1); __ callpropvoid(h,"flash.net::navigateToURL", 1); } else { __ getlocal_0(h); //this __ findpropstrict(h, "[package]flash.events::TextEvent"); __ pushstring(h, "link"); __ pushtrue(h); __ pushtrue(h); __ pushstring(h,(char*)oldaction->data); //url __ constructprop(h,"[package]flash.events::TextEvent", 4); __ callpropvoid(h,"[package]::dispatchEvent", 1); } } else if(oldaction) { fprintf(stderr, "Warning: Couldn't translate button code of button %d to flash 9 abc action\n", id); } __ returnvoid(h); swf_ActionFree(oldaction); } if(tag->id == ST_SHOWFRAME) { if(f) { __ returnvoid(f); f = 0; } frame++; } tag = tag->next; } if(f) { __ returnvoid(f); } } __ returnvoid(c); tag = swf->firstTag; while(tag) { if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) { char buttonname[80]; sprintf(buttonname, "::button%d", swf_GetDefineID(tag)); multiname_t*s = multiname_fromstring(buttonname); //abc_class_slot(cls, multiname_fromstring(buttonname), s); abc_class_slot(cls, multiname_fromstring(buttonname), multiname_fromstring("flash.display::SimpleButton")); } tag = tag->next; } abc_script_t*s = abc_initscript(file); c = s->method->body; c->old.max_stack = 2; c->old.local_count = 1; c->old.init_scope_depth = 1; c->old.max_scope_depth = 9; __ getlocal_0(c); __ pushscope(c); __ getscopeobject(c, 0); __ getlex(c,"::Object"); __ pushscope(c); __ getlex(c,"flash.events::EventDispatcher"); __ pushscope(c); __ getlex(c,"flash.display::DisplayObject"); __ pushscope(c); __ getlex(c,"flash.display::InteractiveObject"); __ pushscope(c); __ getlex(c,"flash.display::DisplayObjectContainer"); __ pushscope(c); __ getlex(c,"flash.display::Sprite"); __ pushscope(c); __ getlex(c,"flash.display::MovieClip"); __ pushscope(c); __ getlex(c,"flash.display::MovieClip"); __ newclass(c,cls); __ popscope(c); __ popscope(c); __ popscope(c); __ popscope(c); __ popscope(c); __ popscope(c); __ popscope(c); __ initproperty(c,scenename2); __ returnvoid(c); //abc_method_body_addClassTrait(c, "rfx:MainTimeline", 1, cls); multiname_t*classname = multiname_fromstring(scenename2); abc_initscript_addClassTrait(s, classname, cls); multiname_destroy(classname); swf_WriteABC(abctag, file); }