From 61b453dedcd9b0dec42c7bf3aa8a68ee01798cd8 Mon Sep 17 00:00:00 2001 From: coldfusion39 Date: Thu, 1 Oct 2020 07:42:21 -0400 Subject: [PATCH] Added a hook for PyInstaller to resovle Impacket library on build --- build_scripts/build_linux.sh | 13 ++++++++++--- build_scripts/build_musl.sh | 13 ++++++++++--- build_scripts/build_windows.sh | 12 +++++++++--- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/build_scripts/build_linux.sh b/build_scripts/build_linux.sh index e81812a6..74f64360 100755 --- a/build_scripts/build_linux.sh +++ b/build_scripts/build_linux.sh @@ -19,12 +19,19 @@ pip install pyinstaller==3.4 pip install . # Hardcode UTF-8 in shells -sed -r -i.bak 's/sys\.std(in|out)\.encoding/"UTF-8"/g' examples/*exec.py +sed -r -i.bak 's/sys\.std(in|out)\.encoding/"UTF-8"/g' examples/*exec.py + +# Create hook directory +mkdir /tmp/custom-hooks + +# Create hook file +echo "from PyInstaller.utils.hooks import copy_metadata" >> /tmp/custom-hooks/hook-impacket.py +echo "datas = copy_metadata('impacket')" >> /tmp/custom-hooks/hook-impacket.py # Create standalone executables for i in examples/*.py -do - pyinstaller --specpath /tmp/spec --workpath /tmp/build --distpath /tmp/out --clean -F $i +do + pyinstaller --specpath /tmp/spec --workpath /tmp/build --distpath /tmp/out --clean --additional-hooks-dir /tmp/custom-hooks -F $i done # Rename binaries and move diff --git a/build_scripts/build_musl.sh b/build_scripts/build_musl.sh index a13f3026..2936d007 100755 --- a/build_scripts/build_musl.sh +++ b/build_scripts/build_musl.sh @@ -19,12 +19,19 @@ pip install pyinstaller==3.4 pip install . # Hardcode UTF-8 in shells -sed -r -i.bak 's/sys\.std(in|out)\.encoding/"UTF-8"/g' examples/*exec.py +sed -r -i.bak 's/sys\.std(in|out)\.encoding/"UTF-8"/g' examples/*exec.py + +# Create hook directory +mkdir /tmp/custom-hooks + +# Create hook file +echo "from PyInstaller.utils.hooks import copy_metadata" >> /tmp/custom-hooks/hook-impacket.py +echo "datas = copy_metadata('impacket')" >> /tmp/custom-hooks/hook-impacket.py # Create standalone executables for i in examples/*.py -do - pyinstaller --specpath /tmp/spec --workpath /tmp/build --distpath /tmp/out --clean -F $i +do + pyinstaller --specpath /tmp/spec --workpath /tmp/build --distpath /tmp/out --clean --additional-hooks-dir /tmp/custom-hooks -F $i done # Rename binaries diff --git a/build_scripts/build_windows.sh b/build_scripts/build_windows.sh index 4dcc172d..e61ec071 100755 --- a/build_scripts/build_windows.sh +++ b/build_scripts/build_windows.sh @@ -4,7 +4,6 @@ set -euo pipefail ### This script is intended to be run in the cdrx/pyinstaller-windows:python2 Docker image - [[ ! -f /.dockerenv ]] && echo "Do not run this script outside of the docker image! Use the Makefile" && exit 1 # Normalize working dir @@ -14,10 +13,17 @@ cd "${ROOT}" # Install impacket pip install . +# Create hook directory +mkdir /tmp/custom-hooks + +# Create hook file +echo "from PyInstaller.utils.hooks import copy_metadata" >> /tmp/custom-hooks/hook-impacket.py +echo "datas = copy_metadata('impacket')" >> /tmp/custom-hooks/hook-impacket.py + # Create standalone executables for i in examples/*.py -do - pyinstaller --specpath /tmp/spec --workpath /tmp/build --distpath /tmp/out --clean -F $i +do + pyinstaller --specpath /tmp/spec --workpath /tmp/build --distpath /tmp/out --clean --additional-hooks-dir /tmp/custom-hooks -F $i done # Rename binaries and move