Skip to content

Commit

Permalink
add idempotent hashing function
Browse files Browse the repository at this point in the history
  • Loading branch information
artoonie committed Oct 25, 2023
1 parent b6077d3 commit 1bd1d03
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/hash.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
:: hash.bat
@echo off

:: NOTE: This script must be placed one level up from the rcv directory

echo Initiating batch hash procedure…
echo %date% %time%

setlocal EnableExtensions EnableDelayedExpansion

set "HASHFILE=all_hashes.txt"
set "TEMPHASHFILE=all_hashes_temp.txt"
set "EXTRACTIONDIR=.\rcv\modules_extracted"
set "MODULESFILE=.\rcv\lib\modules"

if exist %HASHFILE% (
echo Deleting existing hash file, %HASHFILE% ...
del %HASHFILE%
)

if exist %EXTRACTIONDIR% (
echo Deleting existing extracted modules directory, %EXTRACTIONDIR% ...
rmdir /s /q %EXTRACTIONDIR%
)

echo Extracting contents of modules file...
mkdir %EXTRACTIONDIR%
cd %EXTRACTIONDIR%
jimage extract ..\..\%MODULESFILE%

echo Temporarily relocating modules file...
cd ..\..
copy %MODULESFILE% .
del %MODULESFILE%

:: Calculate the hash for every file here and in all subdirectories, appending to the file (format "(filename) = (hash)")
echo Calculating hashes...
for /r .\rcv %%f in (*) do (
<NUL set /p ="%%f = " >> %HASHFILE%
C:\Windows\System32\certutil.exe -hashfile "%%f" SHA512 | findstr /v ":" >> %HASHFILE%
)

echo Restoring modules file...
move .\modules %MODULESFILE%

:: Replace the absolute paths to each file with relative paths (e.g. C:\temp\rcv => .\rcv)

echo Replacing absolute paths with relative paths in hash file...
set "SEARCHTEXT=%cd%"
set "REPLACETEXT=."
for /f "delims=" %%A in ('type "%HASHFILE%"') do (
set "string=%%A"
set "modified=!string:%SEARCHTEXT%=%REPLACETEXT%!"
echo !modified!>>"%TEMPHASHFILE%"
)
del "%HASHFILE%"
rename "%TEMPHASHFILE%" "%HASHFILE%"

echo Sorting the hash file...
sort "%HASHFILE%" > "%TEMPHASHFILE%"
del "%HASHFILE%"
rename "%TEMPHASHFILE%" "%HASHFILE%"

echo Calculating the hash of the entire sorted hash file...
C:\Windows\System32\certutil.exe -hashfile %HASHFILE% SHA512

endlocal
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ jobs:
# run: |
# ./idempotent_hash.bat
- name: "Generate Idempotent SHA512 for Windows"
if: runner.os == 'Windows'
run: |
move .github/workflows/hash.bat build
cd build
hash.bat >> idempotent-hash.sha512
- uses: actions/upload-artifact@v3
with:
name: Package
Expand All @@ -137,6 +144,7 @@ jobs:
${{ github.workspace }}/${{ steps.zipfn.outputs.FILEPATH }}.sha512
${{ github.workspace }}/${{ steps.exefn.outputs.FILEPATH }}
${{ github.workspace }}/${{ steps.exefn.outputs.FILEPATH }}.sha512
build/idempotent-hash.sha512
retention-days: 90

- name: "Upload binaries to release"
Expand Down

0 comments on commit 1bd1d03

Please sign in to comment.