Skip to content

Commit

Permalink
Merge pull request #1623 from volatilityfoundation/issues/issue1618
Browse files Browse the repository at this point in the history
Layers: Reduce double bounds test and simplify intel translation
  • Loading branch information
ikelos authored Feb 21, 2025
2 parents 3ea563b + 346e58e commit 2ffb3ac
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions volatility3/framework/layers/intel.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _translate(self, offset: int) -> Tuple[int, int, str]:
translated address lives in and the layer_name that the address
lives in
"""
entry, position = self._translate_entry(offset)
entry, position = self._translate_entry(offset & self.page_mask)

# Now we're done
if not self._page_is_valid(entry):
Expand All @@ -181,23 +181,8 @@ def _pte_pfn(self, entry: int) -> int:
"""Extracts the page frame number (PFN) from the page table entry (PTE) entry"""
return self._mask(entry, self._maxphyaddr - 1, 0) >> self.page_shift

def _translate_entry(self, offset: int) -> Tuple[int, int]:
"""Translates a specific offset based on paging tables.
Returns the translated entry value
"""
offset &= self.address_mask

if not (self.minimum_address <= offset <= self.maximum_address):
raise exceptions.InvalidAddressException(
offset, f"Address {offset:#x} outside virtual address range"
)

page_address = offset & self.page_mask
return self._translate_page(page_address)

@functools.lru_cache(maxsize=1024)
def _translate_page(self, page_address: int) -> int:
def _translate_entry(self, page_address: int) -> int:
"""Translates a page address based on paging tables.
Args:
Expand All @@ -206,11 +191,6 @@ def _translate_page(self, page_address: int) -> int:
Returns:
the translated entry value
"""
if page_address & ~self.page_mask != 0:
raise exceptions.InvalidAddressException(
page_address,
f"Invalid page address {page_address:#x}. The address must be aligned to the page size",
)
# Setup the entry and how far we are through the offset
# Position maintains the number of bits left to process
# We or with 0x1 to ensure our page_map_offset is always valid
Expand Down Expand Up @@ -310,7 +290,7 @@ def is_valid(self, offset: int, length: int = 1) -> bool:

def is_dirty(self, offset: int) -> bool:
"""Returns whether the page at offset is marked dirty"""
return self._page_is_dirty(self._translate_entry(offset)[0])
return self._page_is_dirty(self._translate_entry(offset & self.page_mask)[0])

def mapping(
self, offset: int, length: int, ignore_errors: bool = False
Expand Down

0 comments on commit 2ffb3ac

Please sign in to comment.