~/til/how-to-decompile-an-python-310-program
How to decompile an python 3.10 program
on-this-page2
Saya mulai ini dari di tempat saya bekerja, saya butuh mendapatkan bagaimana caranya suatu aplikasi dengan ektensi .exe bekerja. Ya, dengan meminta bantuan langsung atau menghubungi pihak yang berkaitan langsung dengan aplikasi tersebut untuk mempertanyakan pertanyaan demikian nampaknya sangat mudah, namun saya rasa tidak. Itu mungkin membutuhkan waktu yang lama dan kemungkinan untuk mendapatkan dokumentasinya bisa di angka 50%, terlebih belum dengan tetek bengek lainnya yang akan makan waktu dan tenaga juga. Maka dari itu saya berangkat dari "Bagaimana jika kita reverse engineering aplikasi ini?" munculah ide untuk mencari-cari informasi (basically this is just chatting with gpt-5 model tho) dan setelah beberapa trial and error saya berhasil untuk decompile basically an python program but it's like compile to an windows program (.exe). Berikut adalah tulisan atau panduan atau mungkin step by step bagaimana saya melakukannya di Arch Linux.
Requirements
Needs to install
uvlibxcrypt-compat
How to
- Install python 3.10.0 with uv command
bash
uv python install 3.10.0- Create an self python 3.10.0 environment
bash
uv venv -p 3.10.0 .venv3100- Activate the environment or source it
bash
source .venv3100/bin/activate.fish- Ensure it's python 3.10.0
bash
python -V- Install or upgrade pip in that environment
bash
python -m ensurepip --upgrade- Install or upgrade toolchain
bash
python -m pip install -U pip wheel setuptools- Install or upgrade the
pyinstxtractor-ng
bash
python -m pip install -U pyinstxtractor-ng- Extract the
.exe
bash
pyinstxtractor-ng program-name.exe- Check the extracted folder
bash
ls program-name.exe_extracted/- Extract the PYZ ones if it's have
bash
pyinstxtractor-ng program-name.exe_extracted/PYZ-00.pyz- Install
pycdcpatched by me
Cause the main pycdc it's have limitation (see the issue), i need like patch first to make like it's decompiling successfully especially what i think it's being like trouble on python 3.10.0 base program. You can see some note in README.md in my fork repository to see the changes.
- Clone the repository
bash
git clone https://github.com/rizkyilhampra/pycdc.git- Build the
pycdcprogram
bash
cmake . && make -j- Decompile
bash
./path-where-is-pycdc-at/pycdc path-to-where-extracted-at/program-name.exe_extracted/program-name.pyc > path-to-where-decompile-file-put/program-name.py- Decompile some file (Optional)
Here is what i do in fish shell
You can like modification my script to fit your purpose
bash
mkdir -p program-name.decompiled/pyzbash
set all_files progarm-name.exe_extracted/PYZ-00.pyz_extracted/config.pyc \
program-name.exe_extracted/PYZ-00.pyz_extracted/util.pyc \
program-name.exe_extracted/PYZ-00.pyz_extracted/test.pyc \
(find program-name.exe_extracted/PYZ-00.pyz_extracted/src -type f -name '*.pyc')bash
set out "program-name.decompiled/pyz/"(basename (string replace -r '\.pyc$' '.py' $f))
./path-where-is-pycdc-at/pycdc $f > $out; or true
end