diff options
| author | jakob <jakob@memeware.net> | 2017-08-29 15:19:54 -0400 |
|---|---|---|
| committer | jakob <jakob@memeware.net> | 2017-08-29 15:19:54 -0400 |
| commit | a0aac5609c87443ea12d04ffb280234c24d13e3f (patch) | |
| tree | 0d509580be6e30a3ff6a26e55a2f46472c91afcd /hypodermic/main.py | |
| parent | e687f96e883af18ef293b6844ef28f0c829d6e3c (diff) | |
Implemented parsing for procfs maps
Diffstat (limited to 'hypodermic/main.py')
| -rw-r--r-- | hypodermic/main.py | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/hypodermic/main.py b/hypodermic/main.py index 05d467a..b0d709b 100644 --- a/hypodermic/main.py +++ b/hypodermic/main.py @@ -15,6 +15,79 @@ # You should have received a copy of the GNU General Public License along # with Hypodermic. If not, see <http://www.gnu.org/licenses/>. +"""Command-line interface to Hypodermic.""" + +import argparse +import sys +import textwrap +import pprint # + +from hypodermic.memory import maps +from hypodermic.ptrace import Process + + +class CustomHelp(argparse.HelpFormatter): + """Modifications to argparse's default HelpFormatter.""" + def _fill_text(self, text, width, indent): + filled = [] + for line in text.splitlines(keepends=True): + filled.append(indent + line) + return "".join(filled) + + def _split_lines(self, text, width): + return text.splitlines() + + def add_usage(self, usage, actions, groups, prefix=None): + prefix = prefix or "Usage: " + both = super(CustomHelp, self) + return both.add_usage(usage, actions, groups, prefix) + def main(): - print("Don't share needles, brah!") + parser = argparse.ArgumentParser( + add_help=False, + formatter_class=CustomHelp, + usage="%(prog)s [-a pid] [-c path] [options]", + description="Don't share needles, brah!" + ) + + doc = parser.add_argument_group("Documentation") + doc.add_argument( + "-h", + "--help", + action="help", + help="Display this help page and exit." + ) + doc.add_argument( + "-V", + "--version", + action="version", + version="What version?", + help="Display the currently installed version and exit." + ) + + proc = parser.add_argument_group("Process Manipulation") + meth = proc.add_mutually_exclusive_group() + proc.add_argument( + "-a", + "--attach", + metavar="PID", + help="The pid of a process to attach to." + ) + proc.add_argument( + "-c", + "--create", + metavar="BIN", + help="The path of a binary to execute and attach to." + ) + + args = parser.parse_args() + + if args.attach is None and args.create is None: + print("No action specified. Quitting!") + sys.exit(1) + + if args.create: + p = Process(path=args.create) + else: + p = Process(pid=args.attach) |