标题: [其他] Virtual Handle——模拟句柄操作 [打印本页]
作者: bailong360 时间: 2016-1-2 16:08 标题: Virtual Handle——模拟句柄操作
本帖最后由 bailong360 于 2016-1-2 16:09 编辑
在硬盘里翻到的
发出来水一帖- ::模拟句柄操作
- ::aiwozhonghuba 2015-1-25
- ::输入示范:>nul 2>nul 3>nul 4>nul 5>nul 6>nul 7>nul 8>nul 9>nul
- @Echo Off&SetLocal EnableDelayedExpansion&Title Virtual Handle
- :Main
- Set /P Argus=Please enter the code:
- Set "New_Argus= "
- If Not "%Last%"=="TRUE" (
- For %%a In (0 1 2) Do Set "Handle%%a=con "
- For /L %%a In (0x3 1 0x12) Do Set "Handle%%a= "
- Set "Last=FALSE"
- )
- For %%a In ("%Argus: =" "%") Do (
- Set "Argu=%%~a"
- If "!Argu:~0,1!"==">" Set "Argu=1!Argu!"
- If "!Argu:~0,1!"=="<" Set "Argu=0!Argu!"
- For /F "Delims=><& Tokens=1,2" %%b In ("!Argu!") Do (
- Set "Handle=%%~b"
- For %%d In (!Handle:~-1!) Do (
- Set "Set_Handle%%~d=%%~c"
- Set "New_Argus=!New_Argus:%%~d =!%%~d "
- )
- )
- )
- Set "New_Argus=%New_Argus:~1%"
- Call :Start "%New_Argus: =" "%"
- Goto Main
- :Start
- Echo 初始状态
- Call :Show_Handle
- Echo 备份及重定向
- :Bak_Redir
- If "%~1"=="" (
- Echo 句柄取回
- Goto Recover
- )
- If "!Handle0_bak!"=="%~1" Echo 句柄%~1为句柄0备份&Echo 无法更改此句柄指向&Pause>nul&Exit
- Set "Argu=%~1"
- Set "Object=!Set_Handle%~1!"
- Set Bak_Finished=FALSE
- For /L %%a In (0x0 1 0x12) Do (
- If "!Handle%%a: =!"=="" (
- If Not !Bak_Finished!==TRUE (
- If Not "!Handle%~1: =!"=="" (
- If Not %%a Geq 10 Echo %~1[!Handle%~1: =!]=^>%%a[!Handle%%a: =!]
- Set "Handle%~1_bak=%%a"
- Set "Handle%%a=!Handle%~1: =! "
- Call :Show_Handle
- ) Else Set "Handle%~1_bak_none=TRUE"
- If Defined Handle%Object% (
- If "!Handle%Object%: =!"=="" Echo 重定向句柄!Argu:~0,1!时&Echo 无法复制此句柄&Pause>nul&Exit
- Echo %~1[!Handle%~1: =!]^<=%Object%[!Handle%Object%: =!]
- Set "Handle%~1=!Handle%Object%: =! "
- ) Else (
- Echo %~1[!Handle%~1: =!]^<="%Object%"
- Set "Handle%~1=%Object% "
- )
- Set Bak_Finished=TRUE
- )
- )
- )
- Call :Show_Handle
- Shift
- Goto Bak_Redir
- :Recover
- For /L %%a In (0x0 1 0x12) Do (
- If Defined Handle%%a_bak (
- For %%b In (!Handle%%a_bak!) Do (
- Set "Bak=!Handle%%a_bak!"
- If %%b Gtr 9 Set "Bak=?"
- Echo %%a[!Handle%%a: =!]^<=!Bak![!Handle%%b: =!]
- Set "Handle%%a=!Handle%%b: =! "
- Set "Handle!Handle%%a_bak!= "
- Set Handle%%a_bak=
- Call :Show_Handle
- )
- ) Else If Defined Handle%%a_bak_none (
- Set "Handle%%a= "
- Echo %%a[!Handle%%a: =!]^<=[]
- Call :Show_Handle
- )
- )
- Set Last=TRUE
- Echo 最终状态
- Call :Show_Handle
- Goto Main
- :Show_Handle
- For /L %%i In (0 1 9) Do Set /P=%%i=!Handle%%i:~0,6!<nul
- Echo;
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |