|
原帖由 victor888 于 2008-11-20 19:17 发表
这是一次重要的更新,请重新下载!
硬盘盘符的顺序根据offset值来调整,而不是以前的经验上的顺序来调整,这才是真正准确的方式,MBRFIX版已经调试通过,DISKPART版调试中,明日亦会提供下载!
教程在原理讨论 ...
以前没仔细看,直接拿来用了,刚才看了一下,这个在PE中用似乎可以更简洁一点
1、因为这个一般要放在load外置之前,因此多数情况下是要放到内核中的,因此内核是什么系统应该是固定的,判断语句可以不要了。
2、我不知道为什么要将这个程序放到system32\temp下执行,PE中直接在system32下执行应该也是无问题的。
由于mountvol这个程序是系统自带的,因此应该只需要MbrFix.exe和批处理就可以了。按以上思路改成如下形式:
(当然,如果放在其他地方用可能还是要用原程序。另外,要提醒一点的就是这个程序是需要FIND程序的,有次我将FIND程序请出了内核,理顺盘符就失败了。可以在前面的说明中申明一下,这个批处理需要FIND程序的支持的,这样就更明朗了。)
::revised on Jun 6, 2009
::created by victor888, QQ:511519860
::ordering drive letters by drive type
::ordered drive letters are assigned to fixed disk, cdrom, usb hard disk and usb stick
::"find.exe" must be in system or path environment variable point to.
@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
::get all drive letters
wmic /? >nul 2>&1
if errorlevel 1 (
for /f "tokens=1 delims= " %%a in ('REG QUERY HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\ /s ^|find "2\\"') do (
set adv=%%a
set adv=!adv:~-3!
set tdv=!adv:~0,2!
if !tdv! equ \\ (
set adv=!adv:~-1!
set ALLDRV=!ALLDRV! !adv!
)
)
) else (
for /f "skip=1" %%a in ('wmic logicaldisk get caption') do (
set adv=%%a
set ALLDRV=!ALLDRV! !adv!
)
)
set ALLDRV=%ALLDRV::=%
::get all mounted volume ids and drive letters
FOR /F %%a in ('mountvol ^|find "\"') do set mtvdrv=!mtvdrv! %%a
set mtvdrv=%mtvdrv: =%
set mtvdrv=%mtvdrv:\\?\Volume= %
set mtvdrv=%mtvdrv:\=%
set mtvdrv=%mtvdrv::=%
for %%a in (%mtvdrv%) do (
set mdrv=%%a
set mdrv=!mdrv:~-1!
set mtdrv=!mtdrv! !mdrv!
)
rem echo Mounted drive letters: %mtdrv%
::get virtual drive letters
set virdrv=%ALLDRV%
for %%a in (%mtdrv%) do (
set virdrv=!virdrv:%%a=!
)
for %%a in (%virdrv%) do set newvirdrv=!newvirdrv! %%a
if defined newvirdrv (
set virdrv=!newvirdrv!
)
::get system volumeid
call :vid_drv %systemdrive:~0,1%
set systemvid=%vd%
::get innternal hard disk number from registry
for /f "skip=1 tokens=1,3 delims= " %%a in ('reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Disk\Enum /s ^|find "\"') do (
set dtype=%%b
set dtype=!dtype:~0,3!
if /i !dtype! neq USB (
set /a m+=1
set hdnum!m!=%%a
)
)
::two founds with using batch file
::1. "?" can not be as an element of string in the for command
::2. one variable can not contain another varable in for command i.e. for %%a in (!ab%c%!) do ..., !ab%c%! has no value
::get innternal hard disk signature and its volume ids
for /l %%a in (1,1,!m!) do (
set /a n=0
for /f %%b in ('mbrfix /drive !hdnum%%a! readsignature') do set sigcode=%%b
for /l %%c in (0,1,7) do set newcode=!newcode! !sigcode:~%%c,1!
for %%d in (!newcode!) do set /a n+=1
if !n! lss 8 (
set /a zeronum=8-!n!
for /l %%e in (1,1,!zeronum!) do set sigcode=0!sigcode!
)
for /l %%c in (0,2,6) do set resigcode=!sigcode:~%%c,2!!resigcode!
for /f "tokens=1,3 delims= " %%d in ('REG QUERY HKLM\SYSTEM\MountedDevices\ /s ^|FIND "Volume" ^|find "!resigcode!"') do (
set vid=%%d
set vid=!vid:~10,38!
set partlen=%%e
set partlen=!partlen:~10,10!
for /l %%g in (0,2,8) do set repartlen=!partlen:~%%g,2!!repartlen!
for /f "delims=0 tokens=*" %%i in ("!repartlen!") do set repartlen=%%i
call set hdptlen%%a=0x!repartlen! %%hdptlen%%a%%
call set hdvidreptlen%%a=%%hdvidreptlen%%a%% !vid!#0x!repartlen!
set repartlen=
)
set resigcode=
call :sort !hdptlen%%a!
for %%f in (!ret!) do (
for %%b in (!hdvidreptlen%%a!) do (
for /f "delims=# tokens=1,2" %%c in ("%%b") do (
if %%d equ %%f (
call set hdvid%%a=%%hdvid%%a%% %%c
set ret=!ret:%%b=!
)
)
)
)
set ret=
)
::get hard disk drive letters according to their volume ids
for /l %%a in (1,1,%m%) do (
for %%b in (!hdvid%%a!) do (
call :vid_drv %%b
set hddrv%%a=!hddrv%%a! !vd!
)
set hdvid=!hdvid! !hdvid%%a!
set hddrv=!hddrv! !hddrv%%a!
set newhddrv=
for %%c in (!hddrv%%a!) do set newhddrv=!newhddrv! %%c
set hddrv%%a=!newhddrv!
)
)
::get other drive letters and volume ids including removable and usb hard disk and cdrom
set otherdrv=%mtdrv%
for %%a in (%hddrv%) do set otherdrv=!otherdrv:%%a=!
set /a n=0
for %%a in (%otherdrv%) do (
for /f "skip=2 tokens=3 delims= " %%b in ('reg query HKLM\SYSTEM\MountedDevices /v \DosDevices\%%a:') do (
set mnreg=%%b
set first8=!mnreg:~0,8!
)
if /i !first8! equ 5f003f00 set remdrv=!remdrv! %%a
if /i !first8! equ 5c003f00 (
set mnreg=!mnreg:23=#!
for /f "tokens=2 delims=#" %%c in ("!mnreg!") do (
set tpcode=%%c
set tpcode=!tpcode:~0,12!
if /i !tpcode! equ 00470045004E set flpdrv=!flpdrv! %%a
if /i !tpcode! equ 004300640052 set dvddrv=!dvddrv! %%a
if /i !tpcode! equ 00520065006D set remdrv=!remdrv! %%a
)
)
if /i !first8! neq 5c003f00 (
if /i !first8! neq 5f003f00 (
if not defined var_!first8! (
set var_!first8!=%%a
) else (
call set var_!first8!=%%var_!first8!%% %%a
)
)
)
)
for /f "tokens=2-3 delims=_=" %%h in ('set var_ 2^>nul') do (
set /a n=n+1
set uhddrv!n!=%%i
)
for /l %%a in (1,1,%n%) do (
for %%b in (!uhddrv%%a!) do (
call :vid_drv %%b
set uhdvid%%a=!uhdvid%%a! !vd!
)
set uhddrv=!uhddrv! !uhddrv%%a!
set uhdvid=!uhdvid! !uhdvid%%a!
)
for %%a in (%dvddrv%) do (
call :vid_drv %%a
set dvdvid=!dvdvid! !vd!
)
for %%a in (%remdrv%) do (
call :vid_drv %%a
set remvid=!remvid! !vd!
)
set totaldrv=%hddrv% %dvddrv% %uhddrv% %remdrv%
set totalvid=%hdvid% %dvdvid% %uhdvid% %remvid%
::remove system drive letters and volume ids
set tempdrv=%virdrv%
set tempdrv=!tempdrv:%systemdrive:~0,1%=!
if /i !tempdrv! equ !virdrv! (
set totaldrv=!totaldrv:%systemdrive:~0,1%=!
set totalvid=!totalvid:%systemvid%=!
)
set totalvid=%totalvid: =%
set fulldrv=CDEFGHIJKLMNOPQRSTUVWXYZ
for %%a in (%virdrv%) do set fulldrv=!fulldrv:%%a=!
set fulldrv=!fulldrv:%systemdrive:~0,1%=!
::ordering drive letters start
set /a e=0
for %%a in (%totaldrv%) do (
call :vdrv %%a
set /a k=k+1
set /a e=e+38
)
for %%a in (%viddrv%) do (
set temp=%%a
set vid=!temp:~0,38!
set drv=!temp:~-1!
mountvol !drv!: \\?\Volume!vid!
)
:vdrv
set nk=!fulldrv:~%k%,1!
if /i %1 neq !nk! (
set ordereddrv=!ordereddrv! %1→!nk!
mountvol %1: /d
set viddrv=!viddrv! !totalvid:~%e%,38!!nk!
)
goto :eof
:vid_drv
for %%a in (%mtvdrv%) do (
set vd=%%a
set l=%1
set l=!l:~0,1!
if !l! equ { (
set rd=!vd:~0,38!
if !rd! equ %1 (
set vd=!vd:~-1!
set mtvdrv=!mtvdrv:%%a=!
goto :eof
)
) else (
set rd=!vd:~-1!
if !rd! equ %1 (
set vd=!vd:~0,38!
if %1 neq %systemdrive:~0,1% set mtvdrv=!mtvdrv:%%a=!
goto :eof
)
)
)
goto :eof
:sort
set num=%1
set str= %*
for %%i in (%*) do if !num! gtr %%i set num=%%i
set ret=%ret% %num%
if not "!str: %num% =!"=="" call :sort !str: %num% = !
goto :eof
[ 本帖最后由 hhh333 于 2009-6-4 09:12 编辑 ] |
|