pyc是一种二进制文件,是由py文件经过编译后,生成的可执行的字节码文件。
pyc文件是可以跨平台部署的,类似Java的.class文件。

两种编译生成pyc文件的方法:
1、编译时选用 -m py_compile
# python -m py_compile test0.py
a = int(input())
b = int(input())
c = int(input())
print(a+b)
for i in range(c):
print(i)
2、使用代码编译
import py_compile
py_compile.compile(r'test0.py')
3、使用-O选项,将.pyc文件优化为.pyo文件(体积更小)
# python -O -m py_compile test0.py
pyc 文件由三大部分组成
PyObject的序列化格式结构
uncompyle6 input.pyc > output.py
uncompyle6 test2.pyc > test2.py
下载:https://github.com/rocky/python-uncompyle6
安装:pip install uncompyle
报错:ValueError: check_hostname requires server_hostname
解决:需要断开代理服务器

将 python 字节码转换为可读的 python 源代码, 包含了反汇编 (pycads) 和反编译 (pycdc) 两种工具
使用
./pycdc xxxx.pyc # 得到py代码
./pycdas xxxx.pyc # 得到字节码
下载:https://github.com/zrax/pycdc
安装:
sudo apt install git #安装git
sudo apt install cmake #安装cmake
git clone https://github.com/zrax/pycdc.git #下载pycdc到桌面
cd pycdc #进入到pycdc的目录
cmake .
make #安装pycdc工具

python pyinstxtractor.py xxx.exe
下载:https://github.com/extremecoders-re/pyinstxtractor
备注:
1.0会去掉头部的struct,2.0已经解决了这个bug
注意: 需要将解包出来的pyc头部加上33 0d 0d 0a 00 00 00 00 00 00 00 00 e3 00 00 00
才能反编译出py
