简体   繁体   中英

How to string.dump a string from arguments if there are any from the lua cli or dumping the code in the file if there are no arguments

I'm working on a lua obfuscator, and I want it to be able to switch from obfuscating code in the file if there are no arguments, or obfuscating the string argument from the lua cli. If that made absolutely no sense here's what I mean.

local Code = function()
    print("test")
end

Dumped = string.dump(Code)

if arg[1] then
    local function Temp()
        loadstring(arg[1])()
    end
    Dumped = string.dump(Temp)
end

The problem with this is that in the dump, it's not actually whatever the argument is, rather the variable. So how'd I get around that and change my string to code? I'm sorry if I make no sense.

Here's what I've tried and the problem:

local Code = function()
    print("test")
end

Dumped = string.dump(Code)

if arg[1] then
    local function Temp()
        loadstring(arg[1])()
    end
    Dumped = string.dump(Temp)
end

print(Dumped)

-- Say if we did lua file.lua print("hello world")
-- Expected result: LuaQ print hello world (with a bunch of whitespace in between)
-- Actual result: LuaQ arg[1] (also with a bunch of whitespace in between)

Right now you are dumping a function that loads the string and runs it. So you are getting the dump of the code that loads a string and runs it. No surprise there.

If you want to dump some other code, then you need to actually dump that code:

local code, codeError = loadstring(arg[1])
if code == nil then
    print("Error:",codeError)
else
    Dumped = string.dump(code)
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM