summaryrefslogtreecommitdiffstats
path: root/sploit/comm.py
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2021-09-01 04:28:42 -0400
committerdusoleil <howcansocksbereal@gmail.com>2021-09-01 04:28:42 -0400
commiteb8a0d6ecc20c673d80e3ceb74e1f51ed61f9236 (patch)
tree8657bf6068c0f882a0d9a84a4efdb5fb55a79607 /sploit/comm.py
parent2b69b26652c63a7e8f681b1b0d7b75d21180a896 (diff)
downloadnsploit-eb8a0d6ecc20c673d80e3ceb74e1f51ed61f9236.tar.gz
nsploit-eb8a0d6ecc20c673d80e3ceb74e1f51ed61f9236.zip
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 <howcansocksbereal@gmail.com>
Diffstat (limited to 'sploit/comm.py')
-rw-r--r--sploit/comm.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/sploit/comm.py b/sploit/comm.py
index f7d2f5d..0ee786b 100644
--- a/sploit/comm.py
+++ b/sploit/comm.py
@@ -7,6 +7,7 @@ import select
import signal
from sploit.log import log
+from sploit.until import bind
class Comm:
def __init__(self, backend):
@@ -26,8 +27,9 @@ class Comm:
log(data)
return data
- def readuntil(self, pred):
+ def readuntil(self, pred, /, *args, **kwargs):
data = b''
+ pred = bind(pred, *args, **kwargs)
while(True):
data += self.back.stdin.read(1)
if(pred(data)):
@@ -35,8 +37,9 @@ class Comm:
log(data)
return data
- def readlineuntil(self, pred):
+ def readlineuntil(self, pred, /, *args, **kwargs):
dataarr = []
+ pred = bind(pred, *args, **kwargs)
while(True):
data = self.back.stdin.readline()
log(data)