6

I am currently developing a game in C and Lua. Because I plan to sell my game when it is finished, I would like to keep the source code closed. So my question is whether there is a way I can hide, or somehow access my Lua code from C, without the user being able to look. Right now, my executable is placed in the same place as my Lua code so it can be accessed.

Thanks for reading this, and any help is appreciated. Please ask me for more details if I am being too vague.

hyrumcoop
  • 362
  • 2
  • 14
  • You could encrypt the Lua source, and assume no-one attempts to extract the key from your executable. – Dai Oct 11 '13 at 01:18
  • How difficult would it be for them to get the encryption key, and are there any other options? – hyrumcoop Oct 11 '13 at 01:20
  • 3
    You can compile your lua script and store the bytecode into a C array and that'll provide some basic source privacy. Beyond that, there's not much more you can do -- any determined attacker can always reverse engineer the binary back into some form of higher level representation. This is true regardless of what language you used to program your game in. – greatwolf Oct 11 '13 at 01:34
  • It's also true regardless of how heavily you encrypt it. (Note that all a cracker needs to do is extract it from memory after your program decrypts it for use...) – This isn't my real name Oct 11 '13 at 01:36
  • So (obviously) there is no way I can guarantee that it won't get cracked, but I am better off encrypting it? – hyrumcoop Oct 11 '13 at 01:43
  • 6
    Do you really need to worry about this? Big game companies have spent insane amount of money on copy protection systems, and they all have been cracked. Spend your time writing a better game. – user694733 Oct 11 '13 at 06:24
  • @hyrumcoop You'll be better off, if you manage to finish the game and sell it. – user1095108 Oct 11 '13 at 07:52
  • 3
    I'm slightly confused why you think anyone would be interested in your Lua code (other than modding which would be a good thing not bad) given that presumably it's completely specific to the rest of your code and useless as a standalone "theft". – Flexo Oct 11 '13 at 08:00

2 Answers2

5

Lua manual says:

[Lua] Chunks can also be precompiled into binary form; see program luac for details. Programs in source and compiled forms are interchangeable; Lua automatically detects the file type and acts accordingly.

This means you can use luac (Lua compiler) to compile your Lua code to binary form, which will not be easily readable, but can still be disassembled to find out what it does (which can be done even with C if you are determined enough).

che
  • 12,097
  • 7
  • 42
  • 71
5

I think the correct answer is, that you can't. You can only make life harder for the cracker. Better protection schemes than compiling code into bytecode have been cracked. If your game does not prove popular, it won't matter anyway. Write the game first, then worry about hiding your code.

user1095108
  • 14,119
  • 9
  • 58
  • 116
  • 4
    Yes, this is correct, you can't. The best obfuscation method I know of is the one described here: http://stackoverflow.com/a/8500005/661171 – cib Oct 11 '13 at 09:54
  • Thank you. I agree that I should focus on what is most important and worry about smaller details later. – hyrumcoop Oct 11 '13 at 21:36