|
3 | 3 | # |
4 | 4 | import binascii |
5 | 5 | import code |
| 6 | +import functools |
6 | 7 | import io |
7 | 8 | import random |
8 | 9 | import string |
@@ -187,6 +188,7 @@ def help(self, *args): |
187 | 188 | def construct_locals(self) -> List[Tuple[List[str], Any]]: |
188 | 189 | """Returns a listing of the functions to be added to the environment.""" |
189 | 190 | return [ |
| 191 | + (["bp", "breakpoint"], self.breakpoint), |
190 | 192 | (["dt", "display_type"], self.display_type), |
191 | 193 | (["db", "display_bytes"], self.display_bytes), |
192 | 194 | (["dw", "display_words"], self.display_words), |
@@ -797,6 +799,36 @@ def create_configurable( |
797 | 799 |
|
798 | 800 | return constructed |
799 | 801 |
|
| 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 | + |
800 | 832 |
|
801 | 833 | class NullFileHandler(io.BytesIO, interfaces.plugins.FileHandlerInterface): |
802 | 834 | """Null FileHandler that swallows files whole without consuming memory""" |
|
0 commit comments