Refactor context backtrace to use ColorConfig (#1325)

pull/1326/head
Gulshan Singh 3 years ago committed by GitHub
parent 4bd4bda36d
commit 9c731ae7cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,33 +0,0 @@
import pwndbg.color.theme as theme
from pwndbg.color import generateColorFunction
from pwndbg.gdblib import config
config_prefix = theme.add_param("backtrace-prefix", "", "prefix for current backtrace label")
config_prefix_color = theme.add_color_param(
"backtrace-prefix-color", "none", "color for prefix of current backtrace label"
)
config_address_color = theme.add_color_param(
"backtrace-address-color", "none", "color for backtrace (address)"
)
config_symbol_color = theme.add_color_param(
"backtrace-symbol-color", "none", "color for backtrace (symbol)"
)
config_label_color = theme.add_color_param(
"backtrace-frame-label-color", "none", "color for backtrace (frame label)"
)
def prefix(x):
return generateColorFunction(config.backtrace_prefix_color)(x)
def address(x):
return generateColorFunction(config.backtrace_address_color)(x)
def symbol(x):
return generateColorFunction(config.backtrace_symbol_color)(x)
def frame_label(x):
return generateColorFunction(config.backtrace_frame_label_color)(x)

@ -11,7 +11,6 @@ import gdb
import pwndbg.arguments
import pwndbg.chain
import pwndbg.color
import pwndbg.color.backtrace as B
import pwndbg.color.context as C
import pwndbg.color.memory as M
import pwndbg.color.syntax_highlight as H
@ -27,9 +26,24 @@ import pwndbg.gdblib.vmmap
import pwndbg.ghidra
import pwndbg.ida
import pwndbg.ui
from pwndbg.color import ColorConfig
from pwndbg.color import ColorParamSpec
from pwndbg.color import message
from pwndbg.color import theme
theme.add_param("backtrace-prefix", "", "prefix for current backtrace label")
# TODO: Should namespace be "context.backtrace"?
c = ColorConfig(
"backtrace",
[
ColorParamSpec("prefix", "none", "color for prefix of current backtrace label"),
ColorParamSpec("address", "none", "color for backtrace (address)"),
ColorParamSpec("symbol", "none", "color for backtrace (symbol)"),
ColorParamSpec("frame-label", "none", "color for backtrace (frame label)"),
],
)
def clear_screen(out=sys.stdout):
"""
@ -767,16 +781,16 @@ def context_backtrace(with_banner=True, target=sys.stdout, width=None):
frame = newest_frame
i = 0
bt_prefix = "%s" % B.config_prefix
bt_prefix = "%s" % pwndbg.gdblib.config.backtrace_prefix
while True:
prefix = bt_prefix if frame == this_frame else " " * len(bt_prefix)
prefix = " %s" % B.prefix(prefix)
addrsz = B.address(pwndbg.ui.addrsz(frame.pc()))
symbol = B.symbol(pwndbg.gdblib.symbol.get(frame.pc()))
prefix = " %s" % c.prefix(prefix)
addrsz = c.address(pwndbg.ui.addrsz(frame.pc()))
symbol = c.symbol(pwndbg.gdblib.symbol.get(frame.pc()))
if symbol:
addrsz = addrsz + " " + symbol
line = map(str, (prefix, B.frame_label("%s%i" % (backtrace_frame_label, i)), addrsz))
line = map(str, (prefix, c.frame_label("%s%i" % (backtrace_frame_label, i)), addrsz))
line = " ".join(line)
result.append(line)

Loading…
Cancel
Save