简体   繁体   English

如何使用.c格式反编译lua [编译为C]

[英]how to decompile lua with .c format [ compiled as C ]

I was trying to edit a program to make it flexible with my own but there is a problem. 我试图编辑一个程序使其具有自己的灵活性,但是存在问题。 It is coded as LUA language and it is compiled as C . 它被编码为LUA语言,并被编译为C。

Now I am trying to decompile this file and develop on this file . 现在,我正在尝试反编译此文件并在此文件上进行开发。 Can someone give any solution ? 有人可以提供任何解决方案吗? As I found we can compile the LUA files like this : 我发现我们可以像这样编译LUA文件:

cc -o test test.c -Wall -I/usr/include/lua5.1 -llua5.1

But now I am trying to DECOMPILE it . 但是现在我试图对其进行分解。 Please help. 请帮忙。

Compiled lua as .C file's photo 将lua编译为.C文件的照片

A file named test.c that you can give as input to cc is a C source file. 可以作为cc输入的名为test.c的文件是C源文件。 You can open it in a text editor and read it. 您可以在文本编辑器中将其打开并阅读。

In this case, it sounds like the C source code has a Lua chunk embedded inside. 在这种情况下,听起来好像C源代码中嵌入了Lua块。 The C code can link with the Lua library and use it to load and execute the Lua chunk. C代码可以链接到Lua库,并使用它来加载和执行Lua块。

Such a C file might look something like this: 这样的C文件可能看起来像这样:

// Disclaimer: tested with Lua 5.3 (64-bit)
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"

#define CODE "print(\"hello world\")\n";
// Or, if the chunk is compiled:
// #define CODE "\x1b\x4c\x75\x61\x53\x00\x19\x93\x0d\x0a\x1a\x0a\x04\x08\x04\x08\x08\x78\x56\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x28\x77\x40\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x04\x00\x00\x00\x06\x00\x40\x00\x41\x40\x00\x00\x24\x40\x00\x01\x26\x00\x80\x00\x02\x00\x00\x00\x04\x06\x70\x72\x69\x6e\x74\x04\x0c\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

int main(int argc, char **argv) {
  lua_State *L = luaL_newstate();
  luaL_openlibs(L);
  luaL_loadbuffer(L, CODE, sizeof(CODE) - 1, NULL);
  lua_call(L, 0, 0);
  lua_close(L);
  return 0;
}

The Lua chunk inside the C source file may or may not be compiled. C源文件中的Lua块可能会编译也可能不会编译。 In either case, it should not be hard to convert it back into a text or binary Lua file. 无论哪种情况,将其转换回文本或二进制Lua文件都不难。

For example, in Lua (if the binary is encoded as in my example with all bytes as two digit hex escapes): 例如,在Lua中(如果二进制文件按照我的示例进行编码,所有字节均为两位十六进制转义符):

-- note: replaces file "out.lua" without asking
local binary = [[\x1b\x4c\x75\x61\x53\x00\x19\x93\x0d\x0a\x1a\x0a\x04\x08\x04\x08\x08\x78\x56\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x28\x77\x40\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x04\x00\x00\x00\x06\x00\x40\x00\x41\x40\x00\x00\x24\x40\x00\x01\x26\x00\x80\x00\x02\x00\x00\x00\x04\x06\x70\x72\x69\x6e\x74\x04\x0c\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00]]

binary = binary:gsub("..(..)", function(n)
  return string.char(tonumber(n, 16))
end)

local f = assert(io.open("out.lua", "wb"))
assert(f:write(binary))
assert(f:close())

If the Lua chunk was not compiled to begin with, there is no need to decompile it. 如果Lua块不是从头开始编译的,则无需对其进行反编译。 If it was compiled, the binary Lua file can be disassembled or decompiled, or even loaded into a compatible Lua interpreter as normal. 如果已编译,则可以正常反汇编或反编译二进制Lua文件,甚至可以将其加载到兼容的Lua解释器中。

There are additional complications that could arise in the C file. C文件中可能还会出现其他复杂情况。 There may be multiple Lua chunks. 可能有多个Lua块。 In this case, you may need to deal with each one individually. 在这种情况下,您可能需要单独处理每一个。 There may also be some additional obfuscation (eg compression) as well. 也可能还有一些其他混淆(例如压缩)。 However, the C program must eventually covert the data into a real Lua chunk before handing it off to the Lua library, so it should be possible grab the wanted data at the point of the hand-off. 但是,C程序必须最终将数据转换为真正的Lua块,然后再将其移交给Lua库,因此应该有可能在移交时获取所需的数据。 (The C or Lua source can be modified to write the data out instead of or in addition to loading it, or the data can be dumped directly from memory, perhaps in a debugger. The worst case is if the data is streamed to lua_load without the whole chunk ever being loaded into memory at the same time, but this can still be handled easily.) (可以修改C或Lua源,以代替装载数据或在装载数据之外写入数据,或者可以在调试器中直接从内存中转储数据。最坏的情况是,将数据流传输到lua_load而没有整个块曾经同时加载到内存中,但这仍然很容易处理。)

yes it is like this but it's all codes are compiled and when i load it it looks like this : 是的,是这样,但是所有代码都已编译,当我加载它时,它看起来像这样:

http://www.upsara.com/images/t0r4_2018-02-21_19-57-20.png http://www.upsara.com/images/t0r4_2018-02-21_19-57-20.png

but i know it is lua and it contains your code which you wrote 但我知道它是lua,它包含您编写的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM