是否可以在Lua字节码内更改值?如何?任何的想法? [英] Is it possible to change a value inside a Lua bytecode? How? Any idea?

查看:114
本文介绍了是否可以在Lua字节码内更改值?如何?任何的想法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不再受支持的脚本,我正在寻找一种方法来更改其中的变量的值...该脚本是加密的(loadstring/bytecode/之类的),例如:loadstring('\27\76\117\97\81\0\1\4\4\4\8\0\')

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\')

我可以找到想要更改的内容(在编译脚本后通过记事本),但是如果尝试更改值,则脚本将无法运行,如果更改并尝试重新编译,则脚本仍将无法运行:"luac: Testing09.lua: unexpected end in precompiled chunk" ...

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" ...

有什么想法吗?我对使用 ollydbg 的程序进行了很长时间的操作,但是我无法在 lua 脚本中使用它.相当长一段时间找不到方法...有什么想法吗?

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?

推荐答案

在Lua字节码中更改字符串很容易.更改字符串后,您只需要调整字符串的长度即可.长度在字符串之前.取决于字符串是32位还是64位平台,该字符串前可能需要四个或八个字节.长度存储在生成字节码的机器的字节序中.请注意,字符串包括结尾的"\ 0",这在长度上算在内.

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" 

使用luac从中生成字节码,然后查看luac.out的转储,并找到字符串及其长度.将这些字节复制到原始文件.

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.

另一种解决方案是编写一个Lua程序,该程序将字节码读取为字符串,为return "this is the new string you want"生成字节码,使用字符串操作对原始字节码进行更改,然后将其写回到文件中.

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.

您还可以尝试我的字节码检查器库 lbci ,它使您可以更改函数中的常数.您将加载字节码(但不执行该字节码),并在找到包含要更改的字符串的常量之后使用setconstant.

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...

这篇关于是否可以在Lua字节码内更改值?如何?任何的想法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆