Skip to content

Instantly share code, notes, and snippets.

@acgrid
Last active May 26, 2018 09:07
Show Gist options
  • Save acgrid/4f2287df0f953456e3570557a4766089 to your computer and use it in GitHub Desktop.
Save acgrid/4f2287df0f953456e3570557a4766089 to your computer and use it in GitHub Desktop.
Everything about extract pyinstaller-ed exe files
@echo off
python %~dp0\pyinstxtractor.py %1
cd %1_extracted
for /F %%i in ("%1") do (
if not exist %%~ni goto :eof
echo %%~ni
python %~dp0\pycize.py %%~ni
uncompyle6 -o %%~ni.py %%~ni.pyc
)

Checkpoints

  • Put pyinstxtractor.py to somewhere included in PATH by cloning python-exe-unpacker or just downloading
  • Clone python-uncompyle6, patch it if on Windows, install
  • Also put pycize.py and depyinstaller.cmd along with pyinstxtractor.py
  • depyinstaller foo.exe and get source
  • If foo is not the real entry name, try to find the real name among the extracted folder, then do the rest

Tools needed

import sys
import binascii
def main():
if len(sys.argv) < 2:
print('[*] Usage: {0} <filename>'.format(sys.argv[0]))
else:
with open(sys.argv[1], "rb") as src, open('{0}.pyc'.format(sys.argv[1]), "wb") as dst:
dst.write(binascii.unhexlify("330D0D0A206A025B0C000000"))
dst.write(src.read())
if __name__ == '__main__':
main()
--- a/uncompyle6/main.py
+++ b/uncompyle6/main.py
@@ -42,7 +42,7 @@ def _get_outstream(outfile):
mode = 'wb'
else:
mode = 'w'
- return open(outfile, mode)
+ return open(outfile, mode, encoding='utf-8')
def decompile(
bytecode_version, co, out=None, showasm=None, showast=False,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment