I am trying to translate the code into binary data, then execute it.
Source:
exec(print(123)) Translated code:
\x65\x78\x65\x63\x28\x22\x70\x72\x69\x6e\x74\x28\x31\x32\x33\x29\x22\x29 When writing this string to a variable, code execution does not occur.
Translated as follows:
a = 'exec("print(123)")' print('\\x'.join([codecs.encode(bytes(x, 'utf8'), 'hex').decode('utf8') for x in a])) What's wrong? Do I translate correctly?
Python 3
exec(None)which leads to TypeError. What is "binary data" in the context of the question is not clear. The mere presence of "\\ x" says that the code is broken. How are you going to perform them? Are you trying to create a pyc file? Or just a code object? What prevents the source code from being directly transmitted? - jfs