How to add filter to a file chooser in batch?

前端 未结 3 1268
隐瞒了意图╮
隐瞒了意图╮ 2021-01-16 12:34

I\'m using this code to create a file chooser with batch File / folder chooser dialog from a Windows batch script

@echo off
set dialog=\"about:

        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-16 12:52

    Just, i want to share my script based on the solution of elzooilogico

    Just give a try for only 2 or 3 or 4 digits numbers to crack 4 digits can be done in 5 minutes or more.

    if you want to crack the password more than 4 digits numbers it will take more time of course. so, to test it, just create a new archive with winrar protected with a password for example :

    password=123

    @echo off
    mode con cols=70 lines=15 & color 0B
    :Rar
    Title WinRar Password Cracker by Hackoo (Only Digits numbers)
    rem set dialog="about:"
    rem for /f "tokens=* delims=" %%p in ('mshta.exe %dialog%') do set "file=%%p"
    set "full="
    set "file=" 
    set "mypath=%~dp0"
    call:fileSelection "%file%", "%mypath%", "Choose a file", file, mypath
    set "full=%mypath%\%file%"
    rem echo(
    rem echo( File is: %file%
    rem echo( Path is: %mypath%
    rem echo(
    rem echo( Full filename: %full%
    rem pause
    cls
    echo           ----------------------------------------------
    echo                          GET DETAIL
    echo           ----------------------------------------------
    echo.
    set "Rarext=.rar"
    echo selected  file is : "%full%"
    setlocal enabledelayedexpansion
    for %%i in ("%file%") do ( 
    set ext=%%~xi
    IF /I Not "!Rarext!"=="!ext!" Color 0C && echo This file is not a winrar file the extension must be ".rar" & pause & cls & goto Rar
    )
    echo.
    echo Hit any key to continue ....
    pause>nul
    :Main
    cls
    rem ******************  MAIN CODE SECTION
    set STARTTIME=!TIME!
    mode con cols=60 lines=15
    Set Unrar="%ProgramFiles%\WinRAR\UnRar.exe"
    SET PSWD=0
    SET DEST=%TEMP%\Hackoo\%RANDOM%
    MD %DEST%
    
    :START
    cls
    color 0A
    rem echo %UNRAR% E -inul -y -P%PSWD% "%full%" "%DEST%"
    SET /A PSWD=%PSWD%+1
    echo.
    echo     0 1 0 %random% 1 1 0 0 1 0 0 1 %random% 1 0 1 0 0 1%random%
    echo     1%random% 0 0 1 0 1 1 1 1 0 0 1 0 0 1 1 1 1 0 0 0 %random%
    echo     1 1 1 1 1 0 1 1 0 0 %random% 1 1 0 1 0 1 0 0 0 1 1 %random%
    echo     0 %random% 0 1 1 1 1 1 0 1 0 1 0 1 %random% 0 0 0 0 0 %random%  
    echo.
    echo  **********************************************************
    echo    Please wait a while... Trying to crack the password... 
    echo              current tested password = %PSWD%
    echo  **********************************************************
    echo.  
    echo     0 1 0 %random% 1 1 0 0 1 0 0 1 %random% 1 0 1 0 0 1 %random%
    echo     1%random% 0 0 1 0 1 1 1 1 0 0 1 0 0 1 1 1 1 0 0 0 %random%
    echo     1 1 1 1 1 0 1 1 0 0 %random% 1 1 0 1 0 1 0 0 0 1 1 %random%
    echo     0 %random% 0 1 1 1 1 1 0 1 0 1 0 1 %random% 0 0 0 0 0 %random%
    %UNRAR% E -inul -y -P%PSWD% "%full%" "%DEST%">nul 2>&1
    IF "%ERRORLEVEL%" EQU "0" GOTO :FINISH
    GOTO START
    :FINISH
    mode con cols=60 lines=15
    RD %DEST% /Q /S
    cls
    echo        ----------------------------------------------
    echo                           CRACKED
    echo        ----------------------------------------------
    echo.
    echo PASSWORD FOUND
    echo FILE  = "%full%"
    echo CRACKED PASSWORD = %PSWD%
    set ENDTIME=!TIME!
    call :GetDuration !STARTTIME! !ENDTIME!
    exit /b
    rem ******************  END MAIN CODE SECTION
    
    :GetDuration
    set function_starttime=%1
    set function_endtime=%2
    
    rem Change formatting for the start and end times
    for /F "tokens=1-4 delims=:.," %%a in ("%function_starttime%") do (
       set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
    )
    
    for /F "tokens=1-4 delims=:.," %%a in ("%function_endtime%") do (
       set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100"
    )
    
    rem Calculate the elapsed time by subtracting values
    set /A elapsed=end-start
    
    rem Format the results for output
    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
    if %hh% lss 10 set hh=0%hh%
    if %mm% lss 10 set mm=0%mm%
    if %ss% lss 10 set ss=0%ss%
    if %cc% lss 10 set cc=0%cc%
    
    set DURATION=%hh%:%mm%:%ss%.%cc%
    
    echo Start Time   : %function_starttime%
    echo Finish Time  : %function_endtime%
    echo          ---------------
    echo Duration : %DURATION%
    echo.
    pause>nul
    exit /b
    
    :fileSelection
    SetLocal & set "file=%~1" & set "folder=%~2"  & rem if selection is canceled restore previous data
    set "dialog=powershell -sta "Add-Type -AssemblyName System.windows.forms^|Out-Null;$f=New-Object System.Windows.Forms.OpenFileDialog;$f.filename='%~1';$f.InitialDirectory='%~2';$f.title='%~3';$f.showHelp=$false;$f.Filter='RAR files (*.rar)^|*.rar';$f.ShowDialog()^|Out-Null;$f.FileName""
    for /f "delims=" %%I in ('%dialog%') do set "res=%%I"
    echo "%res%" | find "\" >NUL && call:stripPath "%res%", file, folder  & rem selection, otherwise cancel. Avoid this if you want full path and filename
    EndLocal & set "%4=%file%" & set "%5=%folder%"
    exit/B 0
    
    :: --------------------- Split path and filename ---------------------
    :stripPath
    SetLocal & set "file=%~nx1" & set "folder=%~dp1"
    EndLocal & set "%2=%file%" & set "%3=%folder:~0,-1%"
    

提交回复
热议问题