Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PySilon Launcher - @deffcolony | Do not merge until more work is completed. #415

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
366 changes: 366 additions & 0 deletions pysilon-launcher.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,366 @@
@echo off
REM PySilon Launcher
REM Created by: Deffcolony
REM All credit to: https://t.me/deffcolony
REM Description:
REM This script can install/start/update/uninstall PySilon
REM
REM This script is intended for use on Windows systems.
REM report any issues or bugs on the GitHub repository.
REM
REM GitHub: https://github.com/mategol/PySilon-malware
REM Issues: https://github.com/mategol/PySilon-malware/issues
title PySilon Launcher [STARTUP CHECK]
setlocal

REM ANSI Escape Code for Colors
set "reset="

REM Strong Foreground Colors
set "white_fg_strong="
set "red_fg_strong="
set "green_fg_strong="
set "yellow_fg_strong="
set "blue_fg_strong="
set "magenta_fg_strong="
set "cyan_fg_strong="

REM Normal Background Colors
set "red_bg="
set "blue_bg="
set "yellow_bg="

REM Environment Variables (winget)
set "winget_path=%userprofile%\AppData\Local\Microsoft\WindowsApps"

REM Environment Variables (miniconda3)
set "miniconda_path=%userprofile%\miniconda3"
set "miniconda_path_mingw=%userprofile%\miniconda3\Library\mingw-w64\bin"
set "miniconda_path_usrbin=%userprofile%\miniconda3\Library\usr\bin"
set "miniconda_path_bin=%userprofile%\miniconda3\Library\bin"
set "miniconda_path_scripts=%userprofile%\miniconda3\Scripts"

REM Define variables for install locations
set "pysilon_install_path=%~dp0PySilon-malware"

REM Define the paths and filenames for the shortcut creation
set "shortcutTarget=%~dp0pysilon-launcher.bat"
set "iconFile=%~dp0pysilon.ico"
set "desktopPath=%userprofile%\Desktop"
set "shortcutName=pysilon.lnk"
set "startIn=%~dp0"
set "comment=pysilon"

cd /d "%~dp0"


REM Get the current PATH value from the registry
for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v PATH') do set "current_path=%%B"

REM Check if the paths are already in the current PATH
echo %current_path% | find /i "%winget_path%" > nul
set "ff_path_exists=%errorlevel%"

setlocal enabledelayedexpansion

REM Append the new paths to the current PATH only if they don't exist
if %ff_path_exists% neq 0 (
set "new_path=%current_path%;%winget_path%"
echo.
echo [DEBUG] "current_path is:%cyan_fg_strong% %current_path%%reset%"
echo.
echo [DEBUG] "winget_path is:%cyan_fg_strong% %winget_path%%reset%"
echo.
echo [DEBUG] "new_path is:%cyan_fg_strong% !new_path!%reset%"

REM Update the PATH value in the registry
reg add "HKCU\Environment" /v PATH /t REG_EXPAND_SZ /d "!new_path!" /f

REM Update the PATH value for the current session
setx PATH "!new_path!" > nul
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%winget added to PATH.%reset%
) else (
set "new_path=%current_path%"
echo %blue_fg_strong%[INFO] winget already exists in PATH.%reset%
)

REM Check if Winget is installed; if not, then install it
winget --version > nul 2>&1
if %errorlevel% neq 0 (
echo %yellow_bg%[%time%]%reset% %yellow_fg_strong%[WARN] Winget is not installed on this system.%reset%
REM Check if the folder exists
if not exist "%~dp0bin" (
mkdir "%~dp0bin"
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Created folder: "bin"
) else (
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO] "bin" folder already exists.%reset%
)
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Installing Winget...
curl -L -o "%~dp0bin\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
start "" "%~dp0bin\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%Winget installed successfully. Please restart the Launcher.%reset%
pause
exit
) else (
echo %blue_fg_strong%[INFO] Winget is already installed.%reset%
)
endlocal

REM Check if Git is installed if not then install git
git --version > nul 2>&1
if %errorlevel% neq 0 (
echo %yellow_bg%[%time%]%reset% %yellow_fg_strong%[WARN] Git is not installed on this system.%reset%
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Installing Git using Winget...
winget install -e --id Git.Git
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%Git installed successfully. Please restart the Launcher.%reset%
pause
exit
) else (
echo %blue_fg_strong%[INFO] Git is already installed.%reset%
)

REM Get the current PATH value from the registry
for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v PATH') do set "current_path=%%B"

REM Check if the paths are already in the current PATH
echo %current_path% | find /i "%miniconda_path%" > nul
set "ff_path_exists=%errorlevel%"

setlocal enabledelayedexpansion

REM Append the new paths to the current PATH only if they don't exist
if %ff_path_exists% neq 0 (
set "new_path=%current_path%;%miniconda_path%;%miniconda_path_mingw%;%miniconda_path_usrbin%;%miniconda_path_bin%;%miniconda_path_scripts%"
echo.
echo [DEBUG] "current_path is:%cyan_fg_strong% %current_path%%reset%"
echo.
echo [DEBUG] "miniconda_path is:%cyan_fg_strong% %miniconda_path%%reset%"
echo.
echo [DEBUG] "new_path is:%cyan_fg_strong% !new_path!%reset%"

REM Update the PATH value in the registry
reg add "HKCU\Environment" /v PATH /t REG_EXPAND_SZ /d "!new_path!" /f

REM Update the PATH value for the current session
setx PATH "!new_path!" > nul
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%miniconda3 added to PATH.%reset%
) else (
set "new_path=%current_path%"
echo %blue_fg_strong%[INFO] miniconda3 already exists in PATH.%reset%
)

REM Check if Miniconda3 is installed if not then install Miniconda3
call conda --version > nul 2>&1
if %errorlevel% neq 0 (
echo %yellow_bg%[%time%]%reset% %yellow_fg_strong%[WARN] Miniconda3 is not installed on this system.%reset%
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Installing Miniconda3 using Winget...
winget install -e --id Anaconda.Miniconda3
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%Miniconda3 installed successfully. Please restart the Launcher.%reset%
pause
exit
) else (
echo %blue_fg_strong%[INFO] Miniconda3 is already installed.%reset%
)

REM Check if Python App Execution Aliases exist
if exist "%LOCALAPPDATA%\Microsoft\WindowsApps\python.exe" (
REM Disable App Execution Aliases for python.exe
powershell.exe Remove-Item "%LOCALAPPDATA%\Microsoft\WindowsApps\python.exe" -Force
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%Removed Execution Alias for python.exe%reset%
) else (
echo %blue_fg_strong%[INFO] Execution Alias for python.exe was already removed.%reset%
)

REM Check if python3.exe App Execution Alias exists
if exist "%LOCALAPPDATA%\Microsoft\WindowsApps\python3.exe" (
REM Disable App Execution Aliases for python3.exe
powershell.exe Remove-Item "%LOCALAPPDATA%\Microsoft\WindowsApps\python3.exe" -Force
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%Removed Execution Alias for python3.exe%reset%
) else (
echo %blue_fg_strong%[INFO] Execution Alias for python3.exe was already removed.%reset%
)


REM Home menu - Frontend
:home
title PySilon Launcher [HOME]
cls
echo %blue_fg_strong%/ Home%reset%
echo ---------------------------------------------------------------
echo What would you like to do?
echo 1. Install PySilon
echo 2. Start PySilon
echo 3. Update
echo 4. Uninstall PySilon
echo 0. Exit

set "choice="
set /p "choice=Choose Your Destiny (default is 1): "

REM Default to choice 1 if no input is provided
if not defined choice set "choice=1"

REM Home menu - Backend
if "%choice%"=="1" (
call :install_pysilon
) else if "%choice%"=="2" (
call :start_pysilon
) else if "%choice%"=="3" (
call :update
) else if "%choice%"=="4" (
call :uninstall_pysilon
) else if "%choice%"=="0" (
exit
) else (
echo %red_bg%[%time%]%reset% %red_fg_strong%[ERROR] Invalid input. Please enter a valid number.%reset%
pause
goto :home
)


:install_pysilon
title PySilon Launcher [INSTALL]
cls
echo %blue_fg_strong%/ Home / Install PySilon%reset%
echo ---------------------------------------------------------------
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Installing PySilon...

set max_retries=3
set retry_count=0

:retry_install_pysilon
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Cloning PySilon repository...
git clone --depth 1 https://github.com/mategol/PySilon-malware.git

if %errorlevel% neq 0 (
set /A retry_count+=1
echo %yellow_bg%[%time%]%reset% %yellow_fg_strong%[WARN] Retry %retry_count% of %max_retries%%reset%
if %retry_count% lss %max_retries% goto :retry_install_pysilon
echo %red_bg%[%time%]%reset% %red_fg_strong%[ERROR] Failed to clone repository after %max_retries% retries.%reset%
pause
goto :home
)
cd /d "%pysilon_install_path%"

REM Create a Conda environment named pysilon
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Creating Conda environment: %cyan_fg_strong%pysilon%reset%
call conda create -n pysilon python=3.11.4 -y

REM Activate the conda environment named pysilon
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Activating Conda environment: %cyan_fg_strong%pysilon%reset%
call conda activate pysilon

REM Install pip requirements
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Installing pip requirements
pip install pillow
pip install pyinstaller
pip install -r requirements.txt

echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%PySilon installed successfully.%reset%

REM Ask if the user wants to create a shortcut
set /p create_shortcut=Do you want to create a shortcut on the desktop? [Y/n]
if /i "%create_shortcut%"=="Y" (

REM Create the shortcut
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Creating shortcut...
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command ^
"$WshShell = New-Object -ComObject WScript.Shell; " ^
"$Shortcut = $WshShell.CreateShortcut('%desktopPath%\%shortcutName%'); " ^
"$Shortcut.TargetPath = '%shortcutTarget%'; " ^
"$Shortcut.IconLocation = '%iconFile%'; " ^
"$Shortcut.WorkingDirectory = '%startIn%'; " ^
"$Shortcut.Description = '%comment%'; " ^
"$Shortcut.Save()"
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%Shortcut created on the desktop.%reset%
pause
)
goto :home


:start_pysilon
title PySilon
cls
echo %blue_fg_strong%/ Home / Start PySilon%reset%
echo ---------------------------------------------------------------

REM Check if the folder exists
if not exist "%pysilon_install_path%" (
echo %red_bg%[%time%]%reset% %red_fg_strong%[ERROR] Directory:%reset% %red_bg%PySilon%reset% %red_fg_strong%not found.%reset%
echo %red_fg_strong%Please install PySilon first%reset%
pause
goto :home
)

REM Activate the pysilon environment
call conda activate pysilon

REM Start pysilon
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% PySilon launched in a new window.
start cmd /k "title PySilon && cd /d %pysilon_install_path% && python builder.py"
goto :home


:update
REM Check if PySilon directory exists
if not exist "%pysilon_install_path%" (
echo %yellow_bg%[%time%]%reset% %yellow_fg_strong%[WARN] PySilon directory not found. Skipping update.%reset%
pause
goto :home
)

REM Update PySilon
set max_retries=3
set retry_count=0

:retry_update_pysilon
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Updating PySilon...
cd /d "%pysilon_install_path%"
call git pull
if %errorlevel% neq 0 (
set /A retry_count+=1
echo %yellow_bg%[%time%]%reset% %yellow_fg_strong%[WARN] Retry %retry_count% of %max_retries%%reset%
if %retry_count% lss %max_retries% goto :retry_update_pysilon
echo %red_bg%[%time%]%reset% %red_fg_strong%[ERROR] Failed to update PySilon repository after %max_retries% retries.%reset%
pause
goto :home
)
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%PySilon updated successfully.%reset%
pause
goto :home


:uninstall_pysilon
title PySilon [UNINSTALL]
setlocal enabledelayedexpansion
chcp 65001 > nul

REM Confirm with the user before proceeding
echo.
echo %red_bg%╔════ DANGER ZONE ══════════════════════════════════════════════════════════════════════════════╗%reset%
echo %red_bg%║ WARNING: This will delete all data of PySilon ║%reset%
echo %red_bg%║ If you want to keep any data, make sure to create a backup before proceeding. ║%reset%
echo %red_bg%╚═══════════════════════════════════════════════════════════════════════════════════════════════╝%reset%
echo.
set /p "confirmation=Are you sure you want to proceed? [Y/N]: "
if /i "%confirmation%"=="Y" (

REM Remove the Conda environment
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Removing the Conda environment 'pysilon'...
call conda deactivate
call conda remove --name pysilon --all -y
call conda clean -a -y

REM Remove the folder PySilon
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Removing the PySilon directory...
cd /d "%~dp0"
rmdir /s /q "%pysilon_install_path%"

echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%PySilon uninstalled successfully.%reset%
pause
goto :home
) else (
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Uninstall canceled.
pause
goto :home
)