Forum

> > CS2D > Scripts > Compiling lua script?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Compiling lua script?

18 replies
To the start Previous 1 Next To the start

old Compiling lua script?

Avo
User Off Offline

Quote
Hi, I just want to ask:

Is there a way to compile lua script for CS2D? I mean no one will be able to read its source. Is it possible? If yes, please write how can I do this.

old Re: Compiling lua script?

DC
Admin Off Offline

Quote
I don't think so. You could remove linebreaks and rename functions/variables to make it pretty annoying to read it but that's probably it.

I guess there is something like precompiled Lua or Lua bytecode or something like that but it's not implemented in CS2D.

old Re: Compiling lua script?

Avo
User Off Offline

Quote
Hmm... I canont find it now, but I have seen someone's script that was fine(worked), but impossible to read.

old Re: Compiling lua script?

Lee
Moderator Off Offline

Quote
If you use string.dump on a function that can encapsulate all of your code, you can save it to a file and later load it using dofile (which works with byte code).

old Re: Compiling lua script?

Avo
User Off Offline

Quote
@user Lee: Any example?

http://lua-users.org/wiki/StringLibraryTutorial here it's explained very shortly...

EDIT:
Fine, I got it.
For the future
More >
edited 1×, last 31.01.13 06:32:11 pm

old Re: Compiling lua script?

Infinite Rain
Reviewer Off Offline

Quote
1
2
3
4
5
6
7
local f = io.open("byte.txt", "w")
f:write(string.dump((function() 

--SCRIPT

 end)()))
f:close()
dofile('byte.txt')

Haven't tested it, but should work.

old Re: Compiling lua script?

gotya2
GAME BANNED Off Offline

Quote
you can compile it into bytecode, and cs2d will still run it.
How to do this:
-Install lua for windows
http://code.google.com/p/luaforwindows/
- open up the windows shell ( cmd.exe)

usage:

luac my_lua.lua

the output file will be called luac.out, rename it to .lua and place it in the autorun directory, or call dofile() on it.
However there exist lua decompilers that can almost 100% convert it back to the original file, but will stop most noobies from opening your files.

You could also encrypt your file in some way ( using XOR for example), store it as a string, then decrypt it in runtime and use loadstring on it.
True obfuscation is very hard to realize using lua.

old Re: Compiling lua script?

KimKat
GAME BANNED Off Offline

Quote
I've found a decent way to compile Lua scripts, so now you can compile Lua code into less readable code online. I believe this is a good way to reduce script size.

You could run your Lua script in the online compiler and then compiling that output with your luac binary to get a neat small lua file whilst it remains perfectly executable in CS2D. That's my theory, so I don't know if it works in practice. But you could try that at least.

Here's a picture on how that works.

After you've got the code from output place the code into script.lua.
Then do this via command line or shell.
1
luac script.lua

Read more about script obfuscation here.

old Re: Compiling lua script?

RichNagel
User Off Offline

Quote
user gotya2 has written
you can compile it into bytecode, and cs2d will still run it.
How to do this:
-Install lua for windows
http://code.google.com/p/luaforwindows/


Hey, that's a pretty good idea!

Anyhow, to save folks the trouble of installing the entire package, I've downloaded and zipped up the binaries here -> Lua_Script_Compiler_v5.1.4.zip. Readme is here -> Lua_Script_Compiler_v5.1.4.txt .

The ZIP contains both the 32-bit and 64-bit versions of the command-line compiler ("LuaC_x86.exe" and "LuaC_x64.exe"), and the readme details usage and syntax.

Anyways, I've tried it out and it works perfectly... CS2D seems to load the resulting binary Lua files just fine

old Re: Compiling lua script?

KimKat
GAME BANNED Off Offline

Quote
@user RichNagel: Thanks for sending those links.

> LuaC binary (x86_64).
This link brings you to a page which has the latest Lua Compiler. It seems most probable to work for all Windows OS users no matter if you're on 64-bit or 32-bit it will work for anybody, but it'll be slower for 64-bit OS users, so pick binary wisely.
Other users shall follow this link below to get their own respective Lua Compiler.
> LuaC binaries.

I feel like the safest choice would be to download the latest luac. If that doesn't work and is not compatible with CS2D just go for the older versions. I heard talk about that newer versions of luac might not have backwards compatability with older versions of Lua script engines or what not. But I'm willing to check if that is actually true or not, so I'm gonna compile a few scripts using the newest luac and use those compiled lua binaries in CS2D in order to verify if you can use newer versions of luac with CS2D and have some fun time writing in Lua once again.

I just wanna say this. Some users are complaining about my posts being too long and such, so I'm giving you a one liner of what I'm gonna do instead.

tl;dr: I am checking if new luac works for CS2D.
edited 1×, last 01.02.13 05:10:18 pm

old Re: Compiling lua script?

DannyDeth
User Off Offline

Quote
luac it. By compiling to byte code first ( which is what the Lua interpreter will do when it loads the scripts anyway ) you will effectively hide your code.

But, really, there's probably nothing you can come up with that is original if you cannot even use Google, right? So why protect what already exists?

old Re: Compiling lua script?

KimKat
GAME BANNED Off Offline

Quote
Good point user DannyDeth. I also am wondering why we're compiling Lua scripts, it's kind of a way to hide source from people though even if you can decompile it easily if you know what to do. But still compiling stuff is fun anyhow, so that's just my opinion.

old Re: Compiling lua script?

DannyDeth
User Off Offline

Quote
user KimKat has written
compiling stuff is fun anyhow

100% true. But, still, it's better to share knowledge you have. Actually, sometimes it might be a good idea to keep it away from eyes that are a bit too young to learn the ways of Master Foo, IMHO.

old Re: Compiling lua script?

Yates
Reviewer Off Offline

Quote
Cool uberproof way: Don't show your code or give access to it.

To prevent something from happening is better than to try and protect yourself.

old Re: Compiling lua script?

KimKat
GAME BANNED Off Offline

Quote
If only Lua was like ASP. Since ASP has this ability to hide the source code yet run/execute the source code content which I find rather cool.

Example of that is here. You can encrypt the content with AES, so perhaps we should find a way to encrypt Lua files and have a secret key or one-way hash algorithm do the job for us. That'd be a definite way of having Lua files totally protected.

In my theory:
1. Encrypting script.lua with secret key using a hashing algorithm program.
2. a. Storing the encrypted Lua file together with the decrypter program in a folder named content ready to be turned into a zip file.
2. b. The archive should look something like this.
• tools/script.lua.
• tools/decrypter.exe.
2. c. This will extract the zip file into (<CS2D>/tools/) and you will have the content there, so that the decrypter is being easily accessable from the Lua via this command.
•
1
os.execute('tools/decrypter.exe maps/my_map.lua');
2. d. This would decrypt the map using the hash algorithm provided in the binary using the secret key within the map's Lua script and hopefully and during this process I just hope someone finds a way to run the content only if the secret key is provided in plain text format without showing the source. The source must always remain hidden, no cheating. If someone manages to figure out a way how to do this it would be epic, so please share if you do find a way.
3. Running the decrypter binary while having the script.lua within the same folder in order to decrypt script.lua.
4. a. There must be a map file that has a Lua script with the same name but with a Lua extension in the maps folder.
4. b. Just like the below example.
• maps/my_map.map
• maps/my_map.lua <-- This file will contain the secret key.

Encrypt with your encryption of choice. For my example I'll just say, Base64 encoded 128-bit Message Digest 5 (MD5) encrypted secret key which will be used by the encrypter somewhere somehow, right? I believe it's possible with just some work. This is just how I would realize it. If someone can realise this though is another question, however I believe it can be done but I personally am not up for it as I don't see the sense in encrypting my Lua files. But it would be a cool experiment in my eyes.
edited 1×, last 01.02.13 10:27:02 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview