From 8eb2b50a9ac19eb275f04de63bfe206fdcc92210 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Tue, 22 Oct 2019 19:00:25 +0300 Subject: [PATCH] ap: ensure only one occurence --- win/tools/autopatch/autopatch.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/win/tools/autopatch/autopatch.py b/win/tools/autopatch/autopatch.py index 5572964..74dc82f 100755 --- a/win/tools/autopatch/autopatch.py +++ b/win/tools/autopatch/autopatch.py @@ -59,6 +59,9 @@ class ExtractException(Exception): class PatternNotFoundException(Exception): pass +class MultipleOccurencesException(Exception): + pass + class UnknownPlatformException(Exception): pass @@ -130,9 +133,11 @@ def make_patch(archive, *, sevenzip=sevenzip) as tgt: f = expand(tgt, sevenzip=sevenzip) offset = f.find(search) - del f if offset == -1: raise PatternNotFoundException("Pattern not found.") + if f[offset+len(search):].find(search) != -1: + raise MultipleOccurencesException("Multiple occurences of pattern found!") + del f print("Pattern found @ %016X" % (offset,), file=sys.stderr) res = []