mirror of
https://github.com/chipsec/chipsec
synced 2026-06-08 13:31:00 +00:00
Fix bug when msgbus_cmd returns wrong value type in windows
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
This commit is contained in:
committed by
dscott90
parent
591c10ec75
commit
aedaa7531f
@@ -521,12 +521,12 @@ class WindowsHelper(Helper):
|
||||
out_buf = self._ioctl(IOCTL_READ_PHYSMEM, in_buf, out_length)
|
||||
return bytes(out_buf)
|
||||
|
||||
def write_phys_mem(self, phys_address: int, length: int, buf: AnyStr):
|
||||
def write_phys_mem(self, phys_address: int, length: int, buf: AnyStr) -> int:
|
||||
hi = (phys_address >> 32) & 0xFFFFFFFF
|
||||
lo = phys_address & 0xFFFFFFFF
|
||||
in_buf = struct.pack('3I', hi, lo, length) + stringtobytes(buf)
|
||||
out_buf = self._ioctl(IOCTL_WRITE_PHYSMEM, in_buf, 4)
|
||||
return out_buf
|
||||
return int.from_bytes(out_buf, 'little')
|
||||
|
||||
# @TODO: Temporarily the same as read_phys_mem for compatibility
|
||||
def read_mmio_reg(self, phys_address: int, size: int) -> int:
|
||||
@@ -559,7 +559,7 @@ class WindowsHelper(Helper):
|
||||
return False
|
||||
in_buf = struct.pack('3I', ((phys_address >> 32) & 0xFFFFFFFF), (phys_address & 0xFFFFFFFF), size) + buf
|
||||
out_buf = self._ioctl(IOCTL_WRITE_MMIO, in_buf, 4)
|
||||
return out_buf
|
||||
return int.from_bytes(out_buf, 'little')
|
||||
|
||||
def alloc_phys_mem(self, length: int, max_pa: int) -> Tuple[int, int]:
|
||||
in_length = 12
|
||||
@@ -620,9 +620,8 @@ class WindowsHelper(Helper):
|
||||
|
||||
def write_msr(self, cpu_thread_id: int, msr_addr: int, eax: int, edx: int) -> int:
|
||||
out_length = 0
|
||||
out_buf = (c_char * out_length)()
|
||||
in_buf = struct.pack('=4I', cpu_thread_id, msr_addr, eax, edx)
|
||||
out_buf = self._ioctl(IOCTL_WRMSR, in_buf, out_length)
|
||||
self._ioctl(IOCTL_WRMSR, in_buf, out_length)
|
||||
return True
|
||||
|
||||
def read_pci_reg(self, bus: int, device: int, function: int, address: int, size: int) -> int:
|
||||
@@ -642,15 +641,13 @@ class WindowsHelper(Helper):
|
||||
bdf = PCI_BDF(bus & 0xFFFF, device & 0xFFFF, function & 0xFFFF, address & 0xFFFF)
|
||||
out_length = 0
|
||||
in_buf = struct.pack('4HIB', bdf.BUS, bdf.DEV, bdf.FUNC, bdf.OFF, value, size)
|
||||
out_buf = self._ioctl(WRITE_PCI_CFG_REGISTER, in_buf, out_length)
|
||||
self._ioctl(WRITE_PCI_CFG_REGISTER, in_buf, out_length)
|
||||
return True
|
||||
|
||||
def load_ucode_update(self, cpu_thread_id: int, ucode_update_buf: bytes) -> bool:
|
||||
in_length = len(ucode_update_buf) + 3
|
||||
out_length = 0
|
||||
out_buf = (c_char * out_length)()
|
||||
in_buf = struct.pack('=IH', cpu_thread_id, len(ucode_update_buf)) + ucode_update_buf
|
||||
out_buf = self._ioctl(IOCTL_LOAD_UCODE_PATCH, in_buf, out_length)
|
||||
self._ioctl(IOCTL_LOAD_UCODE_PATCH, in_buf, out_length)
|
||||
return True
|
||||
|
||||
def read_io_port(self, io_port: int, size: int) -> int:
|
||||
@@ -667,7 +664,7 @@ class WindowsHelper(Helper):
|
||||
|
||||
def write_io_port(self, io_port: int, value: int, size: int) -> bool:
|
||||
in_buf = struct.pack('=HIB', io_port, value, size)
|
||||
out_buf = self._ioctl(IOCTL_WRITE_IO_PORT, in_buf, 0)
|
||||
self._ioctl(IOCTL_WRITE_IO_PORT, in_buf, 0)
|
||||
return True
|
||||
|
||||
def read_cr(self, cpu_thread_id: int, cr_number: int) -> int:
|
||||
@@ -679,7 +676,7 @@ class WindowsHelper(Helper):
|
||||
|
||||
def write_cr(self, cpu_thread_id: int, cr_number: int, value: int) -> int:
|
||||
in_buf = struct.pack('=HQI', cr_number, value, cpu_thread_id)
|
||||
out_buf = self._ioctl(IOCTL_WRCR, in_buf, 0)
|
||||
self._ioctl(IOCTL_WRCR, in_buf, 0)
|
||||
return True
|
||||
|
||||
#
|
||||
|
||||
@@ -84,25 +84,25 @@ class MsgBusCommand(BaseCommand):
|
||||
parser.parse_args(self.argv, namespace=self)
|
||||
|
||||
def msgbus_read(self):
|
||||
self.logger.log("[CHIPSEC] msgbus read: port 0x{:02X} + 0x{:08X}".format(self.port, self.reg))
|
||||
self.logger.log(f'[CHIPSEC] msgbus read: port 0x{self.port:02X} + 0x{self.reg:08X}')
|
||||
return self._msgbus.msgbus_reg_read(self.port, self.reg)
|
||||
|
||||
def msgbus_write(self):
|
||||
self.logger.log("[CHIPSEC] msgbus write: port 0x{:02X} + 0x{:08X} < 0x{:08X}".format(self.port, self.reg, self.val))
|
||||
self.logger.log(f'[CHIPSEC] msgbus write: port 0x{self.port:02X} + 0x{self.reg:08X} < 0x{self.val:08X}')
|
||||
return self._msgbus.msgbus_reg_write(self.port, self.reg, self.val)
|
||||
|
||||
def msgbus_mm_read(self):
|
||||
self.logger.log("[CHIPSEC] MMIO msgbus read: port 0x{:02X} + 0x{:08X}".format(self.port, self.reg))
|
||||
self.logger.log(f'[CHIPSEC] MMIO msgbus read: port 0x{self.port:02X} + 0x{self.reg:08X}')
|
||||
return self._msgbus.mm_msgbus_reg_read(self.port, self.reg)
|
||||
|
||||
def msgbus_mm_write(self):
|
||||
self.logger.log("[CHIPSEC] MMIO msgbus write: port 0x{:02X} + 0x{:08X} < 0x{:08X}".format(self.port, self.reg, self.val))
|
||||
self.logger.log(f'[CHIPSEC] MMIO msgbus write: port 0x{self.port:02X} + 0x{self.reg:08X} < 0x{self.val:08X}')
|
||||
return self._msgbus.mm_msgbus_reg_write(self.port, self.reg, self.val)
|
||||
|
||||
def msgbus_message(self):
|
||||
self.logger.log("[CHIPSEC] msgbus message: port 0x{:02X} + 0x{:08X}, opcode: 0x{:02X}".format(self.port, self.reg, self.opcode))
|
||||
self.logger.log(f'[CHIPSEC] msgbus message: port 0x{self.port:02X} + 0x{self.reg:08X}, opcode: 0x{self.opcode:02X}')
|
||||
if self.val is not None:
|
||||
self.logger.log("[CHIPSEC] Data: 0x{:08X}".format(self.val))
|
||||
self.logger.log(f'[CHIPSEC] Data: 0x{self.val:08X}')
|
||||
return self._msgbus.msgbus_send_message(self.port, self.reg, self.opcode, self.val)
|
||||
|
||||
def run(self):
|
||||
@@ -111,7 +111,7 @@ class MsgBusCommand(BaseCommand):
|
||||
res = self.func()
|
||||
|
||||
if res is not None:
|
||||
self.logger.log("[CHIPSEC] Result: 0x{:08X}".format(res))
|
||||
self.logger.log(f'[CHIPSEC] Result: {hex(res)}')
|
||||
|
||||
|
||||
commands = {'msgbus': MsgBusCommand}
|
||||
|
||||
@@ -64,7 +64,7 @@ class WindowsHelperTest(unittest.TestCase):
|
||||
qpacker = packer()
|
||||
ioctl_dict = {
|
||||
(0x22e028, b'\x00\x00\x00\x004\x12\x00\x00\x08\x00\x00\x00abc'):
|
||||
1,
|
||||
b'\x01',
|
||||
(0x22e024, b'\x00\x00\x00\x00\x00P\x00\x00\x02\x00\x00\x00'):
|
||||
b'\xac\xdc',
|
||||
(0x22e054, b'E#\x01\x00\x00\x00\x00\x00'):
|
||||
|
||||
Reference in New Issue
Block a user