From e53cb16485366dd8a49bfcfe27f5ea6a0bae1952 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Mon, 7 May 2018 23:10:01 +0100 Subject: [PATCH] Vastly speed-up intel memory traversals This uses the exceptions to indicate how much can be skipped in the virtual intel translation layer. This means large holes in the memory can be skipped more quickly. It also eliminates the is_valid/mapping loop. --- volatility/framework/layers/intel.py | 30 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/volatility/framework/layers/intel.py b/volatility/framework/layers/intel.py index c4a543426..7c090a595 100644 --- a/volatility/framework/layers/intel.py +++ b/volatility/framework/layers/intel.py @@ -152,23 +152,27 @@ class Intel(interfaces.layers.TranslationLayerInterface): This allows translation layers to provide maps of contiguous regions in one layer """ if length == 0: - if ignore_errors and not self.is_valid(offset): + try: + mapped_offset, _, layer_name = self._translate(offset) + except exceptions.InvalidAddressException: + if not ignore_errors: + raise raise StopIteration - mapped_offset, _, layer_name = self._translate(offset) yield (offset, mapped_offset, length, layer_name) raise StopIteration while length > 0: - if ignore_errors: - while not self.is_valid(offset) and length > 0: - length -= 1 << self._page_size_in_bits - offset += 1 << self._page_size_in_bits - if length <= 0: - raise StopIteration - chunk_offset, page_size, layer_name = self._translate(offset) - chunk_size = min(page_size - (chunk_offset % page_size), length) - yield (offset, chunk_offset, chunk_size, layer_name) - length -= chunk_size - offset += chunk_size + try: + chunk_offset, page_size, layer_name = self._translate(offset) + except exceptions.PagedInvalidAddressException as excp: + mask = (1 << excp.invalid_bits) - 1 + length_diff = (mask + 1 - (offset & mask)) + length -= length_diff + offset += length_diff + else: + chunk_size = min(page_size - (chunk_offset % page_size), length) + yield (offset, chunk_offset, chunk_size, layer_name) + length -= chunk_size + offset += chunk_size @property def dependencies(self) -> typing.List[str]: