WerWolv / ImHex-Patterns

Hex patterns, include patterns and magic files for the use with the ImHex Hex Editor
https://github.com/WerWolv/ImHex
GNU General Public License v2.0
640 stars 168 forks source link

patterns: Added Lua 5.3 bytecode pattern #285

Closed qux-bbb closed 1 month ago

WerWolv commented 1 month ago

Thanks! Would it make sense maybe to combine all these versions into a single pattern? The version information seems to be in the binary file and the format of all looks reasonably similar

qux-bbb commented 1 month ago

There are some differences between these version, so it's difficult to combine them into a single pattern.

WerWolv commented 1 month ago

Do you possibly also have a Lua 5.4 test file? That's one of the few test files we're missing still

qux-bbb commented 1 month ago

Do you possibly also have a Lua 5.4 test file? That's one of the few test files we're missing still

I'll upload a Lua 5.4 test file.

paxcut commented 1 month ago

i've noticed that in 5.3 and 5.4 the values of type that decide if value is int or floating point are reversed. Did they decide that swapping them provided some sort of advantage?

Lua 5.3

    } else if (type == 3) {  // LUA_TNUMFLT
        double data;
    } else if (type == 0x13) {  // LUA_TNUMINT
        u64 data;

Lua 5.4

    if (type == 3) {
        u64 data;
    } else if (type == 0x13) {
        double data;
qux-bbb commented 1 month ago

I don't know why, here's the code.

Lua 5.3.6

/* Variant tags for numbers */
#define LUA_TNUMFLT (LUA_TNUMBER | (0 << 4))  /* float numbers */
#define LUA_TNUMINT (LUA_TNUMBER | (1 << 4))  /* integer numbers */

    case LUA_TNUMFLT:
      DumpNumber(fltvalue(o), D);
      break;
    case LUA_TNUMINT:
      DumpInteger(ivalue(o), D);
      break;

Lua 5.4.6

/* add variant bits to a type */
#define makevariant(t,v)    ((t) | ((v) << 4))

#define LUA_TNUMBER     3

/* Variant tags for numbers */
#define LUA_VNUMINT makevariant(LUA_TNUMBER, 0)  /* integer numbers */
#define LUA_VNUMFLT makevariant(LUA_TNUMBER, 1)  /* float numbers */

      case LUA_VNUMFLT:
        dumpNumber(D, fltvalue(o));
        break;
      case LUA_VNUMINT:
        dumpInteger(D, ivalue(o));
        break;

https://www.lua.org/ftp/lua-5.3.6.tar.gz
https://www.lua.org/ftp/lua-5.4.6.tar.gz

paxcut commented 1 month ago

I looked into combining all the lua versions into 1 pattern and I can probably do that if there is any interest.