Code Monkey home page Code Monkey logo

luaobfuscator's Introduction

LuaObfuscator

This lua obfuscator was originally designed for Garry's Mod, but should work on vanilla lua. Written for private use in January 2016. I never did anything with it so I decided to put it on GitHub.

Requirements

  • Python 3.4.3+ (VERY IMPORTANT)

Optional Things

  • pyperclip (pip install pyperclip)

Usage

python __main__.py [--input input.lua] [--output output.lua] [--level 1] [--dontcopy] [--debug]

The default values are shown above.

If you don't want the code copied to your clipboard, use --dontcopy.

If your script is not running correctly, use --debug and you may find the issue.

Levels

Passed with the --level x argument.

Lvl Info
0 Original strings, should be very similar in size to input file
1 Creates a small file, less not as good as Lvl 2
2 Creates a small file, recommended level
3 Invisible strings, huge files that appear to be very small, not recommended!

Features

  • Code is tokenized and kind of understood
  • Strings are stripped, ciphered and replaced
  • Code rearrangement while retaining functionality
  • All variables, local and global, are understood and replaced
  • Renaming of variables defined in for loops
  • Basic understanding of code heirarchy

Known issues

  • Garry's Mod Lua adds // comments, which conflicts with Lua 5.3's floor division operator. Code using the floor division operator should be changed to something like math.floor(a/b)

luaobfuscator's People

Contributors

jkusner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

luaobfuscator's Issues

cant obfuscate

C:\Users\rober>C:\Python34\python.exe C:\Users\rober\Desktop\LuaObfuscator-master_main_.py [--input input.lua] [--output output.lua] [--level 1] [--dontcopy] [--debug]
Version: Beta 1.0.3 (Updated on Jun 09, 2016 @ 06:44 AM)
usage: main.py [-h] [--input INPUT] [--output OUTPUT] [--level LEVEL]
[--dontcopy] [--debug]
main.py: error: unrecognized arguments: [--input input.lua] [--output output.lua] [--level 1] [--dontcopy] [--debug]

Traceback (most recent call last)

So I am getting an error when trying to use this script on a linux(centos 7) system. It works perfectly fine on my windows pc, does this not work for linux systems because this is the error I get when I try to run it on linux:

Traceback (most recent call last): File "__main__.py", line 2, in <module> import obfuscator File "/home/obfuscator.py", line 3, in <module> import tokenizer File "/home/tokenizer.py", line 139 print("Fatal error occurred.", "Please check that your input is syntactically correct.", sep="\n") ^ SyntaxError: invalid syntax

'<name>' expected

lua.exe: D:/tools/AAA/LuaObfuscator/__decrypt_0.lua:1: '' expected near '�'

I run this decrypt file alft report a error,way?
Variable name illegal?

How can i do it

Obfuscated file will not run

0 LoganDark ~/Desktop/ShEdit lua main.lua.obf
lua: main.lua.obf:1: <name> expected near char(226)

This happens whether I use level 1, 2, 3, or 4.

Here's the contents of the file I'm trying to obfuscate:

local lex = require('.lib.lexer')

local function getTokens(text)
  return ({lex(text)})[2].getTokenList()
end

local function flattenTokens(tokens)
  local flattened = {}

  local function append(type, data)
    local last = flattened[#flattened]

    if last ~= nil and last.type == type then
      last.data = last.data .. data
    else
      flattened[#flattened + 1] = {type = type, data = data}
    end
  end

  for t = 1, #tokens do
    local token = tokens[t]

    for w = #token.LeadingWhite, 1, -1 do
      local white = token.LeadingWhite[w]

      if white.Data ~= nil and white.Data:len() > 0 then
        append(white.Type, white.Data)
      end
    end

    if token.Data ~= nil and token.Data:len() > 0 then
      append(token.Type, token.Data)
    end
  end

  return flattened
end

local function flatToLines(flattened)
  local function splitTwoLines(tokens)
    local l1 = {}
    local l2 = {}

    for i = 1, #tokens do
      local token = tokens[i]
      local data = token.data
      local pos = data:find('\n')

      if pos then
        local before = data:sub(1, pos - 1)
        local after = data:sub(pos + 1)

        if before:len() > 0 then
          l1[#l1 + 1] = {type = token.type, data = before}
        end

        if after:len() > 0 then
          l2[#l2 + 1] = {type = token.type, data = after}
        end

        for x = i + 1, #tokens do
          l2[#l2 + 1] = {type = tokens[x].type, data = tokens[x].data}
        end

        return l1, l2
      else
        l1[#l1 + 1] = {type = token.type, data = data}
      end
    end

    return l1, nil
  end

  local lines = {}
  local current = flattened

  while current and #current > 0 do
    local l1, l2 = splitTwoLines(current)
    current = l2

    lines[#lines + 1] = l1
  end

  return lines
end

return {
  getTokens = getTokens,
  flattenTokens = flattenTokens,
  flatToLines = flatToLines
}

Here's the command I used to obfuscate it:

0 LoganDark ~/LuaObfuscator
python3.6 __main__.py --input ~/Desktop/ShEdit/main.lua --output ~/Desktop/ShEdit/main.lua.obf --level 3 --dontcopy
Version: Beta 1.0.3 (Updated on Jan 14, 2018 @ 04:34 PM)
Randomly chose XOR value 53.
Stripped 2 strings and 0 comments.
Finished tokenizing 460 tokens.
Beginning Level 3 obfuscation...
Step 1...Done.
Step 2...Done.
Step 3...Done.
Step 4...Done.
Step 5...Done.
Step 6...Done.
Step 7...Done.
Assuming "Data" is a global.
Step 8...Done.
Step 9...Done.
Step 10...Done.
Finished in 0.165 seconds.

It says "Assuming "Data" is a global.", so I think it doesn't realize that tables can be accessed like table.key instead of just table['key'].

"Assuming <var> is a global." while it's not

Example lua code

(Ignore the fact the code itself doesn't work in gmod, it's only about showing you an example)

python __main__.py --input .\sh_gmodstorehack.lua --output obf.lua

local html = vgui.Create("DHTML")
        html:SetPos(42, 42)
        html:SetWidth(280)
        html:SetHeight(120)
        html.button = vgui.Create("DButton")
        html.button:SetText("")
        html.button:SetPos(42, 42 + 120)
        html.button:SetSize(285, 30)

Version: Beta 1.0.3 (Updated on Jun 09, 2016 @ 01:44 PM)
Randomly chose XOR value 216.
Stripped 3 strings and 0 comments.
Finished tokenizing 69 tokens.
Beginning Level 1 obfuscation...
Step 1...Done.
Step 2...Done.
Step 3...Done.
Step 4...Done.
Step 5...Done.
Step 6...Done.
Step 7...Done.
Assuming "button" is a global.
Step 8...Done.
Step 9...Done.
Step 10...Done.
Finished in 0.013 seconds.
Code copied to clipboard.

Also the code i showed is technically working even if there is no point of using it, and the obfuscated version doesn't compile in gmod



[ERROR] lua/perf.lua:1: bad argument #1 to '?' (Panel expected, got nil)
  1. unknown - [C]:-1
   2. unknown - lua/perf.lua:1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.