mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-09-06 01:37:39 +02:00
Windows Registry: Handle exceptions in read calls
These calls to `.read()` can raise an `InvalidAddressException`. Instead of propagating this exception to the caller, this adds debug logging, and pads the data will null bytes. Also updates the docstring for `decode_data()` to indicate that it can raise `TypeError` and `ValueError`.
This commit is contained in:
@@ -276,7 +276,16 @@ class CM_KEY_VALUE(objects.StructType):
|
||||
return RegValueTypes(self.Type)
|
||||
|
||||
def decode_data(self) -> Union[int, bytes]:
|
||||
"""Properly decodes the data associated with the value node"""
|
||||
"""
|
||||
Properly decodes the data associated with the value node.
|
||||
|
||||
If an InvalidAddressException occurs when reading data from the
|
||||
underlying RegistryHive layer, the data will be padded with null bytes
|
||||
of the same length.
|
||||
|
||||
Raises ValueError if the data cannot be read
|
||||
Raises TypeError if the class was not instantiated on a RegistryHive layer
|
||||
"""
|
||||
# Determine if the data is stored inline
|
||||
datalen = self.DataLength
|
||||
data = b""
|
||||
@@ -310,14 +319,26 @@ class CM_KEY_VALUE(objects.StructType):
|
||||
and block_offset < layer.maximum_address
|
||||
):
|
||||
amount = min(BIG_DATA_MAXLEN, datalen)
|
||||
data += layer.read(
|
||||
offset=layer.get_cell(block_offset).vol.offset, length=amount
|
||||
)
|
||||
try:
|
||||
data += layer.read(
|
||||
offset=layer.get_cell(block_offset).vol.offset,
|
||||
length=amount,
|
||||
)
|
||||
except exceptions.InvalidAddressException:
|
||||
vollog.debug(
|
||||
f"Failed to read {amount:x} bytes of data, padding with {amount:x}"
|
||||
)
|
||||
datalen -= amount
|
||||
else:
|
||||
# Suspect Data actually points to a Cell,
|
||||
# but the length at the start could be negative so just adding 4 to jump past it
|
||||
data = layer.read(self.Data + 4, datalen)
|
||||
try:
|
||||
data = layer.read(self.Data + 4, datalen)
|
||||
except exceptions.InvalidAddressException:
|
||||
vollog.debug(
|
||||
f"Failed to read {datalen:x} bytes of data, returning {datalen:x} null bytes"
|
||||
)
|
||||
data = b"\x00" * datalen
|
||||
|
||||
if self.get_type() == RegValueTypes.REG_DWORD:
|
||||
if len(data) != struct.calcsize("<L"):
|
||||
|
||||
Reference in New Issue
Block a user