Skip to content

Commit fa402ce

Browse files
committed
Add adb.uptime and adb.boot_time
1 parent 483adb8 commit fa402ce

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pwnlib/adb/adb.py

+23
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,29 @@ def reboot_bootloader():
162162
with Client() as c:
163163
c.reboot_bootloader()
164164

165+
@with_device
166+
def uptime():
167+
"""boot_time() -> float
168+
169+
Returns:
170+
Uptime of the device, in seconds
171+
"""
172+
up, idle = map(float, read('/proc/uptime').split())
173+
return up
174+
175+
@with_device
176+
def boot_time():
177+
"""boot_time() -> int
178+
179+
Returns:
180+
Boot time of the device, in Unix time, rounded to the
181+
nearest second.
182+
"""
183+
for line in read('/proc/stat').splitlines():
184+
name, value = line.split(None, 1)
185+
if name == 'btime':
186+
return int(value)
187+
165188
class AdbDevice(Device):
166189
"""Encapsulates information about a connected device."""
167190
def __init__(self, serial, type, port=None, product='unknown', model='unknown', device='unknown', features=None, **kw):

0 commit comments

Comments
 (0)