博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python 反编译工具uncompyle2
阅读量:6257 次
发布时间:2019-06-22

本文共 2393 字,大约阅读时间需要 7 分钟。

如何反编译pyc

uncompyle2 是一个可以将pyc文件转换为py源码的工具

下载地址:https://github.com/wibiti/uncompyle2

安装: setup.py install

 

参数:

Usage: uncompyle2 [OPTIONS]... [ FILE | DIR]...

Examples:

uncompyle2 foo.pyc bar.pyc # decompile foo.pyc, bar.pyc to stdout
uncompyle2 -o . foo.pyc bar.pyc # decompile to ./foo.dis and ./bar.dis
uncompyle2 -o /tmp /usr/lib/python1.5 # decompile whole library

Options:

-o <path> 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
<path>
uncompyle -o /tmp bla/fasel.pyc bla/foo.pyc
-> /tmp/fasel.dis, /tmp/foo.dis
uncompyle -o /tmp bla/fasel.pyc bar/foo.pyc
-> /tmp/bla/fasel.dis, /tmp/bar/foo.dis
-s if multiple input files are decompiled, the common prefix
is stripped from these names and the remainder appended to
<path>
uncompyle -o /tmp /usr/lib/python1.5
-> /tmp/smtplib.dis ... /tmp/lib-tk/FixTk.dis
-c <file> attempts a disassembly after compiling <file>
-d do not print timestamps
-m use multiprocessing
--py use '.py' extension for generated files
--norecur don't recurse directories looking for .pyc and .pyo files
--verify compare generated source with input byte-code
(requires -o)
--help show this message

Debugging Options:

--showasm -a include byte-code (disables --verify)
--showast -t include AST (abstract syntax tree) (disables --verify)

Extensions of generated files:

'.pyc_dis' '.pyo_dis' successfully decompiled (and verified if --verify)
'.py' with --py option
+ '_unverified' successfully decompile but --verify failed
+ '_failed' uncompyle failed (contact author for enhancement)

参数其实就是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 + ">" + newname10     try:11         os.system(command)12     except e:13         print file14     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

转载地址:http://batsa.baihongyu.com/

你可能感兴趣的文章
技术出身能做好管理吗?——能!
查看>>
抽象工厂模式
查看>>
如何折叠一段代码使整个代码看起来简洁
查看>>
Quartz2D绘制路径
查看>>
Java知多少(30)多态和动态绑定
查看>>
JDBC操作数据库
查看>>
Android中RelativeLayout的字符水平(垂直居中)对齐
查看>>
--@angularJS--独立作用域scope绑定策略之&符策略
查看>>
乾坤合一~Linux设备驱动之USB主机和设备驱动
查看>>
Python IDLE快捷键【转载合集】
查看>>
Bootstrap中glyphicons-halflings-regular.woff字体报404错notfound
查看>>
[C++] string与int, float, double相互转换
查看>>
ubuntu14.04安装chrome
查看>>
oracle中查询含字母的数据[正则表达式]
查看>>
1002. 写这个号码 (20)(数学啊 ZJU_PAT)
查看>>
【LeetCode】224. Basic Calculator
查看>>
Keil V4.72升级到V5.1X之后
查看>>
Google CFO 辞职信
查看>>
POJ2771_Guardian of Decency(二分图/最大独立集=N-最大匹配)
查看>>
Scala深入浅出实战经典之 List伴生对象操作方法代码实战.
查看>>