How to Decompile PYc
Uncompyle2 is a tool that can convert PYC files to PY source
: Https://github.com/wibiti/uncompyle2
Installation: setup.py Install
Parameters:
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 is 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) |
The parameter is actually the C:\Python27\Scripts\uncompyle2 file, Uncompyle2 is also a py file but does not have a py extension
The code is as follows:
1 #!/usr/bin/env python2 ImportOS3 ImportSYS4 5 defdisplayfile (file):6Unpath=sys.executable7Unpath=unpath[0:unpath.rfind (os.sep)]8newname = File[0:file.rfind ('.')] +'. PY'9Command ="python-u"+unpath+"\scripts\uncompyle2"+ file +">"+newnameTen Try: One os.system (command) A excepte: - Printfile - the if __name__=='__main__': - Print 'Init' -Displayfile ('C:\\pycc.pyc') - Print 'finished'
The PY generated after the test is compiled error:
Syntaxerror:non-ascii character ' \xd6 ' * * * * but no encoding declared
A look at it is a coding problem, said to have the header in the generated py file Plus
#-*-CODING:GBK-*-
Very strange, #-*-Coding:utf8-*-will also error
MORE: http://www.iteye.com/topic/382423
Python Anti-compilation tool Uncompyle2