bench.bat 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. :: Define constants
  4. set "VERACRYPT_PATH=c:\Program Files\VeraCrypt\veracrypt.exe"
  5. set "PASSWORD=test"
  6. set "HIDDEN_PASSWORD=testhidden"
  7. :: Find a free drive letter
  8. call :freedrive mydriveletter || (
  9. echo ERROR: No free drive letter found.
  10. goto :exit
  11. )
  12. echo Using drive letter !mydriveletter!: for our tests
  13. echo.
  14. :: Define an array of hash algorithms and their corresponding container files
  15. set "algorithms[0]=sha512,test.sha512.hc"
  16. set "algorithms[1]=whirlpool,test.whirlpool.hc"
  17. set "algorithms[2]=sha256,test.sha256.hc"
  18. set "algorithms[3]=blake2s,test.blake2s.hc"
  19. set "algorithms[4]=streebog,test.streebog.hc"
  20. :: Loop through each algorithm
  21. for /L %%i in (0,1,4) do (
  22. for /F "tokens=1,2 delims=," %%a in ("!algorithms[%%i]!") do (
  23. set "hash=%%a"
  24. set "container=%%b"
  25. if exist "!container!" (
  26. call :mount_and_measure "!hash!" "!container!" "Normal" "!PASSWORD!"
  27. call :mount_and_measure "!hash!" "!container!" "Hidden" "!HIDDEN_PASSWORD!"
  28. echo.
  29. )
  30. )
  31. )
  32. :: Autodetect test
  33. call :availablevolume testvolume || goto :exit
  34. call :measure_time "Wrong Password (PRF Auto-detection)" ^
  35. "/volume !testvolume! /l !mydriveletter! /password wrongpassword /q /silent /m ro"
  36. echo.
  37. goto :exit
  38. :: Subroutine to mount a volume and measure the time taken
  39. :mount_and_measure
  40. setlocal
  41. set "hash=%~1"
  42. set "container=%~2"
  43. set "type=%~3"
  44. set "volumepassword=%~4"
  45. call :measure_time "%hash% (%type%)" ^
  46. "/volume !container! /hash !hash! /l !mydriveletter! /password !volumepassword! /q /silent /m ro"
  47. if not exist !mydriveletter!:\ (
  48. echo ERROR: Drive letter !mydriveletter!: does not exist after mount operation.
  49. goto :exit
  50. )
  51. "!VERACRYPT_PATH!" /dismount !mydriveletter! /silent /q
  52. exit /b
  53. :: Subroutine to measure the time taken for a command to execute
  54. :measure_time
  55. setlocal
  56. set "oper=%~1"
  57. set "command=%~2"
  58. for /F "tokens=1-4 delims=:.," %%a in ("!time!") do set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
  59. "!VERACRYPT_PATH!" %command%
  60. for /F "tokens=1-4 delims=:.," %%a in ("!time!") do set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
  61. set /A elapsed=end-start
  62. set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100
  63. if %hh% lss 10 set hh=0%hh%
  64. if %mm% lss 10 set mm=0%mm%
  65. if %ss% lss 10 set ss=0%ss%
  66. if %cc% lss 10 set cc=0%cc%
  67. echo %oper% = %hh%:%mm%:%ss%,%cc%
  68. exit /b
  69. rem Finds a free drive letter.
  70. rem
  71. rem Parameters:
  72. rem %1 = Output variable name.
  73. rem
  74. rem Example:
  75. rem call :freedrive mydriveletter && goto :cont
  76. rem echo ERROR: No free drive letter found.
  77. rem goto :EOF
  78. rem :cont
  79. rem echo Found drive letter: %mydriveletter%
  80. :freedrive
  81. setlocal EnableDelayedExpansion
  82. set exitcode=0
  83. set "output_var=%~1"
  84. for %%i in (C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do (
  85. set "drive=%%i:"
  86. rem If 'subst' fails, the drive letter is already in use.
  87. rem This way we can even detect optical drives that have a drive
  88. rem letter but no media in them, a case that goes undetected when
  89. rem using 'if exist'.
  90. subst !drive! %SystemDrive%\ >nul
  91. if !errorlevel! == 0 (
  92. subst !drive! /d >nul
  93. set "drive=%%i"
  94. goto :freedrive0
  95. )
  96. )
  97. set exitcode=1
  98. set drive=
  99. :freedrive0
  100. endlocal & set "%output_var%=%drive%" & exit /b %exitcode%
  101. :: Subroutine to find an available volume
  102. :availablevolume
  103. setlocal EnableDelayedExpansion
  104. set exitcode=0
  105. set "output_var=%~1"
  106. for %%i in (test.sha512.hc,test.sha256.hc,test.whirlpool.hc,test.blake2s.hc) do (
  107. if exist %%i (
  108. set "volume=%%i"
  109. goto :availablevolume0
  110. )
  111. )
  112. set exitcode=1
  113. set volume=
  114. :availablevolume0
  115. endlocal & set "%output_var%=%volume%" & exit /b %exitcode%
  116. :exit
  117. pause