Exemplo n.º 1
0
 public static void Refresh()
 {
     Scan();
     if (WMIDeviceInfo != null)
     {
         DeviceInserted?.Invoke();
     }
 }
Exemplo n.º 2
0
        private void DeviceInsertedEvent(object sender, EventArrivedEventArgs e)
        {
#if DEBUG
            ManagementBaseObject instance = (ManagementBaseObject)e.NewEvent["TargetInstance"];
            foreach (var property in instance.Properties)
            {
                Console.WriteLine(property.Name + " = " + property.Value);
            }
#endif
            DeviceInserted?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 3
0
        static InjectService()
        {
            if (HACGUIKeyset.TempLockpickPayloadFileInfo.Exists)
            {
                HACGUIKeyset.TempLockpickPayloadFileInfo.Delete();
            }


            // Create event handlers to detect when a device is added or removed
            CreateWatcher = new ManagementEventWatcher();
            WqlEventQuery createQuery = new WqlEventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_PnPEntity'");

            CreateWatcher.EventArrived += new EventArrivedEventHandler((s, e) =>
            {
                Refresh();
                if (WMIDeviceInfo != null)
                {
                    DeviceInserted?.Invoke();
                }
            });
            CreateWatcher.Query = createQuery;

            DeleteWatcher = new ManagementEventWatcher();
            WqlEventQuery deleteQuery = new WqlEventQuery("SELECT * FROM __InstanceDeletionEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_PnPEntity'");

            DeleteWatcher.EventArrived += new EventArrivedEventHandler((s, e) =>
            {
                WMIDeviceInfo = null;
                Refresh();
                if (WMIDeviceInfo == null)
                {
                    DeviceRemoved?.Invoke();
                }
            });
            DeleteWatcher.Query = deleteQuery;

            DeviceInserted += () =>
            {
                StatusService.RCMStatus = StatusService.Status.OK;
                if (!LibusbKInstalled)
                {
                    MessageBoxResult result = MessageBox.Show("You have plugged in your console, but it lacks the libusbK driver. Want to install it? (You cannot inject anything until this is done)", "", MessageBoxButton.YesNo);
                    if (result == MessageBoxResult.Yes)
                    {
                        InstallDriver();
                    }
                }
            };

            DeviceRemoved += () =>
            {
                StatusService.RCMStatus = StatusService.Status.Incorrect;
            };
        }
Exemplo n.º 4
0
        public static void Start()
        {
            if (Started)
            {
                throw new Exception("Inject service is already started!");
            }

            Refresh();
            if (WMIDeviceInfo != null)
            {
                Task.Run(() => DeviceInserted?.Invoke());
            }

            CreateWatcher.Start();
            DeleteWatcher.Start();

            Started = true;
        }
Exemplo n.º 5
0
        private void DeviceInsertedEvent(object sender, EventArrivedEventArgs e)
        {
            try
            {
                Console.WriteLine("=== USB EVENT (inserted) ===");
                ManagementBaseObject instance = (ManagementBaseObject)e.NewEvent["TargetInstance"];
                foreach (var property in instance.Properties)
                {
                    Console.WriteLine(property.Name + " = " + property.Value);
                }

                DeviceInserted?.Invoke(this, instance.Properties["DeviceID"].Value.ToString());
            }
            catch
            {
                // ignore exceptions in favor of not crashing
            }
        }
Exemplo n.º 6
0
        public static void Start()
        {
            if (Started)
            {
                throw new Exception("Inject service is already started!");
            }

            if (HACGUIKeyset.TempLockpickPayloadFileInfo.Exists)
            {
                HACGUIKeyset.TempLockpickPayloadFileInfo.Delete();
            }

            Refresh();
            if (WMIDeviceInfo != null)
            {
                Task.Run(() => DeviceInserted?.Invoke());
            }

            CreateWatcher.Start();
            DeleteWatcher.Start();

            Started = true;
        }
Exemplo n.º 7
0
        private void threadRun()
        {
            var usbWatcher = new ManagementEventWatcher();

            usbWatcher.Query = new EventQuery("SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2 OR EventType = 3");

            usbWatcher.EventArrived += (s, ea) =>
            {
                var driveName = $"{ea.NewEvent.Properties["DriveName"].Value}";
                var type      = (USBEventType)(Enum.Parse(typeof(USBEventType), $"{ea.NewEvent.Properties["EventType"].Value}"));

                //get detailed data on the drive that was inserted
                var availableDrives = DriveInfo.GetDrives();
                var info            = DriveInfo.GetDrives().Where(x => driveNameSanitizer(x.Name).Equals(driveNameSanitizer(driveName))).FirstOrDefault();

                Int64?        freeSpace  = null;
                Int64?        totalSpace = null;
                DirectoryInfo root       = null;
                string        volume     = null;
                if (info != null)
                {
                    freeSpace  = info.AvailableFreeSpace.BytesToGigabytes();
                    totalSpace = info.TotalFreeSpace.BytesToGigabytes();
                    volume     = info.VolumeLabel;
                    root       = info.RootDirectory;
                }

                var usbDisk = new USBDisk {
                    Name = driveName, Volume = volume, EntryPoint = root, AvailableSpace = freeSpace, TotalSpace = totalSpace
                };

                switch (type)
                {
                case USBEventType.Inserted:
                    DeviceInserted?.Invoke(this, new USBEventArgs(type, usbDisk));
                    break;

                case USBEventType.Removed:
                    DeviceRemoved?.Invoke(this, new USBEventArgs(type, usbDisk));
                    break;

                default:
                    throw new NotImplementedException("That type was not implemented");
                }
            };

            var cdWatcher = new ManagementEventWatcher();

            cdWatcher.Query = new EventQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType = 5");

            cdWatcher.EventArrived += (s, ea) =>
            {
            };

            if (WatchUSB)
            {
                usbWatcher.Start();
            }
            if (WatchCD)
            {
                cdWatcher.Start();
            }

            while (shouldWatch)
            {
                Thread.Sleep(250);
            }

            usbWatcher.Stop();
            cdWatcher.Stop();
        }