<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>PyInstaller on LEl_FENG Blog</title><link>https://blog.xpdbk.com/en/tags/pyinstaller/</link><description>Recent content in PyInstaller on LEl_FENG Blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>LEl_FENG Copyright</copyright><lastBuildDate>Tue, 12 Sep 2023 21:45:21 +0700</lastBuildDate><atom:link href="https://blog.xpdbk.com/en/tags/pyinstaller/index.xml" rel="self" type="application/rss+xml"/><item><title>A Method for Reverse Engineering a PyInstaller Packaged Program</title><link>https://blog.xpdbk.com/en/posts/debug-pyinstaller-crack/</link><pubDate>Tue, 12 Sep 2023 21:45:21 +0700</pubDate><guid>https://blog.xpdbk.com/en/posts/debug-pyinstaller-crack/</guid><description>&lt;blockquote>
&lt;p>&lt;strong>TL;DR / Geek Summary:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Reverse Engineering: Systematic guide to extracting Python source code from PyInstaller-packaged &lt;code>.exe&lt;/code> files.&lt;/li>
&lt;li>Toolstack: Leveraging &lt;code>pyinstxtractor.py&lt;/code> for extraction and online &lt;code>.pyc&lt;/code>-to-&lt;code>.py&lt;/code> decompilers for restoration.&lt;/li>
&lt;li>Workflow: Compile test script (&lt;code>awa.py&lt;/code>) -&amp;gt; Package with PyInstaller 5.13.0 -&amp;gt; Extract entry point and dependency layers from the PYZ archive.&lt;/li>
&lt;/ul>
&lt;/blockquote>
&lt;h1 id="reverse-engineering-the-source-code-of-a-pyinstaller-packaged-exe-file">
&lt;a href="#reverse-engineering-the-source-code-of-a-pyinstaller-packaged-exe-file" class="heading-anchor" aria-label="Anchor for Reverse engineering the source code of a PyInstaller-packaged exe file">#&lt;/a>
Reverse engineering the source code of a PyInstaller-packaged exe file
&lt;/h1>
&lt;blockquote>
&lt;p>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.&lt;/p>
&lt;/blockquote>
&lt;h2 id="introduction">
&lt;a href="#introduction" class="heading-anchor" aria-label="Anchor for Introduction">#&lt;/a>
Introduction
&lt;/h2>
&lt;blockquote>
&lt;p>We all know that we can use the &lt;strong>PyInstaller&lt;/strong> library to compile &lt;code>.py&lt;/code> files into &lt;code>.exe&lt;/code> files that can be run. This article will cover compiling scripts into &lt;code>.exe&lt;/code> files and then decompiling the source code of the &lt;code>.exe&lt;/code> file to extract the source files.&lt;/p>
&lt;/blockquote>
&lt;h2 id="environment-tools">
&lt;a href="#environment-tools" class="heading-anchor" aria-label="Anchor for Environment Tools">#&lt;/a>
Environment Tools
&lt;/h2>
&lt;blockquote>
&lt;p>&lt;code>Python 3.8.10&lt;/code>: &lt;a class="link" href="https://www.python.org/downloads/release/" target="_blank" rel="noopener"
>Download it yourself if you don&amp;rsquo;t have it&lt;/a>
&lt;span style="white-space: nowrap;">&lt;svg width=".7em"
height=".7em" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m13 3l3.293 3.293l-7 7l1.414 1.414l7-7L21 11V3z" fill="currentColor" />
&lt;path d="M19 19H5V5h7l-2-2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2h14c1.103 0 2-.897 2-2v-5l-2-2v7z"
fill="currentColor">
&lt;/svg>&lt;/span>
&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>&lt;code>Pyinstaller library&lt;/code>: pip install -i &lt;a class="link" href="https://pypi.tuna.tsinghua.edu.cn/simple" target="_blank" rel="noopener"
>https://pypi.tuna.tsinghua.edu.cn/simple&lt;/a>
&lt;span style="white-space: nowrap;">&lt;svg width=".7em"
height=".7em" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m13 3l3.293 3.293l-7 7l1.414 1.414l7-7L21 11V3z" fill="currentColor" />
&lt;path d="M19 19H5V5h7l-2-2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2h14c1.103 0 2-.897 2-2v-5l-2-2v7z"
fill="currentColor">
&lt;/svg>&lt;/span>
pyinstaller==5.13.0&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>&lt;code>pyinstxtractor.py&lt;/code>: &lt;a class="link" href="https://github.com/extremecoders-re/pyinstxtractor" target="_blank" rel="noopener"
>Download address&lt;/a>
&lt;span style="white-space: nowrap;">&lt;svg width=".7em"
height=".7em" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m13 3l3.293 3.293l-7 7l1.414 1.414l7-7L21 11V3z" fill="currentColor" />
&lt;path d="M19 19H5V5h7l-2-2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2h14c1.103 0 2-.897 2-2v-5l-2-2v7z"
fill="currentColor">
&lt;/svg>&lt;/span>
&lt;/p>
&lt;/blockquote>
&lt;h2 id="compiling-the-program">
&lt;a href="#compiling-the-program" class="heading-anchor" aria-label="Anchor for Compiling the Program">#&lt;/a>
Compiling the Program
&lt;/h2>
&lt;h3 id="checking-the-environment">
&lt;a href="#checking-the-environment" class="heading-anchor" aria-label="Anchor for Checking the Environment">#&lt;/a>
Checking the Environment
&lt;/h3>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">python -V
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>If the execution is successful, then it&amp;rsquo;s done.&lt;/p>
&lt;h3 id="writing-the-script">
&lt;a href="#writing-the-script" class="heading-anchor" aria-label="Anchor for Writing the Script">#&lt;/a>
Writing the Script
&lt;/h3>
&lt;p>&lt;strong>awa.py&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># Function
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">def test():
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">print(&amp;#34;====666====&amp;#34;)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">input_text = input(&amp;#34;I&amp;#39;m telling you the truth 1&amp;#34;)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># Print the formatted time and the content entered by the user
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">print(datetime.datetime.now().strftime(&amp;#34;%Y-%m-%d %H:%M:%S &amp;#34;) + input_text)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">if __name__ == &amp;#39;__main__&amp;#39;:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">test()
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="packaging-program">
&lt;a href="#packaging-program" class="heading-anchor" aria-label="Anchor for Packaging Program">#&lt;/a>
Packaging Program
&lt;/h3>
&lt;p>First, install the library &lt;code>pyinstaller&lt;/code> used by the packaging program. Here, we use the &lt;code>Tsinghua mirror&lt;/code> and specify the &lt;code>5.13.0&lt;/code> version library.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">pip install -i https://pypi.tuna.tsinghua.edu.cn/simple &lt;span class="nv">pyinstaller&lt;/span>&lt;span class="o">==&lt;/span>5.13.0
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Locate the folder where the script is located. Mine is &lt;code>D:\&lt;/code>. &lt;code>cd&lt;/code> to this path and enter the following packaging command:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">Pyinstaller -F awa.py
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>After the command finishes executing, you will see the &lt;code>completed successfully.&lt;/code> field, indicating that the &lt;code>.exe&lt;/code> file was successfully generated in the &lt;code>dist&lt;/code> folder.&lt;/p>
&lt;h2 id="reverse-engineering-process">
&lt;a href="#reverse-engineering-process" class="heading-anchor" aria-label="Anchor for Reverse Engineering Process">#&lt;/a>
Reverse Engineering Process
&lt;/h2>
&lt;p>First, we download the decompilation script &lt;code>pyinstxtractor.py&lt;/code> and place it in the same working directory as the &lt;code>.exe&lt;/code> file we want to decompile.&lt;/p>
&lt;p>Then, we continue by &lt;code>cd&lt;/code>ing the &lt;code>dist&lt;/code> folder in the command line, entering the following command and executing it:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">python pyinstxtractor.py awa.exe
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>After execution, you will see the message &lt;code>Successfully&lt;/code>, and a &lt;code>awa.exe_extracted&lt;/code> folder will be generated.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Processing FDP Configuration Online Update 2.exe
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Pyinstaller version: 2.1+
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Python version: 3.8
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Length of package: &lt;span class="m">32503973&lt;/span> bytes
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Found &lt;span class="m">141&lt;/span> files in CArchive
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Beginning extraction...please standby
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Possible entry point: pyiboot01_bootstrap.pyc
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Possible entry point: pyi_rth_pyqt5.pyc
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Possible entry point: pyi_rth_pkgutil.pyc
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Possible entry point: pyi_rth_inspect.pyc
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Possible entry point: Download json.pyc
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Found &lt;span class="m">225&lt;/span> files in PYZ archive
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[&lt;/span>+&lt;span class="o">]&lt;/span> Successfully extracted pyinstaller archive: FDP configuration online update 2.exe
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">You can now use a python decompiler on the pyc files within the extracted direct
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">ory
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">``&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Enter this folder. Inside, you&lt;span class="s1">&amp;#39;ll find many files with the extensions `.dll` and `.pyd`, and a folder named `PYZ-00.pyz_extracted`. This folder contains the **dependency libraries** imported by the program. If you&amp;#39;&lt;/span>ve imported other &lt;span class="sb">`&lt;/span>.py&lt;span class="sb">`&lt;/span> files, you can use a similar method to decompile those dependent &lt;span class="sb">`&lt;/span>.py&lt;span class="sb">`&lt;/span> files.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">In this directory, find &lt;span class="sb">`&lt;/span>awa.pyc&lt;span class="sb">`&lt;/span> and a file with the same name as your &lt;span class="sb">`&lt;/span>awa.exe&lt;span class="sb">`&lt;/span> file.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">!&lt;span class="o">[&lt;/span>Demo&lt;span class="o">](&lt;/span>pyinstaller.webp&lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Then you can take this &lt;span class="sb">`&lt;/span>.pyc&lt;span class="sb">`&lt;/span> file to any &lt;span class="sb">`&lt;/span>.pyc&lt;span class="sb">`&lt;/span> to &lt;span class="sb">`&lt;/span>.py&lt;span class="sb">`&lt;/span> file conversion website found on search engines to convert it.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div></description></item></channel></rss>