Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more adb commands. #703

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions pwnlib/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,48 @@ def setprop(name, value):
"""Writes a property to the system property store."""
return process(['setprop', name, value]).recvall().strip()

def run_cmd(cmd, use_su=False):
"""Run a shell command"""
commands = ['shell']
if use_su:
commands.extend(['su', '-c'])
commands.append(cmd)
return adb(commands)

def install(apk, forward_lock=False, reinstall_and_keep_data=False, install_on_sd_card=False):
"""Install an APK on the device

Arguments:
apk(str): Local path to APK to install.
forward_lock(bool): forward-lock the app. Default=False.
reinstall_and_keep_data(bool): reinstall the app, keeping its data. Default=False.
install_on_sd_card(bool): install on SD card instead of internal storage
"""
args = ['install']
if forward_lock:
args.append('-l')
if reinstall_and_keep_data:
args.append('-r')
if install_on_sd_card:
args.append('-s')
args.append(apk)
return adb(args).splitlines()[-1].strip() == 'Success'

def uninstall(package, keep_data=False):
"""Remove app package from the device

Arguments:
keep_data(bool): keep the data and cache directories.

Returns:
``True`` if the package was removed successfully
"""
args = ['uninstall']
if keep_data:
args.append('-k')
args.append(package)
return adb(args).strip() == 'Success'

def listdir(directory='/'):
"""Returns a list containing the entries in the provided directory.

Expand Down