From e5b172c56c2e5d2f55de884b65ac8457dc638075 Mon Sep 17 00:00:00 2001 From: dusoleil Date: Tue, 31 Aug 2021 19:32:59 -0400 Subject: Add readuntil() and readlineuntil() to Comms Both new functions check the input for a predicate and keep reading until the predicate is true. readuntil() will consume input byte by byte and use the entire string read to check the predicate. It will then return that entire string. readlineuntil() consumes input line by line and only uses the last line to check the predicate. The line that satisfies the predicate is all that is returned. Signed-off-by: dusoleil --- tools/sploit/sploit/comm.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tools') diff --git a/tools/sploit/sploit/comm.py b/tools/sploit/sploit/comm.py index 009f193..9b68c38 100644 --- a/tools/sploit/sploit/comm.py +++ b/tools/sploit/sploit/comm.py @@ -22,6 +22,20 @@ class Comm: log(data) return data + def readuntil(self,pred): + data = b'' + while(not pred(data)): + data += self.back.stdin.read(1) + log(data) + return data + + def readlineuntil(self,pred): + data = b'' + while(not pred(data)): + data = self.back.stdin.readline() + log(data) + return data + def write(self, data): self.back.stdout.write(data) self.back.stdout.flush() -- cgit v1.2.3