Skip to content

[BUG] Function returns table instead of function after obfuscation #50

@wrefgtzweve

Description

@wrefgtzweve

Describe the bug
I'm having an issue where the obfuscated code returns a different value than the non obfuscated code does. This obviously causes lua errors. This is all being ran and tested in the Garry's mod lua environment which is Lua 5.1 luajit. Using prometheus Alpha v0.1.8 (latest tag at this moment). Issue also exists in other lua enviroments such as https://replit.com/languages/lua.

Expected behavior

local wrappedFunctions = {}
local function registerWrap( global, wrapFunc )
    local debugtbl = debug.getinfo( global )
    local function wrap( ... )
        return wrapFunc( ... )
    end

    wrappedFunctions[wrap] = {
        debugtbl = debugtbl
    }

    return wrap
end
print( 0 )
_type = _typet or type
print( 1 )
type = registerWrap( type, function( ... ) return _type( ... ) end )
print( 2 )
print( type )
print( type( "Test1" ), type( true ) )
print( 3 )

Would normally return

0
1
2
function: 0x1531f30
string  boolean
3

To Reproduce

  1. Obfuscate code above using Vm
  2. Run code

Obfuscated code returns in repl:

0
1
2
table: 0x8d3ab0
lua: [string "<eval>"]:1: attempt to call field '?' (a table value)
stack traceback:
    [string "<eval>"]:1: in function 'i'
    [string "<eval>"]:1: in function <[string "<eval>"]:1>
    (tail call): ?
    (tail call): ?
    (tail call): ?

Additional context
The issue does NOT occur when the code is as following and obfuscated.

local function registerWrap( global, wrapFunc )
    local debugtbl = debug.getinfo( global )
    local function wrap( ... )
        return wrapFunc( ... )
    end

    return wrap
end
print( 0 )
_type = _type or type
print( 1 )
type = registerWrap( type, function( ... ) return _type( ... ) end )
print( 2 )
print( type )
print( type( "Test1" ), type( true ) )
print( 3 )

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions