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

Allow ArgparsedCommand to have aliases #621

Merged
merged 1 commit into from Apr 29, 2019
Merged

Conversation

stnevans
Copy link
Contributor

As part of #244, I thought it would be useful if we could add aliases for Argparsed commands.

This pr allows us to give a list of aliases as an optional second argument to ArgparsedCommand.
I'm not totally sure if this is the best way to implement command aliases, so if anyone has a better idea feel free to suggest.
Example usage:
@pwndbg.commands.ArgparsedCommand(parser,aliases=["leakfind2"])
Example output:

pwndbg> leakfind
usage: leakfind [-h] [-p [PAGE_NAME]] [-o [MAX_OFFSET]] [-d [MAX_DEPTH]] [-s [STEP]] [--negative_offset [NEGATIVE_OFFSET]] address
leakfind: error: the following arguments are required: address
pwndbg> leakfind2
usage: leakfind [-h] [-p [PAGE_NAME]] [-o [MAX_OFFSET]] [-d [MAX_DEPTH]] [-s [STEP]] [--negative_offset [NEGATIVE_OFFSET]] address
leakfind: error: the following arguments are required: address

@@ -259,15 +263,15 @@ def split_args(self, argument):

class ArgparsedCommand(object):
"""Adds documentation and offloads parsing for a Command via argparse"""
def __init__(self, parser_or_desc):
def __init__(self, parser_or_desc, aliases=[]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could turn into default argument trap (i.e. the [] is created only once and multiple calls to this method without passing aliases uses the the default value - the same object) but this could be easily spotted imho.

For reference: https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments

@disconnect3d disconnect3d merged commit af4d6fb into pwndbg:dev Apr 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants