Skip to content

Commit 4c0e08c

Browse files
committed
Merge branch 'stable' into beta
2 parents 1b21f7a + 1b47ae1 commit 4c0e08c

File tree

7 files changed

+37
-23
lines changed

7 files changed

+37
-23
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ The table below shows which release corresponds to each branch, and what date th
9292
[2257]: https://github.com/Gallopsled/pwntools/pull/2257
9393
[2225]: https://github.com/Gallopsled/pwntools/pull/2225
9494

95+
## 4.11.2
96+
- [#2349][2349] Fix term.readline omitting a trailing \n
97+
- [#2352][2352] add `RETURN_CONST` as an allowed `_const_code` in safeeval
98+
99+
[2349]: https://github.com/Gallopsled/pwntools/pull/2349
100+
[2352]: https://github.com/Gallopsled/pwntools/pull/2352
101+
95102
## 4.11.1 (`stable`)
96103

97104
- [#2271][2271] FIX: Generated shebang with path to python invalid if path contains spaces

pwnlib/adb/adb.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
from pwnlib.context import LocalContext
6767
from pwnlib.context import context
6868
from pwnlib.device import Device
69+
from pwnlib.exception import PwnlibException
6970
from pwnlib.log import getLogger
7071
from pwnlib.protocols.adb import AdbClient
7172
from pwnlib.util.packing import _decode
@@ -122,7 +123,7 @@ def current_device(any=False):
122123
123124
>>> device = adb.current_device(any=True)
124125
>>> device # doctest: +ELLIPSIS
125-
AdbDevice(serial='emulator-5554', type='device', port='emulator', product='sdk_...phone_armv7', model='sdk ...phone armv7', device='generic')
126+
AdbDevice(serial='emulator-5554', type='device', port='emulator', product='sdk_...phone_...', model='...', device='generic...')
126127
>>> device.port
127128
'emulator'
128129
"""
@@ -252,13 +253,13 @@ class AdbDevice(Device):
252253
253254
>>> device = adb.wait_for_device()
254255
>>> device.arch
255-
'arm'
256+
'amd64'
256257
>>> device.bits
257-
32
258+
64
258259
>>> device.os
259260
'android'
260261
>>> device.product # doctest: +ELLIPSIS
261-
'sdk_...phone_armv7'
262+
'sdk_...phone_...'
262263
>>> device.serial
263264
'emulator-5554'
264265
"""
@@ -1364,7 +1365,7 @@ def compile(source):
13641365
>>> filename = adb.compile(temp)
13651366
>>> sent = adb.push(filename, "/data/local/tmp")
13661367
>>> adb.process(sent).recvall() # doctest: +ELLIPSIS
1367-
b'... /system/bin/linker\n...'
1368+
b'... /system/lib64/libc.so\n...'
13681369
"""
13691370

13701371
ndk_build = misc.which('ndk-build')
@@ -1490,8 +1491,9 @@ class Partitions(object):
14901491
@context.quietfunc
14911492
def by_name_dir(self):
14921493
try:
1493-
return next(find('/dev/block/platform','by-name'))
1494-
except StopIteration:
1494+
with context.local(log_level=logging.FATAL):
1495+
return next(find('/dev/block/platform','by-name'))
1496+
except (StopIteration, PwnlibException):
14951497
return '/dev/block'
14961498

14971499
@context.quietfunc

pwnlib/term/readline.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import six
77
import sys
8+
import os
89

910
from pwnlib.term import keyconsts as kc
1011
from pwnlib.term import keymap as km
@@ -404,7 +405,7 @@ def readline(_size=-1, prompt='', float=True, priority=10):
404405
buffer = (buffer_left + buffer_right)
405406
if buffer:
406407
history.insert(0, buffer)
407-
return force_to_bytes(buffer)
408+
return force_to_bytes(buffer) + b'\n'
408409
except KeyboardInterrupt:
409410
control_c()
410411
finally:
@@ -432,7 +433,7 @@ def raw_input(prompt='', float=True):
432433
float(bool): If set to `True`, prompt and input will float to the
433434
bottom of the screen when `term.term_mode` is enabled.
434435
"""
435-
return readline(-1, prompt, float)
436+
return readline(-1, prompt, float).rstrip(os.linesep.encode())
436437

437438
def str_input(prompt='', float=True):
438439
r"""str_input(prompt='', float=True)
@@ -445,7 +446,7 @@ def str_input(prompt='', float=True):
445446
float(bool): If set to `True`, prompt and input will float to the
446447
bottom of the screen when `term.term_mode` is enabled.
447448
"""
448-
return readline(-1, prompt, float).decode()
449+
return readline(-1, prompt, float).decode().rstrip(os.linesep)
449450

450451
def eval_input(prompt='', float=True):
451452
"""eval_input(prompt='', float=True)
@@ -471,7 +472,7 @@ def eval_input(prompt='', float=True):
471472
Favorite object? 20
472473
"""
473474
from pwnlib.util import safeeval
474-
return safeeval.const(readline(-1, prompt, float))
475+
return safeeval.const(readline(-1, prompt, float).rstrip(os.linesep.encode()))
475476

476477
def init():
477478
global safeeval

pwnlib/tubes/ssh.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -1118,15 +1118,19 @@ def to_carray(py_list):
11181118
python = ssh_process(self, script, tty=True, cwd=cwd, raw=True, level=self.level, timeout=timeout)
11191119

11201120
try:
1121-
python.recvline_contains(b'PWNTOOLS') # Magic flag so that any sh/bash initialization errors are swallowed
1122-
python.recvline() # Python interpreter that was selected
1121+
python.recvline_contains(b'PWNTOOLS') # Magic flag so that any sh/bash initialization errors are swallowed
1122+
try:
1123+
if b'python' not in python.recvline(): # Python interpreter that was selected
1124+
raise ValueError("Python not found on remote host")
1125+
except (EOFError, ValueError):
1126+
self.warn_once('Could not find a Python interpreter on %s\n' % self.host
1127+
+ "Use ssh.system() instead of ssh.process()\n")
1128+
h.failure("Process creation failed")
1129+
return None
1130+
11231131
result = safeeval.const(python.recvline()) # Status flag from the Python script
11241132
except (EOFError, ValueError):
11251133
h.failure("Process creation failed")
1126-
self.warn_once('Could not find a Python interpreter on %s\n' % self.host
1127-
+ "Use ssh.run() instead of ssh.process()\n"
1128-
"The original error message:\n"
1129-
+ python.recvall().decode())
11301134
return None
11311135

11321136
# If an error occurred, try to grab as much output

pwnlib/tubes/tube.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,8 @@ def recv_thread():
900900
while not go.is_set():
901901
if term.term_mode:
902902
data = term.readline.readline(prompt = prompt, float = True)
903-
if data:
904-
data += self.newline
903+
if data.endswith(b'\n') and self.newline != b'\n':
904+
data = data[:-1] + self.newline
905905
else:
906906
stdin = getattr(sys.stdin, 'buffer', sys.stdin)
907907
data = stdin.read(1)

pwnlib/util/safeeval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'BUILD_CONST_KEY_MAP', 'BUILD_STRING',
77
'LOAD_CONST','RETURN_VALUE','STORE_SUBSCR', 'STORE_MAP',
88
'LIST_TO_TUPLE', 'LIST_EXTEND', 'SET_UPDATE', 'DICT_UPDATE', 'DICT_MERGE',
9-
'COPY', 'RESUME',
9+
'COPY', 'RESUME', 'RETURN_CONST'
1010
]
1111

1212
_expr_codes = _const_codes + [

travis/setup_avd_fast.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ set -ex
88
# - arm64-v8a
99
# - x86
1010
# - x86_64
11-
ANDROID_ABI='armeabi-v7a'
11+
ANDROID_ABI='x86_64'
1212
ANDROIDV=android-24
1313

1414
# Create our emulator Android Virtual Device (AVD)
1515
# --snapshot flag is deprecated, see bitrise-steplib/steps-create-android-emulator#18
1616
export PATH=$PATH:"$ANDROID_HOME"/cmdline-tools/latest/bin:"$ANDROID_HOME"/platform-tools
17-
yes | sdkmanager --sdk_root="$ANDROID_HOME" --install "system-images;$ANDROIDV;default;$ANDROID_ABI"
17+
yes | sdkmanager --sdk_root="$ANDROID_HOME" --install "system-images;$ANDROIDV;default;$ANDROID_ABI" "emulator" "platform-tools" "platforms;$ANDROIDV"
1818
yes | sdkmanager --sdk_root="$ANDROID_HOME" --licenses
1919
echo no | avdmanager --silent create avd --name android-$ANDROID_ABI --force --package "system-images;$ANDROIDV;default;$ANDROID_ABI"
2020

21-
"$ANDROID_HOME"/emulator/emulator -avd android-$ANDROID_ABI -no-window -no-boot-anim -read-only -no-audio -no-window -no-snapshot &
21+
"$ANDROID_HOME"/emulator/emulator -avd android-$ANDROID_ABI -no-window -no-boot-anim -read-only -no-audio -no-window -no-snapshot -gpu off -accel off &
2222
adb wait-for-device
2323
adb shell id
2424
adb shell getprop

0 commit comments

Comments
 (0)