Attempt to address #1790. Add ability to parse for modules when a large
section of unidentified data is found.
Signed-off-by: brentholtsclaw <brent.holtsclaw@intel.com>
Python 3.5 introduced `bytes.hex` to represent bytes in hexadecimal:
https://docs.python.org/3.5/library/stdtypes.html#bytes.hex
This function directly returns a string, contrary to `binascii.hexlify`
which returns bytes. Using `binascii.hexlify` without transforming the
output to string actually produced buggy output. For example:
$ ./chipsec_util.py spidesc spi_rom.bin
...
+ 0x0000 Reserved : 0xb'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
This `b'` is not desired. Using `bytes.hex` fixes this issue and makes
the code simpler.
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
`print_buffer_bytes` can directly handle bytes, instead of converting
them to a string.
While at it, replace buggy calls to `print_buffer(buffer)` (when
`buffer` uses type `bytes`) with `print_buffer_bytes(buffer)`.
This fixes `./chipsec_util.py idt 0`. Before it failed with:
[CHIPSEC] Dumping IDT of 8 CPU threads
[cpu0] Physical Address: 0x000000036639E000
[cpu0] # of entries : 256
[cpu0] Contents (4 entries):
Traceback (most recent call last):
File "./chipsec_util.py", line 210, in <module>
sys.exit(main())
File "./chipsec_util.py", line 205, in main
return chipsecMain.main()
File "./chipsec_util.py", line 190, in main
comm.run()
File "chipsec/utilcmd/desc_cmd.py", line 84, in run
self.cs.msr.IDT_all(4)
File "chipsec/hal/msr.py", line 166, in IDT_all
self.IDT(tid, num_entries)
File "chipsec/hal/msr.py", line 158, in IDT
return self.dump_Descriptor_Table(cpu_thread_id, DESCRIPTOR_TABLE_CODE_IDTR, num_entries)
File "chipsec/hal/msr.py", line 144, in dump_Descriptor_Table
print_buffer(dt)
File "chipsec/logger.py", line 493, in print_buffer
prt_str = bytes2string(arr, length)
File "chipsec/logger.py", line 466, in bytes2string
num_string += [f'{ord(c):02X} ']
TypeError: ord() expected string of length 1, but int found
There was another bug in `hal/msr.py` where `ord(dt[...])` was used
instead of `dt`.
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
Using a list of unicode characters instead of bytes is strange in Python
3. Replace these lists with bytes, which is the usual type to hold
binary data.
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
In `SPI.write_spi`, When `len(buf) % 4 != 0`, a dword value to be
written is computed with `ord(buf[...])`. This does not work, as in
Python 3, `buf[...]` directly gives an integer.
Fix this issue by removing the call to `ord`.
Fixes: https://github.com/chipsec/chipsec/issues/1775
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
`oshelper.UnimplementedAPIError` is actually imported from
`chipsec.exceptions`. Importing it directly fixes warnings reported by
Mypy such as:
chipsec/hal/spi.py:201: error: Module has no attribute "UnimplementedAPIError"
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
Currently, `chipsec_util.py spidesc spi_rom.bin` displays:
Master Read/Write Access to Flash Regions
--------------------------------------------------------
Region | CPU | ME
--------------------------------------------------------
f{r:-2d} {spi.SPI_REGION_NAMES[r]:20s} | |
The `f` was not positioned correctly in the formatted string.
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
Found that F86 option adds a conversion routine prior to encode and post
decode. Added the functionality to the EfiCompressor code within
chipsec_tools.
Signed-off-by: brentholtsclaw <brent.holtsclaw@intel.com>