1
0
mirror of synced 2024-12-01 00:57:18 +01:00

Fix psmap display for nodes with default values.

This commit is contained in:
Jennifer Taylor 2021-09-03 04:32:53 +00:00
parent cd1ae9b2fd
commit 929e6be305

View File

@ -41,12 +41,12 @@ def parse_psmap(data: bytes, offset: str, rootname: str, *, verbose: bool = Fals
chunk = data[base:(base + 24)] chunk = data[base:(base + 24)]
base = base + 24 base = base + 24
(nodetype, mandatory, outoffset, width, nameptr, defaultptr) = struct.unpack('<BBHIQQ', chunk) (nodetype, mandatory, outoffset, width, nameptr, default) = struct.unpack('<BBHIQQ', chunk)
else: # 32 bit else: # 32 bit
chunk = data[base:(base + 16)] chunk = data[base:(base + 16)]
base = base + 16 base = base + 16
(nodetype, mandatory, outoffset, width, nameptr, defaultptr) = struct.unpack('<BBHIII', chunk) (nodetype, mandatory, outoffset, width, nameptr, default) = struct.unpack('<BBHIII', chunk)
if nodetype == 0xFF or nodetype == 0x00: # if nodetype is 0 then we probably read garbage if nodetype == 0xFF or nodetype == 0x00: # if nodetype is 0 then we probably read garbage
# End of nodes, see if we should exit # End of nodes, see if we should exit
@ -68,19 +68,26 @@ def parse_psmap(data: bytes, offset: str, rootname: str, *, verbose: bool = Fals
pass pass
# Grab the default # Grab the default
if defaultptr != 0: if default != 0:
defaultptr = pe.virtual_to_physical(defaultptr) try:
defaultptr = pe.virtual_to_physical(default)
except Exception:
defaultptr = 0
if verbose: if verbose:
space = " " * len(saved_root) space = " " * len(saved_root)
print( print(
f"{space}Node offset: {hex(readbase)}{os.linesep}" f"{space}Node offset: {hex(readbase)}{os.linesep}" +
f"{space} Type: {hex(nodetype)}{os.linesep}" f"{space} Type: {hex(nodetype)}{os.linesep}" +
f"{space} Mandatory: {'yes' if mandatory != 0 else 'no'}{os.linesep}" f"{space} Mandatory: {'yes' if mandatory != 0 else 'no'}{os.linesep}" +
f"{space} Name: {name}{os.linesep}" f"{space} Name: {name}{os.linesep}" +
f"{space} Parse Offset: {outoffset}{os.linesep}" f"{space} Parse Offset: {outoffset}{os.linesep}" +
f"{space} Data Width: {width}{os.linesep}" f"{space} Data Width: {width}{os.linesep}" +
f"{space} Default Pointer: {'null' if defaultptr == 0 else hex(defaultptr)}", (
f"{space} Data Pointer: {'null' if defaultptr == 0 else hex(defaultptr)}"
if nodetype == 0x01 else
f"{space} Default: {default}"
),
file=sys.stderr, file=sys.stderr,
) )