Table of contents
TL;DR / Geek Summary:
- Reverse Engineering: Systematic guide to extracting Python source code from PyInstaller-packaged
.exefiles.- Toolstack: Leveraging
pyinstxtractor.pyfor extraction and online.pyc-to-.pydecompilers for restoration.- Workflow: Compile test script (
awa.py) -> Package with PyInstaller 5.13.0 -> Extract entry point and dependency layers from the PYZ archive.
# Reverse engineering the source code of a PyInstaller-packaged exe file
We all know that libraries can be used to compile .py files into .exe files for execution. We will start by compiling a script into a .exe and then decompiling the source code of the .exe to obtain the source file.
# Introduction
We all know that we can use the PyInstaller library to compile
.pyfiles into.exefiles that can be run. This article will cover compiling scripts into.exefiles and then decompiling the source code of the.exefile to extract the source files.
# Environment Tools
Python 3.8.10: Download it yourself if you don’t have it
Pyinstaller library: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller==5.13.0
pyinstxtractor.py: Download address
# Compiling the Program
# Checking the Environment
| |
If the execution is successful, then it’s done.
# Writing the Script
awa.py
| |
# Packaging Program
First, install the library pyinstaller used by the packaging program. Here, we use the Tsinghua mirror and specify the 5.13.0 version library.
| |
Locate the folder where the script is located. Mine is D:\. cd to this path and enter the following packaging command:
| |
After the command finishes executing, you will see the completed successfully. field, indicating that the .exe file was successfully generated in the dist folder.
# Reverse Engineering Process
First, we download the decompilation script pyinstxtractor.py and place it in the same working directory as the .exe file we want to decompile.
Then, we continue by cding the dist folder in the command line, entering the following command and executing it:
| |
After execution, you will see the message Successfully, and a awa.exe_extracted folder will be generated.
| |