Skip to content

Commit 4feba4c

Browse files
fix callPreceded filtering (#213) (#216)
1 parent 1d72f15 commit 4feba4c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ropgadget/options.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
##
88

99
import codecs
10+
from functools import reduce
1011
import re
1112
from struct import pack
1213

@@ -102,18 +103,18 @@ def __isGadgetCallPreceded(gadget):
102103
prevBytes = gadget["prev"]
103104
# TODO: Improve / Semantically document each of these cases.
104105
callPrecededExpressions = [
105-
"\xe8[\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff]$",
106-
"\xe8[\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff]$",
107-
"\xff[\x00-\xff]$",
108-
"\xff[\x00-\xff][\x00-\xff]$",
109-
"\xff[\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff]$",
110-
"\xff[\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff]$",
106+
b"\xe8[\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff]$",
107+
b"\xe8[\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff]$",
108+
b"\xff[\x00-\xff]$",
109+
b"\xff[\x00-\xff][\x00-\xff]$",
110+
b"\xff[\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff]$",
111+
b"\xff[\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff][\x00-\xff]$",
111112
]
112113
return bool(reduce(lambda x, y: x or y, map(lambda x: re.search(x, prevBytes), callPrecededExpressions)))
113114
arch = self.__binary.getArch()
114115
if arch == CS_ARCH_X86:
115116
initial_length = len(self.__gadgets)
116-
self.__gadgets = filter(__isGadgetCallPreceded, self.__gadgets)
117+
self.__gadgets = list(filter(__isGadgetCallPreceded, self.__gadgets))
117118
print("Options().removeNonCallPreceded(): Filtered out {} gadgets.".format(initial_length - len(self.__gadgets)))
118119
else:
119120
print("Options().removeNonCallPreceded(): Unsupported architecture.")

0 commit comments

Comments
 (0)