Skip to content
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
86 changes: 67 additions & 19 deletions lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from __future__ import division
from __future__ import print_function

import os
import ConfigParser

# change below settings to match your needs
## BEGIN OF SETTINGS ##

Expand All @@ -21,23 +24,26 @@

# PEDA global options
OPTIONS = {
"badchars" : ("", "bad characters to be filtered in payload/output, e.g: '\\x0a\\x00'"),
"pattern" : (1, "pattern type, 0 = basic, 1 = extended, 2 = maximum"),
"p_charset" : ("", "custom charset for pattern_create"),
"indent" : (4, "number of ident spaces for output python payload, e.g: 0|4|8"),
"ansicolor" : ("on", "enable/disable colorized output, e.g: on|off"),
"pagesize" : (25, "number of lines to display per page, 0 = disable paging"),
"session" : ("peda-session-#FILENAME#.txt", "target file to save peda session"),
"tracedepth": (0, "max depth for calls/instructions tracing, 0 means no limit"),
"tracelog" : ("peda-trace-#FILENAME#.txt", "target file to save tracecall output"),
"crashlog" : ("peda-crashdump-#FILENAME#.txt", "target file to save crash dump of fuzzing"),
"snapshot" : ("peda-snapshot-#FILENAME#.raw", "target file to save crash dump of fuzzing"),
"autosave" : ("on", "auto saving peda session, e.g: on|off"),
"payload" : ("peda-payload-#FILENAME#.txt", "target file to save output of payload command"),
"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"),
"_teefd" : ("", "internal use only for tracelog/crashlog writing")
"badchars" : ("", str, "bad characters to be filtered in payload/output, e.g: '\\x0a\\x00'"),
"pattern" : (1, int, "pattern type, 0 = basic, 1 = extended, 2 = maximum"),
"p_charset" : ("", str, "custom charset for pattern_create"),
"indent" : (4, int, "number of ident spaces for output python payload, e.g: 0|4|8"),
"ansicolor" : ("on", str, "enable/disable colorized output, e.g: on|off"),
"pagesize" : (25, int, "number of lines to display per page, 0 = disable paging"),
"session" : ("peda-session-#FILENAME#.txt", str, "target file to save peda session"),
"tracedepth": (0, int, "max depth for calls/instructions tracing, 0 means no limit"),
"tracelog" : ("peda-trace-#FILENAME#.txt", str, "target file to save tracecall output"),
"crashlog" : ("peda-crashdump-#FILENAME#.txt", str, "target file to save crash dump of fuzzing"),
"snapshot" : ("peda-snapshot-#FILENAME#.raw", str, "target file to save crash dump of fuzzing"),
"autosave" : ("on", str, "auto saving peda session, e.g: on|off"),
"payload" : ("peda-payload-#FILENAME#.txt", str, "target file to save output of payload command"),
"context" : ("register,code,stack", str, "context display setting, e.g: register, code, stack, all"),
"verbose" : ("off", str, "show detail execution of commands, e.g: True|False"),
"debug" : ("off", str, "show detail error of peda commands, e.g. True|False"),
"code_size" : (8, int, "default number of lines to show for the code context"),
"stack_size": (8, int, "default number of lines to show for the stack context"),
"clearscr" : ("on", str, "clear screen after each step"),
"_teefd" : ("", str, "internal use only for tracelog/crashlog writing")
}

## END OF SETTINGS ##
Expand All @@ -52,6 +58,48 @@ def __init__(self):
"""option format: name = (value, 'help message')"""
pass

@staticmethod
def save():
"""save settings to config file"""
home = os.path.expanduser('~')
cfgdir = os.path.join(home, '.config', 'peda')

if not os.path.exists(cfgdir):
os.mkdir(cfgdir)

config = os.path.join(cfgdir, 'config.ini')
Config = ConfigParser.ConfigParser()

cfgfile = open(config, 'w')

# add the settings to the structure of the file, and lets write it out...
Config.add_section('Options')

for key, value in Option.options.items():
if not key.startswith("_"):
value = Option.get(key)
Config.set('Options', key, value)

Config.write(cfgfile)
cfgfile.close()

@staticmethod
def load():
"""load settings from config file"""
home = os.path.expanduser('~')
config = os.path.join(home, '.config', 'peda', 'config.ini')

Config = ConfigParser.ConfigParser()
if not os.path.exists(config):
return

Config.read(config)
for option in Config.options('Options'):
if option in Option.options.keys():
if Option.options[option][1] == int:
Option.set(option, Config.getint('Options', option))
if Option.options[option][1] == str:
Option.set(option, Config.get('Options', option))

@staticmethod
def reset():
Expand Down Expand Up @@ -80,7 +128,7 @@ def get(name):
def set(name, value):
"""set option"""
if name in Option.options:
Option.options[name] = (value, Option.options[name][1])
Option.options[name] = (value, Option.options[name][1], Option.options[name][2])
return True
else:
return False
Expand All @@ -91,5 +139,5 @@ def help(name=""):
result = {}
for opt in Option.options:
if name in opt and not opt.startswith("_"):
result[opt] = Option.options[opt][1]
result[opt] = Option.options[opt][2]
return result
39 changes: 35 additions & 4 deletions peda.py
Original file line number Diff line number Diff line change
Expand Up @@ -3197,6 +3197,19 @@ def pyhelp(self, *arg):
pyhelp.options = ["%s" % c for c in dir(PEDA) if callable(getattr(PEDA, c)) and \
not c.startswith("_")]


def save(self, *arg):
"""
Save configured options to config file
"""
config.Option.save()

def load(self, *arg):
"""
Load configured options from config file
"""
config.Option.load()

# show [option | args | env]
def show(self, *arg):
"""
Expand Down Expand Up @@ -4270,7 +4283,7 @@ def context_register(self, *arg):

pc = peda.getreg("pc")
# display register info
msg("\033[2J\033[0;0H [%s]" % "registers".center(78, "-"), "blue")
msg("[%s]" % "registers".center(78, "-"), "blue")
self.xinfo("register")

return
Expand All @@ -4285,7 +4298,11 @@ def context_code(self, *arg):
(count,) = normalize_argv(arg, 1)

if count is None:
count = 8
size = config.Option.get("code_size")
try:
count = int(size)
except ValueError:
count = 8

if not self._is_running():
return
Expand Down Expand Up @@ -4354,6 +4371,13 @@ def context_stack(self, *arg):
"""
(count,) = normalize_argv(arg, 1)

if count is None:
size = config.Option.get("stack_size")
try:
count = int(size)
except ValueError:
count = 8

if not self._is_running():
return

Expand All @@ -4376,8 +4400,6 @@ def context(self, *arg):

(opt, count) = normalize_argv(arg, 2)

if to_int(count) is None:
count = 8
if opt is None:
opt = config.Option.get("context")
if opt == "all":
Expand All @@ -4391,6 +4413,10 @@ def context(self, *arg):
if not self._is_running():
return

clearscr = config.Option.get("clearscr")
if clearscr == "on":
msg("\033[2J\033[0;0H")

status = peda.get_status()
# display registers
if "reg" in opt or "register" in opt:
Expand Down Expand Up @@ -6092,6 +6118,9 @@ def complete(self, text, word):
pedacmd = PEDACmd()
pedacmd.help.__func__.options = pedacmd.commands # XXX HACK

# load configuration file
pedacmd.load()

# register "peda" command in gdb
pedaGDBCommand()
Alias("pead", "peda") # just for auto correction
Expand Down Expand Up @@ -6124,6 +6153,8 @@ def sigint_handler(signal, frame):

# custom command aliases, add any alias you want
Alias("phelp", "peda help")
Alias("psave", "peda save")
Alias("pload", "peda load")
Alias("pset", "peda set")
Alias("pshow", "peda show")
Alias("pbreak", "peda pltbreak")
Expand Down