|
7 | 7 | ## |
8 | 8 |
|
9 | 9 | import codecs |
| 10 | +from functools import reduce |
10 | 11 | import re |
11 | 12 | from struct import pack |
12 | 13 |
|
@@ -102,18 +103,18 @@ def __isGadgetCallPreceded(gadget): |
102 | 103 | prevBytes = gadget["prev"] |
103 | 104 | # TODO: Improve / Semantically document each of these cases. |
104 | 105 | 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]$", |
111 | 112 | ] |
112 | 113 | return bool(reduce(lambda x, y: x or y, map(lambda x: re.search(x, prevBytes), callPrecededExpressions))) |
113 | 114 | arch = self.__binary.getArch() |
114 | 115 | if arch == CS_ARCH_X86: |
115 | 116 | initial_length = len(self.__gadgets) |
116 | | - self.__gadgets = filter(__isGadgetCallPreceded, self.__gadgets) |
| 117 | + self.__gadgets = list(filter(__isGadgetCallPreceded, self.__gadgets)) |
117 | 118 | print("Options().removeNonCallPreceded(): Filtered out {} gadgets.".format(initial_length - len(self.__gadgets))) |
118 | 119 | else: |
119 | 120 | print("Options().removeNonCallPreceded(): Unsupported architecture.") |
|
0 commit comments