python py转exe逆向

一、py转exe

安装pyinstaller,安装指令:pip install pyinstaller
打包文件,pyinstaller -F xxx.py(xxx.py,打包的文件)

二、exe转pyc

python 版本一定要和exe文件相同

pyinstxtractor.py  文件名.exe

三、修复pyc

python的pyc文件,python2与python3头有所不同,python2有8字节的头,而python3有16字节的头,主要是魔术字(python版本)和时间属性的二进制信息

四、修复pyd(非必须)

# -*- coding:utf-8 -*-
import glob
import zlib
import tinyaes
from pathlib import Path

CRYPT_BLOCK_SIZE = 16

# key obtained from pyimod00_crypto_key
key = bytes('tianwanggaidihub', 'utf-8')

for p in Path("PYZ-00.pyz_extracted").glob("**/*.pyc.encrypted"):
    inf = open(p, 'rb')  # encrypted file input
    outf = open(p.with_name(p.stem), 'wb')  # output file

    # Initialization vector
    iv = inf.read(CRYPT_BLOCK_SIZE)

    cipher = tinyaes.AES(key, iv)

    # Decrypt and decompress
    plaintext = zlib.decompress(cipher.CTR_xcrypt_buffer(inf.read()))

    # Write pyc header
    # The header below is for Python 3.8
    outf.write(b'\x55\x0d\x0d\x0a\0\0\0\0\0\0\0\0\0\0\0\0')

    # Write decrypted data
    outf.write(plaintext)

    inf.close()
    outf.close()

    # Delete .pyc.encrypted file
    p.unlink()
"""
第一步,获取Crypto 的key,这是打包时由开发者指定的。解包完成后将在根目录形成名为"pyimod00_crypto_key.pyc"的文件,将它转为py文件即可查看key文件;
 在前一步中获取的key是必须文件,否则无法进行解密;对于不同pyton版本头文件(header)也不相同,2.7~3.10如下所示:

Python 2.7: \x03\xf3\x0d\x0a\0\0\0\0

Python 3.0: \x3b\x0c\x0d\x0a\0\0\0\0

Python 3.1: \x4f\x0c\x0d\x0a\0\0\0\0

Python 3.2: \x6c\x0c\x0d\x0a\0\0\0\0

Python 3.3: \x9e\x0c\x0d\x0a\0\0\0\0\0\0\0\0

Python 3.4: \xee\x0c\x0d\x0a\0\0\0\0\0\0\0\0

Python 3.5: \x17\x0d\x0d\x0a\0\0\0\0\0\0\0\0

Python 3.6: \x33\x0d\x0d\x0a\0\0\0\0\0\0\0\0

Python 3.7: \x42\x0d\x0d\x0a\0\0\0\0\0\0\0\0\0\0\0\0

Python 3.8: \x55\x0d\x0d\x0a\0\0\0\0\0\0\0\0\0\0\0\0

Python 3.9: \x61\x0d\x0d\x0a\0\0\0\0\0\0\0\0\0\0\0\0

Python 3.10: \x6f\x0d\x0d\x0a\0\0\0\0\0\0\0\0\0\0\0\0

第二步,执行脚本文件,即可将加密的pyc. encrypted文件转成不加密的pyc文件。
"""

五、pyc转py

方法一:

uncompyle6 -o test.py test.pyc

方法二:

https://tool.lu/pyc/
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值