Модератор: BV
MIT писал(а):Странный серийник какой-то:
SSecurity писал(а):Могу ошибаться, но что-то подобное видел в реестре, когда искал привязку локальных папок на расшаренные ресурсы компа.
jangle писал(а): Если у кого будет желание и время, можете перевести этот код на Visual Basic. Исходник прилагается.
Там все относительно прозрачно, думаю сложностей не будет.
Union unionTS
Cdb(0 To 15) As Byte
buffer(0 To 127) As Byte
Cmd As TCmd
USB As TCmdUSB
End Union
aleksmir писал(а):Подскажите - типы данных Word и dWord - чему эквивалентны в VB5/6?
Ещё... - как синтаксисом VB5/6 описать эти строки:
- Код: Выделить всё
Union unionTS
Cdb(0 To 15) As Byte
buffer(0 To 127) As Byte
Cmd As TCmd
USB As TCmdUSB
End Union
union = type.
Хакер писал(а):union = type.
Точно?
Хакер писал(а):А что за язык-то?
Хакер писал(а):Ну надо в его мануале и смотреть. Если там union имеет такой же смысл, как и в C, то Type не подходит.
iGrok писал(а):Но посмотри на описание этого union'а. Чем он ещё может быть?
UNION Arrs
a1(1 TO 1024) AS BYTE
st AS ASCIIZ * 10
END UNION
FUNCTION PBMAIN
DIM a AS Arrs
a.a1(1) = 72
a.a1(2) = 101
a.a1(3) = 108
a.a1(4) = 108
a.a1(5) = 111
a.a1(6) = 33
' At this point, a.st contains "Hello!"
END FUNCTION
alibek писал(а):Если судить по этому примеру (с сайта PowerBASIC):
...
UNION ничего общего с UDT в VB6 не имеет.
iGrok писал(а):...
Тогда этот кусок не получится перевести "в лоб". Надо смотреть, где и как этот union используется.
Option Explicit
Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice&, ByVal dwIoControlCode&, lpInBuffer As Any, ByVal nInBufferSize&, ipOutBuffer As Any, ByVal nOutBufferSize&, lpBytesReturned As Long, Optional ByVal lpOverlapped&) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Any, ByVal source As Any, ByVal Length&)
Type OVERLAPPED
Internal As Long
InternalHigh As Long
offset As Long
OffsetHigh As Long
hEvent As Long
End Type
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
Const FILE_SHARE_READ = &H1
Const FILE_SHARE_WRITE = &H2
Const OPEN_EXISTING = 3
Const INVALID_HANDLE_VALUE = -1
Const MAX_PATH = 260
'***********************************************************************
Global hPort As Long
Global SA As SECURITY_ATTRIBUTES
Global usbSerialCodes As String
Global LanguageIdS() As Integer
Const METHOD_BUFFERED = 0
Const FILE_ANY_ACCESS = 0
Const FILE_DEVICE_UNKNOWN = 34
Const FILE_DEVICE_USB = FILE_DEVICE_UNKNOWN
Const USB_CONFIGURATION_DESCRIPTOR_TYPE = 2
Const USB_STRING_DESCRIPTOR_TYPE = 3
Const USB_REQUEST_GET_DESCRIPTOR = 6
Const MAXIMUM_USB_STRING_LENGTH = 255
Const USB_GET_NODE_INFORMATION = 258
Const USB_GET_NODE_CONNECTION_INFORMATION = 259
Const USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION = 260
Const USB_GET_NODE_CONNECTION_NAME = 261
Const HCD_GET_ROOT_HUB_NAME = 258
Const HCD_GET_DRIVERKEY_NAME = 265
Const DEVICECONNECTED = 1
Global IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION As Long
Global IOCTL_USB_GET_NODE_CONNECTION_INFORMATION As Long
Global IOCTL_USB_GET_NODE_CONNECTION_NAME As Long
Global IOCTL_USB_GET_NODE_INFORMATION As Long
Global IOCTL_GET_HCD_DRIVERKEY_NAME As Long
Global IOCTL_USB_GET_ROOT_HUB_NAME As Long
Type USB_STRING_DESCRIPTOR 'Ok! Мои художества :)
bLength As Byte 'Size of Descriptor in Bytes
bDescriptorType As Byte 'Constant, string Descriptor (0x03)
bString(1 To MAXIMUM_USB_STRING_LENGTH - 2) As Byte
End Type
Type USB_DEVICE_DESCRIPTOR 'Ok!(18) 'Packet.Data 1 - USB_CONFIGURATION_DESCRIPTOR_TYPE
bLength As Byte 'Specifies the length, in bytes, of this descriptor.
bDescriptorType As Byte 'Specifies the descriptor type. Must be set to USB_DEVICE_DESCRIPTOR_TYPE (1).
bcdUSB As Integer 'Identifies the version of the USB specification that this descriptor structure complies with. This value is a binary-coded decimal number.
bDeviceClass As Byte 'Specifies the class code of the device as assigned by the USB specification group.
bDeviceSubClass As Byte 'Specifies the subclass code of the device as assigned by the USB specification group.
bDeviceProtocol As Byte 'Specifies the protocol code of the device as assigned by the USB specification group.
bMaxPacketSize0 As Byte 'Specifies the maximum packet size, in bytes, for endpoint zero of the device. The value must be set to 8, 16, 32, or 64.
idVendor As Integer 'Specifies the vendor identifier for the device as assigned by the USB specification committee.
idProduct As Integer 'Specifies the product identifier. This value is assigned by the manufacturer and is device-specific.
bcdDevice As Integer 'Identifies the version of the device. This value is a binary-coded decimal number.
iManufacturer As Byte 'Specifies a device-defined index of the string descriptor that provides a string containing the name of the manufacturer of this device.
iProduct As Byte 'Specifies a device-defined index of the string descriptor that provides a string that contains a description of the device.
iSerialNumber As Byte 'Specifies a device-defined index of the string descriptor that provides a string that contains a manufacturer-determined serial number for the device.
bNumConfigurations As Byte 'Specifies the total number of possible configurations for the device.
End Type
Type USB_CONFIGURATION_DESCRIPTOR '+;9(!) 'Packet.Data 2 - USB_CONFIGURATION_DESCRIPTOR_TYPE
bLength As Byte 'Size, in bytes, of this structure.
bDescriptorType As Byte 'Constant value %CONFIGURATION.
wTotalLength As Integer 'Total length of data returned for this configuration. This includes the combined length of all structures — USB_CONFIGURATION_DESCRIPTOR, USB_INTERFACE,
'USB_ENDPOINT_DESCRIPTOR and any class or vendor-specific structures — returned as part of the configuration information.
bNumInterfaces As Byte 'Number of interfaces supported as part of this configuration.
bConfigurationValue As Byte 'Configuration's value, used when the USB system software of a USB device driver requests this configuration.
iConfiguration As Byte 'Index of a string descriptor describing this configuration.
bmAttributes As Byte 'Eight bits of configuration characteristics. Bits zero to four are reserved and should be zero (0). If bit five is set to 1, this configuration supports remote wakeup. If bit six is set to 1,
'then in this configuration the USB device uses power both from the bus and from an external source, such as a battery or wall socket. The MaxPower member gives the amount of bus power required during usual operation.
MaxPower As Byte 'Amount of power required in this configuration when the USB device is fully operational, expressed in units of 2 milliamps. For example, a value of 50 represents power consumption of 100 mA.
'This member is used if the bmAttributes member indicates that the device requires bus power.
End Type
Type USB_INTERFACE_DESCRIPTOR '+;9(!) 'Packet.Data 4 - USB_CONFIGURATION_DESCRIPTOR_TYPE
bLength As Byte 'Length, in bytes, of this structure.
bDescriptorType As Byte 'Constant value INTERFACE.
bInterfaceNumber As Byte 'Interface's number. This value is a zero-based index into an array of interfaces supported by the relevant configuration.
bAlternateSetting As Byte 'Value used to select an alternate setting for the interface identified in bInterfaceNumber.
bNumEndpoints As Byte 'Number of endpoints used by this interface, excluding endpoint zero (0). If this value is zero (0), the interface only uses the default control pipe.
bInterfaceClass As Byte 'Interface class code. The USB working group defines class codes. The value 0xFF represents a vendor-specific class code.
bInterfaceSubClass As Byte 'Interface subclass code. The USB working group defines subclass codes. The meaning of this member depends on the value of bInterfaceClass.
bInterfaceProtocol As Byte 'Interface protocol code. The USB working group defines protocol codes. The value 0xFF indicates a vendor-specific protocol code.
iInterface As Byte 'Index of a string descriptor describing this interface.
End Type
Type Word2Bytes 'Добавил
Lo As Byte
Hi As Byte
End Type
Type USB_ENDPOINT_DESCRIPTOR '+;7(!) 'Packet.Data 5 - USB_CONFIGURATION_DESCRIPTOR_TYPE
bLength As Byte 'Specifies the length, in bytes, of this descriptor.
bDescriptorType As Byte 'Specifies the descriptor type. Must be set to USB_ENDPOINT_DESCRIPTOR_TYPE.
bEndpointAddress As Byte 'Specifies the USB-defined endpoint address. The four low-order bits specify the endpoint number. The high-order bit specifies the direction of data flow on this endpoint: 1 for in, 0 for out.
bmAttributes As Byte 'The two low-order bits specify the endpoint type, one of USB_ENDPOINT_TYPE_CONTROL, USB_ENDPOINT_TYPE_ISOCHRONOUS, USB_ENDPOINT_TYPE_BULK, or USB_ENDPOINT_TYPE_INTERRUPT.
wMaxPacketSize As Word2Bytes 'Integer 'Specifies the maximum packet size that can be sent from or to this endpoint.
bInterval As Byte 'For interrupt endpoints, bInterval contains the polling interval. For other types of endpoint, this value should be ignored. This value reflects the device's configuration in firmware. Drivers cannot change it.
End Type
Type USB_COMMON_DESCRIPTOR 'Ok! Packet.Data header - USB_CONFIGURATION_DESCRIPTOR_TYPE
bLength As Byte 'Lenght in bytes of the descriptor.
bDescriptorType As Byte 'The descriptor type. 1 for USB_DEVICE_DESCRIPTOR, 2 for USB_CONFIGURATION_DESCRIPTOR, 4 for USB_INTERFACE_DESCRIPTOR, 5 for USB_ENDPOINT_DESCRIPTOR, 33 for HID_DESCRIPTOR.
End Type
Type w_Value 'Добавил
DescriptorIndex As Byte
DescriptorType As Byte
End Type
Type SETUP_PACKET 'Ok!
bmRequest As Byte 'The type of USB device request, standard, class, or vendor
bRequest As Byte '0x06 value indicates a request of GET_DESCRIPTOR.
wValue As w_Value 'Type of descriptor to retrieve in the high byte of wValue and the descriptor index in the low byte.
wIndex As Integer 'The device-specific index of the descriptor that is to be retrieved.
wLength As Integer 'The length of the data that is transferred during the second phase of the control transfer.
End Type
Type USB_DESCRIPTOR_REQUEST 'Ok;-!!!
ConnectionIndex As Long 'The port whose descriptors are retrieved.
SetupPacket As SETUP_PACKET 'See SETUP_PACKET type.
Data(1 To MAXIMUM_USB_STRING_LENGTH) As Byte ' As String * 'On output from the IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION I/O control request, this member contains the retrieved descriptors.
End Type
Type USB_HUB_DESCRIPTOR 'Ok (Испр.)
bDescriptorLength As Byte 'The length, in bytes of the descriptor.
bDescriptorType As Byte 'The descriptor type. For hub descriptors, this value should be 0x29.
bNumberOfPorts As Byte 'The number of ports on the hub.
'wHubCharacteristics As WORD 'The hub characteristics. For more information about this member, see Universal Serial Bus Specification.
wHubCharacteristics_Hi As Byte
wHubCharacteristics_Lo As Byte
bPowerOnToPowerGood As Byte 'The time, in 2-millisecond intervals, that it takes the device to turn on completely. For more information about this member, see Universal Serial Bus Specification.
bHubControlCurrent As Byte 'The maximum current requirements, in milliamperes, of the controller component of the hub.
bRemoveAndPowerMask As String * 65 'Not currently implemented. Do not use this member. This member implements DeviceRemovable and PortPwrCtrlMask fields of the hub descriptor. For more information about these fields, see Universal Serial Bus
End Type
Type USB_HUB_NODE 'Ok
UsbHub As Integer 'Indicates that the device is a hub.
UsbMIParent As Integer 'Indicates that the device is a composite device with multiple interfaces.
End Type
Type USB_HUB_INFORMATION 'Ok
HubDescriptor As USB_HUB_DESCRIPTOR 'A USB_HUB_DESCRIPTOR structure that contains selected information from the hub descriptor.
HubIsBusPowered As Long 'A Boolean value that indicates whether the hub is powered. If TRUE, the hub is powered. If FALSE, the hub is not powered.
End Type
Type USB_MI_PARENT_INFORMATION 'Ok
NumberOfInterfaces As Long 'The number of interfaces on the composite device.
End Type
'Union USB_NODE_INFORMATION_UNION
' HubInformation As USB_HUB_INFORMATION 'A USB_HUB_INFORMATION structure that contains information about a parent hub device.
' MiParentInformation As USB_MI_PARENT_INFORMATION 'A USB_MI_PARENT_INFORMATION structure that contains information about a parent non-hub, composite device.
'END UNION
Type USB_NODE_INFORMATION 'Ok
NodeType As USB_HUB_NODE 'A USB_HUB_NODE enumerator that indicates whether the parent device is a hub or a non-hub composite device.
'USB_NODE_INFORMATION_UNION 'See USB_NODE_INFORMATION_UNION union
HubInformation As USB_HUB_INFORMATION 'A USB_HUB_INFORMATION structure that contains information about a parent hub device.
MiParentInformation As USB_MI_PARENT_INFORMATION 'A USB_MI_PARENT_INFORMATION structure that contains information about a parent non-hub, composite device.
End Type
Type USB_HCD_DRIVERKEY_NAME 'Ok;-!!!
ActualLength As Integer 'The length, in bytes, of the string in the DriverKeyName member.
DriverKeyName As String * MAXIMUM_USB_STRING_LENGTH 'wChar array, a NULL-terminated Unicode driver key name for the USB host controller.
End Type
Type USB_NODE_CONNECTION_NAME 'Ok;-!!!
ConnectionIndex As Long 'A value that is greater than or equal to 1 that specifies the number of the port to which the hub is attached.
ActualLength As Long 'The length, in bytes, of the attached hub's symbolic link.
Name As String * MAXIMUM_USB_STRING_LENGTH 'A Unicode symbolic link for the downstream hub that is attached to the port that is indicated by ConnectionIndex.
End Type
Type USB_PIPE_INFO '!!! (Вроде исправил)
EndpointDescriptor As USB_ENDPOINT_DESCRIPTOR 'See USB_ENDPOINT_DESCRIPTOR type
ScheduleOffset(0 To 3) As Byte 'DWORD 'Indicates the schedule offset assigned to the endpoint for this pipe.
End Type
Type USB_NODE_CONNECTION_INFORMATION '!!!
ConnectionIndex As Long 'A value that is greater than or equal to 1 that specifies the number of the port.
DeviceDescriptor As USB_DEVICE_DESCRIPTOR 'A USB_DEVICE_DESCRIPTOR structure that reports the USB device descriptor that is returned by the attached device during enumeration.
CurrentConfigurationValue As Byte 'Value used with SetConfiguration request to specify that current configuration of the device that is connected to the indicated port. See Universal Serial Bus Specification.
LowSpeed As Byte 'If TRUE, the port and its connected device are currently operating at a low speed.
DeviceIsHub As Byte 'Value that indicates if the device that is attached to the port is a hub. If TRUE, the device that is attached to the port is a hub. If FALSE, the device is not a hub.
DeviceAddress(0 To 1) As Byte 'WORD 'The USB-assigned, bus-relative address of the device that is attached to the port.
NumberOfOpenPipes(0 To 3) As Byte 'DWORD 'The number of open USB pipes that are associated with the port.
ConnectionStatus(0 To 3) As Byte 'DWORD 'A USB_CONNECTION_STATUS-typed enumerator that indicates the connection status.
PipeList(1 To 32) As USB_PIPE_INFO 'An array of USB_PIPE_INFO structures that describes the open pipes that are associated with the port.
End Type
'______________________________________________________________________________
Sub Init()
IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION = CTL_Code(FILE_DEVICE_USB, USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, METHOD_BUFFERED, FILE_ANY_ACCESS)
IOCTL_USB_GET_NODE_CONNECTION_INFORMATION = CTL_Code(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_INFORMATION, METHOD_BUFFERED, FILE_ANY_ACCESS)
IOCTL_USB_GET_NODE_CONNECTION_NAME = CTL_Code(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_NAME, METHOD_BUFFERED, FILE_ANY_ACCESS)
IOCTL_USB_GET_NODE_INFORMATION = CTL_Code(FILE_DEVICE_USB, USB_GET_NODE_INFORMATION, METHOD_BUFFERED, FILE_ANY_ACCESS)
IOCTL_GET_HCD_DRIVERKEY_NAME = CTL_Code(FILE_DEVICE_USB, HCD_GET_DRIVERKEY_NAME, METHOD_BUFFERED, FILE_ANY_ACCESS)
IOCTL_USB_GET_ROOT_HUB_NAME = CTL_Code(FILE_DEVICE_USB, HCD_GET_ROOT_HUB_NAME, METHOD_BUFFERED, FILE_ANY_ACCESS)
'Reset SA
SA.nLength = Len(SA)
End Sub
'______________________________________________________________________________
Function CTL_Code&(ByVal dwDeviceType As Long, ByVal dwFunction As Long, _
ByVal dwMethod As Long, ByVal dwAccess As Long) 'Thank to Erwin van de Wiel
dwDeviceType = SHL(dwDeviceType, 16) 'xxxxxxxxxxxxxxxx---------------- 16 bits
dwAccess = SHL(dwAccess, 14) '----------------xx-------------- 2 bits
dwFunction = SHL(dwFunction, 2) '------------------xxxxxxxxxxxx-- 12 bits
'Method '------------------------------xx 2 bits
CTL_Code = dwDeviceType Or dwAccess Or dwFunction Or dwMethod
End Function
'______________________________________________________________________________
Function usbDeviceLanguageId(hHub&, PortIndex&) As Long
Dim Request As USB_DESCRIPTOR_REQUEST
Dim UsbLanguageId As USB_COMMON_DESCRIPTOR 'POINTER
Dim zLanguage As String * MAX_PATH 'ASCIIZ
Dim BytesReturned As Long 'DWORD
Dim Success As Long
If UBound(LanguageIdS) = 0 Then 'Get the languages ids
Request.ConnectionIndex = PortIndex
Request.SetupPacket.bmRequest = &H80
Request.SetupPacket.bRequest = USB_REQUEST_GET_DESCRIPTOR
Request.SetupPacket.wValue.DescriptorType = USB_STRING_DESCRIPTOR_TYPE 'MAK...
Request.SetupPacket.wLength = MAXIMUM_USB_STRING_LENGTH
Success = DeviceIoControl(hHub, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, Request, _
Len(Request), Request, Len(Request), BytesReturned, 0)
If Success Then
CopyMemory VarPtr(UsbLanguageId), VarPtr(Request.Data(1)), Len(UsbLanguageId) 'pUsbLanguageId = VarPtr(Request.Data)
If UsbLanguageId.bDescriptorType = 3 Then 'Constant, string Descriptor = 3
ReDim LanguageIdS(0 To (UsbLanguageId.bLength \ 2) - 1) 'AS WORD AT VARPTR(Request.DATA) + 2
CopyMemory VarPtr(LanguageIdS(1)), VarPtr(Request.Data(1)) + 2, UBound(LanguageIdS) * 2
End If
End If
End If
End Function
'______________________________________________________________________________
Function usbDeviceString(hHub&, PortIndex As Long, Index As Byte) As String
Dim Request As USB_DESCRIPTOR_REQUEST
Dim pBuffer As USB_COMMON_DESCRIPTOR 'POINTER
Dim sBuffer As String
Dim BytesReturned&, Success&, i&
usbDeviceLanguageId hHub, PortIndex
For i = 0 To UBound(LanguageIdS) 'Перебираем все доступные языки, включая Neytral(0)
Request.SetupPacket.wIndex = LanguageIdS(i) 'в надежде получить данные хоть на каком-то.
Request.ConnectionIndex = PortIndex
Request.SetupPacket.bmRequest = &H80
Request.SetupPacket.bRequest = USB_REQUEST_GET_DESCRIPTOR
Request.SetupPacket.wValue.DescriptorType = USB_STRING_DESCRIPTOR_TYPE
Request.SetupPacket.wValue.DescriptorIndex = Index
Request.SetupPacket.wLength = MAXIMUM_USB_STRING_LENGTH
Success = DeviceIoControl(hHub, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, Request, _
Len(Request), Request, Len(Request), BytesReturned, 0)
If Success Then
CopyMemory VarPtr(pBuffer), VarPtr(Request.Data(1)), Len(pBuffer)
sBuffer = Request.Data
sBuffer = Mid(sBuffer, 2, pBuffer.bLength / 2 - 1)
usbDeviceString = Trim(sBuffer)
If Len(usbDeviceString) Then Exit For
End If
Next i
End Function
'______________________________________________________________________________
Function usbDeviceInfo&(hHub&, PortIndex&, pBuffer As USB_DEVICE_DESCRIPTOR)
Dim sManufacturer As String
Dim sProduct As String
Dim iSerialNumber As String
ReDim LanguageIdS(0)
sManufacturer = usbDeviceString(hHub, PortIndex, pBuffer.iManufacturer)
sProduct = usbDeviceString(hHub, PortIndex, pBuffer.iProduct)
iSerialNumber = usbDeviceString(hHub, PortIndex, pBuffer.iSerialNumber)
usbSerialCodes = usbSerialCodes & sProduct & " (" & sManufacturer & "); S/N: " & iSerialNumber & vbCrLf
End Function
'______________________________________________________________________________
Function usbPortEnum(hHub&, PortCount As Byte) As Long
Dim ConnectionInformation As USB_NODE_CONNECTION_INFORMATION
Dim NodeInformation As USB_NODE_INFORMATION
Dim NodeConnection As USB_NODE_CONNECTION_NAME
Dim NodeConnectionName As String 'ASCIIZ * MAXIMUM_USB_STRING_LENGTH
Dim sData As String
Dim hNodeConnection As Long
Dim BytesReturned As Long
Dim Success As Long
Dim ConnectionStatus As Long
Dim PortIndex As Long
For PortIndex = 1 To PortCount '
ConnectionInformation.ConnectionIndex = PortIndex
Success = DeviceIoControl(hHub, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION, _
ByVal VarPtr(ConnectionInformation), Len(ConnectionInformation), _
ByVal VarPtr(ConnectionInformation), Len(ConnectionInformation), _
BytesReturned, 0)
If Success Then
CopyMemory VarPtr(ConnectionStatus), VarPtr(ConnectionInformation.ConnectionStatus(0)), 4
If ConnectionStatus = DEVICECONNECTED Then
If ConnectionInformation.DeviceIsHub Then
NodeConnection.ConnectionIndex = PortIndex
Success = DeviceIoControl(hHub, IOCTL_USB_GET_NODE_CONNECTION_NAME, NodeConnection, _
Len(NodeConnection), NodeConnection, Len(NodeConnection), _
BytesReturned, 0)
If Success Then
NodeConnectionName = Mid(NodeConnection.Name, 2, NodeConnection.ActualLength / 2 - 2)
sData = Mid$(sData, 1 + InStr(sData, ";"))
NodeConnectionName = "\\.\" & NodeConnectionName
hNodeConnection = CreateFile(NodeConnectionName, GENERIC_READ, FILE_SHARE_READ, SA, OPEN_EXISTING, 0, 0)
Success = DeviceIoControl(hNodeConnection, IOCTL_USB_GET_NODE_INFORMATION, _
NodeInformation, Len(NodeInformation), NodeInformation, _
Len(NodeInformation), BytesReturned, 0)
If Success Then
usbDeviceInfo hHub, PortIndex, ConnectionInformation.DeviceDescriptor
usbPortEnum hNodeConnection, NodeInformation.HubInformation.HubDescriptor.bNumberOfPorts
End If
CloseHandle hNodeConnection
End If
Else
usbDeviceInfo hHub, PortIndex, ConnectionInformation.DeviceDescriptor
End If
End If
End If
Next
End Function
'______________________________________________________________________________
Function usbHostControllerInfo&(hHostController&)
Dim NodeInformation As USB_NODE_INFORMATION
Dim DriverKeyName As USB_HCD_DRIVERKEY_NAME
Dim RootHubName As String 'ASCIIZ * %MAXIMUM_USB_STRING_LENGTH 'RootHubName must start with "\\.\"
Dim SystemName As String
Dim hRootHub As Long
Dim BytesReturned As Long
Dim Success As Long
Success = DeviceIoControl(hHostController, IOCTL_GET_HCD_DRIVERKEY_NAME, ByVal VarPtr(DriverKeyName), _
Len(DriverKeyName), ByVal VarPtr(DriverKeyName), Len(DriverKeyName), _
BytesReturned, 0)
If Success Then
SystemName = Mid(DriverKeyName.DriverKeyName, 2, (DriverKeyName.ActualLength - 2) / 2)
Success = DeviceIoControl(hHostController, IOCTL_USB_GET_ROOT_HUB_NAME, ByVal VarPtr(DriverKeyName), _
Len(DriverKeyName), ByVal VarPtr(DriverKeyName), Len(DriverKeyName), _
BytesReturned, 0)
If Success Then
RootHubName = Mid(DriverKeyName.DriverKeyName, 2, DriverKeyName.ActualLength / 2)
RootHubName = "\\.\" & RootHubName
hRootHub = CreateFile(RootHubName, GENERIC_READ, FILE_SHARE_READ, _
SA, OPEN_EXISTING, 0, 0)
If hRootHub <> INVALID_HANDLE_VALUE Then
Success = DeviceIoControl(hRootHub, IOCTL_USB_GET_NODE_INFORMATION, ByVal VarPtr(NodeInformation), _
Len(NodeInformation), ByVal VarPtr(NodeInformation), Len(NodeInformation), _
BytesReturned, 0)
If Success Then
usbPortEnum hRootHub, NodeInformation.HubInformation.HubDescriptor.bNumberOfPorts
CloseHandle hRootHub
End If
End If
End If
End If
End Function
'_______________
Function usbHostControllerEnum() As Long
Dim HostControllerName As String
Dim hHostController As Long
Dim Looper As Long
HostControllerName = "\\.\HCDx"
For Looper = 0 To 9
Mid$(HostControllerName, 8, 1) = Chr$(Looper + 48) '"\\.\HCD0" to "\\.\HCD9"
hHostController = CreateFile(HostControllerName, GENERIC_READ, FILE_SHARE_READ, SA, OPEN_EXISTING, 0, 0)
If Err.LastDllError = 0 And (hHostController <> INVALID_HANDLE_VALUE) Then
usbHostControllerInfo hHostController
CloseHandle hHostController
End If
Next
End Function
Sub Main()
Init
usbHostControllerEnum
MsgBox usbSerialCodes
End Sub
Хакер писал(а):Что за ернел?
0xy писал(а):Исправил (это было для отладки).
Хакер писал(а):0xy писал(а):Исправил (это было для отладки).
Вот уж интересно, как это можно было использовать для отладки?
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 7