Skip to content

Commit b922cbb

Browse files
committed
Merge branch 'beta' into dev
2 parents d5a12c1 + e551b4a commit b922cbb

4 files changed

Lines changed: 44 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ The table below shows which release corresponds to each branch, and what date th
177177
[2704]: https://github.com/Gallopsled/pwntools/pull/2704
178178
[2655]: https://github.com/Gallopsled/pwntools/pull/2655
179179

180+
## 4.15.1
181+
182+
- [#2694][2694] fix: pad bytes fields to correct field size in FileStructure
183+
- [#2701][2701] Fix `adb._build_date()` crash on devices with non-standard locale date strings
184+
185+
[2694]: https://github.com/Gallopsled/pwntools/pull/2694
186+
[2701]: https://github.com/Gallopsled/pwntools/pull/2701
187+
180188
## 4.15.0 (`stable`)
181189

182190
- [#2508][2508] Ignore a warning when compiling with asm on nix

pwnlib/adb/adb.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,28 @@ def __hash__(self, other):
12721272

12731273
def _build_date():
12741274
"""Returns the build date in the form YYYY-MM-DD as a string"""
1275+
import datetime
1276+
1277+
# Use ro.build.date.utc (integer epoch seconds) which is set by the
1278+
# AOSP build system and available on all standard Android devices.
1279+
# This avoids ro.build.date which is locale-dependent and can contain
1280+
# non-ASCII characters that dateutil cannot parse. See #2513.
1281+
utc = getprop('ro.build.date.utc')
1282+
if utc and utc.strip().isdigit():
1283+
try:
1284+
as_datetime = datetime.datetime.fromtimestamp(int(utc.strip()), dateutil.tz.UTC)
1285+
return as_datetime.strftime('%Y-%b-%d')
1286+
except (OSError, OverflowError, ValueError):
1287+
pass
1288+
1289+
# Fallback for non-standard builds missing ro.build.date.utc.
12751290
as_string = getprop('ro.build.date')
1276-
as_datetime = dateutil.parser.parse(as_string)
1291+
if not as_string:
1292+
return ''
1293+
try:
1294+
as_datetime = dateutil.parser.parse(as_string)
1295+
except (ValueError, OverflowError):
1296+
return as_string
12771297
return as_datetime.strftime('%Y-%b-%d')
12781298

12791299
def find_ndk_project_root(source):

pwnlib/filepointer.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,18 @@ class FileStructure(object):
260260
_mode: 0x0
261261
_unused2: 0x0
262262
vtable: 0x0}
263+
264+
Bytes fields are padded to the correct field size.
265+
For example, _unused2 is 40 bytes on i386, so a short value gets
266+
zero-padded to 40, not to context.bytes (4):
267+
268+
>>> context.clear(arch='i386')
269+
>>> fileStr2 = FileStructure(null=0)
270+
>>> fileStr2.vtable = 0x561859f0
271+
>>> old_len = len(bytes(fileStr2))
272+
>>> fileStr2._unused2 = b'AB'
273+
>>> len(bytes(fileStr2)) == old_len
274+
True
263275
"""
264276

265277
vars_=[]
@@ -300,7 +312,7 @@ def __bytes__(self):
300312
structure = b''
301313
for val in self.vars_:
302314
if isinstance(getattr(self, val), bytes):
303-
structure += getattr(self, val).ljust(context.bytes, b'\x00')
315+
structure += getattr(self, val).ljust(self.length[val], b'\x00')
304316
else:
305317
if self.length[val] > 0:
306318
structure += pack(int(getattr(self, val)), self.length[val]*8)
@@ -329,7 +341,7 @@ def struntil(self,v):
329341
structure = b''
330342
for val in self.vars_:
331343
if isinstance(getattr(self, val), bytes):
332-
structure += getattr(self, val).ljust(context.bytes, b'\x00')
344+
structure += getattr(self, val).ljust(self.length[val], b'\x00')
333345
else:
334346
structure += pack(int(getattr(self, val)), self.length[val]*8)
335347
if val == v:

pwnlib/term/readline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def readline(_size=-1, prompt='', float=True, priority=10):
375375
from pwnlib.term import term_mode
376376
if not term_mode:
377377
print(prompt, end='', flush=True)
378-
return getattr(sys.stdin, 'buffer', sys.stdin).readline(_size).rstrip(b'\n')
378+
return force_to_bytes(getattr(sys.stdin, 'buffer', sys.stdin).readline(_size)).rstrip(b'\n')
379379
show_suggestions = False
380380
eof = False
381381
if prompt:

0 commit comments

Comments
 (0)