Advertisement
Guest User

Encryption

a guest
Nov 9th, 2017
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.07 KB | None | 0 0
  1. game.Workspace.Script.Source = ""
  2. local source = function()
  3. _G.findchild = function (instance, name)
  4.     for _, child in pairs(instance:GetChildren()) do
  5.         if child.Name == name then
  6.             return true
  7.         elseif _==#instance:GetChildren() then
  8.             return false
  9.         end
  10.     end
  11. end
  12. print(_G.findchild(game,"Workspace"))
  13. end
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. -- by NotAshley
  21.  
  22. -- thanks to MrNicNac for the original encryption method, and and NecroBumpist for the VM
  23. ajlanlsdf = Instance.new("Script",game.Workspace)
  24. ajlanlsdf.Name = "Script2"
  25. ajlanlsdf.Disabled = true
  26. local encrypt = function(str)
  27.         local Return = "local data = {"
  28.         local LengthDiv = 120
  29.         for i = 1, str:len() do            
  30.             if i == str:len() then
  31.                
  32.                 Return = Return .. "'\\" .. str:sub(i,i):byte() .. "'"
  33.                 if Return:len() > LengthDiv then
  34.                     game.Workspace.Script.Source = game.Workspace.Script.Source..(Return)
  35.                     Return = ""
  36.                 end
  37.             else
  38.                 Return = Return .. "'\\" .. str:sub(i,i):byte() .. "',"
  39.                 if Return:len() > LengthDiv then
  40.                     game.Workspace.Script.Source = game.Workspace.Script.Source..(Return)
  41.                     Return = ""
  42.                 end
  43.             end
  44.             end
  45.         Return = Return .. "}\n"
  46.         game.Workspace.Script.Source = game.Workspace.Script.Source..(Return)
  47. end
  48.  
  49. encrypt(string.dump(source))
  50.  
  51. game.Workspace.Script.Source = game.Workspace.Script.Source.. ([[
  52. local lua_opcode_types = {
  53. "ABC",  "ABx", "ABC",  "ABC",
  54. "ABC",  "ABx", "ABC",  "ABx",
  55. "ABC",  "ABC", "ABC",  "ABC",
  56. "ABC",  "ABC", "ABC",  "ABC",
  57. "ABC",  "ABC", "ABC",  "ABC",
  58. "ABC",  "ABC", "AsBx", "ABC",
  59. "ABC",  "ABC", "ABC",  "ABC",
  60. "ABC",  "ABC", "ABC",  "AsBx",
  61. "AsBx", "ABC", "ABC", "ABC",
  62. "ABx",  "ABC",
  63. }
  64. local lua_opcode_names = {
  65. "MOVE",     "LOADK",     "LOADBOOL", "LOADNIL",
  66. "GETUPVAL", "GETGLOBAL", "GETTABLE", "SETGLOBAL",
  67. "SETUPVAL", "SETTABLE",  "NEWTABLE", "SELF",
  68. "ADD",      "SUB",       "MUL",      "DIV",
  69. "MOD",      "POW",       "UNM",      "NOT",
  70. "LEN",      "CONCAT",    "JMP",      "EQ",
  71. "LT",       "LE",        "TEST",     "TESTSET",
  72. "CALL",     "TAILCALL",  "RETURN",   "FORLOOP",
  73. "FORPREP",  "TFORLOOP",  "SETLIST",  "CLOSE",
  74. "CLOSURE",  "VARARG"
  75. };
  76. local function get_bits(input, n, n2)
  77. if n2 then
  78. local total = 0
  79. local digitn = 0
  80. for i = n, n2 do
  81. total = total + 2^digitn*get_bits(input, i)
  82. digitn = digitn + 1
  83. end
  84. return total
  85. else
  86. local pn = 2^(n-1)
  87. return (input % (pn + pn) >= pn) and 1 or 0
  88. end
  89. end
  90. local function decode_bytecode(bytecode)
  91. local index = 1
  92. local big_endian = false
  93. local int_size;
  94. local size_t;
  95. local get_int, get_size_t;
  96. local get_int8, get_int32, get_int64, get_float64, get_string;
  97. do
  98. function get_int8()
  99. local a = bytecode:byte(index, index);
  100. index = index + 1
  101. return a
  102. end
  103. function get_int32()
  104. local a, b, c, d = bytecode:byte(index, index + 3);
  105. index = index + 4;
  106. return d*16777216 + c*65536 + b*256 + a
  107. end
  108. function get_int64()
  109. local a = get_int32();
  110. local b = get_int32();
  111. return b*4294967296 + a;
  112. end
  113. function get_float64()
  114. local a = get_int32()
  115. local b = get_int32()
  116. return (-2*get_bits(b, 32)+1)*(2^(get_bits(b, 21, 31)-1023))*
  117. ((get_bits(b, 1, 20)*(2^32) + a)/(2^52)+1)
  118. end
  119. function get_string(len)
  120. local str;
  121. if len then
  122. str = bytecode:sub(index, index + len - 1);
  123. index = index + len;
  124. else
  125. len = get_size_t();
  126. if len == 0 then return; end
  127. str = bytecode:sub(index, index + len - 1);
  128. index = index + len;
  129. end
  130. return str;
  131. end
  132. end
  133. local function decode_chunk()
  134. local chunk;
  135. local instructions = {};
  136. local constants    = {};
  137. local prototypes   = {};
  138. local debug = {
  139. lines = {};
  140. };
  141. chunk = {
  142. instructions = instructions;
  143. constants    = constants;
  144. prototypes   = prototypes;
  145. debug = debug;
  146. };
  147. local num;
  148. chunk.name       = get_string();
  149. chunk.first_line = get_int();
  150. chunk.last_line  = get_int();
  151. if chunk.name then chunk.name = chunk.name:sub(1, -2); end
  152. chunk.upvalues  = get_int8();
  153. chunk.arguments = get_int8();
  154. chunk.varg      = get_int8();
  155. chunk.stack     = get_int8();
  156. do
  157. num = get_int();
  158. for i = 1, num do
  159. local instruction = {
  160. };
  161. local data   = get_int32();
  162. local opcode = get_bits(data, 1, 6);
  163. local type   = lua_opcode_types[opcode + 1];
  164. instruction.opcode = opcode;
  165. instruction.type   = type;
  166. instruction.A = get_bits(data, 7, 14);
  167. if type == "ABC" then
  168. instruction.B = get_bits(data, 24, 32);
  169. instruction.C = get_bits(data, 15, 23);
  170. elseif type == "ABx" then
  171. instruction.Bx = get_bits(data, 15, 32);
  172. elseif type == "AsBx" then
  173. instruction.sBx = get_bits(data, 15, 32) - 131071;
  174. end
  175. instructions[i] = instruction;
  176. end
  177. end
  178. do
  179. num = get_int();
  180. for i = 1, num do
  181. local constant = {
  182. };
  183. local type = get_int8();
  184. constant.type = type;
  185. if type == 1 then
  186. constant.data = (get_int8() ~= 0);
  187. elseif type == 3 then
  188. constant.data = get_float64();
  189. elseif type == 4 then
  190. constant.data = get_string():sub(1, -2);
  191. end
  192. constants[i-1] = constant;
  193. end
  194. end
  195. do
  196. num = get_int();
  197. for i = 1, num do
  198. prototypes[i-1] = decode_chunk();
  199. end
  200. end
  201. do
  202. local data = debug.lines
  203. num = get_int();
  204. for i = 1, num do
  205. data[i] = get_int32();
  206. end
  207. num = get_int();
  208. for i = 1, num do
  209. get_string():sub(1, -2);
  210. get_int32();
  211. get_int32();
  212. end
  213. num = get_int();
  214. for i = 1, num do
  215. get_string();
  216. end
  217. end
  218. return chunk;
  219. end
  220. do
  221. assert(get_string(4) == "\27Lua", "Lua bytecode expected.");
  222. assert(get_int8() == 0x51, "Only Lua 5.1 is supported.");
  223. get_int8();
  224. big_endian = (get_int8() == 0);
  225. int_size = get_int8();
  226. size_t   = get_int8();
  227. if int_size == 4 then
  228. get_int = get_int32;
  229. elseif int_size == 8 then
  230. get_int = get_int64;
  231. else
  232. error("Unsupported bytecode target platform");
  233. end
  234. if size_t == 4 then
  235. get_size_t = get_int32;
  236. elseif size_t == 8 then
  237. get_size_t = get_int64;
  238. else
  239. error("Unsupported bytecode target platform");
  240. end
  241. assert(get_string(3) == "\4\8\0",
  242. "Unsupported bytecode target platform");
  243. end
  244. return decode_chunk();
  245. end
  246. local function handle_return(...)
  247. local c = select("#", ...)
  248. local t = {...}
  249. return c, t
  250. end
  251. local function create_wrapper(cache, upvalues)
  252. local instructions = cache.instructions;
  253. local constants    = cache.constants;
  254. local prototypes   = cache.prototypes;
  255.  
  256. local stack, top
  257. local environment
  258. local IP = 1;
  259. local vararg, vararg_size
  260.  
  261. local opcode_funcs = {
  262. [0]  = function(instruction)
  263. stack[instruction.A] = stack[instruction.B];
  264. end,
  265. [1]  = function(instruction)
  266. stack[instruction.A] = constants[instruction.Bx].data;
  267. end,
  268. [2]  = function(instruction)
  269. stack[instruction.A] = instruction.B ~= 0
  270. if instruction.C ~= 0 then
  271. IP = IP + 1
  272. end
  273. end,
  274. [3]  = function(instruction)
  275. local stack = stack
  276. for i = instruction.A, instruction.B do
  277. stack[i] = nil
  278. end
  279. end,
  280. [4] = function(instruction)
  281. stack[instruction.A] = upvalues[instruction.B]
  282. end,
  283. [5]  = function(instruction)
  284. local key = constants[instruction.Bx].data;
  285. stack[instruction.A] = environment[key];
  286. end,
  287. [6]  = function(instruction)
  288. local C = instruction.C
  289. local stack = stack
  290. C = C > 255 and constants[C-256].data or stack[C]
  291. stack[instruction.A] = stack[instruction.B][C];
  292. end,
  293. [7]  = function(instruction)
  294. local key = constants[instruction.Bx].data;
  295. environment[key] = stack[instruction.A];
  296. end,
  297. [8] = function (instruction)
  298. upvalues[instruction.B] = stack[instruction.A]
  299. end,
  300. [9] = function (instruction)
  301. local B = instruction.B;
  302. local C = instruction.C;
  303. local stack, constants = stack, constants;
  304. B = B > 255 and constants[B-256].data or stack[B];
  305. C = C > 255 and constants[C-256].data or stack[C];
  306. stack[instruction.A][B] = C
  307. end,
  308. [10] = function (instruction)
  309. stack[instruction.A] = {}
  310. end,
  311. [11] = function (instruction)
  312. local A = instruction.A
  313. local B = instruction.B
  314. local C = instruction.C
  315. local stack = stack
  316. B = stack[B]
  317. C = C > 255 and constants[C-256].data or stack[C]
  318. stack[A+1] = B
  319. stack[A]   = B[C]
  320. end,
  321. [12] = function(instruction)
  322. local B = instruction.B;
  323. local C = instruction.C;
  324. local stack, constants = stack, constants;
  325. B = B > 255 and constants[B-256].data or stack[B];
  326. C = C > 255 and constants[C-256].data or stack[C];
  327. stack[instruction.A] = B+C;
  328. end,
  329. [13] = function(instruction)
  330. local B = instruction.B;
  331. local C = instruction.C;
  332. local stack, constants = stack, constants;
  333. B = B > 255 and constants[B-256].data or stack[B];
  334. C = C > 255 and constants[C-256].data or stack[C];
  335. stack[instruction.A] = B - C;  
  336. end,
  337. [14] = function(instruction)
  338. local B = instruction.B;
  339. local C = instruction.C;
  340. local stack, constants = stack, constants;
  341. B = B > 255 and constants[B-256].data or stack[B];
  342. C = C > 255 and constants[C-256].data or stack[C];
  343. stack[instruction.A] = B * C;
  344. end,
  345. [15] = function(instruction)
  346. local B = instruction.B;
  347. local C = instruction.C;
  348. local stack, constants = stack, constants;
  349. B = B > 255 and constants[B-256].data or stack[B];
  350. C = C > 255 and constants[C-256].data or stack[C];
  351. stack[instruction.A] = B / C;
  352. end,
  353. [16] = function(instruction)
  354. local B = instruction.B;
  355. local C = instruction.C;
  356. local stack, constants = stack, constants;
  357. B = B > 255 and constants[B-256].data or stack[B];
  358. C = C > 255 and constants[C-256].data or stack[C];
  359. stack[instruction.A] = B % C;      
  360. end,
  361. [17] = function(instruction)
  362. local B = instruction.B;
  363. local C = instruction.C;
  364. local stack, constants = stack, constants;
  365. B = B > 255 and constants[B-256].data or stack[B];
  366. C = C > 255 and constants[C-256].data or stack[C];
  367. stack[instruction.A] = B ^ C;      
  368. end,
  369. [18] = function(instruction)
  370. stack[instruction.A] = -stack[instruction.B]
  371. end,
  372. [19] = function(instruction)
  373. stack[instruction.A] = not stack[instruction.B]
  374. end,
  375. [20] = function(instruction)
  376. stack[instruction.A] = #stack[instruction.B]
  377. end,
  378. [21] = function(instruction)
  379. local B = instruction.B
  380. local result = stack[B]
  381. for i = B+1, instruction.C do
  382. result = result .. stack[i]
  383. end
  384. stack[instruction.A] = result
  385. end,
  386. [22] = function(instruction)
  387. IP = IP + instruction.sBx
  388. end,
  389. [23] = function(instruction)
  390. local A = instruction.A
  391. local B = instruction.B
  392. local C = instruction.C
  393. local stack, constants = stack, constants
  394. A = A ~= 0
  395. B = B > 255 and constants[B-256].data or stack[B]
  396. C = C > 255 and constants[C-256].data or stack[C]
  397. if (B == C) ~= A then
  398. IP = IP + 1
  399. end
  400. end,
  401. [24] = function(instruction)
  402. local A = instruction.A
  403. local B = instruction.B
  404. local C = instruction.C
  405. local stack, constants = stack, constants
  406. A = A ~= 0
  407. B = B > 255 and constants[B-256].data or stack[B]
  408. C = C > 255 and constants[C-256].data or stack[C]
  409. if (B < C) ~= A then
  410. IP = IP + 1
  411. end    
  412. end,
  413. [25] = function(instruction)
  414. local A = instruction.A
  415. local B = instruction.B
  416. local C = instruction.C
  417. local stack, constants = stack, constants
  418. A = A ~= 0
  419. B = B > 255 and constants[B-256].data or stack[B]
  420. C = C > 255 and constants[C-256].data or stack[C]
  421. if (B <= C) ~= A then
  422. IP = IP + 1
  423. end    
  424. end,
  425. [26] = function(instruction)
  426. if stack[instruction.A] == (instruction.C ~= 0) then
  427. IP = IP + 1
  428. end
  429. end,
  430. [27] = function(instruction)
  431. local stack = stack
  432. local B = stack[instruction.B]
  433. if B == (instruction.C ~= 0) then
  434. IP = IP + 1
  435. else
  436. stack[instruction.A] = B
  437. end
  438. end,
  439. [28] = function(instruction)
  440. local A = instruction.A;
  441. local B = instruction.B;
  442. local C = instruction.C;
  443. local stack = stack;
  444. local args, results;
  445. local limit, loop
  446. args = {};
  447. if B ~= 1 then
  448. if B ~= 0 then
  449. limit = A+B-1;
  450. else
  451. limit = top
  452. end
  453. loop = 0
  454. for i = A+1, limit do
  455. loop = loop + 1
  456. args[loop] = stack[i];
  457. end
  458. limit, results = handle_return(stack[A](unpack(args, 1, limit-A)))
  459. else
  460. limit, results = handle_return(stack[A]())
  461. end
  462. top = A - 1
  463. if C ~= 1 then
  464. if C ~= 0 then
  465. limit = A+C-2;
  466. else
  467. limit = limit+A
  468. end
  469. loop = 0;
  470. for i = A, limit do
  471. loop = loop + 1;
  472. stack[i] = results[loop];
  473. end
  474. end
  475. end,
  476. [29] = function (instruction)
  477. local A = instruction.A;
  478. local B = instruction.B;
  479. local C = instruction.C;
  480. local stack = stack;
  481. local args, results;
  482. local top, limit, loop = top
  483. args = {};
  484. if B ~= 1 then
  485. if B ~= 0 then
  486. limit = A+B-1;
  487. else
  488. limit = top
  489. end
  490. loop = 0
  491. for i = A+1, limit do
  492. loop = loop + 1
  493. args[#args+1] = stack[i];
  494. end
  495. results = {stack[A](unpack(args, 1, limit-A))};
  496. else
  497. results = {stack[A]()};
  498. end
  499. return true, results
  500. end,
  501. [30] = function(instruction)
  502. local A = instruction.A;
  503. local B = instruction.B;
  504. local stack = stack;
  505. local limit;
  506. local loop, output;
  507. if B == 1 then
  508. return true;
  509. end
  510. if B == 0 then
  511. limit = top
  512. else
  513. limit = A + B - 2;
  514. end
  515. output = {};
  516. local loop = 0
  517. for i = A, limit do
  518. loop = loop + 1
  519. output[loop] = stack[i];
  520. end
  521. return true, output;
  522. end,
  523. [31] = function(instruction)
  524. local A = instruction.A
  525. local stack = stack
  526. local step = stack[A+2]
  527. local index = stack[A] + step
  528. stack[A] = index
  529. if step > 0 then
  530. if index <= stack[A+1] then
  531. IP = IP + instruction.sBx
  532. stack[A+3] = index
  533. end
  534. else
  535. if index >= stack[A+1] then
  536. IP = IP + instruction.sBx
  537. stack[A+3] = index
  538. end
  539. end
  540. end,
  541. [32] = function(instruction)
  542. local A = instruction.A
  543. local stack = stack
  544. stack[A] = stack[A] - stack[A+2]
  545. IP = IP + instruction.sBx
  546. end,
  547. [33] = function(instruction)
  548. local A = instruction.A
  549. local B = instruction.B
  550. local C = instruction.C
  551. local stack = stack
  552. local offset = A+2
  553. local result = {stack[A](stack[A+1], stack[A+2])}
  554. for i = 1, C do
  555. stack[offset+i] = result[i]
  556. end
  557. if stack[A+3] ~= nil then
  558. stack[A+2] = stack[A+3]
  559. else
  560. IP = IP + 1
  561. end
  562. end,
  563. [34] = function(instruction)
  564. local A = instruction.A
  565. local B = instruction.B
  566. local C = instruction.C
  567. local stack = stack
  568. if C == 0 then
  569. error("NYI: extended SETLIST")
  570. else
  571. local offset = (C - 1) * 50
  572. local t = stack[A]
  573. if B == 0 then
  574. B = top
  575. end
  576. for i = 1, B do
  577. t[offset+i] = stack[A+i]   
  578. end            
  579. end
  580. end,
  581. [35] = function(instruction)
  582. --io.stderr:write("NYI: CLOSE")
  583. --io.stderr:flush()
  584. end,
  585. [36] = function(instruction)
  586. local proto = prototypes[instruction.Bx]
  587. local instructions = instructions
  588. local stack = stack
  589. local indices = {}
  590. local new_upvals = setmetatable({},
  591. {
  592. __index = function(t, k)
  593. local upval = indices[k]
  594. return upval.segment[upval.offset]
  595. end,
  596. __newindex = function(t, k, v)
  597. local upval = indices[k]
  598. upval.segment[upval.offset] = v
  599. end
  600. }
  601. )
  602. for i = 1, proto.upvalues do
  603. local movement = instructions[IP]
  604. if movement.opcode == 0 then
  605. indices[i-1] = {segment = stack, offset = movement.B}
  606. elseif instructions[IP].opcode == 4 then
  607. indices[i-1] = {segment = upvalues, offset = movement.B}
  608. end
  609. IP = IP + 1
  610. end
  611. local _, func = create_wrapper(proto, new_upvals)
  612. stack[instruction.A] = func
  613. end,
  614. [37] = function(instruction)
  615. local A = instruction.A
  616. local B = instruction.B
  617. local stack, vararg = stack, vararg
  618.  
  619. for i = A, A + (B > 0 and B - 1 or vararg_size) do
  620. stack[i] = vararg[i - A]
  621. end
  622. end,
  623. }
  624. local function loop()
  625. local instructions = instructions
  626. local instruction, a, b
  627. while true do
  628. instruction = instructions[IP];
  629. IP = IP + 1
  630. a, b = opcode_funcs[instruction.opcode](instruction);
  631. if a then
  632. return b;
  633. end
  634. end
  635. end
  636. local debugging = {
  637. get_stack = function()
  638. return stack;
  639. end;
  640. get_IP = function()
  641. return IP;
  642. end
  643. };
  644. local function func(...)
  645. local local_stack = {};
  646. local ghost_stack = {};
  647. top = -1
  648. stack = setmetatable(local_stack, {
  649. __index = ghost_stack;
  650. __newindex = function(t, k, v)
  651. if k > top and v then
  652. top = k
  653. end
  654. ghost_stack[k] = v
  655. end;
  656. })
  657. local args = {...};
  658. vararg = {}
  659. vararg_size = select("#", ...) - 1
  660. for i = 0, vararg_size do
  661. local_stack[i] = args[i+1];
  662. vararg[i] = args[i+1]
  663. end
  664. environment = getfenv();
  665. IP = 1;
  666. local thread = coroutine.create(loop)
  667. local a, b = coroutine.resume(thread)
  668. if a then
  669. if b then
  670. return unpack(b);
  671. end
  672. return;
  673. else
  674. local name = cache.name;
  675. local line = cache.debug.lines[IP];
  676. local err  = b:gsub("(.-:)", "");
  677. local output = "";
  678. output = output .. (name and name .. ":" or "");
  679. output = output .. (line and line .. ":" or "");
  680. output = output .. b
  681. error(output, 0);
  682. end
  683. end
  684. return debugging, func;
  685. end
  686. local VM = {
  687. load_bytecode = function(bytecode)
  688. local cache = decode_bytecode(bytecode);
  689. local _, func = create_wrapper(cache);
  690. return func;
  691. end;
  692. utils = {
  693. decode_bytecode = decode_bytecode;
  694. create_wrapper = create_wrapper;
  695. debug_bytecode = function(bytecode)
  696. local cache = decode_bytecode(bytecode)
  697. return create_wrapper(cache);
  698. end;
  699. };
  700. }
  701. ]].."VM.load_bytecode(table.concat(data, [[]]))()")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement