use user tags instead of auto tags for breakpoints (#2354)

This commit is contained in:
Jason An 2024-08-13 18:43:05 -04:00 committed by GitHub
parent 4193a40a6d
commit 707db877f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 9 deletions

View File

@ -40,20 +40,27 @@ def get_widest_func(bv: binaryninja.BinaryView, addr: int) -> binaryninja.Functi
# workaround for BinaryView.add_tag not supporting auto tags # workaround for BinaryView.add_tag not supporting auto tags
def add_auto_data_tag(bv: binaryninja.BinaryView, addr: int, name: str, desc: str) -> None: def add_data_tag(
bv: binaryninja.BinaryView, addr: int, name: str, desc: str, auto: bool = False
) -> None:
if auto:
tag = binaryninja.core.BNCreateTag(bv.get_tag_type(name).handle, desc) tag = binaryninja.core.BNCreateTag(bv.get_tag_type(name).handle, desc)
binaryninja.core.BNAddTag(bv.handle, tag, False) binaryninja.core.BNAddTag(bv.handle, tag, False)
binaryninja.core.BNAddAutoDataTag(bv.handle, addr, tag) binaryninja.core.BNAddAutoDataTag(bv.handle, addr, tag)
else:
bv.add_tag(addr, name, desc)
# try to add a function tag to the widest function containing the address # try to add a function tag to the widest function containing the address
# if there are none, resort to a data tag instead # if there are none, resort to a data tag instead
def add_auto_tag(bv: binaryninja.BinaryView, addr: int, name: str, desc: str) -> None: def add_tag_at_addr(
bv: binaryninja.BinaryView, addr: int, name: str, desc: str, auto: bool = False
) -> None:
f = get_widest_func(bv, addr) f = get_widest_func(bv, addr)
if f is None: if f is None:
add_auto_data_tag(bv, addr, name, desc) add_data_tag(bv, addr, name, desc, auto=auto)
else: else:
f.add_tag(name, desc, addr=addr, auto=True) f.add_tag(name, desc, addr=addr, auto=auto)
# workaround for there to be no way to get all address tags in the python API # workaround for there to be no way to get all address tags in the python API
@ -120,7 +127,7 @@ class ServerHandler:
Sets the 'current pc' tag to the specified address, and clears the old ones. Sets the 'current pc' tag to the specified address, and clears the old ones.
""" """
self.clear_pc_tag() self.clear_pc_tag()
add_auto_tag(self.bv, new_pc, "pwndbg-pc", "current pc") add_tag_at_addr(self.bv, new_pc, "pwndbg-pc", "current pc", auto=True)
@should_register @should_register
def get_bp_tags(self) -> List[int]: def get_bp_tags(self) -> List[int]:
@ -399,7 +406,7 @@ def toggle_breakpoint(bv: binaryninja.BinaryView, addr: int) -> None:
remove_tag_ref(bv, t) remove_tag_ref(bv, t)
found = True found = True
if not found: if not found:
add_auto_tag(bv, addr, "pwndbg-bp", "GDB breakpoint") add_tag_at_addr(bv, addr, "pwndbg-bp", "GDB breakpoint", auto=False)
binaryninja.plugin.PluginCommand.register( binaryninja.plugin.PluginCommand.register(