Just tidy up the multistring searchers slightly.

This commit is contained in:
Mike Auty
2018-01-25 11:27:59 +00:00
parent ccd00afdb2
commit 663cf3eff8
3 changed files with 27 additions and 18 deletions
@@ -21,3 +21,9 @@ class MultiRegexp(object):
raise TypeError("Search haystack must be a byte string")
for match in re.finditer(self._regex, haystack):
yield (match.start(0), match.group())
if __name__ == '__main__':
import multistring_testrig
multistring_testrig.tester(MultiRegexp())
@@ -0,0 +1,19 @@
def tester(searcher):
import argparse
parser = argparse.ArgumentParser(usage = "Searches through a haystack for a set of needles")
parser.add_argument("-n", "--needles", help = "The filename of the file containing newline separated needles",
required = True)
parser.add_argument("haystack", help = "The filename of the binary haystack file to search")
args = parser.parse_args()
with open(args.needles, "rb") as needles_fp:
needles = needles_fp.read().split(b"\n")
with open(args.haystack, "rb") as haystack_fp:
haystack = haystack_fp.read()
for needle in needles:
if len(needle):
searcher.add_pattern(needle)
searcher.preprocess()
for result in searcher.search(haystack):
print("0x{:x} - {}".format(*result))
@@ -72,22 +72,6 @@ class WuManber(object):
if __name__ == '__main__':
import argparse
import multistring_testrig
parser = argparse.ArgumentParser(usage = "Searches through a haystack for a set of needles")
parser.add_argument("-n", "--needles", help = "The filename of the file containing newline separated needles",
required = True)
parser.add_argument("haystack", help = "The filename of the binary haystack file to search")
args = parser.parse_args()
with open(args.needles, "rb") as needles_fp:
needles = needles_fp.read().split(b"\n")
with open(args.haystack, "rb") as haystack_fp:
haystack = haystack_fp.read()
wm = WuManber()
for needle in needles:
if len(needle):
wm.add_pattern(needle)
wm.preprocess()
for result in wm.search(haystack):
print("0x{:x} - {}".format(*result))
multistring_testrig.tester(WuManber())