Skip to content

Commit 34bdc53

Browse files
committed
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' ```
1 parent b2cba03 commit 34bdc53

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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)