Skip to content

Commit f5ec6dc

Browse files
committed
Add in initial version of breakpointing
1 parent 51f0a30 commit f5ec6dc

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

volatility3/cli/volshell/generic.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44
import binascii
55
import code
6+
import functools
67
import io
78
import random
89
import string
@@ -187,6 +188,7 @@ def help(self, *args):
187188
def construct_locals(self) -> List[Tuple[List[str], Any]]:
188189
"""Returns a listing of the functions to be added to the environment."""
189190
return [
191+
(["bp", "breakpoint"], self.breakpoint),
190192
(["dt", "display_type"], self.display_type),
191193
(["db", "display_bytes"], self.display_bytes),
192194
(["dw", "display_words"], self.display_words),
@@ -797,6 +799,36 @@ def create_configurable(
797799

798800
return constructed
799801

802+
def breakpoint(self, address: int, layer_name: Optional[str] = None) -> None:
803+
"""Sets a breakpoint on a particular address (within a specific layer)"""
804+
if layer_name is None:
805+
if self.current_layer is None:
806+
raise ValueError("Current layer must be set")
807+
layer_name = self.current_layer
808+
809+
layer: interfaces.layers.DataLayerInterface = self.context.layers[layer_name]
810+
# Check if the read value is already overloaded
811+
if not hasattr(layer.read, "breakpoints"):
812+
# Layer read is not yet wrapped
813+
def wrapped_read(offset: int, length: int, pad: bool = False) -> bytes:
814+
original_read = getattr(wrapped_read, "original_read")
815+
for breakpoint in getattr(wrapped_read, "breakpoints"):
816+
if (offset <= breakpoint) and (breakpoint < offset + length):
817+
import pdb
818+
819+
pdb.set_trace()
820+
print("Hit breakpoint")
821+
return original_read(offset, length, pad)
822+
823+
setattr(wrapped_read, "breakpoints", set())
824+
setattr(wrapped_read, "original_read", layer.read)
825+
setattr(layer, "read", wrapped_read)
826+
827+
# Add the new breakpoint
828+
breakpoints = getattr(layer.read, "breakpoints")
829+
breakpoints.add(address)
830+
setattr(layer.read, "breakpoints", breakpoints)
831+
800832

801833
class NullFileHandler(io.BytesIO, interfaces.plugins.FileHandlerInterface):
802834
"""Null FileHandler that swallows files whole without consuming memory"""

0 commit comments

Comments
 (0)