-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-SHA256-MJDFv1.bat
More file actions
110 lines (94 loc) · 3.18 KB
/
Copy pathgenerate-SHA256-MJDFv1.bat
File metadata and controls
110 lines (94 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
@echo off
setlocal EnableExtensions DisableDelayedExpansion
cd /d "%~dp0"
set "INTERACTIVE=0"
if "%~1"=="" set "INTERACTIVE=1"
set "TARGET="
if not "%~1"=="" set "TARGET=%~f1"
if not defined TARGET if exist "%~dp0MJDFv1.exe" set "TARGET=%~dp0MJDFv1.exe"
if not defined TARGET if exist "%~dp0dist\MJDFv1.exe" set "TARGET=%~dp0dist\MJDFv1.exe"
set "OUT=%~dp0SHA256SUMS.txt"
set "TMP=%TEMP%\mjdfv1-sha-%RANDOM%-%RANDOM%.txt"
if exist "%TMP%" del /f /q "%TMP%" >nul 2>&1
echo ================================================================
echo MJ DNS FILTER v1 - SHA-256 generator
echo ================================================================
echo.
if not defined TARGET goto :NOT_FOUND
if not exist "%TARGET%" goto :NOT_FOUND
for %%F in ("%TARGET%") do set "BASENAME=%%~nxF"
if /I not "%BASENAME%"=="MJDFv1.exe" goto :WRONG_NAME
echo Input: %TARGET%
echo Output: %OUT%
echo.
set "HASH="
where powershell.exe >nul 2>&1
if not errorlevel 1 (
set "MJDF_HASH_TARGET=%TARGET%"
powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; (Get-FileHash -LiteralPath $env:MJDF_HASH_TARGET -Algorithm SHA256).Hash.ToLowerInvariant()" > "%TMP%" 2>nul
if not errorlevel 1 set /p "HASH="<"%TMP%"
)
if defined HASH goto :HAVE_HASH
rem PowerShell failed or was unavailable. certutil is an inbox Windows fallback.
set "HASH="
where certutil.exe >nul 2>&1
if errorlevel 1 goto :HASH_FAILED
certutil.exe -hashfile "%TARGET%" SHA256 > "%TMP%" 2>nul
if errorlevel 1 goto :HASH_FAILED
for /f "usebackq skip=1 tokens=* delims=" %%H in ("%TMP%") do if not defined HASH set "HASH=%%H"
if not defined HASH goto :HASH_FAILED
set "HASH=%HASH: =%"
:HAVE_HASH
if not defined HASH goto :HASH_FAILED
> "%OUT%" echo %HASH% *MJDFv1.exe
if errorlevel 1 goto :WRITE_FAILED
echo [OK] SHA-256 generated successfully.
echo.
echo %HASH% MJDFv1.exe
echo.
echo Created:
echo %OUT%
echo.
echo GitHub Release v1 assets:
echo MJDFv1.exe
echo SHA256SUMS.txt
echo generate-SHA256-MJDFv1.bat
echo verify-SHA256-MJDFv1.bat
echo.
if exist "%TMP%" del /f /q "%TMP%" >nul 2>&1
if "%INTERACTIVE%"=="1" pause
endlocal & exit /b 0
:NOT_FOUND
echo [ERROR] MJDFv1.exe was not found.
echo.
echo Supported use:
echo 1. Put this BAT beside MJDFv1.exe and double-click it.
echo 2. Put this BAT in the repository root with dist\MJDFv1.exe and double-click it.
echo 3. Drag MJDFv1.exe onto this BAT.
echo 4. Run: generate-SHA256-MJDFv1.bat "C:\path\to\MJDFv1.exe"
echo.
if "%INTERACTIVE%"=="1" pause
endlocal & exit /b 2
:WRONG_NAME
echo [ERROR] The public v1 release binary must be named exactly MJDFv1.exe.
echo Received: %BASENAME%
echo.
echo Use the official release binary named exactly MJDFv1.exe.
echo.
if "%INTERACTIVE%"=="1" pause
endlocal & exit /b 5
:HASH_FAILED
echo [ERROR] SHA-256 calculation failed with both PowerShell and certutil.
echo Verify that MJDFv1.exe is readable and try again.
echo.
if exist "%TMP%" del /f /q "%TMP%" >nul 2>&1
if "%INTERACTIVE%"=="1" pause
endlocal & exit /b 3
:WRITE_FAILED
echo [ERROR] Could not write:
echo %OUT%
echo Check folder permissions and try again.
echo.
if exist "%TMP%" del /f /q "%TMP%" >nul 2>&1
if "%INTERACTIVE%"=="1" pause
endlocal & exit /b 4