SHARE
TWEET

pysefs luau "dumper"

Vzurxy Sep 27th, 2019 (edited) 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.  
  3. The script automatically places the variables into your script environment with the use of getfenv.
  4. Just put this at the top of the script, and you're good to go!
  5.  
  6. EXPLANATION
  7. - dumpFunction
  8. Dumps constants and upvalues of the function, and prints them.
  9.  
  10. Parameters: Function
  11.  
  12. - dumpTable
  13. Dumps the contents of the table, giving all of the information about it.
  14. If the table has metamethods such as __tostring, this would bypass it.
  15.  
  16. Parameters: Table
  17.  
  18. - tableToString
  19. Converts a table into a string.
  20. Example:
  21.  
  22. local myTable = {
  23.    [1] = "Hello, World!";
  24.    [2] = "This is my table.";
  25.    [3] = "I made this myself!";
  26. };
  27. print(tableToString(myTable));
  28.  
  29. expected output:
  30. [1] = Hello, World! (type: string)
  31. [2] = This is my table. (type: string)
  32. [3] = I made this myself! (type: string)
  33.  
  34. Parameters: Table
  35.  
  36. - findString
  37. Dumps all functions' constants within the debug registry, and search for a specific string.
  38. if the second parameter is set to true, it will find all strings that partially match with the string provided (e.g "hello" would find "hello world", and so on).
  39.  
  40. Parameters: String, boolean
  41.  
  42. - countLen
  43. Returns the length of a table, even if it is a dictionary.
  44.  
  45. Parameters: Table
  46.  
  47. - isArray
  48. Returns a boolean on whether the table passed is an array.
  49.  
  50. Parameters: Table
  51.  
  52. - forEach
  53. Loops through the table passed, running the callback function that was passed.
  54. The callback function has 2 arguments passed to it: the Key and the Value of the current table index.
  55.  
  56. Parameters: Table, Callback function
  57.  
  58. The script automatically puts all these functions into your environment by using getfenv.
  59. ]]--
  60.  
  61. local globals = {
  62.     [assert] = true;
  63.     [collectgarbage] = true;
  64.     [error] = true;
  65.     [getfenv] = true;
  66.     [getmetatable] = true;
  67.     [ipairs] = true;
  68.     [loadstring] = true;
  69.     [newproxy] = true;
  70.     [next] = true;
  71.     [pairs] = true;
  72.     [pcall] = true;
  73.     [print] = true;
  74.     [rawequal] = true;
  75.     [rawget] = true;
  76.     [rawset] = true;
  77.     [select] = true;
  78.     [setfenv] = true;
  79.     [setmetatable] = true;
  80.     [tonumber] = true;
  81.     [tostring] = true;
  82.     [type] = true;
  83.     [unpack] = true;
  84.     [xpcall] = true;
  85.     [_G] = true;
  86.     [_VERSION] = true;
  87.     [delay] = true;
  88.     [elapsedTime] = true;
  89.     [LoadLibrary] = true;
  90.     [printidentity] = true;
  91.     [require] = true;
  92.     [settings] = true;
  93.     [spawn] = true;
  94.     [stats] = true;
  95.     [tick] = true;
  96.     [time] = true;
  97.     [typeof] = true;
  98.     [UserSettings] = true;
  99.     [_VERSION] = true;
  100.     [wait] = true;
  101.     [warn] = true;
  102.     [Enum] = true;
  103.     [game] = true;
  104.     [shared] = true;
  105.     [workspace] = true;
  106.     [type] = true;
  107. };
  108.  
  109. setmetatable(globals, {
  110.     __index = function(self, key)
  111.         return tostring(key);
  112.     end;
  113. });
  114.  
  115. local function findString(ToFind, Partly)
  116.     for i,v in next, debug.getregistry() do
  117.         if type(v) == "function" and islclosure(v) then
  118.             for g,b in next, debug.getconstants(v) do
  119.                 if type(b) == "string" and (Partly and (b:lower():match(ToFind:lower())) or b == ToFind) then
  120.                     return v;
  121.                 end;
  122.             end;
  123.         end;
  124.     end;
  125. end;
  126.  
  127. local function forEach(Table, Callback)
  128.     for Key, Value in next, Table do
  129.         Callback(Key, Value);
  130.     end;
  131. end;
  132.  
  133. local function countLen(Table)
  134.     local Count = 0;
  135.     forEach(Table, function(Key, Value) Count = Count + 1; end);
  136.     return Count;
  137. end;
  138.  
  139. local function isArray(Table)
  140.     return not (#Table == 0 and (countLen(Table) > 0));
  141. end;
  142.  
  143. local function tableToString(Table)
  144.     if countLen(Table) == 0 then return "{}"; end;
  145.     local Result = "{"
  146.  
  147.     local isArray = isArray(Table);
  148.  
  149.     for i,v in next, Table do
  150.  
  151.         local BackupMT = {};
  152.         if type(v) == "table" then
  153.             local MT = getrawmetatable(v);
  154.             if MT then
  155.                 for g,b in next, MT do
  156.                     rawset(BackupMT, g, b);
  157.                     rawset(MT, g, nil);
  158.                 end;
  159.             end;
  160.         end;
  161.  
  162.         Result = Result .. "\n  [" .. tostring(type(i) == "number" and i or ('"' .. i .. '"')) .. "] = " .. globals[v] .. " (type: " .. typeof(v) .. ")";
  163.  
  164.         if type(v) == "table" then
  165.             local MT = getrawmetatable(v);
  166.             if MT then
  167.                 for g,b in next, BackupMT do
  168.                     rawset(MT, g, b);
  169.                 end;
  170.             end;
  171.         end;
  172.  
  173.     end;
  174.     Result = Result .. "\n}";
  175.     return Result;
  176. end;
  177.  
  178. -- You can change this to some custom print function
  179. printconsole = warn
  180.  
  181. local isLuaFunction = islclosure;
  182. if isLuaFunction == nil then
  183.     isLuaFunction = function(Function)
  184.         local worked, Err = pcall(coroutine.wrap, Function);
  185.         return worked;
  186.     end;
  187. end;
  188.  
  189. local function dumpFunction(Function)
  190.     if type(Function) ~= "function" then return; end;
  191.     local Upvalues = debug.getupvalues(Function);
  192.     printconsole("Function found!\nUpvalues: " .. tableToString(Upvalues));
  193.     if isLuaFunction(Function) then
  194.         local Constants = debug.getconstants(Function);
  195.         printconsole("Constants: " .. tableToString(Constants))
  196.     end;
  197. end;
  198.  
  199. local function dumpTable(Table)
  200.     if type(Table) ~= "table" then return; end;
  201.     printconsole("Table found!\nContents: " .. tableToString(Table));
  202. end;
  203.  
  204. --[[
  205. getfenv(2).dumpFunction = dumpFunction;
  206. getfenv(2).dumpTable = dumpTable;
  207. getfenv(2).tableToString = tableToString;
  208. getfenv(2).findString = findString;
  209. getfenv(2).countLen = countLen;
  210. getfenv(2).isArray = isArray;
  211. getfenv(2).forEach = forEach;
  212. ]]--
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top