找回密码
 加入
搜索
楼主: skyfree

[效率算法] 有没有纯AU3方法或API方法获取当前分区是否GPT格式的思路?

 火... [复制链接]
发表于 2016-1-8 08:48:11 | 显示全部楼层
找了一段代码,应该可以的

#include <WinAPI.au3>

$_PARTITION_INFORMATION_MBR = 'byte PartitionType;' & _
                'byte BootIndicator;' & _
                'byte RecognizedPartition;' & _
                'dword HiddenSectors;'

$_PARTITION_INFORMATION_GPT = 'byte TypeGuid[16];' & _
                'byte IDGuid[16];' & _
                'int64 Attributes;' & _
                'wchar Name[36];'

$_PARTITION_INFORMATION_EX = 'int PartitionStyle;' & _
                'int64 StartingOffset;' & _
                'int64 PartitionLength;' & _
                'dword PartitionNumber;' & _
                'byte RewritePartition;' & _
                'byte pad[3];' & _
                $_PARTITION_INFORMATION_MBR & _
                $_PARTITION_INFORMATION_GPT


$_PARTITION_INFORMATION_EX_2 = 'int PartitionStyle;' & _
                'int64 StartingOffset;' & _
                'int64 PartitionLength;' & _
                'dword PartitionNumber;' & _
                'byte RewritePartition;' & _
                'byte pad[3];' & _
                $_PARTITION_INFORMATION_GPT



$DRIVE_LAYOUT_INFORMATION_MBR = 'ULONG Signature;'

$DRIVE_LAYOUT_INFORMATION_GPT = 'byte Guid[16];' & _
                'int64 StartingUsableOffset;' & _
                'int64 UsableLength;' & _
                'ulong MaxPartitionCount;'

$_DRIVE_LAYOUT = DllStructCreate('dword PartitionStyle;' & _
                'dword PartitionCount;' & _
                'byte union[40];' & _
                'byte PartitionEntry[8192]')



$hDrive = _WinAPI_CreateFile('.PHYSICALDRIVE0', 2, 0)
Local $Ret = DllCall("kernel32.dll", "int", "DeviceIoControl", _
                "hwnd", $hDrive, _
                "dword", 0x00070050, _
                "ptr", 0, _
                "dword", 0, _
                "ptr", DllStructGetPtr($_DRIVE_LAYOUT), _
                "dword", DllStructGetSize($_DRIVE_LAYOUT), _
                "dword*", 0, _
                "ptr", 0)



Switch DllStructGetData($_DRIVE_LAYOUT, "PartitionStyle")
        Case 0 ;MBR

                $data = DllStructGetData($_DRIVE_LAYOUT, "union")
                $binaryStruct = DllStructCreate('byte[8192]')
                DllStructSetData($binaryStruct, 1, $data)
                $DriveMBRInfo = DllStructCreate($DRIVE_LAYOUT_INFORMATION_MBR, DllStructGetPtr($binaryStruct))
                ConsoleWrite('MBR Signature: ' & Hex(DllStructGetData($DriveMBRInfo, "Signature"), 8) & @CRLF & @CRLF)


                $PartitionCount = DllStructGetData($_DRIVE_LAYOUT, "PartitionCount")

                $PartitionEntry = 'byte[144];'
                For $x = 2 To $PartitionCount
                        $PartitionEntry &= 'byte[144];'
                Next
                $PartitionEntry &= 'byte[8192]'


                $data = DllStructGetData($_DRIVE_LAYOUT, "PartitionEntry")
                $binaryStruct = DllStructCreate('byte[8192]')
                DllStructSetData($binaryStruct, 1, $data)
                $PartitionEntry = DllStructCreate($PartitionEntry, DllStructGetPtr($binaryStruct))


                For $x = 1 To $PartitionCount
                        $Partion = DllStructCreate($_PARTITION_INFORMATION_EX, DllStructGetPtr($PartitionEntry, $x))
                        If Not DllStructGetData($Partion, 'PartitionNumber') Then ContinueLoop
                        ConsoleWrite('PartitionNumber: ' & DllStructGetData($Partion, 'PartitionNumber') & @CRLF)
                        ConsoleWrite('PartitionStyle: ' & DllStructGetData($Partion, 'PartitionStyle') & @CRLF)
                        ConsoleWrite('StartingOffset: ' & DllStructGetData($Partion, 'StartingOffset') & @CRLF)
                        ConsoleWrite('PartitionLength: ' & DllStructGetData($Partion, 'PartitionLength') & @CRLF)
                        ConsoleWrite('RecognizedPartition: ' & DllStructGetData($Partion, 'RecognizedPartition') & @CRLF)
                        ConsoleWrite('PartitionType: ' & DllStructGetData($Partion, 'PartitionType') & @CRLF)
                        ConsoleWrite('BootIndicator: ' & DllStructGetData($Partion, 'BootIndicator') & @CRLF)
                        ConsoleWrite('HiddenSectors: ' & DllStructGetData($Partion, 'HiddenSectors') & @CRLF & @CRLF)
                Next

        Case 1 ;GPT
                ;GPT stuff here ...

                $data = DllStructGetData($_DRIVE_LAYOUT, "union")
                $binaryStruct = DllStructCreate('byte[8192]')
                DllStructSetData($binaryStruct, 1, $data)
                $DriveGPTInfo = DllStructCreate($DRIVE_LAYOUT_INFORMATION_GPT, DllStructGetPtr($binaryStruct))
                ConsoleWrite('Guid: ' & _BeautyGUID(DllStructGetData($DriveGPTInfo, "Guid")) & @CRLF & @CRLF)
                ConsoleWrite('StartingUsableOffset: ' & Int(DllStructGetData($DriveGPTInfo, "StartingUsableOffset")) & @CRLF)
                ConsoleWrite('UsableLength: ' & Int(DllStructGetData($DriveGPTInfo, "UsableLength")) & @CRLF)
                ConsoleWrite('MaxPartitionCount: ' & Int(DllStructGetData($DriveGPTInfo, "MaxPartitionCount")) & @CRLF & @CRLF)

                $PartitionCount = DllStructGetData($_DRIVE_LAYOUT, "PartitionCount")

                $PartitionEntry = 'byte[144];'
                For $x = 2 To $PartitionCount
                        $PartitionEntry &= 'byte[144];'
                Next
                $PartitionEntry &= 'byte[8192]'

                $data = DllStructGetData($_DRIVE_LAYOUT, "PartitionEntry")
                $binaryStruct = DllStructCreate('byte[8192]')
                DllStructSetData($binaryStruct, 1, $data)
                $PartitionEntry = DllStructCreate($PartitionEntry, DllStructGetPtr($binaryStruct))


                For $x = 1 To $PartitionCount
                        $Partion = DllStructCreate($_PARTITION_INFORMATION_EX_2, DllStructGetPtr($PartitionEntry, $x))
                        If Not DllStructGetData($Partion, 'PartitionNumber') Then ContinueLoop
                        ConsoleWrite('Name: ' & DllStructGetData($Partion, 'Name') & @CRLF)
                        ConsoleWrite('PartitionNumber: ' & DllStructGetData($Partion, 'PartitionNumber') & @CRLF)
                        ConsoleWrite('PartitionStyle: ' & DllStructGetData($Partion, 'PartitionStyle') & @CRLF)
                        ConsoleWrite('StartingOffset: ' & DllStructGetData($Partion, 'StartingOffset') & @CRLF)
                        ConsoleWrite('PartitionLength: ' & DllStructGetData($Partion, 'PartitionLength') & @CRLF)
                        ConsoleWrite('TypeGuid: ' & _BeautyGUID(DllStructGetData($Partion, 'TypeGuid')) & @CRLF)
                        ConsoleWrite('IDGuid: ' & _BeautyGUID(DllStructGetData($Partion, 'IDGuid')) & @CRLF)
                        ConsoleWrite('Attributes: ' & Int(DllStructGetData($Partion, 'Attributes')) & @CRLF & @CRLF)
                Next

        Case 2 ; RAW
                ConsoleWrite('RAW Disk - no information available' & @CRLF)

EndSwitch



Func _BeautyGUID($GUID)
        $GUID = StringLower($GUID)
        If StringLeft($GUID, 2) = '0x' Then $GUID = StringTrimLeft($GUID, 2)
        Return '{' & StringLeft($GUID, 8) & '-' & StringMid($GUID, 9, 4) & '-' & StringMid($GUID, 13, 4) & '-' & StringMid($GUID, 17, 4) & '-' & StringRight($GUID, 8) & '}'
EndFunc   ;==>_BeautyGUID



原帖地址 https://www.autoitscript.com/for ... et_drive_layout_ex/
发表于 2016-1-8 11:34:11 | 显示全部楼层
https://msdn.microsoft.com/zh-cn/library/windows/desktop/aa364003(v=vs.85).aspx
DRIVE_LAYOUT_INFORMATION_GPT structure
Contains information about a drive's GUID partition table (GPT) partitions.
Syntax

C++

typedef struct _DRIVE_LAYOUT_INFORMATION_GPT {
  GUID          DiskId;
  LARGE_INTEGER StartingUsableOffset;
  LARGE_INTEGER UsableLength;
  ULONG         MaxPartitionCount;
} DRIVE_LAYOUT_INFORMATION_GPT, *PDRIVE_LAYOUT_INFORMATION_GPT;

这参数不错,可惜不弄C++ ,虫子的出现总会带来惊喜
 楼主| 发表于 2016-1-8 15:41:34 | 显示全部楼层
回复 16# 虫子樱桃


    非常感谢,我试一试。
发表于 2016-1-8 16:06:53 | 显示全部楼层
回复 16# 虫子樱桃


    这段代码似乎和P版很像,而且好像没有P版的全面。
发表于 2016-1-8 16:43:41 | 显示全部楼层
回复 19# haijie1223


    哈哈,没见过,找的老外写的
发表于 2016-1-9 00:20:48 | 显示全部楼层
学下虫子大神的东西
发表于 2016-1-9 10:01:28 | 显示全部楼层
回复 20# 虫子樱桃


    因为没有GPT的环境,虚拟机搭建了一个。好不容易整出GPT分区。用P版的代码,完全可以胜任。老外那个在P版的代码里都包含了,而且P版的更全面。MBR,GPT硬盘完全检测出。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2016-1-9 10:04:02 | 显示全部楼层
回复 18# skyfree


    看看22楼,磁盘编号我自己加的,可能有点错误,应该是2:1,2:2,2:3
发表于 2016-1-9 14:45:56 | 显示全部楼层
回复 23# haijie1223


    没代码啊,求代码
发表于 2016-1-9 15:19:57 | 显示全部楼层
搜一下,就是P版的代码。
发表于 2016-1-9 15:20:03 | 显示全部楼层
回复 24# 虫子樱桃


   
搜一下,就是P版的代码。
发表于 2016-1-10 19:14:12 | 显示全部楼层
回复 26# haijie1223


    不晓得怎么搜,您就放个代码出来呗
发表于 2016-1-10 19:31:04 | 显示全部楼层
回复 27# 虫子樱桃


    作为金牌会员,竟然说不会搜,先鄙视一下
http://www.autoitx.com/forum.php ... 3474&highlight=
发表于 2016-1-11 15:30:24 | 显示全部楼层
学习一下
发表于 2016-1-12 22:59:28 | 显示全部楼层
非常感谢,我是新手,学习一下。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-20 05:29 , Processed in 0.077062 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表