From d69fc63e9f41acd95f12b20bea305125cb574eb0 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Fri, 17 Feb 2023 17:17:04 -0500 Subject: 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 Signed-off-by: dusoleil --- sploit/comm.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sploit/comm.py') 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 -- cgit v1.2.3