private Object MarshalDeviceRegistryProperty(IntPtr source, Int32 length, UInt32 type) { switch (type) { case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_NONE: return(null); case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_SZ: case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_EXPAND_SZ: return(Marshal.PtrToStringAuto(source)); case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_BINARY: return(MarshalEx.ReadByteArray(source, length)); case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_DWORD: //case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_DWORD_LITTLE_ENDIAN: return((UInt32)Marshal.ReadInt32(source)); case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_DWORD_BIG_ENDIAN: return(Endianness.Swap((UInt32)Marshal.ReadInt32(source))); case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_LINK: return(Marshal.PtrToStringUni(source)); case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_MULTI_SZ: return(MarshalEx.ReadMultiSzStringList(source, length)); case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_RESOURCE_LIST: return(null); // TODO case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_FULL_RESOURCE_DESCRIPTOR: return(null); // TODO case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_RESOURCE_REQUIREMENTS_LIST: return(null); // TODO case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_QWORD: //case UsbDeviceWinApi.DeviceRegistryPropertyTypes.REG_QWORD_LITTLE_ENDIAN: return((UInt64)Marshal.ReadInt64(source)); default: return(null); } }
public static String[] ReadMultiSzStringList(IntPtr source, Int32 length) { Byte[] byteArray = MarshalEx.ReadByteArray(source, 0, length); String multiSz = Encoding.Unicode.GetString(byteArray, 0, length); List <String> strings = new List <String>(); Int32 start = 0; Int32 end = multiSz.IndexOf('\0', start); while (end > start) { strings.Add(multiSz.Substring(start, end - start)); start = end + 1; end = multiSz.IndexOf('\0', start); } return(strings.ToArray()); }
private Object MarshalDeviceProperty(IntPtr source, Int32 length, UInt32 type) { // TODO: add other types; now covers only all types that are mentioned in devpkey.h switch (type) { case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_UINT32: return((UInt32)Marshal.ReadInt32(source)); case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_GUID: return(MarshalEx.ReadGuid(source, length)); case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_FILETIME: return(MarshalEx.ReadFileTime(source)); case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_BOOLEAN: return(Marshal.ReadByte(source) != 0); case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_STRING: return(Marshal.PtrToStringUni(source)); case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_SECURITY_DESCRIPTOR: return(MarshalEx.ReadSecurityDescriptor(source, length)); case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_SECURITY_DESCRIPTOR_STRING: return(Marshal.PtrToStringUni(source)); case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_BINARY: return(MarshalEx.ReadByteArray(source, length)); case UsbDeviceWinApi.DevicePropertyTypes.DEVPROP_TYPE_STRING_LIST: return(MarshalEx.ReadMultiSzStringList(source, length)); default: return(null); } }
// TODO: not tested public static RawSecurityDescriptor ReadSecurityDescriptor(IntPtr source, Int32 length) { Byte[] byteArray = MarshalEx.ReadByteArray(source, 0, length); return(new RawSecurityDescriptor(byteArray, 0)); }
public static Guid ReadGuid(IntPtr source, Int32 length) { Byte[] byteArray = MarshalEx.ReadByteArray(source, 0, length); return(new Guid(byteArray)); }
public static Byte[] ReadByteArray(IntPtr source, Int32 length) { return(MarshalEx.ReadByteArray(source, 0, length)); }