prometheus-lua / Prometheus

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

[BUG] Vmify in certain conditions produces code that randomly stops working #71

Open dragonbane0 opened 1 year ago

dragonbane0 commented 1 year ago

Describe the bug As best as I can tell is that too many control structures (if, for) is a struggle as soon as the virtual machine (Vmify) setting is enabled. It took me a long while to make a script that can reliably re-produce the issue without containing any sensitive code (see at the bottom).

My more complex scripts will encounter this bug often. It manifests in that execution stops right when a nested control structure in a table function is supposed to end. A print at the end of the affected control structure will still go through, right outside after it will no longer happen. Call stack doesn't seem to matter, the function is inherently broken. No exception is fired either.

If you move the function around in the file, so will the issue shift to a different place in the code (or sometimes no longer happen). Removing a single if control block anywhere in the file can also fix the issue or move it to a different place. However the amount of code inside the control structures seems to have no effect on the bug (as long as you don't add more control structures that is).

Expected behavior That even more complex scripts don't have this issue with control structures as soon as you use Vmify.

To Reproduce Use the following nonsense script and note how you get 3 logs unobfuscated: "Pre bug", "For loop" and "Post bug". Now obfuscate the script with the Vmify, ConstantArray, NumbersToExpressions and WrapInFunction setting and find that now only the first 2 logs fire and the last one never happens. Leave out the Vmify setting and it all works fine. Even using the Vmify setting standalone already causes the bug.

The source script: https://pastebin.com/6vtiNN6t The obfuscated broken script: https://pastebin.com/9yVSSbSy The config settings: https://pastebin.com/jCxEGGBF

Additional context Lua 5.1

levno-710 commented 1 year ago

I will work on this asap.

This is probably due to some small typo in compiler.lua

At least other fixed bugs that caused random crashes that got worse with bigger programs were due to typos.

dragonbane0 commented 1 year ago

Not sure if you deleting your reply means you managed to re-create it after all, but just for extra context I would like to confirm that I do use the latest Prometheus release v0.2.3 (using the source code version with a Lua 5.1 Windows compiler) and it happens on that.

I was running into issues with the first alpha release too, but I figured there was no use in reporting those, so I've made sure to upgrade to latest beforehand.

It's indeed very finicky though and one random change can "fix" or move the bug entirely.

levno-710 commented 1 year ago

Maybe this bug is the related to lua5.1, because using luajit I can't reproduce this.

I will try Lua 5.1 tomorrow

dragonbane0 commented 1 year ago

Yep. Just compiled it with luajit and the bug doesn't happen at that specific point. There is also a notable file size increase of 8 KB going from lua5.1 to luajit despite identical settings and seed.

Until you can check further I'm not going to say that the bug is completely fixed, compiling with luajit might just move it to a different place yet again.

I will try compiling some of my original more complex scripts again tomorrow and see if luajit makes them all come out completely okay.

levno-710 commented 1 year ago

The size increase may be, because lua5.1 uses a diferent implementation for math.random. Nevertheless, prometheus is supposed to be compatible with lua5.1, so I will try to fix this in the next days. I will also try to see if this issue also occurs for luajit.

dragonbane0 commented 1 year ago

Looks like there might still be some issues with luajit as well. At least 2 of my lua files obfuscated individually worked fine, but put together into the same file had issues. Will try to narrow that down and see if it is related or something else

dragonbane0 commented 1 year ago

Coudn't really narrow it down last time I looked, so hopefully it will be figured out eventually why larger files have issues like this

zxsleebu commented 1 year ago

when executing on luajit sometimes if the file is too big it throws "control structure too long near 'end'"

nacho00112 commented 5 months ago

Is this still happening or it can be closed? @levno-710