4

I got a script that is no longer supported and I'm looking for a way to change the value of a variable in it... The script is encrypted (loadstring/bytecode/something like that) e.g.: loadstring('\27\76\117\97\81\0\1\4\4\4\8\0\')

I can find what I want to change (through notepad after I compile the script), but if I try to change the value, the script won't work, if I change and try to recompile it still won't work: "luac: Testing09.lua: unexpected end in precompiled chunk" ...

Any ideas? I did something like that with a program long a go using ollydbg but I can't use it with lua scripts... I'm kinda lost here, doing some Googling for quite a while couldn't find a way... Any ideas?

Lt_Shade
  • 590
  • 1
  • 7
  • 18
  • possible duplicate of [Best tool(s) for decompiling Lua bytecode?](http://stackoverflow.com/questions/743684/best-tools-for-decompiling-lua-bytecode) – hjpotter92 Oct 08 '13 at 08:35
  • Not really, but I found somethings in that post that could help me... But what I want is a way to change that value... Is just a string that got to be changed and I have no idea how... – user2857670 Oct 08 '13 at 08:38
  • 1
    Do I understand that correctly that you have a lua script, and inside it there is some bytecode loaded with `loadstring`? And what exactly do you want to change, i. e. a string constant for another one or something else? – mpeterv Oct 08 '13 at 11:35
  • possible duplicate of http://stackoverflow.com/questions/3660387/is-it-possible-to-change-strings-content-and-size-in-lua-bytecode-so-that-it-w. – lhf Oct 09 '13 at 12:03

1 Answers1

7

It is easy to change a string in a Lua bytecode. You just have to adjust the length of the string after you change it. The length comes before the string. It probably takes four or eight bytes just before the string, depending on whether you have a 32-bit or 64-bit platform. The length is stored in the endianness of the machine where the bytecode was generated. Note that strings include a trailing '\0' and this counts in the length.

Perhaps it is easier to just copy some bytes directly. Write this file

return "this is the new string you want" 

Generate bytecode from it with luac and look at an dump of luac.out and locate the string and its length. Copy those bytes to the original file.

I don't know whether notepad handles binary data. if it doesn't, you'll need an hex editor to do this.

Another solution is to write a Lua program that reads the bytecode as a strings, generate bytecode for return "this is the new string you want", perform the change in the original bytecode using string operations and write it back to file.

You can also try my bytecode inspector library lbci, which allows you to change constants in functions. You'd load the bytecode (but not execute it), and use setconstant after locating the constant that has the string you want to change.

In all, there is some fun to be had here...

lhf
  • 70,581
  • 9
  • 108
  • 149
  • all right haha I think I can do this now... gonna give it a try soon as I get home, ofc I will feedback here... thanks bro... – user2857670 Oct 08 '13 at 21:46
  • Man I found out how to change! But now since I'm retarded, I can't change the size of the string... I'm using an hex editor (I can change and it WORKS! if the string is of the same size as the original! If its one word long it won't work =\ need to be of the same exactly size...) Any ideas? I'm not really a computer guy anymore =\ And sorry about my english, never had a single english class in my whole life... hope you understand... – user2857670 Oct 09 '13 at 04:48
  • @user2857670, did you try my first suggestion? Perhaps you can post an example of what new string you want and what the old one is. – lhf Oct 09 '13 at 12:01