Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes upon loading bytecode #21

Open
bananasov opened this issue Apr 30, 2024 · 3 comments
Open

Crashes upon loading bytecode #21

bananasov opened this issue Apr 30, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@bananasov
Copy link

bananasov commented Apr 30, 2024

Some Love2D games do not have the source available like Balatro does, an example of such game is Intravenous 2: Mercenarism.

The injector crashes on

let buf_str = CString::new(buf)
.unwrap_or_else(|e| panic!("The byte buffer '{buf:?}' for target {name} contains a non-terminating null char: {e:?}"));
let buf_str = buf_str.to_str()
.unwrap_or_else(|e| panic!("The byte buffer '{buf:?}' for target {name} contains invalid UTF-8: {e:?}"));
and could be fixed by checking the first byte of the slice with \033 (ASCII escape character).

Patching games that use bytecode instead of source might prove to be a major headache as it would probably require writing a disassembler and assembler for Lua(JIT) bytecode.

@ethangreen-dev
Copy link
Owner

Short-term it wouldn't be a bad idea to short-circuit when we detect a bytecode buffer, bonus points if there's a good descriptive message in the error.

Long-term we can implement a decompiler phase to the buffer load step - shouldn't be too hard. I do worry about decomp temporal stability though; emitted code must be the same no matter what.

@ethangreen-dev ethangreen-dev added the enhancement New feature or request label May 2, 2024
@bananasov
Copy link
Author

Short-term it wouldn't be a bad idea to short-circuit when we detect a bytecode buffer, bonus points if there's a good descriptive message in the error.

Long-term we can implement a decompiler phase to the buffer load step - shouldn't be too hard. I do worry about decomp temporal stability though; emitted code must be the same no matter what.

You could also just compile patches to Bytecode and only insert the instructions of the top level function (commonly referred to as a prototype) instead of just decompiling it, it removes a step that could cause performance issues I've made naively but I doubt performance would be a problem.

For the past few days I've been working on a disassembler for multiple Lua versions (currently I have implemented Lua 5.1 and Lua 5.2) including LuaJIT so that should help make supporting bytecode a bit easier.

@ethangreen-dev
Copy link
Owner

My big concern is that the current patch system is fundamentally incompatible with bytecode as, at the very least, we would need to lazily decompile just to provide the pattern / regex patches something to compare against. The regex patch specifically would require the entire source document to be decompiled, so that strategy won't even work all of the time.

Thankfully all of this stuff is easy to cache so performance probably isn't that big of a deal.

I have a couple ideas on ways to move forward but I want to let them sit before I make any decisions. I will say though that this is absolutely something I want to support in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants