int main(int argc, char *argv[]) { int filename_pos = 1; if (argc != filename_pos + 1) { fprintf(stderr, "Usage: delua file.lua\n"); exit(1); } char *filename = argv[filename_pos]; FILE *f = fopen(filename, "rb"); if (f == NULL) { perror(filename); exit(1); } lua_open(); ZIO z; luaZ_Fopen(&z, f, filename); TProtoFunc *tf = luaU_undump1(&z); fclose(f); if (tf == NULL) { fprintf(stderr, "%s isn't a valid lua script\n", filename); exit(1); } decompile(std::cout, tf, "", NULL, 0); lua_close(); return 0; }
/* ** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load */ static int protectedparser (ZIO *z, int bin) { volatile struct C_Lua_Stack oldCLS = L->Cstack; struct lua_longjmp myErrorJmp; volatile int status; TProtoFunc *volatile tf; struct lua_longjmp *volatile oldErr = L->errorJmp; L->errorJmp = &myErrorJmp; if (setjmp(myErrorJmp.b) == 0) { tf = bin ? luaU_undump1(z) : luaY_parser(z); status = 0; } else { /* an error occurred: restore L->Cstack and L->stack.top */ L->Cstack = oldCLS; L->stack.top = L->stack.stack+L->Cstack.base; tf = NULL; status = 1; } L->errorJmp = oldErr; if (status) return 1; /* error code */ if (tf == NULL) return 2; /* 'natural' end */ luaD_adjusttop(L->Cstack.base+1); /* one slot for the pseudo-function */ L->stack.stack[L->Cstack.base].ttype = LUA_T_PROTO; L->stack.stack[L->Cstack.base].value.tf = tf; luaV_closure(0); return 0; }
static void do_undump(ZIO* z) { while (1) { TProtoFunc* Main=luaU_undump1(z); if (Main==NULL) break; if (listing) PrintChunk(Main); } }
static void do_undump(ZIO* z) { for (;;) { TProtoFunc* Main=luaU_undump1(z); if (Main==NULL) break; if (optimizing) luaU_optchunk(Main); if (listing) luaU_printchunk(Main); if (testing) luaU_testchunk(Main); } }
/* ** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load */ static int32 protectedparser(ZIO *z, int32 bin) { int32 status; TProtoFunc *tf; jmp_buf myErrorJmp; jmp_buf *oldErr = lua_state->errorJmp; lua_state->errorJmp = &myErrorJmp; if (setjmp(myErrorJmp) == 0) { tf = bin ? luaU_undump1(z) : luaY_parser(z); status = 0; } else { tf = NULL; status = 1; } lua_state->errorJmp = oldErr; if (status) return 1; // error code if (tf == NULL) return 2; // 'natural' end luaD_adjusttop(lua_state->Cstack.base + 1); // one slot for the pseudo-function lua_state->stack.stack[lua_state->Cstack.base].ttype = LUA_T_PROTO; lua_state->stack.stack[lua_state->Cstack.base].value.tf = tf; luaV_closure(0); return 0; }