prometheus-lua / Prometheus

Lua Obfuscator written in pure Lua
https://levno-710.gitbook.io/prometheus/
GNU Affero General Public License v3.0
202 stars 60 forks source link

[BUG] String key being variable [resolved] #150

Closed Vaxood closed 10 months ago

Vaxood commented 10 months ago

Hey i have this issue my input was

local tbl = {
    ["vaxod"] = true ,
    va = true,
}

output

local g={vaxod=true;va=true};

i was fix it in parser.lua line 943 to 959:

        if(consume(self, TokenKind.Symbol, "[")) then
            local key = self:expression(scope);
            expect(self, TokenKind.Symbol, "]");
            expect(self, TokenKind.Symbol, "=");
            local value = self:expression(scope);
            local tbl = Ast.KeyedTableEntry(key, value)
            tbl.IsStringKey = true 
            table.insert(entries, tbl);
        elseif(is(self, TokenKind.Ident, 0) and is(self, TokenKind.Symbol, "=", 1)) then
            local key = Ast.StringExpression(get(self).value);
            expect(self, TokenKind.Symbol, "=");
            local value = self:expression(scope);
            table.insert(entries, Ast.KeyedTableEntry(key, value));
        else
            local value = self:expression(scope);
            table.insert(entries, Ast.TableEntry(value));
        end

unparser.lua line : 952 to 961

if(entry.kind == AstKind.KeyedTableEntry) the
      if(entry.key.kind == AstKind.StringExpression and self:isValidIdentifier(entry.key.value)) and not entry.IsStringKey then
            code = code .. entry.key.value;
        else
            code = code .. "[" .. self:unparseExpression(entry.key, tableTabbing) .. "]";
        end
        code = code .. self:optionalWhitespace() .. "=" .. self:optionalWhitespace() .. 
                self:unparseExpression(entry.value, tableTabbing);
    else
        code = code .. self:unparseExpression(entry.value, tableTabbing);
    end
levno-710 commented 10 months ago

This is intentional, as the following expressions are equivalent in lua:

{
    ["vaxod"] = true ,
    va = true,
}, {vaxod=true;va=true};