Skip to content

Instantly share code, notes, and snippets.

@baljanak
Created March 16, 2016 04:18
Show Gist options
  • Save baljanak/9ad5ba48afce9d5f1991 to your computer and use it in GitHub Desktop.
Save baljanak/9ad5ba48afce9d5f1991 to your computer and use it in GitHub Desktop.
decompile pyc to py
import os
import ast
import marshal
import uuid
import meta
def pyc2py(pyc_file, path='/tmp'):
with open(pyc_file, 'rb') as fd:
magic, timestamp, source = fd.read(4), fd.read(4), meta.dump_python_source(meta.decompile(marshal.load(fd)))
with open(os.path.join(path, pyc_file.split('.')[0].split('/')[-1] + '.py'), 'w') as wfd:
wfd.write(source)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment