mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-08-17 20:35:40 +02:00
Add in initial version of breakpointing
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#
|
||||
import binascii
|
||||
import code
|
||||
import functools
|
||||
import io
|
||||
import random
|
||||
import string
|
||||
@@ -187,6 +188,7 @@ class Volshell(interfaces.plugins.PluginInterface):
|
||||
def construct_locals(self) -> List[Tuple[List[str], Any]]:
|
||||
"""Returns a listing of the functions to be added to the environment."""
|
||||
return [
|
||||
(["bp", "breakpoint"], self.breakpoint),
|
||||
(["dt", "display_type"], self.display_type),
|
||||
(["db", "display_bytes"], self.display_bytes),
|
||||
(["dw", "display_words"], self.display_words),
|
||||
@@ -797,6 +799,36 @@ class Volshell(interfaces.plugins.PluginInterface):
|
||||
|
||||
return constructed
|
||||
|
||||
def breakpoint(self, address: int, layer_name: Optional[str] = None) -> None:
|
||||
"""Sets a breakpoint on a particular address (within a specific layer)"""
|
||||
if layer_name is None:
|
||||
if self.current_layer is None:
|
||||
raise ValueError("Current layer must be set")
|
||||
layer_name = self.current_layer
|
||||
|
||||
layer: interfaces.layers.DataLayerInterface = self.context.layers[layer_name]
|
||||
# Check if the read value is already overloaded
|
||||
if not hasattr(layer.read, "breakpoints"):
|
||||
# Layer read is not yet wrapped
|
||||
def wrapped_read(offset: int, length: int, pad: bool = False) -> bytes:
|
||||
original_read = getattr(wrapped_read, "original_read")
|
||||
for breakpoint in getattr(wrapped_read, "breakpoints"):
|
||||
if (offset <= breakpoint) and (breakpoint < offset + length):
|
||||
import pdb
|
||||
|
||||
pdb.set_trace()
|
||||
print("Hit breakpoint")
|
||||
return original_read(offset, length, pad)
|
||||
|
||||
setattr(wrapped_read, "breakpoints", set())
|
||||
setattr(wrapped_read, "original_read", layer.read)
|
||||
setattr(layer, "read", wrapped_read)
|
||||
|
||||
# Add the new breakpoint
|
||||
breakpoints = getattr(layer.read, "breakpoints")
|
||||
breakpoints.add(address)
|
||||
setattr(layer.read, "breakpoints", breakpoints)
|
||||
|
||||
|
||||
class NullFileHandler(io.BytesIO, interfaces.plugins.FileHandlerInterface):
|
||||
"""Null FileHandler that swallows files whole without consuming memory"""
|
||||
|
||||
Reference in New Issue
Block a user