Giter Site home page Giter Site logo

pyisrepack's Introduction

pyisrepack

Introduce


将pyc文件重新打入由PyInstaller生成的exe中.
本项目基于 pyinstxtractor

Repository

https://gitee.com/bruce_code/pyisrepack.git
https://github.com/bruce-yan/pyisrepack.git

Usage


Usage: python pyisrepack.py -ori <exe file> -p <pyc file> -o <output file>

How To Do


这是Demo代码, 使用 PyInstaller 将其打包为 main.exe

import sys
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QLabel


def main():
    app = QApplication(sys.argv)
    label = QLabel("Hello world.", alignment=Qt.AlignmentFlag.AlignCenter)
    label.resize(300, 200)
    label.show()
    sys.exit(app.exec())


if __name__ == "__main__":
    main()

运行效果如下

pic1

我们将通过以下步骤将 Hello world 改为 Hello earth

Step1. 使用 pyinstxtractor 将 exe 拆包

python pyinstxtractor.py main.exe

得到如下文件

pic2

其中main.pyc是我们要修改的文件

Step2. 使用 uncompyle6 将 pyc 文件反编译成 python 源文件

uncompyle6 -o . main.pyc

Step3. 修改python代码

label = QLabel("Hello earth.", alignment=Qt.AlignmentFlag.AlignCenter)

Step4. 将修改后的python源代码编译成 pyc

uncompyle6 -c main.py

Step5. 使用 pyisrepack.py 将 pyc 重新压入 exe

python pyisrepack.py -ori main.exe -p main.pyc -o new_main.exe

Step6. 运行效果

pic3

Important


  • 修改前后应尽量保证 Python 版本一致
  • 目前只支持exe中 类型为 "s" 的条目。

使用 pyi-archive_viewer 查看条目类型


 pos, length, uncompressed, iscompressed, type, name
[(0, 225, 293, 1, 'm', 'struct'),
 (225, 1025, 1706, 1, 'm', 'pyimod01_os_path'),
 (1250, 4025, 8765, 1, 'm', 'pyimod02_archive'),
 (5275, 7386, 17758, 1, 'm', 'pyimod03_importers'),
 (12661, 1456, 3638, 1, 'm', 'pyimod04_ctypes'),
 (14117, 824, 1364, 1, 's', 'pyiboot01_bootstrap'),
 (14941, 512, 797, 1, 's', 'pyi_rth_subprocess'),
 (15453, 701, 1065, 1, 's', 'pyi_rth_pkgutil'),
 (16154, 439, 660, 1, 's', 'pyi_rth_inspect'),
 (16593, 330, 441, 1, 's', 'pyi_rth_pyside6'),
 (16923, 381, 529, 1, 's', 'main'),
 (17304, 1173690, 1173690, 0, 'z', 'PYZ-00.pyz')]

See Also


License


GNU General Public License v3.0

pyisrepack's People

Contributors

bruce-yan avatar jin925 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.