RedHat-Israel / ROSE

ROSE project car race game
GNU General Public License v2.0
34 stars 125 forks source link

Encrypted drivers #442

Open nirs opened 2 years ago

nirs commented 2 years ago

The examples drivers are too easy to decompile. Change the code to support encrypted drivers and add a tool to encrypt driver modules.

Examples for encrypting and decrypting: https://pycryptodome.readthedocs.io/en/latest/src/examples.html

Change rose.client.main.load_driver_module() to read client data from file and create a module without importing module from disk. This is better anyway for plugins.

For loading module from decrypted bytes: https://docs.python.org/3.6/library/functions.html#exec

$ cat load.py 
import sys

with open(sys.argv[1], "rb") as f:
    data = f.read()

env = {}
exec(data, env, env)

print(env["driver_name"])
print(env["drive"])

$ python load.py examples/none.py 
No Driver
<function drive at 0x7fb3ea287d90>

The example code does not support pyc files, they are not needed once we use encrypted drivers and are also not portable between python versions so we should stop using them.

The client needs new --key-file argument with the path to the key used to decrypt the driver.