If I obfuscated python code, would it provide the same level of 'security' as c#/java obfuscating?
i.e it makes things a little hard, but really you can still reverse engineer if you really wanted to, its just a bit cryptic.
If I obfuscated python code, would it provide the same level of 'security' as c#/java obfuscating?
i.e it makes things a little hard, but really you can still reverse engineer if you really wanted to, its just a bit cryptic.
Obfuscation is a form of security through obscurity. All obfuscated code can, if the attacker is determined enough, be reversed. There are no exceptions.
Python code gets compiled to bytecode (.pyc
) files as it is imported. You can distribute those .pyc
files instead of the .py
source code files, and the Python interpreter should be able to load them. While Python bytecode is more "obfuscated" than Python source code, it's still relatively easy to disassemble Python bytecode -- but, then again, it's not that hard to disassemble Java bytecode, either.
Why don't you write something and examine the bytecode? Make some functions that depend on random numbers but are almost complete improbable to execute. This way the compiler can't optimize and you'll see more 'junk'.
def myfunc(num):
if (num > 1):
return 1
else:
return 0
>>> dis.dis(myfunc)
2 0 LOAD_FAST 0 (num)
3 LOAD_CONST 1 (1)
6 COMPARE_OP 4 (>)
9 JUMP_IF_FALSE 5 (to 17)
12 POP_TOP
3 13 LOAD_CONST 1 (1)
16 RETURN_VALUE
>> 17 POP_TOP
5 18 LOAD_CONST 2 (0)
21 RETURN_VALUE
22 LOAD_CONST 0 (None)
25 RETURN_VALUE
Obfuscation doesn't provide security. What you describe isn't security.
If you distribute your Python program or your Java program or your C program, it is vunerable. What protects you from people using what you distributed unfairly is the law and people not being jerks.
Obfuscation not only provides no security, it has the potential of breaking working code, hurting performance, and ruining documentation.