/// <summary> /// Read a kernel control register /// </summary> /// <returns>Value of control register</returns> public ulong ReadControlRegister(uint controlRegister) { ulong value = 0; UInt32 io = 0; if (!Nt.DeviceIoControl(g_DeviceHandle, IOCTL_ReadControlRegister, &controlRegister, sizeof(uint), &value, sizeof(ulong), &io, 0)) { throw new Exception("DeviceIonControl failed! - 0x9C402428"); } return(value); }
/// <summary> /// Read buffer, of specified size, at physical address /// </summary> /// <returns>Success</returns> public bool ReadPhysicalAddress(ulong lpAddress, ulong lpBuffer, ulong lLength) { InputReadStruct input = new InputReadStruct(); OutputStruct output = new OutputStruct(); if (lpAddress == 0 || lpBuffer == 0) { return(false); } input.AddressHigh = (uint)HIDWORD(lpAddress); input.AddressLow = (uint)LODWORD(lpAddress); input.Length = (uint)lLength; input.BufferHigh = (uint)HIDWORD(lpBuffer); input.BufferLow = (uint)LODWORD(lpBuffer); UInt32 io = 0; return(Nt.DeviceIoControl(g_DeviceHandle, IOCTL_ReadPhysicalAddress, &input, (uint)Marshal.SizeOf(typeof(InputReadStruct)), &output, (uint)Marshal.SizeOf(typeof(OutputStruct)), &io, 0)); }
/// <summary> /// Write buffer, of specified size, at physical address /// </summary> /// <returns>Success</returns> public bool WritePhysicalAddress(ulong address, ulong buf, ulong len) { if (len % 4 != 0 || len == 0) { throw new Exception("The CPU-Z driver can only write lengths that are aligned to 4 bytes (4, 8, 12, 16, etc)"); } InputWriteStruct in_mem = new InputWriteStruct(); OutputStruct out_mem = new OutputStruct(); if (address == 0 || buf == 0) { return(false); } UInt32 io = 0; if (len == 4) { in_mem.AddressHigh = (uint)HIDWORD(address); in_mem.AddressLow = (uint)LODWORD(address); in_mem.Value = *(uint *)buf; return(Nt.DeviceIoControl(g_DeviceHandle, IOCTL_WritePhysicalAddress, &in_mem, (uint)Marshal.SizeOf(typeof(InputWriteStruct)), &out_mem, (uint)Marshal.SizeOf(typeof(OutputStruct)), &io, 0)); } else { for (uint i = 0; i < len / 4; i++) { in_mem.AddressHigh = (uint)HIDWORD(address + 4 * i); in_mem.AddressLow = (uint)LODWORD(address + 4 * i); in_mem.Value = ((uint *)buf)[i]; if (!Nt.DeviceIoControl(g_DeviceHandle, IOCTL_WritePhysicalAddress, &in_mem, (uint)Marshal.SizeOf(typeof(InputWriteStruct)), &out_mem, (uint)Marshal.SizeOf(typeof(OutputStruct)), &io, 0)) { return(false); } } return(true); } }