Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local plugin = PluginManager():CreatePlugin()
- local toolbar = plugin:CreateToolbar("Script Obfuscator")
- local button = toolbar:CreateButton(
- "",
- "Format selected script.",
- "script_link.png"
- )
- function GetReplacement()
- local s = ""
- for i = 1, math.random(6,20) do
- s = s .. string.char(math.random(65,90)) --97,123 lowercase
- end
- return s
- end
- function GetFiller()
- local s = " --[===["
- for i = 1, math.random(7, 50) do
- s = s .. string.char(math.random(1,9)) .. string.char(math.random(11, 28))--string.char(math.random(1,255))
- end
- s = s .. "]===]"
- return s .. ""
- end
- function RebuildSource(source, ending)
- local tab = [[local StringConstants = {]]
- local index = 1
- if source:find("--", 1, true) then
- print("Source uses '--' symbols (if there are comments, please remove them from the source). Cannot obfuscate.", 0)
- return
- end
- for String in source:gmatch("%[%[.-%]%]") do
- tab = tab .. String .. ";"
- source = source:gsub("%[%[" .. String:sub(3, #String-2) .. "%]%]", "StringConstants[" .. index .. "]")
- index = index + 1
- end
- for String in source:gmatch('%[".-"%]') do
- tab = tab .. String:sub(2, #String-1) .. ";"
- source = source:gsub('%["' .. String:sub(3, #String-2) .. '"%]', "[StringConstants[" .. index .. "]]")
- index = index + 1
- end
- for String in source:gmatch('".-"') do
- tab = tab .. String .. ";"
- source = source:gsub(String, "StringConstants[" .. index .. "]")
- index = index + 1
- end
- for String in source:gmatch("'.-'") do
- tab = tab .. String .. ";"
- source = source:gsub(String, "StringConstants[" .. index .. "]")
- index = index + 1
- end
- tab = tab .. [[}]]
- source = source:gsub(" ", GetFiller)
- return tab .. "\n" .. source .. ending
- end
- function ObfuscateSource(_s)
- --print("Now attempting to obfuscate selected script...")
- local library = {}
- local c = _s.Source -- Cache a copy.
- local x = _s.Source -- Copy in use.
- -------------------------------------------------------------------------------------------
- for fType in x:gmatch("(function %a+%(%))") do
- local replacement = GetReplacement()
- local varName = fType:sub(10, #fType-2)
- print(varName)
- if #varName > 5 then
- library[varName] = replacement
- x = x:gsub(fType, "function " .. replacement)
- end
- end
- for fCall in x:gmatch("(%a+)%(%)") do
- if library[fCall] then
- x = x:gsub(fCall .. [[()]], library[fCall])
- end
- end
- -------------------------------------------------------------------------------------------
- for lType in x:gmatch("(local %a+)") do
- local replacement = GetReplacement()
- local varName = lType:sub(7)
- if #varName > 4 then
- library[varName] = replacement
- x = x:gsub(lType, "local " .. replacement)
- end
- end
- for each in x:gmatch("(%a*)") do
- if library[each] then
- x = x:gsub(each, library[each])
- end
- end
- _s.Source = RebuildSource(x,'\n \n \n--[===[This is a copy of the original source. Delete if unneeded. \n' .. c .. '\n]===]') or c
- end
- button.Click:connect(function()
- local s = Game.Selection:Get()[1]
- if s then
- if s:IsA("Script") then
- ObfuscateSource(s)
- elseif s:IsA("Workspace") then
- Instance.new("Script", Workspace).Source = [==[
- local b = 5
- local bad = 2
- local abd = 5
- local s = 8
- local isUse = true
- local canReplace = false
- local UsarVar = 'Ending of the index'
- local tVariable = [[Essence of the var ]]
- function Hit()
- end
- Hit()
- function Available()
- end
- Available()
- print(b + bad + abd)
- print("Hello world!")
- ]==]
- else
- print("Object selected is not a script, or there are more than one selected objects.")
- end
- else
- print("No object selected!")
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment