int main(int argc, char* argv[]) { lua_State* L; Proto* f; int i=doargs(argc,argv); argc-=i; argv+=i; if (argc<=0) usage("no input files given",NULL); L=lua_open(); luaB_opentests(L); for (i=0; i<argc; i++) { const char* filename=IS("-") ? NULL : argv[i]; if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1)); } f=combine(L,argc); if (listing) luaU_print(f); if (dumping) { FILE* D=fopen(output,"wb"); if (D==NULL) cannot(output,"open","out"); if (stripping) strip(L,f); luaU_dump(L,f,writer,D); if (ferror(D)) cannot(output,"write","out"); fclose(D); } lua_close(L); return 0; }
/* ** open parts that may cause memory-allocation errors */ static void f_luaopen (lua_State *L, void *ud) { int stacksize = *(int *)ud; if (stacksize == 0) stacksize = DEFAULT_STACK_SIZE; else stacksize += LUA_MINSTACK; L->gt = luaH_new(L, 10); /* table of globals */ luaD_init(L, stacksize); luaS_init(L); luaX_init(L); luaT_init(L); lua_newtable(L); lua_ref(L, 1); /* create registry */ lua_register(L, LUA_ERRORMESSAGE, errormessage); #ifdef LUA_DEBUG luaB_opentests(L); if (lua_state == NULL) lua_state = L; /* keep first state to be opened */ #endif LUA_ASSERT(lua_gettop(L) == 0, "wrong API stack"); }
int main(int argc, char* argv[]) { lua_State* L; const char *destfile, *destnum, *srcfile, *srcnum; Proto *fdestroot, *fsrcroot, *fparent, *fdest, *fsrc; int cdest, csrc; char *realdestnum = NULL, *realsrcnum = NULL; FILE* D; int diff, i; gargc = argc; gargv = argv; i = doargs(argc,argv); argc -= i; argv += i; if (printfuncnum && argc < 1) { usage("need 1 arguments for -pn at least", NULL); } if (argc < 4) { usage("need 4 arguments at least", NULL); } L = lua_open(); glstate = L; luaB_opentests(L); destfile = argv[0]; destnum = argv[1]; if (luaL_loadfile(L, destfile) != 0) { fatal(lua_tostring(L, -1)); } fdestroot = toproto(L, -1); if (printfuncnum) { printf("%d\n",0); printFuncStructure(fdestroot, " 0_"); lua_close(L); return EXIT_SUCCESS; } realdestnum = (char*)calloc(strlen(destnum)+1, sizeof(char)); fparent = findParentFunction(fdestroot, destnum, &cdest, realdestnum); if (cdest < 0) { if (realdestnum) { free(realdestnum); realdestnum = NULL; } fatal("cannot find dest function"); } if (fparent == NULL) { fdest = fdestroot; } else { fdest = fparent->p[cdest]; } srcfile = argv[2]; srcnum = argv[3]; if (luaL_loadfile(L, srcfile) != 0) { fatal(lua_tostring(L, -1)); } fsrcroot = toproto(L, -1); realsrcnum = (char*)calloc(strlen(srcnum)+1, sizeof(char)); fsrc = findParentFunction(fsrcroot, srcnum, &csrc, realsrcnum); if (csrc < 0) { if (realdestnum) { free(realdestnum); realdestnum = NULL; } if (realsrcnum) { free(realsrcnum); realsrcnum = NULL; } fatal("cannot find src function"); } if (fsrc == NULL) { fsrc = fsrcroot; } else { fsrc = fsrc->p[csrc]; } if (!replace_sub){ if (fparent == NULL) { if (realdestnum) { free(realdestnum); realdestnum = NULL; } if (realsrcnum) { free(realsrcnum); realsrcnum = NULL; } fatal("cannot use root as dest function"); } fprintf(stderr, "Replacing %s %s with %s %s ...\n", destfile, realdestnum, srcfile, realsrcnum); diff = replaceFunction(fparent, cdest, fsrc); fprintf(stderr, "1 function replaced ok.\n"); } else { fprintf(stderr, "Replacing sub functions of %s %s with those of %s %s ...\n", destfile, realdestnum, srcfile, realsrcnum); diff = replaceSubFunctions(fdest, fsrc); fprintf(stderr, "%d function replaced ok.", MIN(fdest->sizep, fsrc->sizep)); if (fdest->sizep != fsrc->sizep) { fprintf(stderr, " The dest has %d sub functions, but the src has %d . Please have a check.\n", fdest->sizep, fsrc->sizep); } else { fprintf(stderr, "\n"); } } if (realdestnum) { free(realdestnum); realdestnum = NULL; } if (realsrcnum) { free(realsrcnum); realsrcnum = NULL; } if (strict == 1 && diff > 0){ fatal("strip mode on and incompatible functions found, stop writing output."); } D = (output == NULL) ? stdout : fopen(output, "wb"); if (D == NULL) cannot("open"); lua_lock(L); luaU_dump(L, fdestroot, writer, D, 0); lua_unlock(L); if (ferror(D)) cannot("write"); if (fclose(D)) cannot("close"); printf("%s generated!\n", output); lua_close(L); return EXIT_SUCCESS; }
int main(int argc, char* argv[]) { int oargc; char** oargv; char tmp[256]; lua_State* L; Proto* f; int i; oargc = argc; oargv = argv; LDS2 = NULL; i=doargs(argc,argv); argc-=i; argv+=i; if (argc<=0) usage("no input files given",NULL); L=lua_open(); glstate = L; luaB_opentests(L); for (i=0; i<argc; i++) { const char* filename=IS("-") ? NULL : argv[i]; if (luaL_loadfile(L,filename)!=0) fatal(lua_tostring(L,-1)); } if (disassemble) { printf("; This file has been disassembled using luadec " VERSION " by sztupy (http://winmo.sztupy.hu)\n"); printf("; Command line was: "); } else { printf("-- Decompiled using luadec " VERSION " by sztupy (http://winmo.sztupy.hu)\n"); printf("-- Command line was: "); } for (i=1; i<oargc; i++) { printf("%s ",oargv[i]); } printf("\n\n"); f=combine(L,argc); if (guess_locals) { luaU_guess_locals(f,0); } if (lds2) { int i,i2; for (i=-1; i<f->sizep; i++) { Proto * x = f; if (i!=-1) { x = f->p[i]; } for (i2=0; i2<x->sizelocvars; i2++) { if (i2!=0) printf(","); printf("%d-%d",x->locvars[i2].startpc,x->locvars[i2].endpc); } printf(";"); } return 0; } if (functions) { if (disassemble) { sprintf(tmp,"%d",functions); luaU_disassemble(f,debugging,functions,tmp); } else { luaU_decompileFunctions(f, debugging, functions); } } else { if (disassemble) { sprintf(tmp,""); luaU_disassemble(f,debugging,0,tmp); } else { luaU_decompile(f, debugging); } } return 0; }