Skip to content

Commit

Permalink
parse_args: Fix bool type
Browse files Browse the repository at this point in the history
The parse args set the arg behaviour inconsistenly with the other types:
A function had to say 'False' if it wanted the default to be 'True'.
This fixes that.
  • Loading branch information
Grazfather committed Jan 24, 2024
1 parent 219d46f commit a5620e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ 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.blah --> False # set to True because user input declared the option (would have been True 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

0 comments on commit a5620e3

Please sign in to comment.