²³©Ò¬Òª¾¡A¤@Ó¹êÅéºÏºÐ¥i¥H¦A¥Ñ¤À³Îµ{¦¡³Ì¦h¤À³Î¦¨¤TÓ¥Dn¤À³Î©M¤@Ó©µ¦ù¤À³Î¡C±z¥i¥H¦b Windows XP §@·~¨t²Î¤¤¡A§â·Æ¹«´å¼Ð²¾¨ì¡u§Úªº¹q¸£¡v¤W¡A¦A«ö¤U·Æ¹«¥kÁä¡A¿ï¡uºÞ²z¡v¡AµM«á¦b¼u¥Xªºµøµ¡¥ª¥b³¡¡AÂI¿ï¡uºÏºÐºÞ²z¡v¡Aµøµ¡¥k¥b³¡´N·|¥X²{¤U¹Ïªºµe±¡A¨ä¹ê¤U¹Ï¬O¤p¤ì°¸ªº®à¤W«¬¹q¸£ªºµwºÐ¸ê®Æ¡C
ŪªÌ¥i¥H¬Ý±o¥X¨Ó¡A¤p¤ì°¸¦@¦³¤TÓ¹êÅéºÏºÐ ( physical disk)¡A¥H¬õ®Ø¼Ð¥X¡A¤À§O¬O¡GºÏºÐ 0¡BºÏºÐ 1¡BºÏºÐ 2¡CºÏºÐ 0 ¤S³Q¤À³Î¦¨¤TÓ¥Dn¤À³Î»P¤@Ó©µ¦ù¤À³Î¡C¥Dn¤À³Î¤W¥b³¡¥H²`ÂŦâªí¥Ü¡AºÏºÐ¼ÐÅÒ ( volumn ) ¤À§O¬O¡uMS-DOS_6_20¡v¡B¡uXP_PRO¡v¡B¡uXP64_PRO¡v¡C©µ¦ù¤À³Î¥Hºñ®Ø®Ø¦í¡A¤S³Q¤À³Î¬°¤TÓÅÞ¿èºÏºÐ¡A¨CÓÅÞ¿èºÏºÐ¤W¥b³¡¥HÂŦâªí¥Ü¡A¨ä¤¤¤@ÓªººÏºÐ¼ÐÅÒ¬O¡uDATA_1¡v¡A¥t¥~¨âÓ³Q Windows XP »{¬°¬O¡u¤£©úªººÏºÐ¤À³Î¡v¡A¦]¬°³o¨âÓ¤À³Î¬O¡uLinux¡v§@·~¨t²Î©Ò¦û¾Ú¡C
¨CÓ¤À³Î§¡¬O¬°¤FÀx¦s¸ê®Æ¡BÀɮצӹº¤À¡A¦Ó¨CºØ§@·~¨t²Î¦b¸ê®Æ¡BÀɮתº¦w±Æ¤è¦¡¦³©Ò¤£¦P¡A³oºØ¦bºÏºÐ¤¤¦w±Æ¦s©ñ¸ê®Æ©ÎÀɮתº¤è¦¡ºÙ¬°Àɮרt²Î ( file system )¡A¨Ò¦p DOS ¥H FAT12¡BFAT16 ¤è¦¡¦w±Æ¨Ã¦s¨úÀÉ®× ( ¦³Ãö FAT12¡BFAT16 ½Ð°Ñ¦Ò²Õ¦X»y¨¥ªº³nºÐ¤ù¡BµwºÐ(2)FAT )¡FWindows 9x/Me ¥i¥H¨Ï¥Î FAT12¡BFAT16 ©M FAT32 ¤TºØÀɮרt²Î¡FWindows NT/XP °£¤F¤W±©Ò»¡ªº FAT12¡BFAT16¡BFAT32 ¤§¥~¡AÁÙ¥i¨Ï¥Î NTFS¡FLinux «h±`¨Ï¥Î EXT2¡BEXT3 Àɮרt²Î¡C
¦b Windows §@·~¨t²ÎùØ¡A¨CÓ¥Dn¤À³Î©M©µ¦ù¤À³ÎùتºÅÞ¿èºÏºÐ³£·|³Q½á¤©¤@ӺϺо÷¥N¸¹¡A¨Ò¦p¡G¡uC:¡v¡B¡uD:¡v¡K¡Kµ¥µ¥¡A·íµM¦pªG¬O Windows ¤£»{±oªº¤À³Î©Î¬O Windows ¤£»{±oªºÀɮרt²Î¡A´N¤£·|³Q½á¤©ºÏºÐ¾÷¥N¸¹¡C¹³¡uC:¡v¡B¡uD:¡v¡K¡Kµ¥³o¨ÇºÏºÐ¾÷¥N¸¹©Ò¥NªíªººÏºÐ¡A´N¥s°µ¡uÅÞ¿èºÏºÐ¡v( logical driver )¡C¦Ó¦b XP ¥H¤Î§ó«á´Áªº Windows §@·~¨t²ÎªºÅÞ¿èºÏºÐ¡A¤S¦³¥t¤@¼h¤£¦Pªº·N¸q¡A¨º´N¬O°ÊºAºÏºÐ¡CXP ¥i¥H§â¼ÆÓ¤À³Î¦X¨ÖÅܦ¨¤@ÓÅÞ¿èºÏºÐ¡A¦Ó¶È¥Î¤@ӺϺо÷¥N¸¹ªí¥Ü¡C¨CÓ¤À³Î§¡¬°³sÄòªººÏ°Ï¡A¦b MSDN ¤¤ºÙ¬°¡uextent¡v¡A¼ÆÓ¡uextent¡v¥i¦X¨Ö¬°¤@ÓÅÞ¿èºÏºÐ¡A³o¨Ç¡uextent¡v¥i¯à¤À¥¬¦b¤£¦P¹êÅéºÏºÐ¡A¤]¥i¥H¤£¬O³sÄòªººÏ°Ï ( ·íµM¦P¤@Ó¡uextent¡vªººÏ°Ï¬O³sÄòªº )¡C
¥Ñ¤W±ªº¤ÀªR¥iª¾¡A¤@Ó¹êÅéºÏºÐ¥i¥H¦³¤@Ó¥H¤WªºÅÞ¿èºÏºÐ¡A¦Ó¥»³¹©Òn°Q½×ªº¬O¦C¥X¹êÅéºÏºÐ©Ò¥]§tªºÅÞ¿èºÏºÐ¡C
¦b³o¤@³¹ùØ¡A¤p¤ì°¸±Nµo®i¥X¤@ӰƵ{¦¡¡AGetLogicalDriveFromPhysicalDrive¡A¯à§â¹q¸£¤Wªº¨C¤@Ó¹êÅéºÏºÐ©Ò¥]§tªºÅÞ¿èºÏºÐÅã¥Ü¥X¨Ó¡C
¦b Win32 API ùØ¡A¦³Ó¥s°µ DeviceIoControl ªº API ¥i¥H¿é¤JÅÞ¿èºÏºÐ¥N¸¹¦Ó¶Ç¦^¦¹ÅÞ¿èºÏºÐ¬O¦ì©óþÓ¹êÅéºÏºÐ¤W¡F¦ý¬O¦ü¥G¬O¨S¦³¶Ç¤J¹êÅéºÏºÐ¡A¦Ó±o¨ì¸Ó¹êÅéºÏºÐ¥]§tþ¨ÇÅÞ¿èºÏºÐ¡C¤p¤ì°¸ªº·Qªk«Ü²³æ¡A¨º´N¬O§Q¥Î Win32 ¥t¤@Ó API¡AGetLogicalDriveStrings¡A§ä¥X©Ò¦³ªºÅÞ¿èºÏºÐ¾÷¥N¸¹¡A¦A§â³o¨ÇÅÞ¿èºÏºÐ¥N¸¹¤@¤@¥N¤J DeviceIoControl ùØ¡A´N¥i¥H±o¨ì¨CÓÅÞ¿èºÏºÐÄÝ©óþ¤@Ó¹êÅéºÏºÐ¡A¦A©ó¤@¶ô°O¾ÐÅ餤¡A¨Ì¾Ú¹êÅéºÏºÐ½s¸¹¤Àªù§OÃþ§â¦¹ÅÞ¿èºÏºÐ¦s¤J¡C¥ý»¡¤@»¡ GetLogicalDriveFromPhysicalDrive ·|©I¥sªº Win32 API¡C
GetLogicalDriveStrings ¥i¥H§â¹q¸£¤Wªº©Ò¦³ÅÞ¿èºÏºÐ¡A¥]§t³nºÐ¾÷¡BµwºÐ¾÷¡B¥úºÐ¾÷¡BÀH¨ºÐµ¥µ¥¡A¦s¤J¨ì«ü©wªº¦ì§}ùØ¡C¥¦ªºì«¬¬O¡G
INVOKE GetLogicalDriveStrings,nBufferLength,lpBuffer
¥ý»¡²Ä¤GӰѼơAlpBuffer¡A¬O¤@Ó¦ì§}«ü¼Ð¡A«ü¦V¤@Ó½w½Ä°Ï°ì¡AGetLogicalDriveStrings ±N·|§â©Ò¦³ªºÅÞ¿èºÏºÐ¥N¸¹¶ñ¤J¦¹¦ì§}©Ò«üªº½w½Ä°ÏùØ¡C²Ä¤@ӰѼơAnBufferLength¡A¬O½w½Ä°Ïªº¤j¤p¡C³o¨âӰѼƥ²¶·¦b©I¥s GetLogicalDriveStrings «e´N¤w³]©w¦n¡C¦pªG¦¨¥\ªº¨ú±oÅÞ¿èºÏºÐ¥N¸¹¡A«h EAX ¬°ÅÞ¿èºÏºÐ¥N¸¹ªºÁ`ªø«×¡A¦ý¤£¥]§t³Ì«áªº¦r¤¸¡ANULL¡F¦pªG©Ò nBufferLength ©Ò«ü©wªº½w½Ä°Ï¤£°÷¤j¡AEAX ·|¶Ç¦^©Ò»Ý½w½Ä°Ï¤j¤p¡A¦¹¤j¤p«o¤S¥]§t NULL¡C¦pªG GetLogicalDriveStrings µLªk¥¿±`¹B§@¡A«h EAX ¶Ç¦^ FALSE¡C
¨Ò¦p¤p¤ì°¸ªº¹q¸£¦b°õ¦æ§¹¡uINVOKE GetLogicalDriveStrings,104,12f76ch¡v«á¡A½w½Ä°Ï 12F76Ch ªº¤º®eÅܬ°¡G
0012F760 43 3A 5C 00 C:\. 0012F770 44 3A 5C 00 45 3A 5C 00 46 3A 5C 00 47 3A 5C 00 D:\.E:\.F:\.G:\. 0012F780 48 3A 5C 00 49 3A 5C 00 4A 3A 5C 00 4B 3A 5C 00 H:\.I:\.J:\.K:\. 0012F790 4D 3A 5C 00 4E 3A 5C 00 00 M:\.N:\..
¦Óªð¦^È EAX Åܬ° 2Ch¡C
³oÓ API ¨M©w¬YÓÅÞ¿èºÏºÐ¬OÄÝ©óþ¤@ºØÃþ«¬ªºÀx¦s¸Ë¸m¡Gremovable, fixed, CD-ROM, RAM disk, or network drive¡C¨ä쫬¬°¡G
INVOKE GetDriveType,lpRootPathName
lpRootPathName ¬O«ü¦VÅÞ¿èºÏºÐ®Ú¥Ø¿ý¦r¦êªº¦ì§}¡A¥H NULL µ²§À¡A¨Ò¦p¡u"C:\",0¡v¡C¤Ï±×½u¡u\¡v¬O¥²nªº¡C¦b©I¥s GetDriveType ¤§«e¡A¥²¶·¥ý³]©w¦n lpRootPathName¡A¦pªG lpRootPathName ¬° 0¡A¨º»ò GetDriveType ·|¶Ç¦^¥Ø«eÅÞ¿èºÏºÐªºÀx¦s¸Ë¸mÃþ«¬¡Cªð¦^È EAX ¥i¯à¬O¤U±´X¶µ¡A¥kÄæ¥Nªí¨ä·N¸q¡G
ªð¦^È | ¼ÆÈ | ·N¡@¡@¸q |
DRIVE_UNKNOWN | 0 | µLªkÃѧOªº¸Ë¸m |
DRIVE_NO_ROOT_DIR | 1 | µL¦¹®Ú¥Ø¿ý¡A¨Ò¦p¿é¤JªºÅÞ¿èºÏºÐ¿ù»~¡A¥HPµL¦¹®Ú¥Ø¿ý |
DRIVE_REMOVABLE | 2 | ¥i¨ø°£ªºÀx¦s¸Ë¸m¡A¦p³nºÐ¡BUSB ÀH¨ºÐ ( thumb drive )¡BŪ¥d¾÷ ( flash card reader ) µ¥µ¥ |
DRIVE_FIXED | 3 | µwºÐ©Î§Ö°{ºÐ ( flash drive ) |
DRIVE_REMOTE | 4 | ºô¸ôºÏºÐ¾÷ |
DRIVE_CDROM | 5 | ¥úºÐ¾÷ |
DRIVE_RAMDISK | 6 | RAM disk |
¦b²Ä¤Q¤@³¹´¿¸g´£¨ì CreateFile¡A¨º®É¬O¥H¥¦¶}±ÒÀɮסA쫬¬°¡G
CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, // how to create DWORD dwFlagsAndAttributes, // file attributes HANDLE hTemplateFile );
¦ý CreateFile ªº¥\¯à¤£¶È¶È¬O³o¼Ë¡A¥¦ÁÙ¥i¥H¶}±Ò¹êÅéºÏºÐ»PÅÞ¿èºÏºÐ ( ¦b MSDN ùØ¡A¬O»¡¶}±Ò¹êÅéºÏºÐ»PºÏºÐ¼ÐÅÒ¡Aì¤å¬O¡uphysical disks and volumes¡v¡A¦ý¬OºÏºÐ¼ÐÅÒ«üªºÀ³¸Ó´N¬OÅÞ¿èºÏºÐ )¡C¤@¯ë¦Ó¨¥¡A¦b Win32 ¨t²Î¤¤¡A¤×¨ä¬O Windows NT/XP ¥H¤Wªº§@·~¨t²Î¤¤¡A¶}±Ò¹êÅéºÏºÐ¬O¦³¨îªº¡C³o¬O¦]¬°³oºØ°µªk¨ã¦³¦MÀI©Ê¡A°²¦pµ{¦¡¤£·íªº¼g¤J¤À³Î°Ï©Î¬O«nªººÏ°Ï¡A·|³y¦¨§@·~¨t²ÎµLªk¿ë»{¡A¦]¦¹¦b¼¶¼g¦¹Ãþµ{¦¡¹êÀ³¯S§O¤p¤ß¡C°£¦¹¤§¥~¡A¨t²Î¹ï¶}±Ò¹êÅéºÏºÐ»PÅÞ¿èºÏºÐ¤]¦³¤@¨Ç¨î¡G
·í¶}±Ò¹êÅéºÏºÐ®É¡AlpFileName «ü¦V¥H NULL µ²§À¡B§Î¦p¡u\\.\PhysicalDriveX¡vªº¦r¦ê¡A¨Ò¦p¡G
lpFileName | ·N¡@¡@¸q |
"\\.\PhysicalDrive0",0 | ¶}±Ò²Ä¤@Ó¹êÅéºÏºÐ |
"\\.\PhysicalDrive2",0 | ¶}±Ò²Ä¤TÓ¹êÅéºÏºÐ |
·í¶}±ÒÅÞ¿èºÏºÐ®É¡AlpFileName «ü¦V¥H NULL µ²§À¡B§Î¦p¡u\\.\X:¡vªº¦r¦ê¡A¨Ò¦p¡G
lpFileName | ·N¡@¡@¸q |
"\\.\A:",0 | ¶}±Ò A: ºÏºÐ¡A§Y²Ä¤@Ó³nºÐ |
"\\.\C:",0 | ¶}±Ò C: ºÏºÐ¡A§Y²Ä¤@ÓÅÞ¿èºÏºÐ |
¤@¥¹¦¨¥\¶}±Ò¹êÅéºÏºÐ©ÎÅÞ¿èºÏºÐ«á¡ACreateFile ªº¶Ç¦^Ⱥ٬°ª½±µ¦s¨úÀx¦s¸Ë¸m¥N½X ( direct access storage device (DASD) handle )¡A§ÚÌ¥i¥H§Q¥Î¦¹ DASD ¥N½X©I¥s DeviceIoControl API¡C
DeviceIoControl ¯à¶Ç¤J³\¦h¤£¦Pªº±±¨î½X¡A¹ï¬YӸ˸m§@¬Û¹ïÀ³ªº¾Þ§@¡C¨ä쫬¬°¡G
BOOL WINAPI DeviceIoControl( __in HANDLE hDevice, __in DWORD dwIoControlCode, __in_opt LPVOID lpInBuffer, __in DWORD nInBufferSize, __out_opt LPVOID lpOutBuffer, __in DWORD nOutBufferSize, __out_opt LPDWORD lpBytesReturned, __inout_opt LPOVERLAPPED lpOverlapped );
²Ä¤@ӰѼơAhDevice¡A¬O¥Ñ CreateFile ¶Ç¦^ªº¥N½X¡C²Ä¤GӰѼơAdwIoControlCode¡A¬O±±¨î½X¡A¤£¦Pªº±±¨î½X¯à¹ï¸Ë¸m§@¤£¦Pªº¾Þ§@¡A¤]¼vÅT lpInBuffer¡BnInBufferSize¡BlpOutBuffer ©M nOutBufferSize ©Ò¥Nªíªº·N¸q¡ClpBytesReturned «ü¦V¤@ÅܼƦì§}¡ADeviceIoControl ·|§â¶Ç¨ì½w½Ä°Ïªº¸ê®Æªø«×¦s¤J¦¹ÅܼƤ¤¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡C¦pªG½w½Ä°Ï¤Ó¤p¥HP©óµLªk®e¯Ç¶Ç¨Óªº¥ô¦ó¤@µ§¸ê®Æ¡AlpBytesReturned ©Ò«üªºÅܼƷ|Åܬ° 0¡A¥i¥H©I¥s GetLastError¡A¦Ó¶Ç¦^ ERROR_INSUFFICIENT_BUFFER¡F¦pªG½w½Ä°Ï¤Ó¤p¡A¦ý¬O¥i¥H®e¯Ç¼Æµ§¸ê®Æ¡AlpBytesReturned ©Ò«üªºÅܼƷ|Åܬ°¹ê»Ú±o¨ìªº¸ê®Æªø«×¡A¥i¥H©I¥s GetLastError¡A¦Ó¶Ç¦^ ERROR_MORE_DATA¡ClpBytesReturned »P lpOverlapped ¤£¯à¦P®É¬°¹s¡C
¨Æ¹ê¤W¡A¦b MSDN ùØ¡A§â±±¨î½X¤À¦¨¦n´X¶µ¡A¨Ò¦p¦³¡uºÏºÐºÞ²z±±¨î½X¡v( Disk Management Control Codes )¡B¡uÅÞ¿èºÏºÐ±±¨î½X¡v( Volume Management Control Codes )¡B¡u³q°T³]³Æ±±¨î½X¡v( Communications Control Codes ) µ¥µ¥¡C¨C¤@¶µ¤S¥]§t³\¦h±±¨î½X¡A¨Ò¦pºÏºÐºÞ²z±±¨î½X¤S¦³ IOCTL_DISK_CREATE_DISK¡BIOCTL_DISK_GET_DRIVE_GEOMETRY_EX¡BIOCTL_DISK_GET_PARTITION_INFO_EX¡K¡Kµ¥±±¨î½X¡C¦]¦¹±±¨î½X¤Ó¦h¤F¡A©Ò¥H¤p¤ì°¸¶È¶ÈÂǥѩ³¤U¤TÓ±±¨î½X»¡©ú DeviceIoControl ªº¥Îªk¡C
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS |
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS ÄÝ©ó¡uÅÞ¿èºÏºÐ±±¨î½X¡vªº¤@ºØ¡A¥¦ªº¥Øªº¬O¨ú¬YÓÅÞ¿èºÏºÐ¦bþ¤@Ó¹êÅéºÏºÐ¤W¡C©I¥s¤è¦¡¬O¡G BOOL DeviceIoControl( (HANDLE) hDevice, // handle to device IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize (LPVOID) lpOutBuffer, // output buffer (DWORD) nOutBufferSize, // size of output buffer (LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure ); hDevice ¬O¸g¥Ñ©I¥s CreateFile ©Ò±oªº¸Ë¸m¥N½X¡A¦]¬°¬O¨ú±oÅÞ¿èºÏºÐªº¸Ë¸m¥N½X¡A©Ò¥H lpFileName «ü¦VÃþ¦ü¡u"\\.\C:",0¡vªº¦r¦ê¡A¦Ó dwShareMode °Ñ¼Æ¥²¶·¨ã¦³ FILE_SHARE_WRITE ¦ì¤¸¡BdwCreationDisposition °Ñ¼Æ¥²¶·¨ã¦³ OPEN_EXISTING ¦ì¤¸¡C lpOutBuffer «ü¦V¤@ÓºÙ¬° VOLUME_DISK_EXTENTS ªºµ²ºcÅé¡A¦pªG DeviceIoControl ¦¨¥\°õ¦æ¡A§@·~¨t²Î·|§â¥¿½Tªº¸ê®Æ¶ñ¤J¦¹µ²ºcÅéùØ¡C¦¹µ²ºcÅ骺¦¨û¬°¡G VOLUME_DISK_EXTENTS STRUCT NumberOfDiskExtents DWORD ? dwUnknown DWORD ? ;MSDNµL¦¹Äæ¦ì Extents DISK_EXTENT ANYSIZE_ARRAY DUP (<>) VOLUME_DISK_EXTENTS ENDS ³oùتº VOLUME_DISK_EXTENTS »P MSDN ©Ò¦Cªº¤£¦P¡AMSDN ¤¤ªº VOLUME_DISK_EXTENTS ¨S¦³ dwUnknown Äæ¦ì¡A³oÓÄæ¦ì¬O¤p¤ì°¸¦Û¤v¥[¤W¥hªº¡C¦ý¸g¹L§Ú¹ê»Ú¾Þ§@Æ[¹î¡AVOLUME_DISK_EXTENTS µ²ºcÅéÀ³¸Ó¬O¹³¤W±³o¼Ë¤~¯à¥¿½T°õ¦æ¡A§_«h¤£¯à¥¿½T°õ¦æ¡C¦ýºô¸ô¤W°£¤F Air ³ì¤¦ªº³¡¸¨®æ¦³»P§ÚÃþ¦üªºª¬ªp¡A¨ä¾l§¡¨S¦³µo²{¡AÅý§Úı±o«Ü¯Ç´e¡CNumberOfDiskExtents ¬O«ü¦¹ÅÞ¿èºÏºÐ¦³¦h¤ÖÓ¡uextent¡v²Õ¦¨¡A¦pªG¨Ï¥Î°ÊºAºÏºÐ¡ANumberOfDiskExtents ¥i¯à·|¶W¹L 1¡ADeviceIoControl ·|¶Ç¦^ ERROR_MORE_DATA¡A¥Dµ{¦¡À³¸ÓÄ~Äò©I¥s DeviceIoControl¡A±o¨ì¦¹ÅÞ¿èºÏºÐªº©Ò¦³¸ê®Æ¡C²Ä¤TÓÄæ¦ì¡AExtents¡A¤]¬O¤@Óµ²ºcÅé¡ADISK_EXTENT¡A©Ò²Õ¦¨ªº°}¦C¡A¦ý¬O¬d WINDOWS.INC «oµo²{ ANYSIZE_ARRAY ¬° 1¡A¥ç§Y¦¹°}¦C¶È¥Ñ¤@Ó¤¸¯À²Õ¦¨¡CDISK_EXTENT µ²ºcÅ骺¦¨û¬O¡G DISK_EXTENT STRUCT DiskNumber DWORD ? dwUnknown DWORD ? ;MSDNµL¦¹Äæ¦ì StartingOffset LARGE_INTEGER <> ExtentLength LARGE_INTEGER <> DISK_EXTENT ENDS ²Ä¤@ÓÄæ¦ì¡ADiskNumber¡A´N¬O¸ÓÅÞ¿èºÏºÐ¦bþ¤@Ó¹êÅéºÏºÐ¤¤¡A¦pªG¬O¡u0¡v¡Aªí¥Ü¦b¡u\\.\PhysicalDrive0¡v¹êÅéºÏºÐùØ¡C²Ä¤GÓÄæ¦ì¡AdwUnknown¡A¤]©M VOLUME_DISK_EXTENTS ªº dwUnknown ¤@¼Ë¡A¤£ª¾¦ó¬G¡A»P§Ú¹êÅ礣²Å¡C²Ä¤T¡B²Ä¥|ÓÄæ¦ì¬O 64 ¦ì¤¸ªøªº¾ã¼Æ¡A¤À§Oªí¥Ü¦¹ÅÞ¿èºÏºÐ±q¹êÅéºÏºÐªº²Ä´XӦ줸²Õ¶}©l¡A¦Óªø«×¬°¦h¤Ö¦ì¤¸²Õ¡C¥¦Ìªº¸ê®Æ§ÎºA¬° LARGE_INTEGER¡A¥i¥H¦b WINDOWS.INC ùاä¨ì¡G LARGE_INTEGER UNION STRUCT LowPart DWORD ? HighPart DWORD ? ENDS QuadPart QWORD ? LARGE_INTEGER ENDS ¦A¦^¨ì DeviceIoControl ªº²Ä¤»Ó°Ñ¼Æ¡AnOutBufferSize¡Aªí¥Ü½w½Ä°Ï¤j¤p¡A¦¹³B¶ñ¤W¡uSIZEOF VOLUME_DISK_EXTENTS¡v§Y¥i¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡A¥²¶·¦b©I¥s«e±À¤J°ïÅ|¡C²Ä¤CӰѼơAlpBytesReturned¡A«ü¦V¬YÓÅܼơA¥HÀò±o¹ê»Ú¤W±q DeviceIoControl ¶Ç¦^ªº¸ê®Æªø«×¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡C³Ì«á¤@ӰѼơAlpOverlapped¡A¥¦¬O¤@Ó¦ì§}¡A«ü¦V OVERLAPPED µ²ºcÅé¡C¦pªG lpBytesReturned ¬° NULL¡A´N¥²¶·³]©w lpOverlapped ¬°¬YÓ OVERLAPPED µ²ºcÅ骺¦ì§}¡F¦pªG lpBytesReturned ¤w³]¬° ¬YÓÅܼƪº¦ì§}¡AlpOverlapped ´N¥²¶·¬° NULL¡C¦pªG DeviceIoControl °õ¦æ¦¨¥\¡A¶Ç¦^Ȭ°«D¹s¡FY¥¢±Ñ¡A¶Ç¦^Ȭ° 0¡A¥i¥H©I¥s GetLastError¡A¦pªG GetLastError ¶Ç¦^ ERROR_MORE_DATA¡A´Nªí¥Ü½w½Ä°Ï¤Ó¤p¡A¤£¨¬¥H®e¯Ç¶Ç¦^ªº¸ê®Æ¡C |
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX |
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX ÄÝ©ó¡uºÏºÐºÞ²z±±¨î½X¡vªº¤@ºØ¡A¥Î¨Ó¨ú±o¹êÅéºÏºÐªº¸ê®Æ¡A¦pºÏ¬W ( cylinders ) Á`¼Æ¡B¨CºÏ¬W©Ò§tºÏy ( tracks ) ¼Æ¡A¨CºÏy©Ò§tºÏ°Ï ( sectors ) ¼Æ¡B¨CºÏ°Ï©Ò§t¦ì¤¸²Õ ( bytes ) ¼Æ¡A¨ä쫬¬°¡G BOOL DeviceIoControl( (HANDLE) hDevice, // handle to volume IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize (LPVOID) lpOutBuffer, // output buffer (DWORD) nOutBufferSize, // size of output buffer (LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure ); hDevice ¬O©I¥s CreateFile ¶Ç¦^¨Óªºª½±µ¦s¨úÀx¦s¸Ë¸m¥N½X¡A©I¥s CreateFile ®É¡AlpFileName À³«ü¦VÃþ¦ü¡u\\.\PhysicalDriveX¡v¦r¦êªº¦ì§}¡A½Ð°Ñ¦Ò«e±ªº»¡©ú¡ClpOutBuffer «ü¦V DISK_GEOMETRY_EX µ²ºcÅ骺¦ì§}¡A¦pªG DeviceIoControl °õ¦æ¥¿½T¡A§@·~¨t²Î·|§â¸ê®Æ¶ñ¤J¦¹µ²ºcÅ餺¡A³oÓµ²ºcÅ骺Äæ¦ì¬O¡G DISK_GEOMETRY_EX STRUCT Geometry DISK_GEOMETRY <> DiskSize LARGE_INTEGER <> DataOne BYTE ? DISK_GEOMETRY_EX ENDS ²Ä¤GÓÄæ¦ì¡ADiskSize¡A¬O¤@Ó 64 ¦ì¤¸ªº¥¿¾ã¼Æ¡Aªí¥ÜºÏºÐ¤j¤p¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡CGeometry ¬O¤@Ó DISK_GEOMETRY µ²ºcÅé¡A¦UÄæ¦ì¬O¡G DISK_GEOMETRY STRUCT Cylinders LARGE_INTEGER <> MediaType MEDIA_TYPE ? TracksPerCylinder DWORD ? ;¨CºÏ¬W©Ò§tºÏy¼Æ SectorsPerTrack DWORD ? ;¨CºÏy©Ò§tºÏ°Ï¼Æ BytesPerSector DWORD ? ;¨CºÏ°Ï©Ò§t¦ì¤¸²Õ¼Æ DISK_GEOMETRY ENDS Cylinders ¬O¤@Ó 64 ¦ì¤¸ªº¥¿¾ã¼Æ¡Aªí¥ÜºÏ¬WÁ`¼Æ¡CMediaType ¬O¤@Ó 32 ¦ì¤¸ªº¥¿¾ã¼Æ¡A¥NªíÀx¦s´CÅ骺Ãþ«¬¡A¦p³nºÐ¤ù¡BºÏ¥ú¾÷©ÎµwºÐµ¥µ¥¡A¦ý¤j³¡¤À§¡¤w²^¨O¡A²{¦b±`¥Îªº¤j·§¥u³Ñ¤U RemovableMedia ©M FixedMedia¡A¤À§Oªí¥ÜÀH¨ºÐ©MµwºÐ¡C¨ä¥LªºÄæ¦ì§Ú·Q´N¤£¥²»¡©ú¤F¡C ¦A¦^¨ì DeviceIoControl ªº²Ä¤»Ó°Ñ¼Æ¡AnOutBufferSize¡Aªí¥Ü½w½Ä°Ï¤j¤p¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡AÀ³¸Ó¶ñ¤J¡uSIZEOF DISK_GEOMETRY_EX¡v¡ClpBytesReturned «ü¦V¤@ÓÅܼƪº¦ì§}¡ADeviceIoControl ·|§â¶Ç¦^ªº¸ê®Æªø«×¶ñ¤J¦¹ÅܼÆùØ¡A¶Ç¦^ªº¸ê®Æªø«×³æ¦ì¬O¦ì¤¸²Õ¡C¦pªG nOutBufferSize ©Ò«ü©wªº¤j¤p¤Ó¤p¡A«h©I¥s¥¢±Ñ¡AlpBytesReturned ¬° 0¡A¥i¥H©I¥s GetLastError¡A¦Ó¶Ç¦^ ERROR_INSUFFICIENT_BUFFER¡C¦pªG lpOverlapped ¬° NULL¡A«h lpBytesReturned ¤£¥i¬° NULL¡C¦pªG DeviceIoControl °õ¦æ¦¨¥\¡A¶Ç¦^«D¹sÈ¡F¦pªG¥¢±Ñ¡A¶Ç¦^ 0¡A©I¥s GetLastError ±o¨ì§ó¦h¸ê°T¡C |
IOCTL_DISK_GET_LENGTH_INFO |
IOCTL_DISK_GET_LENGTH_INFO ÄÝ©ó¡uºÏºÐºÞ²z±±¨î½X¡vªº¤@ºØ¡A¥Î©ó¨ú±o¹êÅéºÏºÐ©ÎÅÞ¿èºÏºÐªº¤j¤p¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡C©I¥s DeviceIoControl ®Éªº¦U°Ñ¼Æ¬°¡G BOOL DeviceIoControl( (HANDLE) hDevice, // handle to device IOCTL_DISK_GET_LENGTH_INFO, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize (LPVOID) lpOutBuffer, // output buffer (DWORD) nOutBufferSize, // size of output buffer (LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure ); ¨ä¤¤ hDevice ¬OÅÞ¿èºÏºÐ¥N½X©Î¹êÅéºÏºÐ¥N½X¡A©I¥s CreateFile ¥i¶Ç¦^³o¨âºØ¥N½X¡ClpOutBuffer «ü¦V GET_LENGTH_INFORMATION µ²ºcÅé¡A¦¹µ²ºcÅé¥u¦³¤@ÓÄæ¦ì¡G GET_LENGTH_INFORMATION STRUCT LengthOfDev LARGE_INTEGER <> GET_LENGTH_INFORMATION ENDS ¦b MSDN ³oÓÄæ¦ìºÙ¬° Length¡A¦ý¬O»P MASM ªº«O¯d¦r¬Û¦P¡A¦]¦¹¤p¤ì°¸§ï¬° LengthOfDev¡A¥¦¬O 64 ¦ì¤¸ªº¥¿¾ã¼Æ¡C¦pªG hDevice ¬OÅÞ¿èºÏºÐ¡A«h LengthOfDev ¬OÅÞ¿èºÏºÐ¤j¤p¡F¦pªG hDevice ¬O¹êÅéºÏºÐ¡A«h LengthOfDev ¬O¹êÅéºÏºÐ¤j¤p¡C§¡¥H¦ì¤¸²Õ¬°³æ¦ì¡C¨ä¥L°Ñ¼Æ»P«e±¬Û¦P¡A½Ð¦Û¦æ°Ñ¦Ò¡C |
»¡§¹ GetLogicalDriveFromPhysicalDrive ¥Î¨ìªº API «á¡A¤p¤ì°¸¥ýµ¹¤j®a¬Ý¬Ý GetLogicalDriveFromPhysicalDrive ªºì©l½X¡AµM«á¦AÁ¿¸Ñ¬yµ{¡C©³¤U´N¬Oì©l½X¡G
;-----------------------------------------------------------------------------------------------;001 ;¦¹°Æµ{¦¡¡AGetLogicalDriveFromPhysicalDrive¡A¯à¨ú¨CÓ¹êÅéµwºÐ¤¤©Ò§tªºÅÞ¿èºÏºÐ¡A¨Ã¶Ç¦^µ¹¥Dµ{¦¡ ;¿é¤J¡GlpData¡Ðn¶Ç¦^ªº¸ê®Æ¦ì§}¡A¦pªGGetLogicalDriveFromPhysicalDrive¥¿½T°õ¦æ¡A·|¦b¦¹¦ì§}¶ñ¤W ; ®æ¦¡¬°¡u'\\.\PhysicalDrive0',0,'C:',0,'D:',0, ; '\\.\PhysicalDrive1',0,'E:',0,0¡v ; ªí¥Ü²Ä¤@Ó¹êÅéµwºÐ(§Y\\.\PhysicalDrive0)¦³¨âÓÅÞ¿èºÏºÐ¡AC¡BD ; ²Ä¤GÓ¹êÅéµwºÐ(§Y\\.\PhysicalDrive1)¶È¤@ÓÅÞ¿èºÏºÐ¡AE ; ¥H¡u0,0¡v¬°µ²§À ; ¦pªG¥Dµ{¦¡¶Ç¨ÓªºlpData¬°¹s¡A¶Ç¦^ÈEAX¬°©Ò»Ý®e¯Çªº¸ê®Æ¤j¤p(¥H¦ì¤¸²Õ¬°³æ¦ì) ;¿é¥X¡GEAX¡ÐY¦¨¥\¡AEAX¬°¶Ç¦^ªº¸ê®Æ¤j¤p(¥H¦ì¤¸²Õ¬°³æ¦ì)¡A¥BlpData©Ò«ü¦ì§}·|¶ñ¤J¥¿½Tªº¸ê®Æ ;010 ; Y¥¢±Ñ¡AEAX¡×0 GetLogicalDriveFromPhysicalDrive PROC USES esi edi ebx, lpData:DWORD LOCAL aryLogicalDrive[104]:BYTE ;¨CÓÅÞ¿èºÏºÐ¾÷¦WºÙ¬°¡u'C:\',0¡v¡A³Ì¦h26Ó LOCAL szDeviceName[8]:BYTE ;'\\.\C:',0 LOCAL vde:VOLUME_DISK_EXTENTS LOCAL idx:DWORD ;©I¥sGetLogicalDriveStrings±o¨ìÅÞ¿èÀx¦s¸Ë¸m¦Wªº°}¦C¯Á¤Þ LOCAL nOut:DWORD ;©I¥sDeviceIoControl¶Ç¦^Ū¨ú¦h¤Ö¦ì¤¸²Õ LOCAL nData:DWORD ;hMem¤º©Ò°O¸üªº«n¸ê®Æ¤j¤p¡A¥ç§Yn¶Ç¦^ªº¸ê®Æ¤j¤p¡A¥H¦ì¤¸²Õ¬°³æ¦ì LOCAL nPhysicalDriver:DWORD ;¹êÅéµwºÐÓ¼Æ LOCAL hDevice,hMem:HANDLE ;020 LOCAL szPhyDrive[20]:BYTE sub ecx,ecx cld mov idx,ecx mov nData,ecx ;025 mov nPhysicalDriver,ecx ;ªì©l¤ÆszPhyDrive¦r¦ê¡A¥ç§Y¶ñ¤J"\\.\PhysicalDrive0",0 lea edi,szPhyDrive mov DWORD PTR [edi],5c2e5c5ch mov DWORD PTR [edi+4],73796850h ;030 mov DWORD PTR [edi+8],6c616369h mov DWORD PTR [edi+12],76697244h mov DWORD PTR [edi+16],3065h ;ªì©l¤ÆszDeviceName¦r¦ê¡A¥ç§Y¶ñ¤J"\\.\",?,":",0 lea edi,szDeviceName ;035 mov DWORD PTR [edi],5c2e5c5ch mov WORD PTR [edi+5],3ah ;¹w¯d2KBªÅ¶¡¦s©ñn¶Ç¦^ªº¸ê®Æ(¨CÓÅÞ¿èºÏºÐ¦û3Ӧ줸²Õ¡a¦p¡uC:¡v,0¡b¡A°²³]¨CÓ¹êÅéµwºÐ³£¦³ 26 ;ÓÅÞ¿èºÏ°Ï¡A¬G¦û26*3¡×78¦ì¤¸²Õ¡A¦A¥[¤W¡u"\\.\PhysicalDrive1",0¡v¦@19Ӧ줸²Õ¡A¬G¨CÓ¹êÅéµw ;ºÐ¦û97Ӧ줸²Õ¡A°²³]¦³20Ó¹êÅéµwºÐ¡A¦@»Ýn1940Ӧ줸²Õ¡A¦ý¦A¥[¤W³Ì«á¤@Ó0¡A¦³971Ӧ줸²Õ¡A ;¬°¨D«OÀI¡A¦V¨t²În¨D2KB) INVOKE GlobalAlloc,GPTR,2048 mov hMem,eax INVOKE GetLogicalDriveStrings,SIZEOF aryLogicalDrive,ADDR aryLogicalDrive ;045 next_drv: mov edx,idx lea esi,aryLogicalDrive shl edx,2 add esi,edx mov al,[esi] ;AL¡×ÅÞ¿èÀx¦s¸Ë¸m¦WºÙ¡A¦p"C"¡B"D"µ¥µ¥ ;050 cmp al,0 jz finished lea edi,szDeviceName mov [edi+4],al INVOKE GetDriveType,esi ;055 ;YEAX¡×DRIVE_FIXED¡A«h¦¹ÅÞ¿èºÏºÐ¥i¯à¦bµwºÐ©ÎÀH¨ºÐ(flash driver)¤W .IF eax==DRIVE_FIXED INVOKE CreateFile,ADDR szDeviceName,GENERIC_READ,FILE_SHARE_READ or \ FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0 cmp eax,INVALID_HANDLE_VALUE ;060 je error mov hDevice,eax INVOKE DeviceIoControl,hDevice,IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,0,0,ADDR vde,\ SIZEOF VOLUME_DISK_EXTENTS,ADDR nOut,0 INVOKE CloseHandle,hDevice ;065 ;pºâÀ³¸Ó§â¦¹ÅÞ¿èºÏºÐ¦s¦bhMemªºþÓ¦ì§}¡A¦¹¦ì§}«e´XӦ줸²Õ¬°"\\.\PhysicalDrive"¡AY ;¤£¬Oªº¸Ü¡A«hªí¥Ü¦¹ÅÞ¿èºÏºÐ¬°©|¥¼³Q¦¹°Æµ{¦¡³B²z¹Lªº¹êÅéµwºÐ mov eax,vde.Extents.DiskNumber sub edx,edx mov bl,al ;070 mov ecx,97 ;Windows¤¤¡A¨CÓ¹êÅéµwºÐ³Ì¦h26ÓÅÞ¿èºÏºÐ¡A¨CÓÅÞ¿èºÏºÐ¦û3¦ì¤¸²Õ mov edi,hMem;(¦p¡uC:\,0¡v)¡A¦A¥[¤W¡u\\.\PhysicalDrive?",0¡v¡A¦@97¦ì¤¸²Õ mul ecx lea esi,szPhyDrive add edi,eax ;075 ;§ä¨ì·sªº¹êÅéµwºÐ¡A§âszPhyDrive¦r¦ê¦s¤JEDI©Ò«ü¦ì§} .IF BYTE PTR [edi]==0 mov ecx,19 rep movsb add [edi-2],bl ;080 inc nPhysicalDriver jmp save_driver .ENDIF ;·j´MhMem¸Ì¡A¦¹¹êÅéµwºÐ"\\.\PhysicalDrive?",0,'C:',0,'D:',0,0,0¡K¡K«áþ¤@Ó¦ì§}¬OªÅµÛªº mov al,0 ;085 mov ecx,97 @@: repne scasb cmp BYTE PTR [edi],0 jne @b ;¨ú±oÅÞ¿èºÏºÐ¦WºÙ¡A¦s©óAL ;090 save_driver: lea edx,szDeviceName mov ah,':' mov al,[edx+4] stosw xor al,al ;095 stosb .ENDIF inc idx jmp next_drv ;100 ;¤w¦bhMem°O¿ý¤F¹êÅéµwºÐ¥]§tþ¨ÇÅÞ¿èºÏºÐ¡A²{¦bn§â¥¦¶Çµ¹¥Dµ{¦¡«ü©wªº°O¾ÐÅé¤F finished: mov edi,lpData sub edx,edx mov idx,edx .WHILE idx<=20 ;105 mov eax,97 sub edx,edx mov esi,hMem mul idx add esi,eax ;ESI¡×¦bhMemùØ¡A¬YÓ¹êÅéµwºÐªº¶}©l¦ì§} ;110 .IF BYTE PTR [esi]=="\" mov ecx,19 add nData,ecx .IF edi==0 add esi,ecx ;115 .ELSE rep movsb .ENDIF xor ebx,ebx ;EBX¡×ÅÞ¿èºÏºÐÓ¼Æ next_logic_drv: cmp BYTE PTR [esi],0 ;120 jz finish_the_phy mov ecx,3 add nData,ecx .IF edi==0 add esi,ecx ;125 .ELSE lodsw stosw lodsb stosb ;130 .ENDIF inc ebx cmp ebx,26 jb next_logic_drv .ENDIF ;135 finish_the_phy: inc idx .ENDW .IF edi!=0 mov BYTE PTR [edi],0 .ENDIF ;140 INVOKE GlobalFree,hMem mov eax,nData inc eax jmp exit error: INVOKE GlobalFree,hMem ;145 xor eax,eax exit: ret GetLogicalDriveFromPhysicalDrive ENDP ;-----------------------------------------------------------------------------------------------;149
¦A¨Ón»¡¤@»¡ GetLogicalDriveFromPhysicalDrive ªº¬yµ{¡G
GetLogicalDriveFromPhysicalDrive °Æµ{¦¡¤@¶}©l¡A¬Oªì©l¤Æ¦UÓ°Ï°ìÅܼơC
²Ä 38¡ã43 ¦æ¡A¬O«Ø¥ß¤@Ó°O¾ÐÅé°Ï¶ô¡A¦¹°O¾ÐÅé°Ï¶ô¦ì§}¬O¦b hMem ÅܼÆùØ¡A¦¹°O¾ÐÅé°Ï¶ô±N¨Ì·Ó¨CÓ¹êÅéºÏºÐ¤ºªºÅÞ¿èºÏºÐ¨Ó¤À°t¡C¦ý¬O¦bµ{¦¡¤@¶}©l®É¡A§Ṳ́£ª¾¹D¨CÓ¹êÅéºÏºÐ¦³´XÓÅÞ¿èºÏºÐ¡A©Ò¥H°²³]³Ì¦h 26 ÓÅÞ¿èºÏºÐ ( ¨Æ¹ê¤W¡AWindows §@·~¨t²Î´N¥u¯à¿ë»{ A: ¨ì Z: ¦@ 26 ÓÅÞ¿èºÏºÐ¡A³o¨ÇÅÞ¿èºÏºÐ¥]§t¤F³nºÐ¡BµwºÐ¡B¥úºÐ¡BÀH¨ºÐ¡Bºô¸ôºÏºÐµ¥µ¥ )¡C¨CÓÅÞ¿èºÏºÐ¦û¤F 3 Ӧ줸²Õ¡A¨Ò¦p¡u"C:",0¡v¡A¦A¥[¤W¡u"\\.\PhysicalDrive1",0¡v¦@19Ӧ줸²Õ¡A¬G¨CÓ¹êÅéµwºÐ¦û 97 Ӧ줸²Õ¡C°²³]¦³ 20 Ó¹êÅéµwºÐ¡A¦@»Ýn 1940 Ӧ줸²Õ¡A©Ò¥H¦V¨t²În¨D 2KB¡C
GetLogicalDriveFromPhysicalDrive °õ¦æªñµ²§ô®É¡AhMem ªº¤º®e·|¬O¹³¤U±³o¼Ë¡G
00146068 5C 5C 2E 5C 50 68 79 73 69 63 61 6C 44 72 69 76 \\.\PhysicalDriv 00146078 65 30 00 43 3A 00 45 3A 00 48 3A 00 49 3A 00 00 e0.C:.E:.H:.I:.. 00146088 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00146098 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 001460A8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 001460B8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 001460C8 00 5C 5C 2E 5C 50 68 79 73 69 63 61 6C 44 72 69 .\\.\PhysicalDri 001460D8 76 65 31 00 46 3A 00 47 3A 00 4A 3A 00 00 00 00 ve1.F:.G:.J:.... 001460E8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 001460F8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00146108 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00146118 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00146128 00 00 5C 5C 2E 5C 50 68 79 73 69 63 61 6C 44 72 ..\\.\PhysicalDr 00146138 69 76 65 32 00 44 3A 00 00 00 00 00 00 00 00 00 ive2.D:......... hMem ªº¤º®e
¥Ñ¤W± hMem ªº¤º®e¨Ó¬Ý¡A¤p¤ì°¸·Qªk«Ü²³æ¡A¥ý¬°¨CÓ¹êÅéºÏºÐ¹w¯d 97 Ӧ줸²Õ¡A¦A¨M©w¦UÓÅÞ¿èºÏºÐ¦ì©óþÓ¹êÅéºÏºÐ¤¤¡AµM«ápºâ¸ÓÅÞ¿èºÏºÐÀ³¸Ó¶ñ¤Jþ¤@Ó¹êÅéºÏºÐ©ÒÄݪº°Ï¶ô¡A¦Aµy¥[¾ã²z§R¥h¦h¾lªºªÅ¶¡§Y¥i¡C
²Ä 44¡ã45 ¦æ¬O©I¥s GetLogicalDriveStrings¡A±o¨ìÅÞ¿èºÏºÐªº®Ú¥Ø¿ý¦W¶ñ¤J aryLogicalDrive ùر¡AaryLogicalDrive ¬O¤@Ó°Ï°ì°}¦C¡A¦¹°}¦C¦@ 104 ¦ì¤¸²Õ ( 26¡Ñ4¡×104 )¡C·í GetLogicalDriveStrings °õ¦æ§¹«á¡AaryLogicalDrive ¤º®eÅܬ°¡G
0012F760 43 3A 5C 00 C:\. 0012F770 44 3A 5C 00 45 3A 5C 00 46 3A 5C 00 47 3A 5C 00 D:\.E:\.F:\.G:\. 0012F780 48 3A 5C 00 49 3A 5C 00 4A 3A 5C 00 4B 3A 5C 00 H:\.I:\.J:\.K:\. 0012F790 4D 3A 5C 00 4E 3A 5C 00 00 M:\.N:\..
²Ä 46 ¦æ¶}©l¡A¬O¥H idx ÅܼƬ°¯Á¤ÞÈ¡A¥ç§Y idx ¥Ñ 0 ¶}©l¨C¦¸¼W¥[¤@¡AÀËÅç¨CÓÅÞ¿èºÏºÐ¦ì©óþ¤@Ó¹êÅéºÏºÐùØ¡C
¦¹¤@¶¥¬qµ{¦¡ªº¤u§@¬O§â¦b hMem ©Ò«ü¦ì§}ªº°O¾ÐÅ餺®e¶Ç¦^¨ì¥Dµ{¦¡«ü©wªº¦ì§}¡A¦¹¦ì§}¬O¥H°Ñ¼Æ¡AlpData¡A¶Çµ¹ GetLogicalDriveFromPhysicalDrive ªº¡A¦b²Ä 102 ¦æ¡A«ü©w EDI ¬° lpData¡C¦¹¬qµ{¦¡¤´¥H idx ¬°¯Á¤Þ¡A©Ò¥H¥ý±N¨ä²MªÅ¡A¦]¬°¤§«e°²³]³Ì¦h¨t²Î±µ¤F 20 Ó¹êÅéºÏºÐ¡A©Ò¥H idx ¦b¤p©ó 20 ®É¡A¤~°µ±µ¤U¨Óªº¨BÆJ¡A¦]¦¹§â±µ¤U¨Óªº¨BÆJ©ñ¦b¤@Ó¡u.WHILE¡v©M¡u.ENDW¡v°j°éùØ¡C±µ¤U¨Óªº¨BÆJ¡A¤p¤ì°¸¤]²Ó¤À´X¬q»¡©ú¡G
²Ä 138¡ã140 ¦æ¡A¦pªG EDI ¤£¬°¹s¡Aªí¥Ü¥²¶·¶Ç¦^¦UÓ¹êÅéºÏºÐ©Ò§tªºÅÞ¿èºÏºÐ¦WºÙ¡A¨ì¦¹¬°¤î´X¥G§¹¦¨¡A³Ì«á¦A¶ñ¤J¤@Ӧ줸²Õªº¹s¡A¨Ï¨äÅܦ¨¨âÓ¡u0¡v¡A§@¬°¸ê®Æªºµ²§À¡C²Ä 141 ¦æ¡AÄÀ©ñ hMem °O¾ÐÅé°Ï¶ô¡C²Ä 142¡ã143 ¦æ¡A¦]¬°¦h¤F¤@Ӧ줸²Õªº¡u0¡v¡A©Ò¥H©Ò»Ý°O¾ÐÅéªø«×¦A¼W¥[¤@¡A¨Ã¦s©ó EAX ùØ¡A§@¬°¶Ç¦^È¡C
©³¤U¤p¤ì°¸´N¥H¤@Ó¨Ò¤l¡A»¡©ú¦p¦ó©I¥s GetLogicalDriveFromPhysicalDrive¡C§Ú·QÁÙ¬O¨Ï¥Î²Ä 20 ³¹ªº¤èªk«Ø¥ß HD.DLL °ÊºA³sµ²µ{¦¡®w¡CHD.ASM ªºì©l½X¦p¤U¡G
.586 .MODEL FLAT,STDCALL OPTION CASEMAP:NONE INCLUDE WINDOWS.INC INCLUDE KERNEL32.INC INCLUDELIB KERNEL32.LIB IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS EQU 560000h DISK_EXTENT STRUCT DiskNumber DWORD ? dwUnknown DWORD ? ;MSDNµL¦¹Äæ¦ì StartingOffset LARGE_INTEGER <> ExtentLength LARGE_INTEGER <> DISK_EXTENT ENDS VOLUME_DISK_EXTENTS STRUCT NumberOfDiskExtents DWORD ? dwUnknown DWORD ? ;MSDNµL¦¹Äæ¦ì Extents DISK_EXTENT ANYSIZE_ARRAY DUP (<>) VOLUME_DISK_EXTENTS ENDS ;*************************************************************************************************** .CODE ;--------------------------------------------------------------------------------------------------- ;¶i¤J¡þÂ÷¶}°Æµ{¦¡ DLLEntry PROC hInstDLL,dwReason,dwReserved mov eax,TRUE ;¤£»Ý¨Æ«e³B²z©Î¨Æ«á²M²z¡A¬G¶Èªð¦^TRUE ret DLLEntry ENDP ;--------------------------------------------------------------------------------------------------- ;¦¹°Æµ{¦¡¡AGetLogicalDriveFromPhysicalDrive¡A¯à¨ú¨CÓ¹êÅéµwºÐ¤¤©Ò§tªºÅÞ¿èºÏºÐ¡A¨Ã¶Ç¦^µ¹¥Dµ{¦¡ ;¿é¤J¡GlpData¡Ðn¶Ç¦^ªº¸ê®Æ¦ì§}¡A¦pªGGetLogicalDriveFromPhysicalDrive¥¿½T°õ¦æ¡A·|¦b¦¹¦ì§}¶ñ¤W ; ®æ¦¡¬°¡u'\\.\PhysicalDrive0',0,'C:',0,'D:',0, ; '\\.\PhysicalDrive1',0,'E:',0,0¡v ; ªí¥Ü²Ä¤@Ó¹êÅéµwºÐ(§Y\\.\PhysicalDrive0)¦³¨âÓÅÞ¿èºÏºÐ¡AC¡BD ; ²Ä¤GÓ¹êÅéµwºÐ(§Y\\.\PhysicalDrive1)¶È¤@ÓÅÞ¿èºÏºÐ¡AE ; ¥H¡u0,0¡v¬°µ²§À ; ¦pªG¥Dµ{¦¡¶Ç¨ÓªºlpData¬°¹s¡A¶Ç¦^ÈEAX¬°©Ò»Ý®e¯Çªº¸ê®Æ¤j¤p(¥H¦ì¤¸²Õ¬°³æ¦ì) ;¿é¥X¡GEAX¡ÐY¦¨¥\¡AEAX¬°¶Ç¦^ªº¸ê®Æ¤j¤p(¥H¦ì¤¸²Õ¬°³æ¦ì)¡A¥BlpData©Ò«ü¦ì§}·|¶ñ¤J¥¿½Tªº¸ê®Æ ; Y¥¢±Ñ¡AEAX¡×0 GetLogicalDriveFromPhysicalDrive PROC USES esi edi ebx, lpData:DWORD LOCAL aryLogicalDrive[104]:BYTE ;¨CÓÅÞ¿èºÏºÐ¾÷¦WºÙ¬°¡u'C:\',0¡v¡A³Ì¦h26Ó LOCAL szDeviceName[8]:BYTE ;'\\.\C:',0 LOCAL vde:VOLUME_DISK_EXTENTS LOCAL idx:DWORD ;©I¥sGetLogicalDriveStrings±o¨ìÅÞ¿èÀx¦s¸Ë¸m¦Wªº°}¦C¯Á¤Þ LOCAL nOut:DWORD ;©I¥sDeviceIoControl¶Ç¦^Ū¨ú¦h¤Ö¦ì¤¸²Õ LOCAL nData:DWORD ;hMem¤º©Ò°O¸üªº«n¸ê®Æ¤j¤p¡A¥ç§Yn¶Ç¦^ªº¸ê®Æ¤j¤p¡A¥H¦ì¤¸²Õ¬°³æ¦ì LOCAL nPhysicalDriver:DWORD ;¹êÅéµwºÐÓ¼Æ LOCAL hDevice,hMem:HANDLE LOCAL szPhyDrive[20]:BYTE sub ecx,ecx cld mov idx,ecx mov nData,ecx mov nPhysicalDriver,ecx ;ªì©l¤ÆszPhyDrive¦r¦ê¡A¥ç§Y¶ñ¤J"\\.\PhysicalDrive0",0 lea edi,szPhyDrive mov DWORD PTR [edi],5c2e5c5ch mov DWORD PTR [edi+4],73796850h mov DWORD PTR [edi+8],6c616369h mov DWORD PTR [edi+12],76697244h mov DWORD PTR [edi+16],3065h ;ªì©l¤ÆszDeviceName¦r¦ê¡A¥ç§Y¶ñ¤J"\\.\",?,":",0 lea edi,szDeviceName mov DWORD PTR [edi],5c2e5c5ch mov WORD PTR [edi+5],3ah ;¹w¯d2KBªÅ¶¡¦s©ñn¶Ç¦^ªº¸ê®Æ(¨CÓÅÞ¿èºÏºÐ¦û3Ӧ줸²Õ¡a¦p¡uC:¡v,0¡b¡A°²³]¨CÓ¹êÅéµwºÐ³£¦³ 26 ;ÓÅÞ¿èºÏ°Ï¡A¬G¦û26*3¡×78¦ì¤¸²Õ¡A¦A¥[¤W¡u"\\.\PhysicalDrive1",0¡v¦@19Ӧ줸²Õ¡A¬G¨CÓ¹êÅéµw ;ºÐ¦û97Ӧ줸²Õ¡A°²³]¦³20Ó¹êÅéµwºÐ¡A¦@»Ýn1940Ӧ줸²Õ¡A¦ý¦A¥[¤W³Ì«á¤@Ó0¡A¦³971Ӧ줸²Õ¡A ;¬°¨D«OÀI¡A¦V¨t²În¨D2KB) INVOKE GlobalAlloc,GPTR,2048 mov hMem,eax INVOKE GetLogicalDriveStrings,SIZEOF aryLogicalDrive,ADDR aryLogicalDrive next_drv: mov edx,idx lea esi,aryLogicalDrive shl edx,2 add esi,edx mov al,[esi] ;AL¡×ÅÞ¿èÀx¦s¸Ë¸m¦WºÙ¡A¦p"C"¡B"D"µ¥µ¥ cmp al,0 jz finished lea edi,szDeviceName mov [edi+4],al INVOKE GetDriveType,esi ;YEAX¡×DRIVE_FIXED¡A«h¦¹ÅÞ¿èºÏºÐ¥i¯à¦bµwºÐ©ÎÀH¨ºÐ(flash driver)¤W .IF eax==DRIVE_FIXED INVOKE CreateFile,ADDR szDeviceName,GENERIC_READ,FILE_SHARE_READ or \ FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0 cmp eax,INVALID_HANDLE_VALUE je error mov hDevice,eax INVOKE DeviceIoControl,hDevice,IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,0,0,ADDR vde,\ SIZEOF VOLUME_DISK_EXTENTS,ADDR nOut,0 INVOKE CloseHandle,hDevice ;pºâÀ³¸Ó§â¦¹ÅÞ¿èºÏºÐ¦s¦bhMemªºþÓ¦ì§}¡A¦¹¦ì§}«e´XӦ줸²Õ¬°"\\.\PhysicalDrive"¡AY ;¤£¬Oªº¸Ü¡A«hªí¥Ü¦¹ÅÞ¿èºÏºÐ¬°©|¥¼³Q¦¹°Æµ{¦¡³B²z¹Lªº¹êÅéµwºÐ mov eax,vde.Extents.DiskNumber sub edx,edx mov bl,al mov ecx,97 ;Windows¤¤¡A¨CÓ¹êÅéµwºÐ³Ì¦h26ÓÅÞ¿èºÏºÐ¡A¨CÓÅÞ¿èºÏºÐ¦û3¦ì¤¸²Õ mov edi,hMem;(¦p¡uC:\,0¡v)¡A¦A¥[¤W¡u\\.\PhysicalDrive?",0¡v¡A¦@97¦ì¤¸²Õ mul ecx lea esi,szPhyDrive add edi,eax ;§ä¨ì·sªº¹êÅéµwºÐ¡A§âszPhyDrive¦r¦ê¦s¤JEDI©Ò«ü¦ì§} .IF BYTE PTR [edi]==0 mov ecx,19 rep movsb add [edi-2],bl inc nPhysicalDriver jmp save_driver .ENDIF ;·j´MhMem¸Ì¡A¦¹¹êÅéµwºÐ"\\.\PhysicalDrive?",0,'C:',0,'D:',0,0,0¡K¡K«áþ¤@Ó¦ì§}¬OªÅµÛªº mov al,0 mov ecx,97 @@: repne scasb cmp BYTE PTR [edi],0 jne @b ;¨ú±oÅÞ¿èºÏºÐ¦WºÙ¡A¦s©óAL save_driver: lea edx,szDeviceName mov ah,':' mov al,[edx+4] stosw xor al,al stosb .ENDIF inc idx jmp next_drv ;¤w¦bhMem°O¿ý¤F¹êÅéµwºÐ¥]§tþ¨ÇÅÞ¿èºÏºÐ¡A²{¦bn§â¥¦¶Çµ¹¥Dµ{¦¡«ü©wªº°O¾ÐÅé¤F finished: mov edi,lpData sub edx,edx mov idx,edx .WHILE idx<=20 mov eax,97 sub edx,edx mov esi,hMem mul idx add esi,eax ;ESI¡×¦bhMemùØ¡A¬YÓ¹êÅéµwºÐªº¶}©l¦ì§} .IF BYTE PTR [esi]=="\" mov ecx,19 add nData,ecx .IF edi==0 add esi,ecx .ELSE rep movsb .ENDIF xor ebx,ebx ;EBX¡×ÅÞ¿èºÏºÐÓ¼Æ next_logic_drv: cmp BYTE PTR [esi],0 jz finish_the_phy mov ecx,3 add nData,ecx .IF edi==0 add esi,ecx .ELSE lodsw stosw lodsb stosb .ENDIF inc ebx cmp ebx,26 jb next_logic_drv .ENDIF finish_the_phy: inc idx .ENDW .IF edi!=0 mov BYTE PTR [edi],0 .ENDIF INVOKE GlobalFree,hMem mov eax,nData inc eax jmp exit error: INVOKE GlobalFree,hMem xor eax,eax exit: ret GetLogicalDriveFromPhysicalDrive ENDP ;*************************************************************************************************** END DLLEntry
±N¤W±¦s¦¨ HD.ASM «á¡A¦A«Ø¥ß¤@Ó HD.DEF ¯Â¤å¦rÀÉ¡A¤º®e¦p¤U¡G
EXPORTS GetLogicalDriveFromPhysicalDrive=GetLogicalDriveFromPhysicalDrive
µM«á¶}±Ò¡u©R¥O´£¥Ü¦r¤¸¡v¡A¿é¤J¤U±«ü¥O¡G
E:\HomePage\SOURCE\Win32\HD_Info>ml /c hd.asm [Enter] Microsoft (R) Macro Assembler Version 6.14.8444 Copyright (C) Microsoft Corp 1981-1997. All rights reserved. Assembling: hd.asm *********** ASCII build *********** E:\HomePage\SOURCE\Win32\HD_Info>link /DLL /SUBSYSTEM:WINDOWS /DEF:hd.def hd.obj [Enter] Microsoft (R) Incremental Linker Version 5.12.8078 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. Creating library hd.lib and object hd.exp E:\HomePage\SOURCE\Win32\HD_Info>
¨ì¦¹¡A¤w«Ø¥ß¦n HD.DLL °ÊºA³sµ²µ{¦¡®w¤F¡C±µµÛ¦A«Ø¥ß LOGICAL.ASM¡A·í°µ´ú¸Õ HD.DLL ªº´ú¸ÕÀÉ¡ALOGICAL.ASM ì©l½X¦p¤U¡G
.586 .MODEL FLAT,STDCALL OPTION CASEMAP:NONE INCLUDE WINDOWS.INC INCLUDE KERNEL32.INC INCLUDE USER32.INC INCLUDELIB KERNEL32.LIB INCLUDELIB USER32.LIB INCLUDELIB HD.LIB GetLogicalDriveFromPhysicalDrive PROTO lpData:DWORD ;********************************************************************* .DATA hMem HANDLE ? szData DB 256 DUP (0) szTitle DB 'ÅÞ¿èºÏºÐ»P¹êÅéºÏºÐ',0 ;********************************************************************* .CODE ;--------------------------------------------------------------------- start: INVOKE GetLogicalDriveFromPhysicalDrive,0 inc eax INVOKE GlobalAlloc,GPTR,eax mov hMem,eax INVOKE GetLogicalDriveFromPhysicalDrive,hMem mov edi,OFFSET szData mov esi,hMem nxtphy: cmp DWORD PTR [esi],5c2e5c5ch ;"\\.\" jne error add esi,4 mov ecx,14 rep movsb @@: inc esi cmp BYTE PTR [esi],'\' je cr_lf cmp BYTE PTR [esi],0 je endstr mov al,' ' stosb lodsw stosw jmp @b cr_lf: mov ax,0a0dh stosw jmp nxtphy error: endstr: mov al,0 stosb INVOKE MessageBox,0,OFFSET szData,OFFSET szTitle,MB_OK or \ MB_ICONINFORMATION INVOKE GlobalFree,hMem INVOKE ExitProcess,NULL ;********************************************************************* END start
¦b¡u©R¥O´£¥Ü¦r¤¸¡v¡A¿é¤J¤U±«ü¥O¥H²ÕĶ¨Ã³sµ²¡G
E:\HomePage\SOURCE\Win32\HD_Info>ml logical.asm [Enter]
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.
Assembling: logical.asm
***********
ASCII build
***********
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/SUBSYSTEM:WINDOWS
"logical.obj"
"/OUT:logical.exe"
E:\HomePage\SOURCE\Win32\HD_Info>logical [Enter]
°õ¦æµ²ªG¦p¤U¡G