Skip to main content

Reverse Python Exe (repyexe)

PyPi version PyPI pyversions

Description

Reverse Engineer Windows executable file compiled using Python.

Usage

$ repyexe <exe_files and pyc_files>
from repyexe.decompile import decompile_exe

decompile_exe("samples/khaki.exe")

The version of Python used must be the same minor version as the one used to compile the file. If a different one is chosen, the script will exit with a message telling you which version to use. Use pyenv or something similar to switch your Python version.

For CX_Freeze files, the Python code is not located within the exe file but in pyc files in lib\library.zip, which needs to be manually extracted (using tools like uncompyle6).

Background

This script aims to automate the reverse engineering of malware for analysis as much as possible.

Most of the Python executable files are compiled using Py2exe, PyInstaller or CX_Freeze. While this script aims to decompile any exe file, it is currently limited to only those compiled using these 3 libraries. A warning will be shown for exe files that do not match the signatures of files compiled using these libraries.

This script can also bypass the following deobsfucation techniques (only enabled on Py2exe):

  • NOP, ROT_TWO, ROT_THREE, LOAD_CONST & POP_TOP
  • EXTENDED_ARG

Supported Files

Python <= 3.7
Limited support for Python 3.8

Tested on files listed in tested.md

  • Python 2 using Py2exe
  • Python 3 using Py2exe
  • Python 2 using Py2exe with obsfucation
  • Python 3 using Py2exe with obsfucation
  • Python 2 using PyInstaller
  • Python 3 using PyInstaller
  • Python 2 using PyInstaller --onefile
  • Python 3 using PyInstaller --onefile
  • Python 3 using CX_Freeze

Known Issues

  1. Some JUMP instructions to EXTENDED_ARG instructions result in an error in uncompyle6's ifelsestmt.py file. Make the following changes to the file.

TODO

  • Also support folders created by the 3 libraries (which would also automate the reverse engineering of files created by CX_Freeze)

Requirements

  • uncompyle6
  • pefile

Credits

  1. Repo: PyInstaller Extractor by Extreme Coders
  2. Repo: bytecode_graph by Joshua Homan, Mandiant
  3. Article: Deobsfuscating Python Bytecode by Joshua Homan, Mandiant

Metadata

Release files for repyexe 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for repyexe 0.1.3
File Size Uploaded Provenance
repyexe-0.1.3.tar.gz 13.1 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for repyexe 0.1.3
File Interpreter ABI Platform
repyexe-0.1.3-py3-none-any.whl Python 3 none any Details
repyexe-0.1.3-py2-none-any.whl Python 2 none any Details

Total release size: 41.3 kB

Release files / repyexe-0.1.3.tar.gz

Download URL repyexe-0.1.3.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3f373dee5f568523001c0619ca1d37a940d202514cc806aa9053625c9a1248fd
BLAKE2b-256 checksum
How to use checksums
a2c4b202d5f92fcfc0457c982e6e11fd808ea8e3147ebf49273bf7e04daf5aec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.9

Release files / repyexe-0.1.3-py3-none-any.whl

Download URL repyexe-0.1.3-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
232099ab607a5a69d2bb695c55ce026a859e7fb031679882e2a19f82080ea825
BLAKE2b-256 checksum
How to use checksums
4438a48f5eff15f4abcbe7a91bdf023ccc0cd2311f88152a40d8c3f6bf2798f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.9

Release files / repyexe-0.1.3-py2-none-any.whl

Download URL repyexe-0.1.3-py2-none-any.whl
Size 14.1 kB
Tags Python 2
SHA-256 checksum
How to use checksums
f9d3eda195a6957c9aea0aa31afc35ec27f5675703f0dfd631f17d70f49b2449
BLAKE2b-256 checksum
How to use checksums
6851dbfd23032d619149036a265ead7dfebfe9ef5b1fed545c602eb2c86eb876
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.9

Security for repyexe 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.3 This release

3 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page