C ++ Encrypting and decrypting Lua files

I have a program (a small game) written in C ++ that gets its configuration from Lua files (they are mainly modules for the program). For example, a program gets its name, version, and what it is and is not allowed to do, and what the player can do from Lua files. The problem is that when I start distributing this small game to several people, they can set up Lua files that I don’t want, so I thought about encrypting them and then decrypting them when the program starts, but I just can’t understand the concept of how to actually do it and how. In general, this is a fairly simple task, as I imagine it?

As I see it, it looks like this: Encrypt the lua files with some program in a specific encryption method. Write C ++ code to a program that first decrypts Lua files and then starts reading them. Is this concept correct? Encryption itself can be as weak as possible if it works.

+6
source share
3 answers

Using luac, I was finally able to get all this to work.

I used this phrase to compile with luac (there tester.lua is the name of the output file, and test.lua is the file that was compiled):

 luac -o tester.lua test.lua 

Everything works automatically, regardless of whether it is compiled or not. Now the problem is that anyone can put the compiled lua file in an uncompiled version, and it will work anyway, because the dofile reads both normal and compiled lua. What would you recommend as a solution, so that the makefile only reads compiled lua files, and not uncompiled ones?

+5
source

Yes, that’s basically it.

Assuming you have something like

 runLuaFromFile("config.lua"); 

you want to do

  • load the text file "config.lua" into memory (for example, as a line)
  • decrypt string
  • runLuaFromMemory(myString);

obviously runLuaFromFile and runLuaFromMemory are not real functions, they are just placeholders for any Lua system you use

+4
source

Distributing precompiled Lua files instead of the source is likely to be sufficient for your purposes. See luac .

+3
source

Source: https://habr.com/ru/post/957595/


All Articles