/// <summary> /// Opens the registry key at the address specified by the DeviceKey property /// </summary> /// <returns>A RegistryKey instance for successful call, otherwise null</returns> /// <exception cref="WindowsDisplayAPI.Exceptions.InvalidRegistryAddressException">Registry address is invalid or unknown.</exception> public Microsoft.Win32.RegistryKey OpenDeviceKey() { if (string.IsNullOrWhiteSpace(DeviceKey)) { return(null); } const string machineRootName = "\\Registry\\Machine\\"; const string userRootName = "\\Registry\\Current\\"; if (DeviceKey.StartsWith(machineRootName, System.StringComparison.InvariantCultureIgnoreCase)) { return(Microsoft.Win32.Registry.LocalMachine.OpenSubKey( DeviceKey.Substring(machineRootName.Length), Microsoft.Win32.RegistryKeyPermissionCheck.ReadSubTree )); } if (DeviceKey.StartsWith(userRootName, System.StringComparison.InvariantCultureIgnoreCase)) { return(Microsoft.Win32.Registry.Users.OpenSubKey( DeviceKey.Substring(userRootName.Length), Microsoft.Win32.RegistryKeyPermissionCheck.ReadSubTree )); } throw new Exceptions.InvalidRegistryAddressException("Registry address is invalid or unknown."); }
/// <summary> /// Function to retrieve a raw input mouse. /// </summary> /// <param name="key">The key for the raw input device.</param> /// <param name="deviceHandle">The device handle.</param> /// <returns></returns> private IRawInputDeviceData <GorgonRawMouseData> GetRawInputMouseDevice(DeviceKey key, IntPtr deviceHandle) { if (_mouseDevices.TryGetValue(key, out IRawInputDeviceData <GorgonRawMouseData> result)) { return(result); } key.DeviceHandle = deviceHandle; return(!_mouseDevices.TryGetValue(key, out result) ? null : result); }
private void DerivePerConsoleKeys() { var kek = new byte[0x10]; // Derive the device key if (!PerConsoleKeySource.IsEmpty() && !KeyblobKeys[0].IsEmpty()) { Crypto.DecryptEcb(KeyblobKeys[0], PerConsoleKeySource, DeviceKey, 0x10); } // Derive save key if (!SaveMacKekSource.IsEmpty() && !SaveMacKeySource.IsEmpty() && !DeviceKey.IsEmpty()) { Crypto.GenerateKek(DeviceKey, SaveMacKekSource, kek, AesKekGenerationSource, null); Crypto.DecryptEcb(kek, SaveMacKeySource, SaveMacKey, 0x10); } // Derive BIS keys if (DeviceKey.IsEmpty() || BisKekSource.IsEmpty() || AesKekGenerationSource.IsEmpty() || AesKeyGenerationSource.IsEmpty() || RetailSpecificAesKeySource.IsEmpty()) { return; } // If the user doesn't provide bis_key_source_03 we can assume it's the same as bis_key_source_02 if (BisKeySource[3].IsEmpty() && !BisKeySource[2].IsEmpty()) { Array.Copy(BisKeySource[2], BisKeySource[3], 0x20); } Crypto.DecryptEcb(DeviceKey, RetailSpecificAesKeySource, kek, 0x10); if (!BisKeySource[0].IsEmpty()) { Crypto.DecryptEcb(kek, BisKeySource[0], BisKeys[0], 0x20); } Crypto.GenerateKek(DeviceKey, BisKekSource, kek, AesKekGenerationSource, AesKeyGenerationSource); for (int i = 1; i < 4; i++) { if (!BisKeySource[i].IsEmpty()) { Crypto.DecryptEcb(kek, BisKeySource[i], BisKeys[i], 0x20); } } }
public DeviceResources(IFactory factory, IDeviceHandle<IHMDDevice, IHMDInfo> handle) { if (factory == null || handle == null) throw new ArgumentNullException(); Info = handle.DeviceInfo; Device = handle.CreateDevice(); Sensor = Device.Sensor; Fusion = factory.CreateSensorFusion(Sensor); if (Info == null) throw new ArgumentNullException(); if (Device == null) throw new ArgumentNullException(); if (Sensor == null) throw new ArgumentNullException(); Key = new DeviceKey(Sensor.Info); }
public DeviceResources(IFactory factory, IHMDDevice handle) { if (factory == null || handle == null) throw new ArgumentNullException(); Info = handle.Info; Device = handle; Sensor = Device.GetSensorState(0.0); if (Info == null) throw new ArgumentNullException(); if (Device == null) throw new ArgumentNullException(); if (Sensor == null) System.Diagnostics.Trace.TraceWarning("Unable to create Sensor"); if (Sensor != null) Key = new DeviceKey(Device.SensorInfo); }
public DeviceResources(IFactory factory, IDeviceHandle<IHMDDevice, IHMDInfo> handle) { if (factory == null || handle == null) throw new ArgumentNullException(); Info = handle.DeviceInfo; Device = handle.CreateDevice(); Sensor = Device.Sensor; Fusion = factory.CreateSensorFusion(Sensor); if (Info == null) throw new ArgumentNullException(); if (Device == null) throw new ArgumentNullException(); if (Sensor == null) System.Diagnostics.Trace.TraceWarning("Unable to create Sensor"); if (Sensor != null) Key = new DeviceKey(Sensor.Info); }
private void DerivePerConsoleKeys() { var kek = new byte[0x10]; // Derive the device key if (!PerConsoleKeySource.IsEmpty() && !KeyblobKeys[0].IsEmpty()) { Crypto.DecryptEcb(KeyblobKeys[0], PerConsoleKeySource, DeviceKey, 0x10); } // Derive save key if (!SaveMacKekSource.IsEmpty() && !SaveMacKeySource.IsEmpty() && !DeviceKey.IsEmpty()) { Crypto.GenerateKek(DeviceKey, SaveMacKekSource, kek, AesKekGenerationSource, null); Crypto.DecryptEcb(kek, SaveMacKeySource, SaveMacKey, 0x10); } // Derive BIS keys if (DeviceKey.IsEmpty() || BisKeySource[0].IsEmpty() || BisKeySource[1].IsEmpty() || BisKeySource[2].IsEmpty() || BisKekSource.IsEmpty() || AesKekGenerationSource.IsEmpty() || AesKeyGenerationSource.IsEmpty() || RetailSpecificAesKeySource.IsEmpty()) { return; } Crypto.DecryptEcb(DeviceKey, RetailSpecificAesKeySource, kek, 0x10); Crypto.DecryptEcb(kek, BisKeySource[0], BisKeys[0], 0x20); Crypto.GenerateKek(DeviceKey, BisKekSource, kek, AesKekGenerationSource, AesKeyGenerationSource); Crypto.DecryptEcb(kek, BisKeySource[1], BisKeys[1], 0x20); Crypto.DecryptEcb(kek, BisKeySource[2], BisKeys[2], 0x20); // BIS keys 2 and 3 are the same Array.Copy(BisKeys[2], BisKeys[3], 0x20); }
public void TestJoypadSingleButtonPress(byte joypadMode, DeviceKey key, byte expectedValue) { var device = TestUtils.CreateTestDevice(new byte[] { 0x0E, 0x00, // LD C, 00 - 2 m-cycles 0x3E, joypadMode, // LD A, 0xDF - 2 m-cycles 0xE2, // LD (C), A (set joypad to look at normal keys) - 2 m-cycles 0xF2, // LD A, (C) (get joypad state into A) - 2 m-cycles 0xF2, // LD A, (C) (get joypad state into A) - 2 m-cycles }); for (var ii = 0; ii < 13; ii++) { device.Step(); // Step 5 + 8 times to set up tests and execute up to first joypad query } Assert.Equal(joypadMode, device.CPU.Registers.A); // Double check joypad register is correct // Check key press is registered device.HandleKeyDown(key); device.Step(); device.Step(); Assert.Equal(expectedValue, device.CPU.Registers.A); device.HandleKeyUp(key); }
public static void GetDeviceKey() { try { Console.WriteLine("Proyecto de prueba in C#\r"); Console.WriteLine("------------------------\n"); Console.WriteLine("Obteniendo el numero del dispositivo como test para validar la conexion"); var client = new RestClient("http://192.168.15.27:8090/getDeviceKey"); client.Timeout = -1; var request = new RestRequest(Method.GET); IRestResponse response = client.Execute(request); Console.WriteLine("El numero del dispositivo es: " + response.Content); DeviceKey myDeserializedClass = JsonConvert.DeserializeObject <DeviceKey>(response.Content); Console.WriteLine("------------------------------------------------------------------------------------------------------------------------\n"); } catch (Exception e) { Console.WriteLine(e); } }
private void RemoveDevice(IDeviceHandle<ISensorDevice, ISensorInfo> handle) { _lock.EnterWriteLock(); try { var key = new DeviceKey(handle.DeviceInfo); DeviceResources resources; if (!_nativeResources.TryGetValue(key, out resources)) return; RemoveDevice(resources); } finally { _lock.ExitWriteLock(); } }
internal void Keyup(DeviceKey key) { _keyStates[key] = false; // TODO - Handle interrupts on key up? Some docs say true. }
internal void Keydown(DeviceKey key) { _keyStates[key] = true; CheckForInterrupts(); }
public static byte BitMask(this DeviceKey key) => key switch {
/// <summary> /// Function to provide filtering of window messages for the application. /// </summary> /// <param name="m">Window message to filter.</param> /// <returns><b>true</b> if the message is processed by this method, or <b>false</b> if not.</returns> public bool PreFilterMessage(ref Message m) { if ((m.Msg != RawInputApi.WmRawInput) || (m.HWnd != _hwnd)) { if (!NoLegacyMouse) { return(false); } // If we have no legacy messages turned on for the mouse, then do not process them. switch (m.Msg) { /*case WM_XBUTTONDBLCLK: * case WM_XBUTTONDOWN: * case WM_XBUTTONUP: * case WM_RBUTTONDBLCLK: * case WM_RBUTTONDOWN:*/ case WM_RBUTTONUP: /*case WM_NCRBUTTONDBLCLK: * case WM_NCRBUTTONDOWN: * case WM_NCRBUTTONUP: * case WM_NCXBUTTONDBLCLK: * case WM_NCXBUTTONDOWN: * case WM_NCXBUTTONUP: * case WM_NCMOUSEHOVER: * case WM_NCMOUSELEAVE: * case WM_NCMOUSEMOVE: * case WM_NCLBUTTONDBLCLK: * case WM_NCLBUTTONDOWN: * case WM_NCLBUTTONUP: * case WM_NCMBUTTONDBLCLK: * case WM_NCMBUTTONDOWN: * case WM_NCMBUTTONUP: * case WM_MOUSELEAVE: * case WM_MOUSEMOVE: * case WM_MOUSEWHEEL: * case WM_MOUSEHWHEEL: * case WM_MOUSEHOVER: * case WM_MOUSEACTIVATE: * case WM_LBUTTONDBLCLK: * case WM_LBUTTONDOWN: * case WM_LBUTTONUP: * case WM_MBUTTONDBLCLK: * case WM_MBUTTONDOWN: * case WM_MBUTTONUP: * case WM_CAPTURECHANGED:*/ return(true); default: return(false); } } RAWINPUT data = RawInputApi.GetRawInputData(m.LParam); var key = new DeviceKey { DeviceType = data.Header.Type, DeviceHandle = IntPtr.Zero }; switch (data.Header.Type) { case RawInputType.Keyboard: IRawInputDeviceData <GorgonRawKeyboardData> keyboard = GetRawInputKeyboardDevice(key, data.Header.Device); if (keyboard == null) { return(false); } RawInputDispatcher.Dispatch(keyboard, ref data.Union.Keyboard); break; case RawInputType.Mouse: IRawInputDeviceData <GorgonRawMouseData> mouse = GetRawInputMouseDevice(key, data.Header.Device); if (mouse == null) { return(false); } RawInputDispatcher.Dispatch(mouse, ref data.Union.Mouse); break; case RawInputType.HID: IRawInputDeviceData <GorgonRawHIDData> hid = GetRawInputHid(key, data.Header.Device); if (hid == null) { return(false); } RawInputDispatcher.Dispatch(hid, ref data.Union.HID); break; } return(true); }