From dbaba63a74415ee2a0991d936ea93bbe97512828 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Wed, 4 Jan 2023 01:34:26 +0100 Subject: [PATCH] Minor improvements (some of #1465) (#1493) * lib/memory.py: use 'if collection' instead of 'if len(collection) > 0' * commands/__init__.py: use 'not line' instead of 'len(line)==0' * hexdump.py: use 'not data' instead of 'len(data)==0' * commands/nearpc.py: use `if p` instead of `if len("%s" % p)>0` I double checked that this works fine: ``` pwndbg> set nearpc-branch-marker-contiguous Set contiguous branch marker line for nearpc command to ''. pwndbg> pi str(pwndbg.commands.nearpc.nearpc_branch_marker_contiguous) '' pwndbg> pi bool(pwndbg.commands.nearpc.nearpc_branch_marker_contiguous) False ``` --- pwndbg/commands/__init__.py | 2 +- pwndbg/commands/nearpc.py | 2 +- pwndbg/hexdump.py | 2 +- pwndbg/lib/memory.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pwndbg/commands/__init__.py b/pwndbg/commands/__init__.py index 3f44861ba..c5e0e8a4e 100644 --- a/pwndbg/commands/__init__.py +++ b/pwndbg/commands/__init__.py @@ -52,7 +52,7 @@ def list_current_commands(): line = line.strip() # Skip non-command entries if ( - len(line) == 0 + not line or line.startswith("Command class:") or line.startswith("Unclassified commands") ): diff --git a/pwndbg/commands/nearpc.py b/pwndbg/commands/nearpc.py index 81df359e5..5040d4774 100644 --- a/pwndbg/commands/nearpc.py +++ b/pwndbg/commands/nearpc.py @@ -191,7 +191,7 @@ def nearpc(pc=None, lines=None, to_string=False, emulate=False): # Otherwise if it's a branch and it *is* contiguous, just put # and empty line. elif prev and any(g in prev.groups for g in (CS_GRP_CALL, CS_GRP_JUMP, CS_GRP_RET)): - if len("%s" % nearpc_branch_marker_contiguous) > 0: + if nearpc_branch_marker_contiguous: result.append("%s" % nearpc_branch_marker_contiguous) # For syscall instructions, put the name on the side diff --git a/pwndbg/hexdump.py b/pwndbg/hexdump.py index 6ca58438b..f46e14f7c 100644 --- a/pwndbg/hexdump.py +++ b/pwndbg/hexdump.py @@ -87,7 +87,7 @@ def hexdump( load_color_scheme() # If there's nothing to print, just print the offset and address and return - if len(data) == 0: + if not data: yield H.offset("+%04x " % len(data)) + H.address("%#08x " % (address + len(data))) # Don't allow iterating over this generator again diff --git a/pwndbg/lib/memory.py b/pwndbg/lib/memory.py index 78880cd99..32d21046f 100644 --- a/pwndbg/lib/memory.py +++ b/pwndbg/lib/memory.py @@ -94,7 +94,7 @@ class Page: @property def is_memory_mapped_file(self) -> bool: - return len(self.objfile) > 0 and self.objfile[0] != "[" and self.objfile != "" + return self.objfile and self.objfile[0] != "[" and self.objfile != "" @property def read(self) -> bool: