Advertisement
Hello_Starlight

bacon lua thing? idk

Jan 24th, 2022
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.14 KB | None | 0 0
  1. local Select = select;
  2. local Byte = string.byte;
  3. local Sub = string.sub;
  4.  
  5. local Opmode = {
  6. {b = 'OpArgR', c='OpArgN'}, {b = 'OpArgK', c='OpArgN'}, {b = 'OpArgU', c='OpArgU'},
  7. {b = 'OpArgR', c='OpArgN'}, {b = 'OpArgU', c='OpArgN'}, {b = 'OpArgK', c='OpArgN'},
  8. {b = 'OpArgR', c='OpArgK'}, {b = 'OpArgK', c='OpArgN'}, {b = 'OpArgU', c='OpArgN'},
  9. {b = 'OpArgK', c='OpArgK'}, {b = 'OpArgU', c='OpArgU'}, {b = 'OpArgR', c='OpArgK'},
  10. {b = 'OpArgK', c='OpArgK'}, {b = 'OpArgK', c='OpArgK'}, {b = 'OpArgK', c='OpArgK'},
  11. {b = 'OpArgK', c='OpArgK'}, {b = 'OpArgK', c='OpArgK'}, {b = 'OpArgK', c='OpArgK'},
  12. {b = 'OpArgR', c='OpArgN'}, {b = 'OpArgR', c='OpArgN'}, {b = 'OpArgR', c='OpArgN'},
  13. {b = 'OpArgR', c='OpArgR'}, {b = 'OpArgR', c='OpArgN'}, {b = 'OpArgK', c='OpArgK'},
  14. {b = 'OpArgK', c='OpArgK'}, {b = 'OpArgK', c='OpArgK'}, {b = 'OpArgR', c='OpArgU'},
  15. {b = 'OpArgR', c='OpArgU'}, {b = 'OpArgU', c='OpArgU'}, {b = 'OpArgU', c='OpArgU'},
  16. {b = 'OpArgU', c='OpArgN'}, {b = 'OpArgR', c='OpArgN'}, {b = 'OpArgR', c='OpArgN'},
  17. {b = 'OpArgN', c='OpArgU'}, {b = 'OpArgU', c='OpArgU'}, {b = 'OpArgN', c='OpArgN'},
  18. {b = 'OpArgU', c='OpArgN'}, {b = 'OpArgU', c='OpArgN'}
  19. };
  20.  
  21. local Opcode = { -- Opcode types.
  22. 'ABC', 'ABx', 'ABC', 'ABC';
  23. 'ABC', 'ABx', 'ABC', 'ABx';
  24. 'ABC', 'ABC', 'ABC', 'ABC';
  25. 'ABC', 'ABC', 'ABC', 'ABC';
  26. 'ABC', 'ABC', 'ABC', 'ABC';
  27. 'ABC', 'ABC', 'AsBx', 'ABC';
  28. 'ABC', 'ABC', 'ABC', 'ABC';
  29. 'ABC', 'ABC', 'ABC', 'AsBx';
  30. 'AsBx', 'ABC', 'ABC', 'ABC';
  31. 'ABx', 'ABC';
  32. };
  33.  
  34. -- rlbi author -> Rerumu
  35. -- special thanks;
  36. -- @cntkillme for providing faster bit extraction
  37. -- @Eternal for being #1 bug finder and providing better float decoder
  38. -- @stravant for contributing to the original project this is derived from
  39.  
  40. -- rerubi is an upgrade to the original Lua VM in Lua
  41. -- the prime goal of rerubi is to be the fastest:tm: alternative
  42. -- to a Lua in Lua bytecode execution
  43.  
  44. local function gBit(Bit, Start, End) -- No tail-calls, yay.
  45. if End then -- Thanks to cntkillme for giving input on this shorter, better approach.
  46. local Res = (Bit / 2 ^ (Start - 1)) % 2 ^ ((End - 1) - (Start - 1) + 1);
  47.  
  48. return Res - Res % 1;
  49. else
  50. local Plc = 2 ^ (Start - 1);
  51.  
  52. if (Bit % (Plc + Plc) >= Plc) then
  53. return 1;
  54. else
  55. return 0;
  56. end;
  57. end;
  58. end;
  59.  
  60. local function GetMeaning(ByteString)
  61. local Pos = 1;
  62. local gSizet;
  63. local gInt;
  64.  
  65. local function gBits8() -- Get the next byte in the stream.
  66. local F = Byte(ByteString, Pos, Pos);
  67.  
  68. Pos = Pos + 1;
  69.  
  70. return F;
  71. end;
  72.  
  73. local function gBits32()
  74. local W, X, Y, Z = Byte(ByteString, Pos, Pos + 3);
  75.  
  76. Pos = Pos + 4;
  77.  
  78. return (Z * 16777216) + (Y * 65536) + (X * 256) + W;
  79. end;
  80.  
  81. local function gBits64()
  82. return gBits32() * 4294967296 + gBits32();
  83. end;
  84.  
  85. local function gFloat()
  86. -- thanks @Eternal for giving me this so I could mangle it in here and have it work
  87. local Left = gBits32();
  88. local Right = gBits32();
  89. local IsNormal = 1
  90. local Mantissa = (gBit(Right, 1, 20) * (2 ^ 32))
  91. + Left;
  92.  
  93. local Exponent = gBit(Right, 21, 31);
  94. local Sign = ((-1) ^ gBit(Right, 32));
  95.  
  96. if (Exponent == 0) then
  97. if (Mantissa == 0) then
  98. return Sign * 0 -- +-0
  99. else
  100. Exponent = 1
  101. IsNormal = 0
  102. end
  103. elseif (Exponent == 2047) then
  104. if (Mantissa == 0) then
  105. return Sign * (1 / 0) -- +-Inf
  106. else
  107. return Sign * (0 / 0) -- +-Q/Nan
  108. end
  109. end
  110.  
  111. -- sign * 2**e-1023 * isNormal.mantissa
  112. return math.ldexp(Sign, Exponent - 1023) * (IsNormal + (Mantissa / (2 ^ 52)))
  113. end;
  114.  
  115. local function gString(Len)
  116. local Str;
  117.  
  118. if Len then
  119. Str = Sub(ByteString, Pos, Pos + Len - 1);
  120.  
  121. Pos = Pos + Len;
  122. else
  123. Len = gSizet();
  124.  
  125. if (Len == 0) then return; end;
  126.  
  127. Str = Sub(ByteString, Pos, Pos + Len - 1);
  128.  
  129. Pos = Pos + Len;
  130. end;
  131.  
  132. return Str;
  133. end;
  134.  
  135. local function ChunkDecode()
  136. local Instr = {};
  137. local Const = {};
  138. local Proto = {};
  139. local Chunk = {
  140. Instr = Instr; -- Instructions
  141. Const = Const; -- Constants
  142. Proto = Proto; -- Prototypes
  143. Lines = {}; -- Lines
  144. Name = gString(); -- Grab name string.
  145. FirstL = gInt(); -- First line.
  146. LastL = gInt(); -- Last line.
  147. Upvals = gBits8(); -- Upvalue count.
  148. Args = gBits8(); -- Arg count.
  149. Vargs = gBits8(); -- Vararg type.
  150. Stack = gBits8(); -- Stack.
  151. };
  152. local ConstantReferences = {}; -- for an optimization
  153.  
  154. if Chunk.Name then
  155. Chunk.Name = Sub(Chunk.Name, 1, -2);
  156. end;
  157.  
  158.  
  159. for Idx = 1, gInt() do -- Loading instructions to the chunk.
  160. local Data = gBits32();
  161. local Opco = gBit(Data, 1, 6);
  162. local Type = Opcode[Opco + 1];
  163. local Mode = Opmode[Opco + 1];
  164.  
  165. local Inst = {
  166. Enum = Opco;
  167. Value = Data;
  168. gBit(Data, 7, 14); -- Register A.
  169. };
  170.  
  171. if (Type == 'ABC') then -- Most common, basic instruction type.
  172. Inst[2] = gBit(Data, 24, 32);
  173. Inst[3] = gBit(Data, 15, 23);
  174. elseif (Type == 'ABx') then
  175. Inst[2] = gBit(Data, 15, 32);
  176. elseif (Type == 'AsBx') then
  177. Inst[2] = gBit(Data, 15, 32) - 131071;
  178. end;
  179.  
  180. -- Precompute data for some instructions
  181. do
  182. -- TEST and TESTSET
  183. if Opco == 26 or Opco == 27 then
  184. Inst[3] = Inst[3] == 0;
  185. end
  186.  
  187. -- EQ, LT, LE
  188. if Opco >= 23 and Opco <= 25 then
  189. Inst[1] = Inst[1] ~= 0;
  190. end
  191.  
  192. -- Anything that looks at a constant using B
  193. if Mode.b == 'OpArgK' then
  194. Inst[3] = Inst[3] or false; -- Simply to guarantee that Inst[4] is inserted in the array part
  195. if Inst[2] >= 256 then
  196. local Cons = Inst[2] - 256;
  197. Inst[4] = Cons;
  198.  
  199. local ReferenceData = ConstantReferences[Cons];
  200. if not ReferenceData then
  201. ReferenceData = {};
  202. ConstantReferences[Cons] = ReferenceData;
  203. end
  204.  
  205. ReferenceData[#ReferenceData + 1] = {Inst = Inst, Register = 4}
  206. end
  207. end
  208.  
  209. -- Anything that looks at a constant using C
  210. if Mode.c == 'OpArgK' then
  211. Inst[4] = Inst[4] or false -- Simply to guarantee that Inst[5] is inserted in the array part
  212. if Inst[3] >= 256 then
  213. local Cons = Inst[3] - 256;
  214. Inst[5] = Cons;
  215.  
  216. local ReferenceData = ConstantReferences[Cons];
  217. if not ReferenceData then
  218. ReferenceData = {};
  219. ConstantReferences[Cons] = ReferenceData;
  220. end
  221.  
  222. ReferenceData[#ReferenceData + 1] = {Inst = Inst, Register = 5}
  223. end
  224. end
  225. end
  226.  
  227. Instr[Idx] = Inst;
  228. end;
  229.  
  230. for Idx = 1, gInt() do -- Load constants.
  231. local Type = gBits8();
  232. local Cons;
  233.  
  234. if (Type == 1) then -- Boolean
  235. Cons = (gBits8() ~= 0);
  236. elseif (Type == 3) then -- Float/Double
  237. Cons = gFloat();
  238. elseif (Type == 4) then
  239. Cons = Sub(gString(), 1, -2);
  240. end;
  241.  
  242. -- Finish precomputing constants
  243. local Refs = ConstantReferences[Idx - 1];
  244. if Refs then
  245. for i = 1, #Refs do
  246. Refs[i].Inst[Refs[i].Register] = Cons
  247. end
  248. end
  249.  
  250. -- Write Constant to pool
  251. Const[Idx - 1] = Cons;
  252. end;
  253.  
  254. for Idx = 1, gInt() do -- Nested function prototypes.
  255. Proto[Idx - 1] = ChunkDecode();
  256. end;
  257.  
  258. do -- Debugging
  259. local Lines = Chunk.Lines;
  260.  
  261. for Idx = 1, gInt() do
  262. Lines[Idx] = gBits32();
  263. end;
  264.  
  265. for _ = 1, gInt() do -- Locals in stack.
  266. gString(); -- Name of local.
  267. gBits32(); -- Starting point.
  268. gBits32(); -- End point.
  269. end;
  270.  
  271. for _ = 1, gInt() do -- Upvalues.
  272. gString(); -- Name of upvalue.
  273. end;
  274. end;
  275.  
  276. return Chunk; -- Finished chunk.
  277. end;
  278.  
  279. do -- Most of this chunk I was too lazy to reformat or change
  280. assert(gString(4) == "\27Lua", "Lua bytecode expected.");
  281. assert(gBits8() == 0x51, "Only Lua 5.1 is supported.");
  282.  
  283. gBits8(); -- Probably version control.
  284. gBits8(); -- Is small endians.
  285.  
  286. local IntSize = gBits8(); -- Int size
  287. local Sizet = gBits8(); -- size_t
  288.  
  289. if (IntSize == 4) then
  290. gInt = gBits32;
  291. elseif (IntSize == 8) then
  292. gInt = gBits64;
  293. else
  294. error('Integer size not supported', 2);
  295. end;
  296.  
  297. if (Sizet == 4) then
  298. gSizet = gBits32;
  299. elseif (Sizet == 8) then
  300. gSizet = gBits64;
  301. else
  302. error('Sizet size not supported', 2);
  303. end;
  304.  
  305. assert(gString(3) == "\4\8\0", "Unsupported bytecode target platform");
  306. end;
  307.  
  308. return ChunkDecode();
  309. end;
  310.  
  311. local function _Returns(...)
  312. return Select('#', ...), {...};
  313. end;
  314.  
  315. local function Wrap(Chunk, Env, Upvalues)
  316. local Instr = Chunk.Instr;
  317. local Const = Chunk.Const;
  318. local Proto = Chunk.Proto;
  319.  
  320. local function OnError(Err, Position) -- Handle your errors in whatever way.
  321. local Name = Chunk.Name or 'Code';
  322. local Line = Chunk.Lines[Position] or '?';
  323.  
  324. error(string.format('%s:%s: %s', Name, Line, tostring(Err)), 0);
  325. end;
  326.  
  327. return function(...)
  328. local InstrPoint, Top = 1, -1;
  329. local Vararg, Varargsz = {}, Select('#', ...) - 1;
  330.  
  331. local GStack = {};
  332. local Lupvals = {};
  333. local Stack = setmetatable({}, {
  334. __index = GStack;
  335. __newindex = function(_, Key, Value)
  336. if (Key > Top) then
  337. Top = Key;
  338. end;
  339.  
  340. GStack[Key] = Value;
  341. end;
  342. });
  343.  
  344. local function Loop()
  345. local Inst, Enum;
  346.  
  347. while true do
  348. Inst = Instr[InstrPoint];
  349. Enum = Inst.Enum;
  350. InstrPoint = InstrPoint + 1;
  351.  
  352. if (Enum == 0) then -- MOVE
  353. Stack[Inst[1]] = Stack[Inst[2]];
  354. elseif (Enum == 1) then -- LOADK
  355. Stack[Inst[1]] = Const[Inst[2]];
  356. elseif (Enum == 2) then -- LOADBOOL
  357. Stack[Inst[1]] = (Inst[2] ~= 0);
  358.  
  359. if (Inst[3] ~= 0) then
  360. InstrPoint = InstrPoint + 1;
  361. end;
  362. elseif (Enum == 3) then -- LOADNIL
  363. local Stk = Stack;
  364.  
  365. for Idx = Inst[1], Inst[2] do
  366. Stk[Idx] = nil;
  367. end;
  368. elseif (Enum == 4) then -- GETUPVAL
  369. Stack[Inst[1]] = Upvalues[Inst[2]];
  370. elseif (Enum == 5) then -- GETGLOBAL
  371. Stack[Inst[1]] = Env[Const[Inst[2]]];
  372. elseif (Enum == 6) then -- GETTABLE
  373. local Stk = Stack;
  374. Stk[Inst[1]] = Stk[Inst[2]][Inst[5] or Stk[Inst[3]]];
  375. elseif (Enum == 7) then -- SETGLOBAL
  376. Env[Const[Inst[2]]] = Stack[Inst[1]];
  377. elseif (Enum == 8) then -- SETUPVAL
  378. Upvalues[Inst[2]] = Stack[Inst[1]];
  379. elseif (Enum == 9) then -- SETTABLE
  380. local Stk = Stack
  381. Stk[Inst[1]][Inst[4] or Stk[Inst[2]]] = Inst[5] or Stk[Inst[3]]
  382. elseif (Enum == 10) then -- NEWTABLE
  383. Stack[Inst[1]] = {};
  384. elseif (Enum == 11) then -- SELF
  385. local Stk = Stack;
  386. local A = Inst[1];
  387. local B = Stk[Inst[2]];
  388. local C = Inst[5] or Stk[Inst[3]];
  389. Stk[A + 1] = B;
  390. Stk[A] = B[C];
  391. elseif (Enum == 12) then -- ADD
  392. local Stk = Stack;
  393. Stk[Inst[1]] = (Inst[4] or Stk[Inst[2]]) + (Inst[5] or Stk[Inst[3]]);
  394. elseif (Enum == 13) then -- SUB
  395. local Stk = Stack;
  396. Stk[Inst[1]] = (Inst[4] or Stk[Inst[2]]) - (Inst[5] or Stk[Inst[3]]);
  397. elseif (Enum == 14) then -- MUL
  398. local Stk = Stack;
  399. Stk[Inst[1]] = (Inst[4] or Stk[Inst[2]]) * (Inst[5] or Stk[Inst[3]]);
  400. elseif (Enum == 15) then -- DIV
  401. local Stk = Stack;
  402. Stk[Inst[1]] = (Inst[4] or Stk[Inst[2]]) / (Inst[5] or Stk[Inst[3]]);
  403. elseif (Enum == 16) then -- MOD
  404. local Stk = Stack;
  405. Stk[Inst[1]] = (Inst[4] or Stk[Inst[2]]) % (Inst[5] or Stk[Inst[3]]);
  406. elseif (Enum == 17) then -- POW
  407. local Stk = Stack;
  408. Stk[Inst[1]] = (Inst[4] or Stk[Inst[2]]) ^ (Inst[5] or Stk[Inst[3]]);
  409. elseif (Enum == 18) then -- UNM
  410. Stack[Inst[1]] = -Stack[Inst[2]];
  411. elseif (Enum == 19) then -- NOT
  412. Stack[Inst[1]] = (not Stack[Inst[2]]);
  413. elseif (Enum == 20) then -- LEN
  414. Stack[Inst[1]] = #Stack[Inst[2]];
  415. elseif (Enum == 21) then -- CONCAT
  416. local Stk = Stack;
  417. local B = Inst[2];
  418. local K = Stk[B];
  419.  
  420. for Idx = B + 1, Inst[3] do
  421. K = K .. Stk[Idx];
  422. end;
  423.  
  424. Stack[Inst[1]] = K;
  425. elseif (Enum == 22) then -- JMP
  426. InstrPoint = InstrPoint + Inst[2];
  427. elseif (Enum == 23) then -- EQ
  428. local Stk = Stack;
  429. local B = Inst[4] or Stk[Inst[2]];
  430. local C = Inst[5] or Stk[Inst[3]];
  431.  
  432. if (B == C) ~= Inst[1] then
  433. InstrPoint = InstrPoint + 1;
  434. end;
  435. elseif (Enum == 24) then -- LT
  436. local Stk = Stack;
  437. local B = Inst[4] or Stk[Inst[2]];
  438. local C = Inst[5] or Stk[Inst[3]];
  439.  
  440. if (B < C) ~= Inst[1] then
  441. InstrPoint = InstrPoint + 1;
  442. end;
  443. elseif (Enum == 25) then -- LE
  444. local Stk = Stack;
  445. local B = Inst[4] or Stk[Inst[2]];
  446. local C = Inst[5] or Stk[Inst[3]];
  447.  
  448. if (B <= C) ~= Inst[1] then
  449. InstrPoint = InstrPoint + 1;
  450. end;
  451. elseif (Enum == 26) then -- TEST
  452. if Inst[3] then
  453. if Stack[Inst[1]] then
  454. InstrPoint = InstrPoint + 1;
  455. end
  456. elseif Stack[Inst[1]] then
  457. else
  458. InstrPoint = InstrPoint + 1;
  459. end
  460. elseif (Enum == 27) then -- TESTSET
  461. local B = Stack[Inst[2]];
  462.  
  463. if Inst[3] then
  464. if B then
  465. InstrPoint = InstrPoint + 1;
  466. else
  467. Stack[Inst[1]] = B
  468. end
  469. elseif B then
  470. Stack[Inst[1]] = B
  471. else
  472. InstrPoint = InstrPoint + 1;
  473. end
  474. elseif (Enum == 28) then -- CALL
  475. local A = Inst[1];
  476. local B = Inst[2];
  477. local C = Inst[3];
  478. local Stk = Stack;
  479. local Args, Results;
  480. local Limit, Edx;
  481.  
  482. Args = {};
  483.  
  484. if (B ~= 1) then
  485. if (B ~= 0) then
  486. Limit = A + B - 1;
  487. else
  488. Limit = Top;
  489. end;
  490.  
  491. Edx = 0;
  492.  
  493. for Idx = A + 1, Limit do
  494. Edx = Edx + 1;
  495.  
  496. Args[Edx] = Stk[Idx];
  497. end;
  498.  
  499. Limit, Results = _Returns(Stk[A](unpack(Args, 1, Limit - A)));
  500. else
  501. Limit, Results = _Returns(Stk[A]());
  502. end;
  503.  
  504. Top = A - 1;
  505.  
  506. if (C ~= 1) then
  507. if (C ~= 0) then
  508. Limit = A + C - 2;
  509. else
  510. Limit = Limit + A - 1;
  511. end;
  512.  
  513. Edx = 0;
  514.  
  515. for Idx = A, Limit do
  516. Edx = Edx + 1;
  517.  
  518. Stk[Idx] = Results[Edx];
  519. end;
  520. end;
  521. elseif (Enum == 29) then -- TAILCALL
  522. local A = Inst[1];
  523. local B = Inst[2];
  524. local Stk = Stack;
  525. local Args, Results;
  526. local Limit;
  527. local Rets = 0;
  528.  
  529. Args = {};
  530.  
  531. if (B ~= 1) then
  532. if (B ~= 0) then
  533. Limit = A + B - 1;
  534. else
  535. Limit = Top;
  536. end
  537.  
  538. for Idx = A + 1, Limit do
  539. Args[#Args + 1] = Stk[Idx];
  540. end
  541.  
  542. Results = {Stk[A](unpack(Args, 1, Limit - A))};
  543. else
  544. Results = {Stk[A]()};
  545. end;
  546.  
  547. for Index in pairs(Results) do -- get return count
  548. if (Index > Rets) then
  549. Rets = Index;
  550. end;
  551. end;
  552.  
  553. return Results, Rets;
  554. elseif (Enum == 30) then -- RETURN
  555. local A = Inst[1];
  556. local B = Inst[2];
  557. local Stk = Stack;
  558. local Edx, Output;
  559. local Limit;
  560.  
  561. if (B == 1) then
  562. return;
  563. elseif (B == 0) then
  564. Limit = Top;
  565. else
  566. Limit = A + B - 2;
  567. end;
  568.  
  569. Output = {};
  570. Edx = 0;
  571.  
  572. for Idx = A, Limit do
  573. Edx = Edx + 1;
  574.  
  575. Output[Edx] = Stk[Idx];
  576. end;
  577.  
  578. return Output, Edx;
  579. elseif (Enum == 31) then -- FORLOOP
  580. local A = Inst[1];
  581. local Stk = Stack;
  582.  
  583. local Step = Stk[A + 2];
  584. local Index = Stk[A] + Step;
  585.  
  586. Stk[A] = Index;
  587.  
  588. if (Step > 0) then
  589. if Index <= Stk[A + 1] then
  590. InstrPoint = InstrPoint + Inst[2];
  591.  
  592. Stk[A + 3] = Index;
  593. end;
  594. else
  595. if Index >= Stk[A + 1] then
  596. InstrPoint = InstrPoint + Inst[2];
  597.  
  598. Stk[A + 3] = Index;
  599. end
  600. end
  601. elseif (Enum == 32) then -- FORPREP
  602. local A = Inst[1];
  603. local Stk = Stack;
  604.  
  605. -- As per mirroring the real vm
  606. Stk[A] = assert(tonumber(Stk[A]), '`for` initial value must be a number');
  607. Stk[A + 1] = assert(tonumber(Stk[A + 1]), '`for` limit must be a number');
  608. Stk[A + 2] = assert(tonumber(Stk[A + 2]), '`for` step must be a number');
  609.  
  610. Stk[A] = Stk[A] - Stk[A + 2];
  611.  
  612. InstrPoint = InstrPoint + Inst[2];
  613. elseif (Enum == 33) then -- TFORLOOP
  614. local A = Inst[1];
  615. local C = Inst[3];
  616. local Stk = Stack;
  617.  
  618. local Offset = A + 2;
  619. local Result = {Stk[A](Stk[A + 1], Stk[A + 2])};
  620.  
  621. for Idx = 1, C do
  622. Stack[Offset + Idx] = Result[Idx];
  623. end;
  624.  
  625. if (Stk[A + 3] ~= nil) then
  626. Stk[A + 2] = Stk[A + 3];
  627. else
  628. InstrPoint = InstrPoint + 1;
  629. end;
  630. elseif (Enum == 34) then -- SETLIST
  631. local A = Inst[1];
  632. local B = Inst[2];
  633. local C = Inst[3];
  634. local Stk = Stack;
  635.  
  636. if (C == 0) then
  637. InstrPoint = InstrPoint + 1;
  638. C = Instr[InstrPoint].Value;
  639. end;
  640.  
  641. local Offset = (C - 1) * 50;
  642. local T = Stk[A]; -- Assuming T is the newly created table.
  643.  
  644. if (B == 0) then
  645. B = Top - A;
  646. end;
  647.  
  648. for Idx = 1, B do
  649. T[Offset + Idx] = Stk[A + Idx];
  650. end;
  651. elseif (Enum == 35) then -- CLOSE
  652. local A = Inst[1];
  653. local Cls = {}; -- Slight doubts on any issues this may cause
  654.  
  655. for Idx = 1, #Lupvals do
  656. local List = Lupvals[Idx];
  657.  
  658. for Idz = 0, #List do
  659. local Upv = List[Idz];
  660. local Stk = Upv[1];
  661. local Pos = Upv[2];
  662.  
  663. if (Stk == Stack) and (Pos >= A) then
  664. Cls[Pos] = Stk[Pos];
  665. Upv[1] = Cls; -- @memcorrupt credit me for the spoonfeed
  666. end;
  667. end;
  668. end;
  669. elseif (Enum == 36) then -- CLOSURE
  670. local NewProto = Proto[Inst[2]];
  671. local Stk = Stack;
  672.  
  673. local Indexes;
  674. local NewUvals;
  675.  
  676. if (NewProto.Upvals ~= 0) then
  677. Indexes = {};
  678. NewUvals = setmetatable({}, {
  679. __index = function(_, Key)
  680. local Val = Indexes[Key];
  681.  
  682. return Val[1][Val[2]];
  683. end,
  684. __newindex = function(_, Key, Value)
  685. local Val = Indexes[Key];
  686.  
  687. Val[1][Val[2]] = Value;
  688. end;
  689. }
  690. );
  691.  
  692. for Idx = 1, NewProto.Upvals do
  693. local Mvm = Instr[InstrPoint];
  694.  
  695. if (Mvm.Enum == 0) then -- MOVE
  696. Indexes[Idx - 1] = {Stk, Mvm[2]};
  697. elseif (Mvm.Enum == 4) then -- GETUPVAL
  698. Indexes[Idx - 1] = {Upvalues, Mvm[2]};
  699. end;
  700.  
  701. InstrPoint = InstrPoint + 1;
  702. end;
  703.  
  704. Lupvals[#Lupvals + 1] = Indexes;
  705. end;
  706.  
  707. Stk[Inst[1]] = Wrap(NewProto, Env, NewUvals);
  708. elseif (Enum == 37) then -- VARARG
  709. local A = Inst[1];
  710. local B = Inst[2];
  711. local Stk, Vars = Stack, Vararg;
  712.  
  713. Top = A - 1;
  714.  
  715. for Idx = A, A + (B > 0 and B - 1 or Varargsz) do
  716. Stk[Idx] = Vars[Idx - A];
  717. end;
  718. end;
  719. end;
  720. end;
  721.  
  722. local Args = {...};
  723.  
  724. for Idx = 0, Varargsz do
  725. if (Idx >= Chunk.Args) then
  726. Vararg[Idx - Chunk.Args] = Args[Idx + 1];
  727. else
  728. Stack[Idx] = Args[Idx + 1];
  729. end;
  730. end;
  731.  
  732. local A, B, C = pcall(Loop); -- Pcalling to allow yielding
  733.  
  734. if A then -- We're always expecting this to come out true (because errorless code)
  735. if B and (C > 0) then -- So I flipped the conditions.
  736. return unpack(B, 1, C);
  737. end;
  738.  
  739. return;
  740. else
  741. OnError(B, InstrPoint - 1); -- Didn't get time to test the `-1` honestly, but I assume it works properly
  742. end;
  743. end;
  744. end;
  745.  
  746. return function(BCode, Env) -- lua_function LoadBytecode (string BCode, table Env)
  747. local Buffer = GetMeaning(BCode);
  748.  
  749. return Wrap(Buffer, Env or getfenv(0)), Buffer;
  750. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement