zoukankan      html  css  js  c++  java
  • 将 Python 打包的 exe 进行反编译

    Python 打包成 exe 之后,是否能从二进制文件中恢复出源代码?没有加密的话是可以的。

    首先需要解包

    直接从 github 上下载就行:https://github.com/countercept/python-exe-unpacker

    使用也简单:python pyinstxtractor.py xxx.exe

    解包后,得到 xxx.exe_extracted 就是所有的 pyc 文件了。

    找到 xxx.exe_extractedstruct 中的 pyc 签名信息:

    然后可以并使用下面的脚本进行拼接(PYZ-00.pyz_extracted 里面的 pyc 只缺中间一部分):

    import os
    import argparse
    
    parser =argparse.ArgumentParser()
    parser.add_argument('--filename', '-f', type=str, help="file name of the file to be modified!")
    args = parser.parse_args()
    
    if args.filename:
        print("filename: " + args.filename)
        if os.access(args.filename, os.W_OK):
            print("-    processing...")
        else:
            print("-    access is denied! exit!")
            exit(0)
    else:
        print("-h for help!")
        exit(0)
    
    structBytes=b'x70x79x69x30x10x01x00x00'
    
    with open(args.filename, "rb") as f:
        bytes = f.read()
    bytes=bytes[:8]+structBytes+bytes[12:]
    with open(args.filename, "wb") as g:
        g.write(bytes)
    
    print("-    successed!")

    多个文件的话。。。再叠加个批处理吧,顺便直接用 uncompyle6 把 pyc 反编译成 python 源代码 = =

    set "path" "C:DevAppAnaconda3Scripts;C:DevAppAnaconda3;C:DevAppAnaconda3DLLs;C:DevAppAnaconda3\Libraryin;%path%" /m
    @echo
    off set here=%~dp0 pushd %here% cd xxx.exe_extractedPYZ-00.pyz_extracted for /f "delims=" %%i in ('dir /s/b "*.pyc"') do (
      python.exe %here%cooking.py -f %%i
      start uncompyle6 -o . %%i
    ) popd

     这里之所以用 start,是因为有些 pyc 没法直接反编译,这样的话 script 会被卡住。用 start 开始新进程,并行处理,有一两个卡住也没关系。

    最后发现有 4 个没法反编译,从文件大小可以看出来:

     还好,可以从文件名猜到用了什么库。

    ——————
    无论在哪里做什么,只要坚持服务、创新、创造价值,其他的东西自然都会来的。
  • 相关阅读:
    后端开发-Mybatis开发之一
    Zeppelin推荐
    构建Maven项目
    linux使用curl进行WebService接口测试
    html和jsp的区别及优缺点
    Ajax实现Web长连接
    java生成二维码
    Android调用传感器和震动
    【Head First设计模式-读书笔记】装饰者模式
    【Head First设计模式-读书笔记】观察者模式
  • 原文地址:https://www.cnblogs.com/pied/p/14677930.html
Copyright © 2011-2022 走看看