如何反编译pyc
uncompyle2 是一个可以将pyc文件转换为py源码的工具
下载地址:https://github.com/wibiti/uncompyle2
安装: setup.py install
参数:
Usage: uncompyle2 [OPTIONS]... [ FILE | DIR]... Examples: Options: Debugging Options: Extensions of generated files: |
参数其实就是C:\Python27\Scripts\uncompyle2 文件里面, uncompyle2也是一个py文件但没有py扩展
代码如下:
1 #! /usr/bin/env python 2 import os 3 import sys 4 5 def displayFile(file): 6 unPath= sys.executable 7 unPath=unPath[ 0 : unPath.rfind( os.sep ) ] 8 newname = file[0:file.rfind(‘.‘)] + ‘.py‘ 9 command = "python -u "+unPath+"\scripts\uncompyle2 " + file + ">" + newname 10 try: 11 os.system(command) 12 except e: 13 print file 14 15 if __name__ == ‘__main__‘: 16 print ‘init‘ 17 displayFile(‘C:\\pycc.pyc‘) 18 print ‘finished‘
经过测试 反编译后生成的py 执行报错:
SyntaxError: Non-ASCII character ‘\xd6‘ ***** but no encoding declared
一看就知道是编码问题, 说有在生成的py文件的头部加
# -*- coding: gbk -*-
很奇怪,# -*- coding: UTF8 -*- 也会报错
更多:http://www.iteye.com/topic/382423