From eb8a0d6ecc20c673d80e3ceb74e1f51ed61f9236 Mon Sep 17 00:00:00 2001 From: dusoleil Date: Wed, 1 Sep 2021 04:28:42 -0400 Subject: Add Convenience Utility to readuntil() readuntil() and readlineuntil() will now automatically bind() a predicate and given arguments to produce the single function predicate required. The 'until' module will provide convenience utilities for use with readuntil() and readlineuntil(). For now, it contains functools.partial renamed as bind(), lastline() which can call a predicate with the last element of the array of lines given from readlineuntil(), and simplified versions of re.search and re.fullmatch renamed as contains and equals. These allow us to write powerful and legible statements like: comm.readlineuntil(lastline,contains,b'Enter') Signed-off-by: dusoleil --- sploit/until.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 sploit/until.py (limited to 'sploit/until.py') diff --git a/sploit/until.py b/sploit/until.py new file mode 100644 index 0000000..b4f390f --- /dev/null +++ b/sploit/until.py @@ -0,0 +1,14 @@ +from functools import partial as bind +import re + +def lastline(pred, /, *args, **kwargs): + s = args[-1] + args = args[:-1] + p = bind(pred, *args, **kwargs) + return p(s[-1]) + +def contains(regex, s): + return re.search(regex, s) + +def equals(regex, s): + return re.fullmatch(regex, s) -- cgit v1.2.3