Skip to content

Commit fa6397c

Browse files
committed
Drop newline in tube.recvline by default
Change the default value of the `drop` parameter to `True` to avoid the common `recvline().strip()` dance and be in line with other readline implementations.
1 parent d1021e7 commit fa6397c

File tree

36 files changed

+100
-96
lines changed

36 files changed

+100
-96
lines changed

docs/source/intro.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ For example, remote connections via :mod:`pwnlib.tubes.remote`.
4343
>>> conn.send(b'USER anonymous\r\n')
4444
>>> conn.recvuntil(b' ', drop=True)
4545
b'331'
46-
>>> conn.recvline()
46+
>>> conn.recvline(drop=False)
4747
b'Please specify the password.\r\n'
4848
>>> conn.close()
4949

@@ -65,7 +65,7 @@ Interacting with processes is easy thanks to :mod:`pwnlib.tubes.process`.
6565
>>> sh.recvline(timeout=1)
6666
b''
6767
>>> sh.recvline(timeout=5)
68-
b'hello world\n'
68+
b'hello world'
6969
>>> sh.close()
7070

7171
Not only can you interact with processes programmatically, but you can
@@ -91,7 +91,7 @@ a ``process`` tube.
9191
>>> sh.recvline(timeout=1)
9292
b''
9393
>>> sh.recvline(timeout=5)
94-
b'hello world\n'
94+
b'hello world'
9595
>>> shell.close()
9696

9797
Packing Integers

pwnlib/adb/adb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def __do_deferred_initialization(self):
322322
r.recvuntil('OK')
323323
r.recvline() # Rest of the line
324324
r.sendline('avd name')
325-
self.avd = r.recvline().strip()
325+
self.avd = r.recvline()
326326
except:
327327
pass
328328

pwnlib/asm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def make_elf(data,
608608
>>> p = process(filename)
609609
>>> p.sendline(b'echo Hello; exit')
610610
>>> p.recvline()
611-
b'Hello\n'
611+
b'Hello'
612612
"""
613613
retval = None
614614

pwnlib/elf/corefile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class Corefile(ELF):
361361
>>> io = process(elf.path, env=env)
362362
>>> io.sendline(b'echo hello')
363363
>>> io.recvline()
364-
b'hello\n'
364+
b'hello'
365365
366366
The process is still running, but accessing its :attr:`.process.corefile` property
367367
automatically invokes GDB to attach and dump a corefile.

pwnlib/encoders/amd64/delta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class amd64DeltaEncoder(i386DeltaEncoder):
1818
>>> p = run_shellcode(encoded)
1919
>>> p.sendline(b'echo hello; exit')
2020
>>> p.recvline()
21-
b'hello\n'
21+
b'hello'
2222
"""
2323
assembly = '''
2424
base:

pwnlib/encoders/arm/xor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ArmXorEncoder(Encoder):
2121
>>> p = run_shellcode(encoded)
2222
>>> p.sendline(b'echo hello; exit')
2323
>>> p.recvline()
24-
b'hello\n'
24+
b'hello'
2525
"""
2626

2727
arch = 'arm'

pwnlib/encoders/i386/xor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class i386XorEncoder(Encoder):
3333
>>> p = run_shellcode(encoded)
3434
>>> p.sendline(b'echo hello; exit')
3535
>>> p.recvline()
36-
b'hello\n'
36+
b'hello'
3737
>>> encoders.i386.xor.encode(asm(shellcraft.execve('/bin/sh')), avoid=bytearray([0x31]))
3838
b'\xd9\xd0\xd9t$\xf4^\xfcj\x07Y\x83\xc6\x19\x89\xf7\xad\x93\xad1\xd8\xabIu\xf7\x00\x00\x00\x00h\x01\x01\x01\x00\x00\x00\x00\x01\x814$\x00\x00\x00\x00.ri\x01\x00\x00\x00\x00h/bi\x00\x00\x00\x01n\x89\xe30\x00\x01\x00\x00\xc90\xd2j\x00\x00\x00\x00\x0bX\xcd\x80'
3939
"""

pwnlib/encoders/mips/xor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class MipsXorEncoder(Encoder):
109109
>>> p = run_shellcode(encoded)
110110
>>> p.sendline(b'echo hello; exit')
111111
>>> p.recvline()
112-
b'hello\n'
112+
b'hello'
113113
"""
114114

115115
arch = 'mips'

pwnlib/filesystem/ssh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def mkdir(self, mode=0o777, parents=False, exist_ok=True):
500500
>>> f = SSHPath('dirA/dirB/dirC', ssh=ssh_conn)
501501
>>> f.mkdir(parents=True)
502502
>>> ssh_conn.run(['ls', '-la', f.absolute().path], env={'LC_ALL': 'C.UTF-8'}).recvline()
503-
b'total 8\n'
503+
b'total 8'
504504
"""
505505
if exist_ok and self.is_dir():
506506
return

pwnlib/gdb.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def debug_assembly(asm, gdbscript=None, vma=None, api=False):
194194
>>> assembly = shellcraft.echo("Hello world!\n")
195195
>>> io = gdb.debug_assembly(assembly)
196196
>>> io.recvline()
197-
b'Hello world!\n'
197+
b'Hello world!'
198198
"""
199199
tmp_elf = make_elf_from_assembly(asm, vma=vma, extract=False)
200200
os.chmod(tmp_elf, 0o777)
@@ -229,7 +229,7 @@ def debug_shellcode(data, gdbscript=None, vma=None, api=False):
229229
>>> shellcode = asm(assembly)
230230
>>> io = gdb.debug_shellcode(shellcode)
231231
>>> io.recvline()
232-
b'Hello world!\n'
232+
b'Hello world!'
233233
"""
234234
if isinstance(data, str):
235235
log.error("Shellcode is cannot be unicode. Did you mean debug_assembly?")
@@ -489,7 +489,7 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por
489489
490490
>>> io.sendline(b"echo hello")
491491
>>> io.recvline()
492-
b'hello\n'
492+
b'hello'
493493
494494
Interact with the process
495495
@@ -513,7 +513,7 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por
513513
514514
>>> io.sendline(b"echo hello")
515515
>>> io.recvline()
516-
b'hello\n'
516+
b'hello'
517517
518518
Interact with the process
519519
@@ -525,7 +525,7 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por
525525
>>> io = gdb.debug(args=[b'\xde\xad\xbe\xef'], gdbscript='continue', exe="/bin/sh")
526526
>>> io.sendline(b"echo $0")
527527
>>> io.recvline()
528-
b'\xde\xad\xbe\xef\n'
528+
b'\xde\xad\xbe\xef'
529529
>>> io.close()
530530
531531
Demonstrate that LD_PRELOAD is respected
@@ -571,15 +571,15 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por
571571
>>> io = gdb.debug(args=[b'\xde\xad\xbe\xef'], gdbscript='continue', exe="/bin/sh", ssh=shell)
572572
>>> io.sendline(b"echo $0")
573573
>>> io.recvline()
574-
b'$ \xde\xad\xbe\xef\n'
574+
b'$ \xde\xad\xbe\xef'
575575
>>> io.close()
576576
577577
Using an empty args[0] on a remote process
578578
579579
>>> io = gdb.debug(args=[], gdbscript='continue', exe="/bin/sh", ssh=shell)
580580
>>> io.sendline(b"echo $0")
581581
>>> io.recvline()
582-
b'$ \n'
582+
b'$ '
583583
>>> io.close()
584584
585585
@@ -616,12 +616,12 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por
616616
617617
>>> io.gdb.continue_nowait()
618618
>>> io.recvline()
619-
b'foo\n'
619+
b'foo'
620620
>>> io.close()
621621
622622
>>> ssh_io.gdb.continue_nowait()
623623
>>> ssh_io.recvline()
624-
b'foo\n'
624+
b'foo'
625625
>>> ssh_io.close()
626626
>>> shell.close()
627627
"""
@@ -983,7 +983,7 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
983983
... quit
984984
... ''')
985985
>>> io.recvline()
986-
b'Hello from process debugger!\n'
986+
b'Hello from process debugger!'
987987
>>> io.sendline(b'echo Hello from bash && exit')
988988
>>> io.recvall()
989989
b'Hello from bash\n'
@@ -1007,7 +1007,7 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
10071007
Observe the forced line
10081008
10091009
>>> io.recvline()
1010-
b'Hello from process debugger!\n'
1010+
b'Hello from process debugger!'
10111011
10121012
Interact with the program in a regular way
10131013
@@ -1031,7 +1031,7 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
10311031
... quit
10321032
... ''')
10331033
>>> io.recvline()
1034-
b'Hello from remote debugger!\n'
1034+
b'Hello from remote debugger!'
10351035
>>> io.sendline(b'echo Hello from bash && exit')
10361036
>>> io.recvall()
10371037
b'Hello from bash\n'
@@ -1052,12 +1052,12 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
10521052
... end
10531053
... ''')
10541054
>>> gdbserver.recvline(timeout=10) # doctest: +ELLIPSIS
1055-
b'Remote debugging from host 127.0.0.1, ...\n'
1055+
b'Remote debugging from host 127.0.0.1, ...'
10561056
>>> gdbserver.recvline(timeout=10)
1057-
b'Hello from gdbserver debugger!\n'
1057+
b'Hello from gdbserver debugger!'
10581058
>>> gdbserver.sendline(b'echo Hello from bash && exit')
10591059
>>> gdbserver.recvline(timeout=10)
1060-
b'Hello from bash\n'
1060+
b'Hello from bash'
10611061
>>> gdbserver.close()
10621062
10631063
Attach to processes running on a remote machine via an SSH :class:`.ssh` process
@@ -1071,10 +1071,10 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
10711071
... quit
10721072
... ''')
10731073
>>> io.recvline(timeout=5) # doctest: +SKIP
1074-
b'Hello from ssh debugger!\n'
1074+
b'Hello from ssh debugger!'
10751075
>>> io.sendline(b'This will be echoed back')
10761076
>>> io.recvline()
1077-
b'This will be echoed back\n'
1077+
b'This will be echoed back'
10781078
>>> io.close()
10791079
10801080
To attach to remote gdbserver, assume you have a socat server delivering gdbserver
@@ -1095,7 +1095,7 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
10951095
... io.recvline()
10961096
... io.close()
10971097
... server.close()
1098-
b'Hello\n'
1098+
b'Hello'
10991099
"""
11001100
if context.noptrace:
11011101
log.warn_once("Skipping debug attach since context.noptrace==True")

0 commit comments

Comments
 (0)