Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off & setlocal enableDelayedExpansion
- REM Records time before and after, displays how long it took
- call :init
- call :macros
- :start
- set /a nP+=1
- call :text "(Running payload)" 0b 0
- echo.
- set tB=%time%
- REM ###### <Payload section> ######
- if !np! equ 1 (
- for /l %%a in (1,1,1000) do call :calculateAverage 32 73 62 25 19
- ) else (
- for /l %%a in (1,1,1000) do %calculateAverage% 32 73 62 25 19
- )
- REM ###### </Payload Section> ######
- set tA=%time%
- REM Trap potential leading spaces
- for %%a in (%tA%) do (set tA=%%a)
- for %%a in (%tB%) do (set tB=%%a)
- REM Split to components
- for /f "tokens=1-4 delims=:." %%a in ("%tB%") do (
- set bH=%%a
- set bM=%%b
- set bS=%%c
- set bC=%%d
- )
- for /f "tokens=1-4 delims=:." %%a in ("%tA%") do (
- set aH=%%a
- set aM=%%b
- set aS=%%c
- set aC=%%d
- )
- REM Trap potential leading zeros
- if "%bH:~0,1%" EQU "0" set /a bH=%bH:~1,1% 2>nul
- if "%bM:~0,1%" EQU "0" set /a bM=%bM:~1,1%
- if "%bS:~0,1%" EQU "0" set /a bS=%bS:~1,1%
- if "%bC:~0,1%" EQU "0" set /a bC=%bC:~1,1%
- if "%aH:~0,1%" EQU "0" set /a aH=%aH:~1,1% 2>nul
- if "%aM:~0,1%" EQU "0" set /a aM=%aM:~1,1%
- if "%aS:~0,1%" EQU "0" set /a aS=%aS:~1,1%
- if "%aC:~0,1%" EQU "0" set /a aC=%aC:~1,1%
- REM Convert the hours, minutes, seconds and cents into just cents
- set /a eCT=(^
- %aC% + (%aS% * 100) + (%aM% * 6000) + (%aH% * 360000)) - (^
- %bC% + (%bS% * 100) + (%bM% * 6000) + (%bH% * 360000))
- REM Trap for midnight
- if %eCT% LSS 0 (
- set /a eCT+=8640000
- )
- REM Convert to hours, Minutes, Seconds and Cents
- call :toComponents %eCT%
- REM Report the result
- cls
- call :text "Payload execution complete" 0b 0
- echo .
- for /l %%a in (1,1,6) do (echo.)
- call :text " Elapsed" 0d 0
- echo : %eH%:%eM%:%eS%.%t%
- REM Calculate the average scan time
- set /a tT+=%eCT%
- set /a avg=%tT% / %nP%
- call :toComponents %avg%
- REM Report the average scan time, except if this is first run
- REM call :text " Average" 0e 0
- REM echo : %eH%:%eM%:%eS%.%t%
- REM Show the number of executions
- if %nP% GTR 1 (
- call :text " Passes" 02 0
- echo : %nP%
- )
- if %nP% EQU 1 echo.
- for /l %%a in (1,1,6) do (echo.)
- call :text "Press any key to repeat" 08 0
- echo ...& echo.
- pause >nul
- goto :start
- :init
- set /a nP=0
- set /a tT=0
- REM Initialise backspace variable, required for Text function
- for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (set "z=%%a")
- call :text "Press" 03 0
- call :text " any" 08 0
- call :text " key to" 07 0
- call :text " execute the" 0b 0
- call :text " payload" 0f 0
- echo ...
- pause >nul
- cls
- goto :eof
- :toComponents
- set /a eH=0
- set /a eM=0
- set /a eS=0
- set /a t=%1
- :hours
- if %t% GTR 360000 (
- set /a eH+=1
- set /a t-=360000
- goto :hours
- )
- :minutes
- if %t% GTR 6000 (
- set /a eM+=1
- set /a t-=6000
- goto :minutes
- )
- :seconds
- if %t% GTR 100 (
- set /a eS+=1
- set /a t-=100
- goto :seconds
- )
- REM Add leading zeros as required
- if "%eH:~1,1%" EQU "" set eH=0%eH%
- if "%eM:~1,1%" EQU "" set eM=0%eM%
- if "%eS:~1,1%" EQU "" set eS=0%eS%
- if "%t:~1,1%" EQU "" set t=0%t%
- goto :eof
- :text
- <nul set /p .=. > "%~1"
- findstr /v /a:%2 /R "^$" "%~1" nul
- if "%3" EQU "0" <nul set /p z=%z%%z%%z%
- if "%3" NEQ "0" echo %z%%z%%z%
- del "%~1" > nul 2>&1
- goto :eof
- REM :calculateAverage FUNCTION
- :calculateAverage
- if %5 gtr 0 ( set "div=5"
- ) else if %4 gtr 0 ( set "div=4"
- ) else if %3 gtr 0 ( set "div=3"
- ) else if %2 gtr 0 ( set "div=2"
- ) else if %1 gtr 0 set "div=1"
- set /a "sum=%1 + %2 + %3 + %4 + %5", "avg=sum / div"
- echo The average is !avg!
- goto :eof
- :macros
- set ^"LF=^
- ^" Above empty line is required - do not remove
- set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
- REM %calculateAverage% function MACRO
- set calculateAverage=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
- if %%5 gtr 0 ( set "div=5"%\n%
- ) else if %%4 gtr 0 ( set "div=4"%\n%
- ) else if %%3 gtr 0 ( set "div=3"%\n%
- ) else if %%2 gtr 0 ( set "div=2"%\n%
- ) else if %%1 gtr 0 set "div=1"%\n%
- set /a "sum=%%1 + %%2 + %%3 + %%4 + %%5"%\n%
- for /f "tokens=1,2" %%a in ("^!sum^! ^!div^!") do (%\n%
- set /a "avg=%%a / %%b"%\n%
- for /f %%0 in ("^!avg^!") do echo The average is %%0%\n%
- )%\n%
- )) else set args=
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement