I’m writing a code protection program and I face with a really annoying bug. To execute code I need to decrypt it and I doing it in a separate file where it decrypts and executes. With one file projects everything works just fine, but with multi file projects I got error module 'include' has no attribute 'foo'
.
GitHub repo
It happens cuz code executes in script_12529881.py
but include.py
imports and I need to execute it there but if I use exec it gonna be unsafe cuz hackers can just replace with print and get source code.
File hierarchy:
│ include.py
│ main.py
│
└───PySheild
script_12529881.py
Encrypted file:
from PySheild.script_12529881 import PySheild
PySheild(b'xx')
File for decrypt:
class PySheild:
def __init__(self, code):
self.code = code
self.farnetKey = b''
self.DeObfuscate()
def DeObfuscate(self):
self.DecryptFernet()
self.BaseDecrypt()
exec(self.code)
Method that works but unsafe:
exec(PySheild(b'xv').Exec)# Exec returns code
Will be glad for any help
ByteCorum is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.