stoneharry

Untitled

Aug 27th, 2013
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.67 KB | None | 0 0
  1. local plugin = PluginManager():CreatePlugin()
  2. local toolbar = plugin:CreateToolbar("Script Obfuscator")
  3. local button = toolbar:CreateButton(
  4.     "",
  5.     "Format selected script.",
  6.     "script_link.png"
  7. )
  8.  
  9. function GetReplacement()
  10.     local s = ""
  11.     for i = 1, math.random(6,20) do
  12.         s = s .. string.char(math.random(65,90)) --97,123 lowercase
  13.     end
  14.     return s
  15. end
  16.  
  17. function GetFiller()
  18.     local s = " --[===["
  19.     for i = 1, math.random(7, 50) do
  20.         s = s .. string.char(math.random(1,9)) .. string.char(math.random(11, 28))--string.char(math.random(1,255))
  21.     end
  22.     s = s .. "]===]"
  23.     return s .. ""
  24. end
  25.  
  26. function RebuildSource(source, ending)
  27.     local tab = [[local StringConstants = {]]
  28.     local index = 1
  29.     if source:find("--", 1, true) then
  30.         print("Source uses '--' symbols (if there are comments, please remove them from the source). Cannot obfuscate.", 0)
  31.         return
  32.     end
  33.     for String in source:gmatch("%[%[.-%]%]") do
  34.         tab = tab .. String .. ";"
  35.         source = source:gsub("%[%[" .. String:sub(3, #String-2) .. "%]%]", "StringConstants[" .. index .. "]")
  36.         index = index + 1
  37.     end
  38.     for String in source:gmatch('%[".-"%]') do
  39.         tab = tab .. String:sub(2, #String-1) .. ";"
  40.         source = source:gsub('%["' .. String:sub(3, #String-2) .. '"%]', "[StringConstants[" .. index .. "]]")
  41.         index = index + 1
  42.     end
  43.     for String in source:gmatch('".-"') do
  44.         tab = tab .. String .. ";"
  45.         source = source:gsub(String, "StringConstants[" .. index .. "]")
  46.         index = index + 1
  47.     end
  48.     for String in source:gmatch("'.-'") do
  49.         tab = tab .. String .. ";"
  50.         source = source:gsub(String, "StringConstants[" .. index .. "]")
  51.         index = index + 1
  52.     end
  53.     tab = tab .. [[}]]
  54.     source = source:gsub(" ", GetFiller)
  55.     return tab .. "\n" .. source .. ending
  56. end
  57.  
  58. function ObfuscateSource(_s)
  59.     --print("Now attempting to obfuscate selected script...")
  60.     local library = {}
  61.     local c = _s.Source -- Cache a copy.
  62.     local x = _s.Source -- Copy in use.
  63.     -------------------------------------------------------------------------------------------
  64.     for fType in x:gmatch("(function %a+%(%))") do
  65.         local replacement = GetReplacement()
  66.         local varName = fType:sub(10, #fType-2)
  67.         print(varName)
  68.         if #varName > 5 then
  69.             library[varName] = replacement
  70.             x = x:gsub(fType, "function " .. replacement)
  71.         end
  72.     end
  73.     for fCall in x:gmatch("(%a+)%(%)") do
  74.         if library[fCall] then
  75.             x = x:gsub(fCall .. [[()]], library[fCall])
  76.         end
  77.     end
  78.     -------------------------------------------------------------------------------------------
  79.     for lType in x:gmatch("(local %a+)") do
  80.         local replacement = GetReplacement()
  81.         local varName = lType:sub(7)
  82.         if #varName > 4 then
  83.             library[varName] = replacement
  84.             x = x:gsub(lType, "local " .. replacement)
  85.         end
  86.     end
  87.     for each in x:gmatch("(%a*)") do
  88.         if library[each] then
  89.             x = x:gsub(each, library[each])
  90.         end
  91.     end
  92.     _s.Source = RebuildSource(x,'\n \n \n--[===[This is a copy of the original source. Delete if unneeded. \n' .. c .. '\n]===]') or c
  93. end
  94. button.Click:connect(function()
  95.     local s = Game.Selection:Get()[1]
  96.     if s then
  97.         if s:IsA("Script") then
  98.             ObfuscateSource(s)
  99.         elseif s:IsA("Workspace") then
  100.             Instance.new("Script", Workspace).Source = [==[
  101.             local b = 5
  102.             local bad = 2
  103.             local abd = 5
  104.             local s = 8
  105.             local isUse = true
  106.             local canReplace = false
  107.             local UsarVar = 'Ending of the index'
  108.             local tVariable = [[Essence of the var ]]
  109.  
  110.             function Hit()
  111.  
  112.             end
  113.  
  114.             Hit()
  115.            
  116.             function Available()
  117.            
  118.             end
  119.            
  120.             Available()
  121.  
  122.             print(b + bad + abd)
  123.             print("Hello world!")
  124.             ]==]
  125.         else
  126.             print("Object selected is not a script, or there are more than one selected objects.")
  127.         end
  128.     else
  129.         print("No object selected!")
  130.     end
  131. end)
Advertisement
Add Comment
Please, Sign In to add comment