diff options
author | Malfurious <m@lfurio.us> | 2023-02-17 17:17:04 -0500 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2023-02-18 14:06:32 -0500 |
commit | d69fc63e9f41acd95f12b20bea305125cb574eb0 (patch) | |
tree | 5407dcf7689e7c472203ace449931094fe6dd410 | |
parent | 9635fefa61f889da10feabfdd43be90e5701f314 (diff) | |
download | sploit-d69fc63e9f41acd95f12b20bea305125cb574eb0.tar.gz sploit-d69fc63e9f41acd95f12b20bea305125cb574eb0.zip |
comm: Strip \n character from readline()
Line-oriented reads now strip the newline from the end of their returned
string. Additionally, readall() strips the newline, but only from the
string that gets logged to the user's terminal (goodbye to all the "\n"
printed at the end of each line).
Of course, these functions are called by other parts of the read API and
have downstream effects. Consideration was given to the entire API with
these rules in mind:
- Raw reads (or non-line-oriented reads) will not filter ANY of
their read content. They are logged to the screen as one "line"
of log text with \n characters shown in-place (not actually
resetting the terminal cursor). If reading binary, these bytes
dont actually mean line termination anyway.
functions: read, readall(_nonblock) *, readuntil
- Line-oriented reads will strip the terminating \n, log the single
line to the screen, and return it.
functions: readline, readlineuntil **
* readall(_nonblock) functions turn out to be a special case. They will
operate as raw reads, returning a blob of content. However, we
generally want to run them on line-oriented input, so they log according
to the line-oriented rules.
** Although content returned from readlineuntil will have \n's stripped,
the lines are returned in an array, so we can still distinguish them.
Signed-off-by: Malfurious <m@lfurio.us>
Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
-rw-r--r-- | sploit/comm.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/sploit/comm.py b/sploit/comm.py index 0ba6e89..f1415bc 100644 --- a/sploit/comm.py +++ b/sploit/comm.py @@ -32,6 +32,8 @@ class Comm: def readline(self): data = self.back.stdin.readline() + if data.endswith(b'\n'): + data = data[:-1] if(data == b''): raise BrokenPipeError('Tried to read on broken pipe') if self.logonread : ilog(data, file=sys.stdout, color=NORMAL) @@ -41,7 +43,8 @@ class Comm: data = b'' try: for line in self.back.stdin: - if self.logonread : ilog(line, file=sys.stdout, color=NORMAL) + tolog = (line[:-1] if line.endswith(b'\n') else line) + if self.logonread : ilog(tolog, file=sys.stdout, color=NORMAL) data += line except KeyboardInterrupt: pass |