public static ReadOnlyCollection <USBController> GetHostControllers() { List <USBController> list = new List <USBController>(); Guid guid = new Guid("3abf6f2d-71c4-462a-8a92-1e6861e6af27"); IntPtr deviceInfoSet = Acer_USB_Library.SetupDiGetClassDevs(ref guid, 0, IntPtr.Zero, 18); if (deviceInfoSet.ToInt32() != -1) { IntPtr intPtr = Marshal.AllocHGlobal(2048); int num = 0; bool flag; do { USBController uSBController = new USBController(); uSBController.ControllerIndex = num; SP_DEVICE_INTERFACE_DATA structure = default(SP_DEVICE_INTERFACE_DATA); structure.cbSize = Marshal.SizeOf(structure); flag = Acer_USB_Library.SetupDiEnumDeviceInterfaces(deviceInfoSet, IntPtr.Zero, ref guid, num, ref structure); if (flag) { SP_DEVINFO_DATA structure2 = default(SP_DEVINFO_DATA); structure2.cbSize = Marshal.SizeOf(structure2); SP_DEVICE_INTERFACE_DETAIL_DATA sP_DEVICE_INTERFACE_DETAIL_DATA = default(SP_DEVICE_INTERFACE_DETAIL_DATA); sP_DEVICE_INTERFACE_DETAIL_DATA.cbSize = 4 + Marshal.SystemDefaultCharSize; int num2 = 0; int deviceInterfaceDetailDataSize = 2048; if (Acer_USB_Library.SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref structure, ref sP_DEVICE_INTERFACE_DETAIL_DATA, deviceInterfaceDetailDataSize, ref num2, ref structure2)) { uSBController.ControllerDevicePath = sP_DEVICE_INTERFACE_DETAIL_DATA.DevicePath; int num3 = 0; int num4 = 1; if (Acer_USB_Library.SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref structure2, 0, ref num4, intPtr, 2048, ref num3)) { uSBController.ControllerDeviceDesc = Marshal.PtrToStringAuto(intPtr); } if (Acer_USB_Library.SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref structure2, 9, ref num4, intPtr, 2048, ref num3)) { uSBController.ControllerDriverKeyName = Marshal.PtrToStringAuto(intPtr); } } list.Add(uSBController); } num++; }while (flag); Marshal.FreeHGlobal(intPtr); Acer_USB_Library.SetupDiDestroyDeviceInfoList(deviceInfoSet); } return(new ReadOnlyCollection <USBController>(list)); }
protected static string GetRootHubDevicePath(USBController controller) { // Now get the system name of it's root hub for interrogation char[] decoded = null; IOCTLcommand ioctl = new IOCTLcommand(); ioctl.ioctlNo = UsbApi.CTL_CODE(0x00000022, (uint)UsbApi.UsbIoctlFunction.HCD_GET_ROOT_HUB_NAME, 0, 0x0); ioctl.inputBuffer = null; ioctl.outputMaxSize = 260; try { IntPtr hDevice = UsbApi.OpenDevice(controller.devicePath, true); IoStatus status = UsbApi.DeviceIoControl(hDevice, ioctl); UsbApi.CloseDevice(hDevice); // struct {ULONG Length; WCHAR Name[256];} DriverKeyName; decoded = Encoding.Unicode.GetChars(status.buffer, IntPtr.Size, (int)status.size - IntPtr.Size); } catch (Exception) { } return((decoded == null) ? null : "\\\\.\\" + new String(decoded)); }
private void OnTimedConfCheckEvent(object source, ElapsedEventArgs e) { bool oldUSBSerialAC = Configuration.UsbSerialAccessControl; bool oldPrinterMonitor = Configuration.PrinterMonitor; bool oldArchiveInbound = Configuration.ArchiveInbound; bool oldBlockScreenShot = Configuration.BlockScreenShot; bool oldRemStorEncryption = Configuration.RemovableStorageEncryption; bool oldHasEncryptionKey = Configuration.HasEncryptionKey; String oldPrinterPrefix = Configuration.PrinterPrefix; if (SeapClient.HasNewConfiguration()) { Logger.GetInstance().Info("New configuration notified."); Configuration.GetUserConf(); if (Configuration.UsbSerialAccessControl && !oldUSBSerialAC) { Core.USBController.Activate(); } else if (!Configuration.UsbSerialAccessControl && oldUSBSerialAC) { Core.USBController.Deactive(); } if (Configuration.UsbSerialAccessControl) { USBController.InvalidateCache(); Core.USBController.GetUSBStorages(); } if (Configuration.PrinterMonitor && !oldPrinterMonitor) { Service.PrinterController.getInstance().Start(); } else if (!Configuration.PrinterMonitor && oldPrinterMonitor) { Service.PrinterController.getInstance().Stop(); } else if (Configuration.PrinterMonitor && (Configuration.PrinterPrefix != oldPrinterPrefix)) { Service.PrinterController.getInstance().Stop(); Service.PrinterController.getInstance().Start(); } if (Configuration.RemovableStorageEncryption && !oldRemStorEncryption) { DiskCryptor.StartDcrypt(); } else if (!Configuration.RemovableStorageEncryption && oldRemStorEncryption) { DiskCryptor.StopDcrypt(); } if (oldArchiveInbound != Configuration.ArchiveInbound || oldUSBSerialAC != Configuration.UsbSerialAccessControl) { Logger.GetInstance().Debug("New mydlpmf configuration"); MyDLPEP.MiniFilterController.GetInstance().Stop(); MyDLPEP.MiniFilterController.GetInstance().Start(); MyDLPEP.FilterListener.getInstance().StartListener(); } if (oldBlockScreenShot) { ScreenShotContoller.Stop(); } if (Configuration.BlockScreenShot) { ScreenShotContoller.Start(); } } if (Configuration.RemovableStorageEncryption) { if (oldHasEncryptionKey) { if (!SeapClient.HasKeyfile()) { Configuration.HasEncryptionKey = false; DiskCryptor.AfterKeyLose(); } } else { if (SeapClient.HasKeyfile()) { Configuration.HasEncryptionKey = true; DiskCryptor.AfterKeyReceive(); } } } }
// // Return a list of USB Host Controllers // public static System.Collections.ObjectModel.ReadOnlyCollection<USBController> GetHostControllers() { List<USBController> HostList = new List<USBController>(); Guid HostGUID = new Guid(GUID_DEVINTERFACE_HUBCONTROLLER); // We start at the "root" of the device tree and look for all // devices that match the interface GUID of a Hub Controller IntPtr h = SetupDiGetClassDevs(ref HostGUID, 0, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (h.ToInt32() != INVALID_HANDLE_VALUE) { IntPtr ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE); bool Success; int i = 0; do { USBController host = new USBController(); host.ControllerIndex = i; // create a Device Interface Data structure SP_DEVICE_INTERFACE_DATA dia = new SP_DEVICE_INTERFACE_DATA(); dia.cbSize = Marshal.SizeOf(dia); // start the enumeration Success = SetupDiEnumDeviceInterfaces(h, IntPtr.Zero, ref HostGUID, i, ref dia); if (Success) { // build a DevInfo Data structure SP_DEVINFO_DATA da = new SP_DEVINFO_DATA(); da.cbSize = Marshal.SizeOf(da); // build a Device Interface Detail Data structure SP_DEVICE_INTERFACE_DETAIL_DATA didd = new SP_DEVICE_INTERFACE_DETAIL_DATA(); if (IntPtr.Size == 8) // for 64 bit operating systems didd.cbSize = 8; else didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // now we can get some more detailed information int nRequiredSize = 0; int nBytes = BUFFER_SIZE; var result = SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da); if (result) { host.ControllerDevicePath = didd.DevicePath; // get the Device Description and DriverKeyName int RequiredSize = 0; int RegType = REG_SZ; if (SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DEVICEDESC, ref RegType, ptrBuf, BUFFER_SIZE, ref RequiredSize)) { host.ControllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuf); } if (SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref RegType, ptrBuf, BUFFER_SIZE, ref RequiredSize)) { host.ControllerDriverKeyName = Marshal.PtrToStringAuto(ptrBuf); } } HostList.Add(host); } i++; } while (Success); Marshal.FreeHGlobal(ptrBuf); SetupDiDestroyDeviceInfoList(h); } // convert it into a Collection return new System.Collections.ObjectModel.ReadOnlyCollection<USBController>(HostList); }
public USBHub(USBController hostC) { controller = hostC; deviceDesc = "RootHub"; devicePath = GetRootHubDevicePath(controller); }
public static ReadOnlyCollection <USBController> GetHostControllers() { var HostList = new List <USBController>(); var HostGUID = new Guid(GUID_DEVINTERFACE_COMPORT); // We start at the "root" of the device tree and look for all // devices that match the interface GUID of a Hub Controller var h = SetupDiGetClassDevs(ref HostGUID, 0, IntPtr.Zero, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (h.ToInt32() == INVALID_HANDLE_VALUE) { return(new ReadOnlyCollection <USBController>(HostList)); } var ptrBuf = Marshal.AllocHGlobal(BUFFER_SIZE); bool Success; var i = 0; do { var host = new USBController { ControllerIndex = i }; // create a Device Interface Data structure var dia = new SP_DEVICE_INTERFACE_DATA(); dia.cbSize = Marshal.SizeOf(dia); // start the enumeration Success = SetupDiEnumDeviceInterfaces(h, IntPtr.Zero, ref HostGUID, i, ref dia); if (Success) { // build a DevInfo Data structure var da = new SP_DEVINFO_DATA(); da.cbSize = Marshal.SizeOf(da); // build a Device Interface Detail Data structure var didd = new SP_DEVICE_INTERFACE_DETAIL_DATA { cbSize = 4 + Marshal.SystemDefaultCharSize }; // now we can get some more detailed information var nRequiredSize = 0; const int nBytes = BUFFER_SIZE; if (SetupDiGetDeviceInterfaceDetail(h, ref dia, ref didd, nBytes, ref nRequiredSize, ref da)) { host.ControllerDevicePath = didd.DevicePath; // get the Device Description and DriverKeyName var RequiredSize = 0; var RegType = REG_SZ; if (SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DEVICEDESC, ref RegType, ptrBuf, BUFFER_SIZE, ref RequiredSize)) { host.ControllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuf); } if (SetupDiGetDeviceRegistryProperty(h, ref da, SPDRP_DRIVER, ref RegType, ptrBuf, BUFFER_SIZE, ref RequiredSize)) { host.ControllerDriverKeyName = Marshal.PtrToStringAuto(ptrBuf); } } HostList.Add(host); } i++; } while (Success); Marshal.FreeHGlobal(ptrBuf); SetupDiDestroyDeviceInfoList(h); // convert it into a Collection return(new ReadOnlyCollection <USBController>(HostList)); }