Don't Starve Together

Don't Starve Together

Lua Decode Kits
Vyuri 8 Dec, 2021 @ 10:49pm
English (Google) translation
lua decoding toolkit

Notice! This is not a mod in itself! ! !
Notice! This is not a mod in itself! ! !
Notice! This is not a mod in itself! ! !

If you are learning how to make mods and want to refer to mods written by others, but find that they are all garbled, then this article is for you.

In recent years, individual authors have referred to the labor results in the open source community for creation, but are reluctant to share their own codes for various reasons, so they have used various encodings and pseudo-encryptions to prevent others from reading and learning. This behavior violates the original open source spirit of the community, spoils the atmosphere, and prevents players who are passionate about creating mods from learning, and seriously hinders the injection of fresh blood in the mod community.
(Of course, it is recommended to read the official code directly for learning to make mods. There are also many people on github that have compiled the documents of the official library, which is very convenient.)
In order to deal with some simple coding or so-called encryption measures, some coding cases and solutions are provided here.

It is recommended that the tool [Visual Studio Code] is used to process code and highlight code. If the code is not coded, but is formatted into a single line, you can use VSCode's lua format plug-in to format it into a standard format for reading

1. Escape the string type
[Insert picture 1]


feature:
There are a lot of strings of "\" plus three digits in the file, which essentially just encode the readable string into escape characters

solution:
Open 1.lua-string-decoder/lua-string-decoder.html in the mod folder, load the lua file that needs to be decoded, it will automatically decode and download the formatted plaintext file

2.loadstring type



feature:

There are a lot of strings with "\" plus 2-3 digits in the file, but the difference from the first is that there is a loadstring function before the string

solution:

This is actually using the first method to treat all codes as string type encoding, and then call Lua's loadstring method to load the string into code
A more convenient way is
(1). Change loadstring("code") to print("code") and copy this part to a new lua file, execute it in the lua environment, and output it to file 2.
For example, create a new file in the 2.lua5.1 for-loadstring-decode folder, such as code.lua, copy the print("code") above and save
(Assuming you are a windows system)
(2). Then in the 2.lua5.1 for-loadstring-decode folder, press and hold shift+right-click, and choose to open the PowerShell window here in the menu, and enter

.\lua5.1 code.lua> decode.lua

implement
(3). Then the code in decode.lua generated in the directory is the original code.

Precautions

Pay attention to whether the output file encoding is utf-8, sometimes the output file is utf-16, when saving and using, the file must be saved with utf-8 encoding before it can be used.
Some people use loadstring to recursively encode several times. For example, the decoded code is still loadstring. In this case, the above operation can be repeated several times. If there are many recursions, it is recommended to write a script to automatically execute until some normal code appears. Common non-escaped strings in, such as "function" and the like.


3.luac precompiled type



Feature: The file ends with .lua but opens a binary file. After opening with vscode, there are a lot of unreadable symbols in the text, but you can see LuaR or LuaQ readable text at the beginning of the file

solution:

This is pre-compiled with Luac, which can speed up the efficiency of executing Lua code and prevent the file from being read.
According to LuaR or LuaQ, the version of lua can be judged. R and Q represent the hexadecimal numbers 0x51 and 0x52, which are lua5.1 and lua5.2 versions.
The decompiler unluac.jar of lua5.1 version is provided by default in the mod file. If it is another version, you need to find the unluac warehouse in modinfo to download it or search for other versions of luac decompiler tools in github
Take the lua5.1 version as an example:
(1) Open the 2.lua5.1 for-loadstring-decode folder in the mod folder, and copy the lua script that needs to be decompiled, such as 1.lua
(2) Similarly shift+right click here to open the PowerShell window and enter java -jar unluac.jar --1.lua> 2.lua
(3) 2.lua is the decompiled file, but the variable name inside will mostly lose the original name due to compilation, so you need to identify the functions of each class and function by yourself


4. Function name substitution type



feature:

Functions and strings themselves are not encoded, but a large number of variable names and functions have been replaced with hard-to-read forms such as
function i1ll11lli11lii = xxx
illl11lliiilliiooii11li = true or something

solution:

Directly use the replace function of the editor to first replace the difficult-to-read characters in the file with shorter characters such as uppercase A B C,
Then analyze their purpose according to the code content and change the name yourself. If it is troublesome, you can write a script to automatically replace it.


Concluding remarks

The above are just solutions to the more common coding methods. In many cases, authors will use multiple coding methods in combination. These are some pseudo encryptions. Most real encryptions need to cooperate with key decryption. The level of that level requires specific analysis of the specific situation, and the above methods and memory reading tools are used to mine the password.

This tutorial was written on a whim. Cryptography is not my area of ​​expertise. There are still many shortcomings. Welcome to correct me.
This mod and all auxiliary tools including lua environment use MIT protocol
< >
Showing 1-1 of 1 comments
Neil  [developer] 8 Dec, 2021 @ 10:57pm 
thanks for your work!
< >
Showing 1-1 of 1 comments
Per page: 1530 50