⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enumdisk.bat

📁 KmdKit 汇编下开发驱动的工具 由俄罗斯某强男开发
💻 BAT
📖 第 1 页 / 共 2 页
字号:
	xor eax, eax
	ret					; return FALSE
	
GetRegistryProperty endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                     GetDeviceProperty                                             
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

GetDeviceProperty proc uses esi edi ebx hIntDevInfo:HDEVINFO, dwIndex:DWORD

comment ^
Routine Description:
    This routine enumerates the disk devices using the Device interface
    GUID DiskClassGuid. Gets the Adapter & Device property from the port
    driver. Then sends IOCTL through SPTI to get the device Inquiry data.

Arguments:
    hIntDevInfo	- Handles to the interface device information list
    dwIndex		- Device member 

Return Value:
	TRUE or FALSE. This decides whether to continue or not
^

local InterfaceData:SP_DEVICE_INTERFACE_DATA
local pInterfaceDetailData:PSP_DEVICE_INTERFACE_DETAIL_DATA
local StoragePropertyQuery:STORAGE_PROPERTY_QUERY
local adpDesc:PSTORAGE_ADAPTER_DESCRIPTOR
local devDesc:PSTORAGE_DEVICE_DESCRIPTOR
local hDevice:HANDLE
local cbReturned:DWORD
local cbInterfaceDetail:DWORD
local cb:DWORD
local buffer[128]:CHAR
local DataBuf[1024]:BYTE

	mov InterfaceData.cbSize, sizeof SP_DEVICE_INTERFACE_DATA

	invoke SetupDiEnumDeviceInterfaces, hIntDevInfo, 0, \
					addr GUID_DEVINTERFACE_DISK, dwIndex, addr InterfaceData

	.if eax == FALSE

		invoke GetLastError

		.if eax == ERROR_NO_MORE_ITEMS
			invoke PrintConsole, $CTA0("No more interfaces.\n\n"), 0
		.else
			invoke wsprintf, addr buffer, \
					$CTA0("SetupDiEnumDeviceInterfaces failed with error: %d\n"), eax
			invoke PrintConsole, addr buffer, 0
		.endif

		jmp ExitWithFalse
  
	.endif

	; Find out required buffer size, so pass NULL 

	and cb, 0

	invoke SetupDiGetDeviceInterfaceDetail, hIntDevInfo, \
							addr InterfaceData, NULL, 0, addr cb, NULL

	; This call returns ERROR_INSUFFICIENT_BUFFER with cb 
	; set to the required buffer size. Ignore the above error and
	; pass a bigger buffer to get the detail data

	.if eax == FALSE

		invoke GetLastError

		.if eax != ERROR_INSUFFICIENT_BUFFER

			invoke wsprintf, addr buffer, $CTA0("SetupDiGetDeviceInterfaceDetail failed with error: %d\n"), eax
			invoke PrintConsole, addr buffer, 0

			jmp ExitWithFalse

		.endif
	.endif
	
	; Allocate memory to get the interface detail data
	; This contains the devicepath we need to open the device

	mov eax, cb
	mov cbInterfaceDetail, eax

	invoke malloc, cbInterfaceDetail
	.if eax == NULL

		invoke PrintConsole, $CTA0("Unable to allocate memory to get the interface detail data.\n"), 0

		jmp ExitWithFalse

	.endif

	mov esi, eax
	assume esi:ptr SP_DEVICE_INTERFACE_DETAIL_DATA

	mov [esi].cbSize, sizeof SP_DEVICE_INTERFACE_DETAIL_DATA

	invoke SetupDiGetDeviceInterfaceDetail, hIntDevInfo, \
					addr InterfaceData, esi, cbInterfaceDetail, addr cb, NULL

	.if eax == FALSE

		invoke GetLastError

		invoke wsprintf, addr buffer, \
					$CTA0("SetupDiGetDeviceInterfaceDetail failed with error: %d\n"), eax
		invoke PrintConsole, addr buffer, 0

		invoke free, esi

		jmp ExitWithFalse
  
	.endif

	; Now we have the device path. Open the device interface
	; to send Pass Through command

	invoke wsprintf, addr buffer, $CTA0("Interface: %s\n"), addr [esi].DevicePath
	invoke PrintConsole, addr buffer, 0

	invoke CreateFile, addr [esi].DevicePath, GENERIC_READ + GENERIC_WRITE, \
						FILE_SHARE_READ + FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL
	mov hDevice, eax

	; We have the handle to talk to the device. 
	; So we can release the InterfaceDetailData buffer

	invoke free, esi
	assume esi:nothing

	.if hDevice == INVALID_HANDLE_VALUE

		invoke GetLastError

		invoke wsprintf, addr buffer, $CTA0("CreateFile failed with error: %d\n"), eax
		invoke PrintConsole, addr buffer, 0

		jmp ExitWithTrue
  
	.endif

	mov StoragePropertyQuery.PropertyId, StorageAdapterProperty
	mov StoragePropertyQuery.QueryType, PropertyStandardQuery

	invoke DeviceIoControl, hDevice, IOCTL_STORAGE_QUERY_PROPERTY, \
						addr StoragePropertyQuery, sizeof STORAGE_PROPERTY_QUERY, \
						addr DataBuf, sizeof DataBuf, addr cbReturned, NULL                    

	.if eax == 0

		invoke GetLastError

		invoke wsprintf, addr buffer, $CTA0("DeviceIoControl failed with error: %d\n"), eax
		invoke PrintConsole, addr buffer, 0

	.else

		lea esi, DataBuf
		assume esi:ptr STORAGE_ADAPTER_DESCRIPTOR

		invoke PrintConsole, $CTA0("\nAdapter Properties\n"), 0
		invoke PrintConsole, $CTA0("------------------\n"), 0

		movzx eax, [esi].BusType
		shl eax, 2					; * sizeof LPSTR
		invoke wsprintf, addr buffer, $CTA0("Bus Type       : %s\n"), g_apszBusType[eax]
		invoke PrintConsole, addr buffer, 0

		invoke wsprintf, addr buffer, $CTA0("Max. Tr. Length: 0x%x\n"), [esi].MaximumTransferLength
		invoke PrintConsole, addr buffer, 0

		invoke wsprintf, addr buffer, $CTA0("Max. Phy. Pages: 0x%x\n"), [esi].MaximumPhysicalPages
		invoke PrintConsole, addr buffer, 0
		
		invoke wsprintf, addr buffer, $CTA0("Alignment Mask : 0x%x\n"), [esi].AlignmentMask
		invoke PrintConsole, addr buffer, 0

		assume esi:nothing

		mov StoragePropertyQuery.PropertyId, StorageDeviceProperty
		mov StoragePropertyQuery.QueryType, PropertyStandardQuery

		invoke DeviceIoControl, hDevice, IOCTL_STORAGE_QUERY_PROPERTY, addr StoragePropertyQuery, \
							sizeof STORAGE_PROPERTY_QUERY, addr DataBuf, sizeof DataBuf, addr cbReturned, NULL                    

		.if eax == 0

			invoke GetLastError

			invoke wsprintf, addr buffer, $CTA0("DeviceIoControl failed with error: %d\n"), eax
			invoke PrintConsole, addr buffer, 0

		.else

			invoke PrintConsole, $CTA0("\nDevice Properties\n"), 0
			invoke PrintConsole, $CTA0("-----------------\n"), 0

			lea esi, DataBuf
			assume esi:ptr STORAGE_DEVICE_DESCRIPTOR
		
			; Our device table can handle only 16 devices.

			mov eax, g_cbDeviceType
			shr eax, 2						; / sizeof LPSTR
			.if [esi].DeviceType > al
                mov ecx, 0Fh
			.else
				movzx ecx, [esi].DeviceType
			.endif

			invoke wsprintf, addr buffer, $CTA0("Device Type     : %s (0x%X)\n"), g_apszDeviceType[ecx*sizeof LPSTR], ecx
			invoke PrintConsole, addr buffer, 0

			movzx ecx, [esi].DeviceTypeModifier
			.if [esi].DeviceTypeModifier
				invoke wsprintf, addr buffer, $CTA0("Device Modifier : 0x%x\n"), ecx
				invoke PrintConsole, addr buffer, 0
			.endif

			.if [esi].RemovableMedia
				mov ecx, $CTA0("Yes")
			.else
				mov ecx, $CTA0("No")
			.endif

			invoke wsprintf, addr buffer, $CTA0("Removable Media : %s\n"), ecx
			invoke PrintConsole, addr buffer, 0

			mov ebx, [esi].VendorIdOffset
			mov al, byte ptr [esi+ebx]
			.if ebx  &&  al != NULL
				invoke PrintConsole, $CTA0("Vendor ID       : "), 0

				.while ebx < cbReturned

					.break .if byte ptr [esi+ebx] == NULL

					movzx ecx, byte ptr [esi+ebx]
					invoke wsprintf, addr buffer, $CTA0("%c"), ecx
					invoke PrintConsole, addr buffer, 0
			
					inc ebx
				.endw

				invoke PrintConsole, $CTA0("\n"), 0
			.endif			

			mov ebx, [esi].ProductIdOffset
			mov al, byte ptr [esi+ebx]
			.if ebx &&  al != NULL

				invoke PrintConsole, $CTA0("Product ID      : "), 0

				.while ebx < cbReturned

					.break .if byte ptr [esi+ebx] == NULL

					movzx ecx, byte ptr [esi+ebx]
					invoke wsprintf, addr buffer, $CTA0("%c"), ecx
					invoke PrintConsole, addr buffer, 0
			
					inc ebx
				.endw

				invoke PrintConsole, $CTA0("\n"), 0
			.endif
			
			mov ebx, [esi].ProductRevisionOffset
			mov al, byte ptr [esi+ebx]
			.if ebx  &&  al != NULL

				invoke PrintConsole, $CTA0("Product Revision: "), 0

				.while ebx < cbReturned

					.break .if byte ptr [esi+ebx] == NULL

					movzx ecx, byte ptr [esi+ebx]
					invoke wsprintf, addr buffer, $CTA0("%c"), ecx
					invoke PrintConsole, addr buffer, 0
			
					inc ebx
				.endw

				invoke PrintConsole, $CTA0("\n"), 0
			.endif

			mov ebx, [esi].SerialNumberOffset
			mov al, byte ptr [esi+ebx]
			.if ebx  &&  al != NULL

				invoke PrintConsole, $CTA0("Serial Number   : "), 0

				.while ebx < cbReturned

					.break .if byte ptr [esi+ebx] == NULL

					movzx ecx, byte ptr [esi+ebx]
					invoke wsprintf, addr buffer, $CTA0("%c"), ecx
					invoke PrintConsole, addr buffer, 0
			
					inc ebx
				.endw

				invoke PrintConsole, $CTA0("\n"), 0
			.endif
		.endif
	.endif

	; Close handle the device

	invoke CloseHandle, hDevice

ExitWithTrue:
	xor eax, eax
	inc eax
	ret					; return TRUE

ExitWithFalse:
	xor eax, eax
	ret					; return FALSE

GetDeviceProperty endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                       start                                                       
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

start proc uses esi edi ebx

local buffer[128]:BYTE
local hDevInfo:HDEVINFO
local hIntDevInfo:HDEVINFO
    
	invoke GetStdHandle, STD_OUTPUT_HANDLE
	.if eax != INVALID_HANDLE_VALUE

		mov g_hConsoleOutput, eax

		invoke PrintConsole, $CTA0("\nEnumDisk - Enumerates all the disk devices\n\n"), \
											FOREGROUND_BLUE + FOREGROUND_INTENSITY

		; Get device information set that contains all devices present on system

		invoke SetupDiGetClassDevs, addr GUID_DEVCLASS_DISKDRIVE, NULL, NULL, DIGCF_PRESENT 
		.if eax != INVALID_HANDLE_VALUE

			mov hDevInfo, eax

			; Get the interface device information set that contains all devices present on system

			invoke SetupDiGetClassDevs, addr GUID_DEVINTERFACE_DISK, \
                 			NULL, NULL, DIGCF_PRESENT + DIGCF_DEVICEINTERFACE

			.if eax != INVALID_HANDLE_VALUE

				mov hIntDevInfo, eax

				; Enumerate all the disk devices

				xor ebx, ebx
				.while TRUE 

					mov eax, ebx
					inc eax				; make it one-based
					invoke wsprintf, addr buffer, $CTA0("\n\n### Properties for Device %d ###\n"), eax
					invoke PrintConsole, addr buffer, 0
				
					invoke GetRegistryProperty, hDevInfo, ebx
					.break .if eax == FALSE

					invoke GetDeviceProperty, hIntDevInfo, ebx
					.break .if eax == FALSE

					inc ebx

				.endw
    
				invoke PrintConsole, $CTA0("\n\n### End of Device List ###\n"), 0

				invoke SetupDiDestroyDeviceInfoList, hIntDevInfo
			
			.else
				invoke PrintConsole, $CTA0("Error: Can't get interface device information set\n"), 0
			.endif

			invoke SetupDiDestroyDeviceInfoList, hDevInfo
    
		.else
			invoke PrintConsole, $CTA0("Error: Can't get device information set.\n"), 0
		.endif

	.else
		invoke MessageBox, NULL, $CTA0("Can't get console standard output handle."), \
											NULL, MB_OK + MB_ICONERROR
	.endif

	invoke ExitProcess, 0

start endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                                                                                   
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

end start

:make

set exe=EnumDisk

\masm32\bin\ml /nologo /c /coff %exe%.bat
\masm32\bin\link /nologo /out:%exe%.exe /subsystem:console %exe%.obj

del %exe%.obj

echo.
pause
exit

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -