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

parse_arguments: Fix bool type #1056

Merged
merged 1 commit into from
Jan 26, 2024
Merged
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
8 changes: 4 additions & 4 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ A basic example would be as follow:
class MyCommand(GenericCommand):
[...]

@parse_arguments({"foo": [1,]}, {"--bleh": "", ("--blah", "-l): True})
@parse_arguments({"foo": [1,]}, {"--bleh": "", ("--blah", "-l): False})
def do_invoke(self, argv, *args, **kwargs):
args = kwargs["arguments"]
if args.foo == 1: ...
Expand All @@ -216,9 +216,9 @@ gef➤ mycommand --blah 3 14 159 2653
The function `MyCommand!do_invoke()` can use the command line argument value

```python
args.foo --> [3, 14, 159, 2653] # a List(int) from user input
args.bleh --> "" # the default value
args.blah --> True # set to True because user input declared the option (would have been False otherwise)
args.foo == [3, 14, 159, 2653] # a List(int) from user input
args.bleh == "" # the default value
args.blah == True # set to True because user input declared the option (would have been False otherwise)
```

### Adding new architectures
Expand Down
25 changes: 13 additions & 12 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,10 @@ def wrapper(*args: Any, **kwargs: Any) -> Callable:
argname = [argname,]
if argtype is int:
argtype = int_wrapper
if argtype is bool:
parser.add_argument(*argname, action="store_true" if argvalue else "store_false")
else:
parser.add_argument(*argname, type=argtype, default=argvalue)
elif argtype is bool:
parser.add_argument(*argname, action="store_false" if argvalue else "store_true")
continue
parser.add_argument(*argname, type=argtype, default=argvalue)

parsed_args = parser.parse_args(*(args[1:]))
kwargs["arguments"] = parsed_args
Expand Down Expand Up @@ -4722,7 +4722,7 @@ def format_matrix(self) -> Dict[int, Tuple[str, str, str]]:
}

@only_if_gdb_running
@parse_arguments({"location": "$pc", }, {("--length", "-l"): 256, "--bitlen": 0, "--lang": "py", "--clip": True,})
@parse_arguments({"location": "$pc", }, {("--length", "-l"): 256, "--bitlen": 0, "--lang": "py", "--clip": False,})
def do_invoke(self, _: List[str], **kwargs: Any) -> None:
"""Default value for print-format command."""
args: argparse.Namespace = kwargs["arguments"]
Expand Down Expand Up @@ -6014,7 +6014,7 @@ def __init__(self) -> None:
super().__init__(prefix=False)
return

@parse_arguments({"host": "", "port": 0}, {"--pid": -1, "--qemu-user": True, "--qemu-binary": ""})
@parse_arguments({"host": "", "port": 0}, {"--pid": -1, "--qemu-user": False, "--qemu-binary": ""})
def do_invoke(self, _: List[str], **kwargs: Any) -> None:
if gef.session.remote is not None:
err("You already are in remote session. Close it first before opening a new one...")
Expand Down Expand Up @@ -6116,7 +6116,7 @@ def __init__(self) -> None:
return

@only_if_gdb_running
@parse_arguments({"address": "$pc"}, {"--i": 1, "--b": True, "--f": True, "--n": True})
@parse_arguments({"address": "$pc"}, {"--i": 1, "--b": False, "--f": False, "--n": False})
def do_invoke(self, _: List[str], **kwargs: Any) -> None:
args : argparse.Namespace = kwargs["arguments"]
address = parse_address(args.address)
Expand Down Expand Up @@ -6237,7 +6237,7 @@ def __init__(self) -> None:
return

@only_if_gdb_running
@parse_arguments({"addr": ""}, {"--reset": True})
@parse_arguments({"addr": ""}, {"--reset": False})
def do_invoke(self, _: List[str], **kwargs: Any) -> None:
global gef

Expand Down Expand Up @@ -6293,7 +6293,7 @@ def __init__(self) -> None:
super().__init__(complete=gdb.COMPLETE_LOCATION)
return

@parse_arguments({"address": ""}, {"--allow-unaligned": True, "--number": 1})
@parse_arguments({"address": ""}, {"--allow-unaligned": False, "--number": 1})
@only_if_gdb_running
def do_invoke(self, _: List[str], **kwargs: Any) -> None:
args : argparse.Namespace = kwargs["arguments"]
Expand Down Expand Up @@ -6398,7 +6398,7 @@ def __init__(self) -> None:
self["peek_nb_byte"] = (16, "Hexdump N first byte(s) inside the chunk data (0 to disable)")
return

@parse_arguments({"arena_address": ""}, {("--all", "-a"): True, "--allow-unaligned": True, "--min-size": 0, "--max-size": 0, ("--count", "-n"): -1, ("--summary", "-s"): True, "--resolve": True})
@parse_arguments({"arena_address": ""}, {("--all", "-a"): False, "--allow-unaligned": False, "--min-size": 0, "--max-size": 0, ("--count", "-n"): -1, ("--summary", "-s"): False, "--resolve": False})
@only_if_gdb_running
def do_invoke(self, _: List[str], **kwargs: Any) -> None:
args = kwargs["arguments"]
Expand Down Expand Up @@ -7070,7 +7070,7 @@ def __init__(self) -> None:
self["ps_command"] = (f"{gef.session.constants['ps']} auxww", "`ps` command to get process information")
return

@parse_arguments({"pattern": ""}, {"--attach": True, "--smart-scan": True})
@parse_arguments({"pattern": ""}, {"--attach": False, "--smart-scan": False})
def do_invoke(self, _: List, **kwargs: Any) -> None:
args : argparse.Namespace = kwargs["arguments"]
do_attach = args.attach
Expand Down Expand Up @@ -8135,7 +8135,7 @@ def __init__(self) -> None:
return

@only_if_gdb_running
@parse_arguments({"address": "",}, {("--reverse", "-r"): True, ("--size", "-s"): 0})
@parse_arguments({"address": "",}, {("--reverse", "-r"): False, ("--size", "-s"): 0})
def do_invoke(self, _: List[str], **kwargs: Any) -> None:
valid_formats = ["byte", "word", "dword", "qword"]
if not self.format or self.format not in valid_formats:
Expand Down Expand Up @@ -11007,6 +11007,7 @@ def root(self) -> Optional[pathlib.Path]:
self._root = pathlib.Path(f"/proc/{self.pid}/root")
return self._root


class GefRemoteSessionManager(GefSessionManager):
"""Class for managing remote sessions with GEF. It will create a temporary environment
designed to clone the remote one."""
Expand Down
Loading