Skip to content

Commit 604b98c

Browse files
authored
Fix pwn constgrep when it matches a non-constant type (Fixes #2344) (#2345)
* Fix pwn constgrep when it matches a non-constant type This commit fixes the following issue: ``` root@pwndbg:~# pwn constgrep a Traceback (most recent call last): File "/usr/local/bin/pwn", line 8, in <module> sys.exit(main()) File "/usr/local/lib/python3.10/dist-packages/pwnlib/commandline/main.py", line 58, in main commands[args.command](args) File "/usr/local/lib/python3.10/dist-packages/pwnlib/commandline/constgrep.py", line 110, in main for _, k in sorted(out): TypeError: '<' not supported between instances of 'Constant' and 'type' ``` Note that it was caused because of the following type object being matched and fetched from the module object: ``` ipdb> out[25:27] [(Constant('CS', 0xd), 'CS'), (<class 'pwnlib.constants.constant.Constant'>, 'Constant')] ipdb> sorted(out[24:27]) *** TypeError: '<' not supported between instances of 'type' and 'Constant' ``` * Add test for `pwn constgrep C` to the CI * Add changelog entry
1 parent 3fbd21a commit 604b98c

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ jobs:
172172
pwn constgrep -c freebsd -m ^PROT_ '3 + 4'
173173
pwn constgrep ^MAP_ 0
174174
pwn constgrep -e O_RDWR
175+
pwn constgrep C
175176
176177
pwn libcdb file /lib/x86_64-linux-gnu/libc.so.6
177178
pwn libcdb lookup puts 5f0 __libc_start_main_ret d0a

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ The table below shows which release corresponds to each branch, and what date th
9191
- [#2161][2161] Fix freebsd amd64 SyscallABI
9292
- [#2160][2161] Fix invalid shellcraft.mov on arm64
9393
- [#2284][2161] Fix invalid shellcraft.pushstr_array on arm64
94+
- [#2345][2345] Fix pwn constgrep when it matches a non-constant type
9495

9596
[2242]: https://github.com/Gallopsled/pwntools/pull/2242
9697
[2277]: https://github.com/Gallopsled/pwntools/pull/2277
@@ -110,6 +111,7 @@ The table below shows which release corresponds to each branch, and what date th
110111
[2325]: https://github.com/Gallopsled/pwntools/pull/2325
111112
[2336]: https://github.com/Gallopsled/pwntools/pull/2336
112113
[2161]: https://github.com/Gallopsled/pwntools/pull/2161
114+
[2345]: https://github.com/Gallopsled/pwntools/pull/2345
113115

114116
## 4.12.0 (`beta`)
115117

pwnlib/commandline/constgrep.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ def main(args):
9191
if not matcher.search(k):
9292
continue
9393

94+
# Check if the value has proper type
95+
val = getattr(mod, k)
96+
if not isinstance(val, pwnlib.constants.constant.Constant):
97+
continue
98+
9499
# Check the constant
95100
if constant is not None:
96-
val = getattr(mod, k)
97101
if args.mask_mode:
98102
if constant & val != val:
99103
continue
@@ -102,7 +106,7 @@ def main(args):
102106
continue
103107

104108
# Append it
105-
out.append((getattr(mod, k), k))
109+
out.append((val, k))
106110
maxlen = max(len(k), maxlen)
107111

108112
# Output all matching constants

0 commit comments

Comments
 (0)