Advertisement
StefanBashkir

Untitled

Feb 2nd, 2014
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.04 KB | None | 0 0
  1. function Sav()
  2.     local tab       = {}
  3.     local x, y      = 0,50
  4.     Workspace:ClearAllChildren();
  5. end
  6. ------------31----------------------------0
  7. --iABC :    A:8 B:9 C:9     Op:6
  8. --iABx :    A:8 Bx:18       Op:6
  9. --iAsBx :   A:8 sBx:18      Op:6
  10. _G.bit = {
  11.     new = function(str)
  12.         return tonumber(str, 2)
  13.     end,
  14.     get = function(num, n, n2)
  15.         if n2 then
  16.             local total = 0
  17.             local digitn = 0
  18.             for i = n, n2 do
  19.                 total = total + 2^digitn*_G.bit.get(num, i)
  20.                 digitn = digitn + 1
  21.             end
  22.             return total
  23.         else
  24.             local pn = 2^(n-1)
  25.             return (num % (pn + pn) >= pn) and 1 or 0  
  26.         end
  27.     end,
  28.     getstring = function(num, mindigit, sep)
  29.         mindigit = mindigit or 0
  30.         local pow = 0
  31.         local tot = 1
  32.         while tot <= num do
  33.             tot = tot * 2
  34.             pow = pow + 1
  35.         end
  36.         ---
  37.         if pow < mindigit then pow = mindigit end
  38.         ---
  39.         local str = ""
  40.         for i = pow, 1, -1 do
  41.             str = str.._G.bit.get(num, i)..(i==1 and "" or (sep or "-"))
  42.         end
  43.         return str
  44.     end
  45. }
  46.  
  47. repeat wait() until _G.bit
  48. local bit = _G.bit
  49. local EncodeOp = {
  50. iABC = function(op, a, b, c)
  51.  
  52. end,
  53. iABx = function(op, a, bx)
  54.  
  55. end,
  56. iAsBx = function(op, a, sbx)
  57.  
  58. end
  59. }
  60.  
  61. local LuaOp = {
  62. MOVE = 0,
  63. LOADK = 1,
  64. LOADBOOL = 2,
  65. LOADNIL = 3,
  66. GETUPVAL = 4,
  67. GETGLOBAL = 5,
  68. GETTABLE = 6,
  69. SETGLOBAL = 7,
  70. SETUPVAL = 8,
  71. SETTABLE = 9,
  72. NEWTABLE = 10,
  73. SELF = 11,
  74. ADD = 12,
  75. SUB = 13,
  76. MUL = 14,
  77. DIV = 15,
  78. MOD = 16,
  79. POW = 17,
  80. UNM = 18,
  81. NOT = 19,
  82. LEN = 20,
  83. CONCAT = 21,
  84. JMP = 22,
  85. EQ = 23,
  86. LT = 24,
  87. LE = 25,
  88. TEST = 26,
  89. TESTSET = 27,
  90. CALL = 28,
  91. TAILCALL = 29,
  92. RETURN = 30,
  93. FORLOOP = 31,
  94. FORPREP = 32,
  95. TFORLOOP = 33,
  96. SETLIST = 34,
  97. CLOSE = 35,
  98. CLOSURE = 36,
  99. VARARG = 37
  100. }
  101.  
  102. local LuaOpName = {
  103. "MOVE",
  104. "LOADK",
  105. "LOADBOOL",
  106. "LOADNIL",
  107. "GETUPVAL",
  108. "GETGLOBAL",
  109. "GETTABLE",
  110. "SETGLOBAL",
  111. "SETUPVAL",
  112. "SETTABLE",
  113. "NEWTABLE",
  114. "SELF",
  115. "ADD",
  116. "SUB",
  117. "MUL",
  118. "DIV",
  119. "MOD",
  120. "POW",
  121. "UNM",
  122. "NOT",
  123. "LEN",
  124. "CONCAT",
  125. "JMP",
  126. "EQ",
  127. "LT",
  128. "LE",
  129. "TEST",
  130. "TESTSET",
  131. "CALL",
  132. "TAILCALL",
  133. "RETURN",
  134. "FORLOOP",
  135. "FORPREP",
  136. "TFORLOOP",
  137. "SETLIST",
  138. "CLOSE",
  139. "CLOSURE",
  140. "VARARG"
  141. }
  142.  
  143. local LuaOpType = {
  144. iABC = 0,
  145. iABx = 1,
  146. iAsBx = 2
  147. }
  148.  
  149. local LuaOpTypeLookup = {
  150. LuaOpType.iABC,
  151. LuaOpType.iABx,
  152. LuaOpType.iABC,
  153. LuaOpType.iABC,
  154. LuaOpType.iABC,
  155. LuaOpType.iABx,
  156. LuaOpType.iABC,
  157. LuaOpType.iABx,
  158. LuaOpType.iABC,
  159. LuaOpType.iABC,
  160. LuaOpType.iABC,
  161. LuaOpType.iABC, --self = ?
  162. LuaOpType.iABC,
  163. LuaOpType.iABC,
  164. LuaOpType.iABC,
  165. LuaOpType.iABC,
  166. LuaOpType.iABC,
  167. LuaOpType.iABC,
  168. LuaOpType.iABC,
  169. LuaOpType.iABC,
  170. LuaOpType.iABC,
  171. LuaOpType.iABC,
  172. LuaOpType.iAsBx,
  173. LuaOpType.iABC,
  174. LuaOpType.iABC,
  175. LuaOpType.iABC,
  176. LuaOpType.iABC,
  177. LuaOpType.iABC,
  178. LuaOpType.iABC,
  179. LuaOpType.iABC,
  180. LuaOpType.iABC,
  181. LuaOpType.iAsBx,
  182. LuaOpType.iAsBx,
  183. LuaOpType.iABC,
  184. LuaOpType.iABC,
  185. LuaOpType.iABC,
  186. LuaOpType.iABx,
  187. LuaOpType.iABC
  188. }
  189.  
  190. --[[
  191. ==HEADER==
  192. 4 : ESC "Lua" (0x1B4C7561)
  193. 1 : 0x51
  194. 1 : Format version, 0 = official
  195. 1 : Endianness (0 = big, 1 = little)
  196. 1 : size of int in bytes (4)
  197. 1 : size of size_t in bytes (4)
  198. 1 : size of instruction in bytes (4)
  199. 1 : size of lua_Number in bytes (8)
  200. 1 : (0 = FP, 1 = integral) (should be 0)
  201.  
  202. ==STRING==
  203. Size_t : String data size
  204. Bytes : String data including \0 at end
  205.  
  206. ==FUNCTION==
  207. String : source name
  208. Integer : line defined
  209. Integer : last line defined
  210. 1 : number of upvalues
  211. 1 : number of arguments
  212. 1 : (1 = VARARG_HASBVARARG, 2 = VARARG_ISVARARG, 4 = VARARG_NEEDSARG)
  213. 1 : max stack size
  214. List : list of instructions
  215. List : list of constants
  216. List : list of function prototypes
  217. == optional ==
  218. List : list of source line positions
  219. List : list of locals
  220. List : list of upvalues
  221.  
  222. == INSTRUCTION LIST ==
  223. Integer : size of code
  224. [Instruction] : the code
  225.  
  226. == CONST LIST ==
  227. Integer : size of constant list
  228. [
  229.     1 : (0 = NIL, 1 = BOOLEAN, 3 = NUMBER, 4 = STRING)
  230.     Const : the constant (none for NIL, 0 or 1 for BOOL, Number for NUMBER, String for STRING)
  231. ]
  232.  
  233. == FUNC PROTO LIST ==
  234. Integer : number of function protos
  235. [Functions] : function prototype data or function blocks
  236.  
  237. ]]
  238.  
  239. function GetOpString(op)
  240.     local opcode = GetOpCode(op)
  241.     local ty = GetOpCodeType(opcode)
  242.     local name = GetOpCodeName(opcode)
  243.     if ty == LuaOpType.iABC then
  244.         local b = GetOpB(op)
  245.         if b >= 256 then b = "256+"..(b-256) end
  246.         local c = GetOpC(op)
  247.         if c >= 256 then c = "256+"..(c-256) end
  248.         return "OP="..name.." A="..GetOpA(op).." B="..b.." C="..c
  249.     elseif ty == LuaOpType.iABx then
  250.         return "OP="..name.." A="..GetOpA(op).." Bx="..GetOpBx(op)     
  251.     elseif ty == LuaOpType.iAsBx then
  252.         return "OP="..name.." A="..GetOpA(op).." sBx="..GetOpsBx(op)   
  253.     end
  254.     return "OP=<Bad Type>"
  255. end
  256. function GetOpCodeType(opcode)
  257.     return LuaOpTypeLookup[opcode+1]
  258. end
  259. function GetOpCodeName(opcode)
  260.     return LuaOpName[opcode+1]
  261. end
  262. function GetOpCode(op)
  263.     return bit.get(op, 1, 6)
  264. end
  265. function GetOpA(op)
  266.     return bit.get(op, 7, 14)
  267. end
  268. function GetOpB(op)
  269.     return bit.get(op, 24, 32)
  270. end
  271. function GetOpC(op)
  272.     return bit.get(op, 15, 23)
  273. end
  274. function GetOpBx(op)
  275.     return bit.get(op, 15, 32)
  276. end
  277. function GetOpsBx(op)
  278.     return GetOpBx(op) - 131071
  279. end
  280.  
  281. function _G.DumpChunk(chunk, indent)
  282.     local indent = indent or 0
  283.     local index = 1
  284.     local big_endian = false
  285.     ------------------------------------
  286.     local function print2(...)
  287.         print(string.rep("_", indent*2), ...)
  288.     end
  289.     local function GetInt8()
  290.         local a = chunk:sub(index, index):byte()
  291.         index = index + 1
  292.         return a
  293.     end
  294.     local function GetInt16(str, inx)
  295.         local a = GetInt8()
  296.         local b = GetInt8()
  297.         return 256*b + a
  298.     end
  299.     local function GetInt32(str, inx)
  300.         local a = GetInt16()
  301.         local b = GetInt16()
  302.         return 65536*b + a
  303.     end
  304.     local function GetFloat64()
  305.         --[[print("A="..a.." B'"..b)
  306.         print("Bits="..bit.getstring(b, 32).."_"..bit.getstring(a, 32))
  307.         print("Bits="..bit.get(b, 32).."__"..bit.getstring(bit.get(b, 21, 31), 11).."__"..bit.getstring(bit.get(b, 1, 20), 20).."-"..bit.getstring(a, 32))
  308.         print("Sign="..sign..", Exp="..exponent..", Frac="..fraction)]]
  309.         --[[local sign = -2*bit.get(b, 32)+1
  310.         local exponent = bit.get(b, 21, 31)-1023
  311.         local fraction = (bit.get(b, 1, 20)*(2^32) + a)/(2^52)+1
  312.         return sign*(2^exponent)*fraction]]
  313.         local a = GetInt32()
  314.         local b = GetInt32()
  315.         return (-2*bit.get(b, 32)+1)*(2^(bit.get(b, 21, 31)-1023))*((bit.get(b, 1, 20)*(2^32) + a)/(2^52)+1)
  316.     end
  317.     local function GetString(len)
  318.         local str = chunk:sub(index, index+len-1)
  319.         index = index + len
  320.         return str
  321.     end
  322.     ------------------------------------
  323.     local function GetTypeInt()
  324.         local a = GetInt8()
  325.         local b = GetInt8()
  326.         local c = GetInt8()
  327.         local d = GetInt8()
  328.         return d*16777216 + c*65536 + b*256 + a
  329.     end
  330.     local function GetTypeString()
  331.         local tmp = GetInt32(str, index)
  332.         return GetString(tmp)
  333.     end
  334.     local function GetTypeFunction()
  335.         print2("====FUNCTION DEF====")
  336.         print2("Source Name \""..GetTypeString():sub(1, -2).."\", Lines "..GetTypeInt().." to "..GetTypeInt())
  337.         print2("Upvalues : "..GetInt8()..", Arguments : "..GetInt8()..", VargFlag : "..GetInt8()..", Max Stack Size : "..GetInt8())
  338.         do
  339.             local num = GetInt32()
  340.             print2("Instructions : "..num.." {")
  341.             indent = indent + 1
  342.             for i = 1, num do
  343.                 local op = GetInt32()
  344.                 local opcode = GetOpCode(op)
  345.                 print2(GetOpString(op))
  346.             end
  347.             indent = indent - 1
  348.             print2("}")
  349.         end
  350.         do
  351.             local num = GetInt32()
  352.             if num > 0 then
  353.                 print2("Constants : "..num.." {")
  354.                 indent = indent + 1
  355.                 for i = 1, num do
  356.                     local ty = GetInt8()
  357.                     if ty == 0 then
  358.                         print2((i-1).." : NIL")
  359.                     elseif ty == 1 then
  360.                         print2((i-1).." : BOOL = "..(GetInt8() == 0 and "false" or "true"))
  361.                     elseif ty == 3 then
  362.                         print2((i-1).." : NUMBER = "..GetFloat64())
  363.                     elseif ty == 4 then
  364.                         print2((i-1).." : STRING = \""..GetTypeString():sub(1, -2).."\"")
  365.                     end
  366.                 end
  367.                 indent = indent - 1
  368.                 print2("}")
  369.             else
  370.                 print2("Constants : 0 {}")
  371.             end
  372.         end
  373.         do
  374.             local num = GetInt32()
  375.             if num > 0 then
  376.                 print2("Functions Protos : "..num.." {")
  377.                 indent = indent + 1
  378.                 for i = 1, num do
  379.                     GetTypeFunction()
  380.                 end
  381.                 indent = indent - 1
  382.                 print2("}")
  383.             else
  384.                 print2("Function Protos : 0 {}")
  385.             end
  386.         end
  387.         do
  388.             --strip debug info
  389.             local numsrc = GetInt32()
  390.             for i = 1, numsrc do GetInt32() end
  391.             local numlocal = GetInt32()
  392.             for i = 1, numlocal do GetTypeString() GetInt32() GetInt32() end
  393.             local numups = GetInt32()
  394.             for i = 1, numups do GetTypeString() end
  395.         end
  396.     end
  397.     ---------------------------------------
  398.     --get chunk start
  399.     print2("====HEADER====")
  400.     print2("Chunk Identifier : "..GetString(4))
  401.     print2("Version number : "..GetInt8())
  402.     print2("Format : "..((GetInt8() == 0) and "Official" or "Unofficial"))
  403.     big_endian = (GetInt8() == 0)
  404.     print2("Format version : "..(big_endian and "Big Endian (0)" or "Little Endian (1)"))
  405.     print2("Size of int : "..GetInt8().." bytes")
  406.     print2("Size of size_t : "..GetInt8().." bytes")
  407.     print2("Size of instruction : "..GetInt8().." bytes")
  408.     print2("Size of lua_Number : "..GetInt8().." bytes")
  409.     print2("Number format : "..((GetInt8() == 0) and "FP" or "INT"))
  410.     GetTypeFunction()
  411. end
  412.  
  413.  
  414.  
  415. _G.DumpChunk(string.dump(Sav))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement