def decrypt_pyc(pyc_file, new_pyc_file=None): try: pyc_code = dedrop.decrypt(pyc_file) except: print("[!] Failing for %s" % pyc_file) import traceback traceback.print_exc() return if not new_pyc_file: # new_pyc_file = pyc_file.replace(".pyc", ".npyc") new_pyc_file = "output.pyc" print("[+] writing to", new_pyc_file) with open(new_pyc_file, "wb") as f: # Note: getting the version magic right is crucial! # f.write(b'3\r\r\n') # won't work when original bytecode version corresponds to python 3.5.4 f.write(b'B\r\r\n') # valid for python 3.7.2 # We don't care about a timestamp f.write(b'\x00\x00\x00\x00') f.write(b'\x00\x00\x00\x00') # required for modern python version f.write(b'\x00\x00\x00\x00') # required for modern python versions, xxx bytecode = dedrop.bytecode(pyc_code) x = marshal3.dumps(pyc_code) f.write(x)
def dump_code(self, x): co_code = remap_opcodes(dedrop.bytecode(x)) self._write(TYPE_CODE) self.w_long(x.co_argcount) self.w_long(x.co_nlocals) self.w_long(x.co_stacksize) self.w_long(x.co_flags) self.dump(co_code) self.dump(x.co_consts) self.dump(x.co_names) self.dump(x.co_varnames) self.dump(x.co_freevars) self.dump(x.co_cellvars) self.dump(x.co_filename) self.dump(x.co_name) self.w_long(x.co_firstlineno) self.dump(x.co_lnotab)
def dump_ecode(self, x): """dump encrypted bytecode""" co_code = dedrop.bytecode(x) self._write(TYPE_CODE) self.w_long(x.co_argcount) self.w_long(x.co_nlocals) self.w_long(x.co_stacksize) self.w_long(x.co_flags) self.dump(co_code) self.dump(x.co_consts) self.dump(x.co_names) self.dump(x.co_varnames) self.dump(x.co_freevars) self.dump(x.co_cellvars) self.dump(x.co_filename) self.dump(x.co_name) self.w_long(x.co_firstlineno) self.dump(x.co_lnotab)