forked from Perfare/AssetStudio
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from buoutuanzi/LuaAsset
添加在 export 和 preview 时反编译 lua 功能
- Loading branch information
Showing
96 changed files
with
11,289 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace AssetStudio | ||
{ | ||
internal class LuaByte : TextAsset | ||
{ | ||
private LuaByteInfo m_LuaByteInfo; | ||
|
||
public LuaByte(ObjectReader reader, LuaByteInfo luaByteInfo) : base(reader) | ||
{ | ||
m_LuaByteInfo = luaByteInfo; | ||
} | ||
|
||
public override byte[] GetProcessedScript() | ||
{ | ||
if (!m_LuaByteInfo.HasDecompiled) | ||
{ | ||
LuaDecompileUtils.DecompileLua(m_LuaByteInfo); | ||
} | ||
return m_LuaByteInfo.ProcessedByte; | ||
} | ||
|
||
public override byte[] GetRawScript() | ||
{ | ||
return m_LuaByteInfo.RawByte; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace AssetStudio | ||
{ | ||
public static class TextAssetFactory | ||
{ | ||
public static TextAsset Create(ObjectReader reader) | ||
{ | ||
reader.Reset(); | ||
reader.ReadAlignedString(); // 跳过文件名 | ||
byte[] content = reader.ReadUInt8Array(); | ||
bool success = LuaByteParser.TryParseLuaByte(content, out LuaByteInfo luaInfo); | ||
if (success) | ||
{ | ||
return new LuaByte(reader, luaInfo); | ||
} | ||
else | ||
{ | ||
return new TextAsset(reader); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
*.lua[co] | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Packages | ||
*.egg | ||
*.egg-info | ||
dist | ||
build | ||
eggs | ||
parts | ||
bin | ||
var | ||
sdist | ||
develop-eggs | ||
.installed.cfg | ||
lib | ||
lib64 | ||
__pycache__ | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.coverage | ||
.tox | ||
nosetests.xml | ||
|
||
# Translations | ||
*.mo | ||
|
||
# Mr Developer | ||
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
.*.swp | ||
|
||
|
||
.vscode | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2013 Andrian Nord | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# What is new ? | ||
|
||
Support decompilation of 64 bit luajit bytecode | ||
|
||
支持反编译64位luajit字节码 | ||
|
||
## Ref | ||
|
||
[luajit反编译、解密 - 『软件调试区』 - 吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn](https://www.52pojie.cn/thread-1378796-1-1.html) | ||
|
||
# zzwlpx's ReadMe | ||
|
||
代码在fork https://github.com/NightNord/ljd 的基础上修改的 | ||
|
||
主要修正了原版本没有将_read_header函数解析过的header中的flag值带进_read_protoypes。 | ||
|
||
解决了原代码只能解析带调试信息的luajit字节码,而解析不带调试信息字节码时报错的问题。 | ||
|
||
此版本可解析luajit2.1.0-beta2的字节码文件。如果要解析其它版本的luajit字节码文件,需要将 | ||
|
||
luajit源码中的opcode,写进instruction.py 和 code.py | ||
|
||
|
||
使用说明:python main.py "path of luajit-bytecode" | ||
|
||
解释文档:http://www.freebuf.com/column/177810.html | ||
|
||
参考:https://github.com/NightNord/ljd | ||
https://github.com/feicong/lua_re/blob/master/lua/lua_re3.md | ||
https://bbs.pediy.com/thread-216800.htm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
LuaJIT raw-bytecode decompiler (LJD) | ||
=== | ||
|
||
The original name was _ljwthgnd_ as in _LuaJIT 'What The Hell is Going On' | ||
Decompiler_ named under the LuaJIT C sources variable naming convention. | ||
|
||
|
||
__WARNING!__ This code is nor finished, nor tested yet! There is no even | ||
slightest warranty that resulting code is even near to the original. Use it at | ||
your own risk of the wasted time. | ||
|
||
__SECOND WARNING!__ And, BTW, this all is a one huge prototype. Because the | ||
"release" version should be written into lua itself. Because it's cool to | ||
decompile the decompiler - a great test too! | ||
|
||
Requirements | ||
--- | ||
|
||
Python __3.0+__ from python.org | ||
|
||
|
||
How to use it | ||
--- | ||
|
||
There is no argument parsing right now, so comment out things in the ```main.py``` | ||
script and launch it as in ```main.py path/to/file.luac``` | ||
|
||
TODO | ||
--- | ||
|
||
There is a lot of work to do, in the order of priority | ||
|
||
0. Logical subexpressions in while statements: | ||
```lua | ||
while x < (xi and 2 or 3) do | ||
print ("Hello crazy world!") | ||
end | ||
``` | ||
|
||
Logical subexpressions (the subexpressions used as operands in | ||
ariphmetic or comparison operations inside other exrpressions) are | ||
currently supported only for ifs. To support them for whiles and | ||
repeat untils an expression unwarping logic should be moved at the | ||
very beginning. But it won't work without all fixes being done in | ||
a loop unwarping logic. So we need to split that and move the fixes | ||
before expressions before loops before ifs. That's not that easy... | ||
|
||
1. AST Mutations: | ||
1. Use the line information (or common sense if there is no line | ||
information) to squash similar expressions into a single expression. | ||
|
||
2. Formatting improvements | ||
1. Use the line information (or common sense) to preserve empty lines | ||
and break long statements like in the original code. | ||
|
||
This is mostly done, but only in the "common sense" part. | ||
|
||
2. Use method-style calls and definitions for tables. | ||
|
||
3. Features not supported: | ||
1. GOTO statement (from lua 5.2). All the required functionality is | ||
now in place, but that's rather a low-priority task right now. | ||
|
||
2. Local sub-blocks: | ||
```lua | ||
do | ||
... | ||
end | ||
``` | ||
These subblocks are not reflected anyhow directly in the bytecode. | ||
The only way to guess them is to watch local variable scopes, which | ||
is simple enough in case of non-stripped bytecode and a bit | ||
harder otherwise. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
#zzw 20180714 support str encode | ||
gFlagDic = {'strEncode' : 'ascii'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# | ||
# Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# | ||
# Copyright (C) 2013 Andrian Nord. See Copyright Notice in main.py | ||
# | ||
|
Oops, something went wrong.