Windows使用uncompyle6

安装:
pip install uncompyle6

cmd下查看使用方法:
uncompyle6 --help

Usage:
  uncompile [OPTIONS]... [ FILE | DIR]...
  uncompile [--help | -h | --V | --version]
Examples:
  uncompile      foo.pyc bar.pyc       # decompile foo.pyc, bar.pyc to stdout
  uncompile -o . foo.pyc bar.pyc       # decompile to ./foo.pyc_dis and ./bar.pyc_dis
  uncompile -o /tmp /usr/lib/python1.5 # decompile whole library
Options:
  -o      output decompiled files to this path:
                if multiple input files are decompiled, the common prefix
                is stripped from these names and the remainder appended to
                
                  uncompyle6 -o /tmp bla/fasel.pyc bla/foo.pyc
                    -> /tmp/fasel.pyc_dis, /tmp/foo.pyc_dis
                  uncompyle6 -o /tmp bla/fasel.pyc bar/foo.pyc
                    -> /tmp/bla/fasel.pyc_dis, /tmp/bar/foo.pyc_dis
                  uncompyle6 -o /tmp /usr/lib/python1.5
                    -> /tmp/smtplib.pyc_dis ... /tmp/lib-tk/FixTk.pyc_dis
  -c      attempts a disassembly after compiling
  -d            print timestamps
  -p   use number of processes
  -r            recurse directories looking for .pyc and .pyo files
  --verify      compare generated source with input byte-code
  --linemaps    generated line number correspondencies between byte-code
                and generated source output
  --help        show this message
Debugging Options:
  --asm     -a  include byte-code         (disables --verify)
  --grammar -g  show matching grammar
  --tree    -t  include syntax tree       (disables --verify)
Extensions of generated files:
  '.pyc_dis' '.pyo_dis'   successfully decompiled (and verified if --verify)
    + '_unverified'       successfully decompile but --verify failed
    + '_failed'           decompile failed (contact author for enhancement)

反编译:
uncompyle6   -o   .   pyc文件名

说明:
-o后面可以加上文件路径,代表反编译文件输出的位置,“.”表示输出到当前文件夹
反编译成功后会返回“ # Successfully decompiled file

简单的批量反编译脚本:

# encoding=utf8
import os
import uncompyle6
from uncompyle6 import decompile_file
def main():
    path = 'C:\filename'.decode('utf8')        # Windows下
    for root, dirs, files in os.walk(path):
        if root != path:
            break
        for filename in files:
            if filename.endswith('pyc'):
                print filename
                os.system('uncompyle6 -o . %s'%filename)
    
if __name__ == '__main__':
    main()

你可能感兴趣的:(python2.7,uncompyle6)