0

My goal is to decompile, modify and recompile a lua script. I can do this easily expect that the header of the resulting binary file changes from the original one. The binary chunk I decompile starts with the following header:

1b4c 7561 5100 0104 0804 0400

The header in the generated file is:

1b4c 7561 5100 0104 0804 0800

As you can see the only thing that changes between them is the value of Size of lua_Number (source, see page 7)

I've tried changing the target platform and even the version but couldn't get the correct header in the end. Is there by any chance a way to set this as an option in some way?

Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
Stud
  • 521
  • 4
  • 8
  • 1
    You can use [this tool](https://lua-bytecode.github.io/) to convert a Lua bytecode to another platform and/or another size of numbers. Select your generated bytecode and convert it to EnBi `L4804`. – Egor Skriptunoff Oct 26 '19 at 14:41
  • 1
    Another option would be to build Lua with `#define LUA_NUMBER float` instead of `#define LUA_NUMBER double` (see details in luaconf.h) - this Lua will generate bytecode having 4-byte float numbers. – Egor Skriptunoff Oct 26 '19 at 14:43
  • Thanks you two for you suggestions. I didn't try the tool yet, mostly because it'd be a bit problematic to do this manually each time. Modifying lua's sources works well and allows me to recompile scripts exactly as they were originally. This is the answer I was looking for. – Stud Oct 27 '19 at 21:06
  • You can run this tool programmatically, see comments under [the similar question](https://stackoverflow.com/questions/58428342/it-is-possible-to-luaj-convert-a-script-to-the-binary-representation-of-lua-5-2) – Egor Skriptunoff Oct 27 '19 at 21:33

0 Answers0