public void ReadRegions() { MemoryBasicInformation memInfo = new MemoryBasicInformation(); IntPtr current = IntPtr.Zero; while (current.ToInt64() < m_maxAddress.ToInt64() && Kernel32.VirtualQueryEx(m_handle, current, out memInfo, (uint)Marshal.SizeOf(memInfo)) != 0) { if ((int)memInfo.State == 4096 && (int)memInfo.Protect == 4 && (uint)memInfo.RegionSize != 0) { byte[] regionData = new byte[(int)memInfo.RegionSize]; ulong bytesRead = 0; if (!Kernel32.ReadProcessMemory(m_handle, memInfo.BaseAddress, regionData, (ulong)memInfo.RegionSize, ref bytesRead)) { throw new Exception("Failed to read process memory at " + memInfo.BaseAddress + ". Error code: " + Marshal.GetLastWin32Error()); } m_regions.Add(memInfo.BaseAddress, regionData); } current = PointerUtils.Add(memInfo.BaseAddress, memInfo.RegionSize); } Console.WriteLine("Regions: {0}", m_regions.Count); }
private void DoDevTypHandle(ref WndProcClient.WindowMessage m, ref String text) { DEV_BROADCAST_HANDLE hdrHandle = (DEV_BROADCAST_HANDLE)Marshal.PtrToStructure(m.lParam, typeof(DEV_BROADCAST_HANDLE)); var pData = PointerUtils.Add(m.lParam, _OffsetOfData); if (BluetoothDeviceNotificationEvent.BthPortDeviceInterface == hdrHandle.dbch_eventguid) { text += "GUID_BTHPORT_DEVICE_INTERFACE"; } else if (BluetoothDeviceNotificationEvent.RadioInRange == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_RADIO_IN_RANGE"; BTH_RADIO_IN_RANGE inRange = (BTH_RADIO_IN_RANGE)Marshal.PtrToStructure(pData, typeof(BTH_RADIO_IN_RANGE)); text += String.Format(" 0x{0:X12}", inRange.deviceInfo.address); text += String.Format(" is ({0}) 0x{0:X}", inRange.deviceInfo.flags); text += String.Format(" was ({0}) 0x{0:X}", inRange.previousDeviceFlags); var bdi0 = BLUETOOTH_DEVICE_INFO.Create(inRange.deviceInfo); var e = BluetoothWin32RadioInRangeEventArgs.Create( inRange.previousDeviceFlags, inRange.deviceInfo.flags, bdi0); DeviceInRange?.Invoke(this, e); } else if (BluetoothDeviceNotificationEvent.RadioOutOfRange == hdrHandle.dbch_eventguid) { BTH_RADIO_OUT_OF_RANGE outOfRange = (BTH_RADIO_OUT_OF_RANGE)Marshal.PtrToStructure(pData, typeof(BTH_RADIO_OUT_OF_RANGE)); text += "GUID_BLUETOOTH_RADIO_OUT_OF_RANGE"; text += String.Format(System.Globalization.CultureInfo.InvariantCulture, " 0x{0:X12}", outOfRange.deviceAddress); var e = BluetoothWin32RadioOutOfRangeEventArgs.Create( outOfRange.deviceAddress); DeviceOutOfRange?.Invoke(this, e); } else if (BluetoothDeviceNotificationEvent.PinRequest == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_PIN_REQUEST"; } else if (BluetoothDeviceNotificationEvent.L2capEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_L2CAP_EVENT"; } else if (BluetoothDeviceNotificationEvent.HciEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_HCI_EVENT"; } else if (BluetoothDeviceNotificationEvent.AuthenticationRequestEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_AUTHENTICATION_REQUEST"; } else if (BluetoothDeviceNotificationEvent.KeyPressEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_KEYPRESS_EVENT"; } else if (BluetoothDeviceNotificationEvent.HciVendorEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_HCI_VENDOR_EVENT"; } else { text += "Unknown event: " + hdrHandle.dbch_eventguid; } Log.Verbose("Interop.Win32: Device changed: " + text); }