diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2c49502 --- /dev/null +++ b/.gitignore @@ -0,0 +1,102 @@ +LatestBuild +Podfile.lock +SuperDylib/SuperDylib.mm + +Super/TargetApp/*.app +Super/TargetApp/*.ipa + +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xccheckout +*.xcscmblueprint + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + + +## Obj-C/Swift specific +*.hmap +*.ipa +*.dSYM.zip +*.dSYM + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +Pods/ + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output + +# Code Injection +# +# After new code Injection tools there's a generated folder /iOSInjectionProject +# https://github.com/johnno1962/injectionforxcode + +iOSInjectionProject/ diff --git a/luac.bt b/luac.bt new file mode 100644 index 0000000..900e0f1 --- /dev/null +++ b/luac.bt @@ -0,0 +1,440 @@ +//------------------------------------------------ +//--- 010 Editor v8.0 Binary Template +// +// File: luac.bt +// Authors: fei_cong(346345565@qq.com) +// Version: 1.0 +// Purpose: +// Category: Programming +// File Mask: *.luac, *.lua +// ID Bytes: 1B 4c 75 61 +// History: +// 1.0 fei_cong: Initial version, support lua 5.2. +// +// License: This file is released into the public domain. People may +// use it for any purpose, commercial or otherwise. +//------------------------------------------------ + +enum LUA_DATATYPE { + LUA_TNIL = 0, + LUA_TBOOLEAN = 1, + LUA_TLIGHTUSERDATA = 2, + LUA_TNUMBER = 3, + LUA_TSTRING = 4, + LUA_TTABLE = 5, + LUA_TFUNCTION = 6, + LUA_TUSERDATA = 7, + LUA_TTHREAD = 8, + LUA_NUMTAGS = 9, + + LUA_TLCL = (LUA_TFUNCTION | (0 << 4)), /* Lua closure */ + LUA_TLCF = (LUA_TFUNCTION | (1 << 4)), /* light C function */ + LUA_TCCL = (LUA_TFUNCTION | (2 << 4)), /* C closure */ + + LUA_TSHRSTR = (LUA_TSTRING | (0 << 4)), /* short strings */ + LUA_TLNGSTR = (LUA_TSTRING | (1 << 4)), /* long strings */ + + LUA_TNUMFLT = (LUA_TNUMBER | (0 << 4)), /* float numbers */ + LUA_TNUMINT = (LUA_TNUMBER | (1 << 4)) /* integer numbers */ +}; + +enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ + +#define SIZE_C 9 +#define SIZE_B 9 +#define SIZE_Bx (SIZE_C + SIZE_B) +#define SIZE_A 8 +#define SIZE_Ax (SIZE_C + SIZE_B + SIZE_A) + +#define SIZE_OP 6 + +#define POS_OP 0 +#define POS_A (POS_OP + SIZE_OP) +#define POS_C (POS_A + SIZE_A) +#define POS_B (POS_C + SIZE_C) +#define POS_Bx POS_C +#define POS_Ax POS_A + +#define MAXARG_Bx ((1<>1) + +//forward declaration +struct Proto; +struct Inst; +struct Code; + +/* +** Macros to operate RK indices +*/ + +/* this bit 1 means constant (0 means register) */ +#define BITRK (1 << (SIZE_B - 1)) + +/* test whether value is a constant */ +//#define ISK(x) ((x) & BITRK) +int ISK(int x) { + return ((x) & BITRK); +} + +/* gets the index of the constant */ +//#define INDEXK(r) ((int)(r) & ~BITRK) +int INDEXK(int r) { + return ((r) & ~BITRK); +} + +#define MAXINDEXRK (BITRK - 1) + +/* code a constant index as a RK value */ +//#define RKASK(x) ((x) | BITRK) +int RKASK(int x) { + return ((x) | BITRK); +} + +//#define CC(r) (ISK((r)) ? 'K' : 'R') +int CC(int r) { + return (ISK((r)) ? 'K' : 'R'); +} + +//#define CV(r) (ISK((r)) ? INDEXK(r) : r) +int CV(int r) { + return (ISK((r)) ? INDEXK(r) : r); +} + +//TODO: update LUA_NUMBER & LUA_INTEGER length. +#define LUA_NUMBER double +#define LUA_INTEGER int64 //ptrdiff_t + +/* type of numbers in Lua */ +typedef LUA_NUMBER lua_Number; + +/* type for integer functions */ +typedef LUA_INTEGER lua_Integer; + + +typedef struct { + int b ; /* booleans */ + int tt_ ; +} lua_Val; + +typedef struct { + union Value { + //GCObject *gc; /* collectable objects */ + //void *p; /* light userdata */ + lua_Val val; /* booleans */ + //lua_CFunction f; /* light C functions */ + lua_Integer i ; /* integer numbers */ + lua_Number n ; /* float numbers */ + } value_ ; +} TValue ; + +typedef uint32 lu_int32; +typedef lu_int32 Instruction; + +#define MAXSTACK 250 +#define MAXCONSTSIZE 1024 + +typedef struct { + uint32 signature ; //".lua" + uchar version ; + uchar format ; + uchar endian ; + uchar size_int ; + uchar size_size_t ; + uchar size_Instruction ; + uchar size_lua_Number ; + uchar lua_num_valid ; + if (version == 0x52) { + uchar luac_tail[0x6] ; + } +} GlobalHeader; + +typedef struct { + LUA_DATATYPE const_type; + if (constant.const_type == LUA_TBOOLEAN) { + uchar bool_val; + } else if (const_type == LUA_TNUMBER) { + TValue num_val ; + } else if (const_type == LUA_TSTRING) { + uint64 string_size ; + char str_val[string_size]; + } else if (const_type == LUA_TNIL) { + } else { + Warning("need update,const_type:%x\n", const_type); + } +} Constant ; + +string number2str(TValue &o) { + local string ret; + local string fmt; + if (get_inst_sz() == 4) { + fmt = "(=%.7g)"; + } else if (get_inst_sz() == 8) { + fmt = "(=%.14g)"; + } else { + Warning("error inst size.\n"); + } + local int tt = o.value_.val.tt_; + //Printf("tt:%x\n", tt); + local lua_Integer i = o.value_.i; + local lua_Number n = o.value_.n; + SPrintf(ret, "%.14g", ((tt == (3 | (1 << 4))) ? i : n)); + + return ret; +} + +string numflt2str(TValue &o) { + local string ret; + local string fmt; + if (get_inst_sz() == 4) { + fmt = "(=%.7g)"; + } else if (get_inst_sz() == 8) { + fmt = "(=%.14g)"; + } else { + Warning("error inst size.\n"); + } + local lua_Number n = o.value_.n; + SPrintf(ret, "%.14g", n); + + return ret; +} + +string numint2str(TValue &o) { + local string ret; + local string fmt; + if (get_inst_sz() == 4) { + fmt = "(=%.7g)"; + } else if (get_inst_sz() == 8) { + fmt = "(=%.14g)"; + } else { + Warning("error inst size.\n"); + } + local lua_Integer i = o.value_.i; + SPrintf(ret, "%.14g", i); + + return ret; +} + +string ConstantRead(Constant& constant) { + local string str; + switch (constant.const_type) { + case LUA_TBOOLEAN: + { + SPrintf(str, "%s", constant.bool_val ? "true" : "false"); + return str; + } + case LUA_TNIL: + { + return "nil"; + } + case LUA_TNUMBER: + { + return number2str(constant.num_val); + } + case LUA_TSTRING: + { + return "(=\"" + constant.str_val + "\")"; + } + case LUA_TNUMFLT: + { + return numflt2str(constant.num_val); + } + case LUA_TNUMINT: + { + return numint2str(constant.num_val); + } + case LUA_TSHRSTR: + case LUA_TLNGSTR: + { + return "(=\"" + constant.str_val + "\")"; + } + default: + return ""; + } +} + +typedef struct { + //uint64 name_size ; + //char name[name_size]; + uchar instack ; + uchar idx ; +} Upvaldesc; + +typedef struct { + uint64 varname_size ; + char varname[varname_size]; + uint32 startpc ; + uint32 endpc ; +} LocVar ; + +string LocVarRead(LocVar &val) { + return val.varname; +} + +typedef struct { + uint32 sizek ; + local uint32 sz = sizek; + while (sz-- > 0) { + Constant constant; + } +} Constants ; + +typedef struct { + uint32 sizeupvalues ; + local uint32 sz = sizeupvalues; + while (sz-- > 0) { + Upvaldesc upvalue; + } +} Upvaldescs ; + +#define NUM_OPCODES ((int)OP_EXTRAARG + 1) + +typedef struct { + uint32 linedefined ; + uint32 lastlinedefined ; + uchar numparams ; + uchar is_vararg; + uchar maxstacksize ; +} ProtoHeader; + +typedef struct(string level) { + uint32 sizep ; + local uint32 sz = sizep; + local uint32 i = 0; + local string s_level; + while (sz-- > 0) { + SPrintf(s_level, "%s_%d", level, i++); + Proto proto(s_level); + }; +} Protos ; + +typedef struct { + uint32 sizelineinfo ; + local uint32 sz = sizelineinfo; + while (sz-- > 0) { + uint32 line; + }; +} Lines ; + +typedef struct { + uint64 src_string_size ; + char str[src_string_size]; +} SourceName ; + +string SourceNameRead(SourceName &name) { + return name.str; +} + +typedef struct { + uint32 sizelocvars; + local uint32 sz = sizelocvars; + while (sz-- > 0) { + LocVar local_var; + }; +} LocVars ; + +typedef struct { + uint64 name_size ; + char var_str[name_size]; +} UpValueName ; + +string UpValueNameRead(UpValueName& name) { + return name.var_str; +} + +typedef struct { + uint32 size_upvalue_names ; + local uint32 sz = size_upvalue_names; + while (sz-- > 0) { + UpValueName upvalue_name; + } +} UpValueNames ; + +typedef struct(int pc) { + local int pc_ = pc; + local uchar inst_sz = get_inst_sz(); + if (inst_sz == 4) { + uint32 inst; + } else { + Warning("Error size_Instruction."); + } +} Inst ; + +typedef struct { + uint32 sizecode ; + local uchar inst_sz = get_inst_sz(); + local int pc = 1; + if (inst_sz == 4) { + local uint32 sz = sizecode; + while (sz-- > 0) { + Inst inst(pc); + pc++; + } + } else { + Warning("Error size_Instruction."); + } +} Code ; + +typedef struct(string level) { + local string level_ = level; + //Printf("level:%s\n", level_); + + //header + ProtoHeader header; + + //code + Code code; + + // constants + Constants constants; + + // functions + Protos protos(level_); + + // upvalues + Upvaldescs upvaldescs; + + // string + SourceName src_name; + + // lines + Lines lines; + + // locals + LocVars loc_vars; + + // upvalue names + UpValueNames names; +} Proto ; + +string ProtoRead(Proto& proto) { + return "function level " + proto.level_; +} + +uchar get_inst_sz() { + return luac.header.size_Instruction; + //return ReadByte(9); +} + +uchar get_lua_version() { + return luac.header.version; +} + +typedef struct { + GlobalHeader header; + Proto proto("0"); +} Luac; + +////////////////////////////////start from here////////////////// +// $ luac -o ~/Desktop/allopcodes52.luac ~/git/luadec/bin/allopcodes-5.2.lua +local char endian = ReadByte(6); +//Printf("Endian:%d\n", endian); + +if (endian == 1) { + LittleEndian(); +} else if(0 == endian) { + BigEndian(); +} else { + Warning("Error endian."); +} + +Luac luac; \ No newline at end of file