Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configurable colors for addresses #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"context" : ("register,code,stack", "context display setting, e.g: register, code, stack, all"),
"verbose" : ("off", "show detail execution of commands, e.g: on|off"),
"debug" : ("off", "show detail error of peda commands, e.g: on|off"),
"color_addr_data" : ("blue", "color of addresses to data"),
"color_addr_code" : ("red", "color of addresses to code"),
"color_addr_rodata" : ("green", "color of addresses to rodata"),
"color_addr_value" : ("none", "color of data"),
"_teefd" : ("", "internal use only for tracelog/crashlog writing")
}

Expand Down Expand Up @@ -93,3 +97,11 @@ def help(name=""):
if name in opt and not opt.startswith("_"):
result[opt] = Option.options[opt][1]
return result

@staticmethod
def get_default(name):
"""get default value of option"""
if name in Option.options:
return Option.options[name][1]
else:
return None
30 changes: 18 additions & 12 deletions lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,25 @@ def check_badchars(data, chars=None):
return True
return False

@memoized
def get_color_for_type(type):
"""Get the color to color an address of a given type"""
colorcode = config.Option.get("color_addr_%s" % type)
if colorcode not in ["black", "red", "green", "yellow", "blue", "purple", "cyan", "white", "none"]:
colorcode = config.Option.get_default("color_addr_%s" % type)
if colorcode == "none":
colorcode = None
return colorcode

def format_address(addr, type):
"""Colorize an address"""
colorcodes = {
"data": "blue",
"code": "red",
"rodata": "green",
"value": None
}
return colorize(addr, colorcodes[type])
return format_address_color(addr, get_color_for_type(type))


@memoized
def format_address_color(addr, colorcode):
"""Colorize an address"""
return colorize(addr, colorcode)


@memoized
def format_reference_chain(chain):
Expand All @@ -461,10 +470,7 @@ def format_reference_chain(chain):
else:
first = True
for (v, t, vn) in chain:
if t != "value":
text += "%s%s " % ("--> " if not first else "", format_address(v, t))
else:
text += "%s%s " % ("--> " if not first else "", v)
text += "%s%s " % ("--> " if not first else "", format_address(v, t))
first = False

if vn:
Expand Down
5 changes: 4 additions & 1 deletion peda.py
Original file line number Diff line number Diff line change
Expand Up @@ -4404,7 +4404,10 @@ def context(self, *arg):
if "stack" in opt or "SIGSEGV" in status:
self.context_stack(count)
msg("[%s]" % ("-"*78), "blue")
msg("Legend: %s, %s, %s, value" % (red("code"), blue("data"), green("rodata")))
msg("Legend: %s, %s, %s, %s" % (colorize("code", get_color_for_type("code")),
colorize("data", get_color_for_type("data")),
colorize("rodata", get_color_for_type("rodata")),
colorize("value", get_color_for_type("value"))))

# display stopped reason
if "SIG" in status:
Expand Down