Skip to content

Commit

Permalink
v1.2.8
Browse files Browse the repository at this point in the history
- Updated Windows abd command
- Create new Linux & MacOS releases
- Allows you start/stop Bluetooth and WiFi services remotely
- Improved README docs
  • Loading branch information
Hifumi committed Jun 30, 2022
1 parent 186e5a4 commit 703979a
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ dmypy.json

# Pyre type checker
.pyre/

releases/
49 changes: 32 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,60 @@
# Droid
Droid is a remote communications script created to communicate with an Android device on the local network over the Android debug bridge (adb) in a much easier way
Droid is a remote communications script created to communicate with Android devices on the local network over the Android debug bridge (adb)

NOTE: Script does require Android platform tools (adb) to be installed
NOTE: Script does require Android debug bridge (adb) to be installed before

First release is now available! Versions for Linux and macOS are currently available.

## Usage
```bash
python3 droid.py -ip 127.0.0.1
./droid -ip 127.0.0.1
```

## Options
```
-ip, --ip_address | IP address of the Android device
-up, --upload | Name & location of the APK to upload (ex: ~/Downloads/ApkName.apk)
-rm, --remove | Removes the old APK with the same package name
-c, --connect | Connects to the Android device
-up, --upload | Absolute path of the APK to upload (ex: ~/Downloads/ApkName.apk)
-rm, --remove | Removes the old APK with the same package name (requires the -p flag)
-c, --connect | Connects to the Android device (requires the -ip flag)
-d, --disconnect | Disconnects from the Android device
-r, --reboot | Remotely reboots the Android device
-p, --package | The package name of the APK (ex: com.android.ui)
-p, --package | The package name of the APK you would like to replace (ex: com.android.ui)
-dn, --download | Download a file from the Android device
-ps, --push | Name & location of the file on your local machine
-loc, --location | Location on the Android device to push or remove the selected file
-rmf, --file | Remove a specified file from the Android device
-f, --file | Name of the file on your local machine (ex: ~/Downloads/ApkName.apk)
-loc, --location | Location on the Android device to push or remove the selected file (ex: /sdcard/Downloads)
-rmf, --rmfile | Remove a file from the Android device (set the absolute path using -loc)
-bl, --bluetooth | Start or stop bluetooth service for the Android device
-w, --wifi | Start or stop wifi service for the Android device
```

I would recommend running this command before doing anything else to confirm you can successfully connect to the Android device on your network
```bash
python3 droid.py -ip 127.0.0.1 -c
./droid -ip 127.0.0.1 -c
```

## Example(s)
This example connects to the Android device (127.0.0.1 is an example), removes the specified APK package (`com.android.ui`), and then uploads a new APK called `test_apk_v1.apk`
This example connects to the Android device (127.0.0.1), removes the specified APK package (`com.android.ui`), and then uploads a new APK called `test_apk_v1.apk`
```bash
./droid -ip 127.0.0.1 -c -rm -p com.android.ui -up ~/Downloads/test_apk_v1.apk
```

This example downloads a test images from the Android device onto your local machine (automatically saves it in the ~/Downloads folder on most platforms)
```bash
./droid -ip 127.0.0.1 --download /sdcard/cool_pic.png
```

Once you're finished working within the environment, you can run this command to disconnect from the Android device:
```bash
python3 droid.py -ip 127.0.0.1 -c -rm -p com.android.ui -up ~/Downloads/test_apk_v1.apk
./droid -ip 127.0.0.1 -d
```

This example connects to the Android device (127.0.0.1 is an example) and downloads an image
We now have the option to control the bluetooth service on Android devices. You can `start` the service by running this command (stopping the service uses the `stop` argument):
```bash
python3 droid.py -ip 127.0.0.1 --download /sdcard/cool_pic.png
./droid -ip 127.0.0.1 -bl=start
```

Once you're finished working within the Android environment, you can run this command to disconnect:
You can `stop` the service by running this command (starting the service uses the `start` argument):
```bash
python3 droid.py -ip 127.0.0.1 -d
./droid -ip 127.0.0.1 -w=stop
```
NOTE: When turning the wifi off, if you are communicating with the Android device remotely, this will result in the device being disconnected and unusable until the network is re-established.
126 changes: 99 additions & 27 deletions droid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import os, argparse, sys, time, platform
# ------------------------------------------------------------------------------------------#
# Droid is a remote communications script created to communicate with Android devices #
# #
# Author(s): Hifumi1337 #
# Version: 1.2.8 #
# ------------------------------------------------------------------------------------------#

import os, argparse, sys, time, platform
from subprocess import getoutput

parser = argparse.ArgumentParser()
Expand All @@ -12,19 +18,21 @@
parser.add_argument('-r', '--reboot', help="Remotely reboots the Android device", action='store_true', default=False, required=False)
parser.add_argument('-p', '--package', help="The package name of the APK (ex: com.android.ui)", default=None, required=False)
parser.add_argument('-dn', '--download', help="Download a file from the Android device", default=None, required=False)
parser.add_argument('-ps', '--push', help="Name & location of the file on your local machine", default=None, required=False)
parser.add_argument('-f', '--file', help="Name & location of the file on your local machine", default=None, required=False)
parser.add_argument('-loc', '--location', help="Location on the Android device to push or remove the selected file", default=None, required=False)
parser.add_argument('-rmf', '--file', help="Remove a specified file from the Android device", action='store_true', default=False, required=False)
parser.add_argument('-rmf', '--rmfile', help="Remove a file from the Android device (set the absolute path using -loc)", action='store_true', default=False, required=False)
parser.add_argument('-bl', '--bluetooth', help="Start or stop bluetooth service for the Android device", default=None, required=False)
parser.add_argument('-w', '--wifi', help="Start or stop wifi service for the Android device", default=None, required=False)

args = parser.parse_args()

author = "Hifumi1337"
version = "0.2.7"
version = "1.2.8"

if platform.system() == 'Darwin':
adb = "$HOME/Library/Android/sdk/platform-tools/adb"
elif platform.system() == 'Windows':
adb = "%LOCALAPPDATA%\Android\sdk\platform-tools/adb"
adb = "%LOCALAPPDATA%\Android\sdk\platform-tools\\adb"
elif platform.system() == 'Linux':
whoami = getoutput("whoami")
adb = f"/home/{whoami}/Android/Sdk/platform-tools/adb"
Expand All @@ -41,79 +49,137 @@ def banner(self):
{author} | v{version}
""")


"""
Connect to the Android device
"""
def connect_ip(self):
try:
ip_address = args.ip_address
print("Connecting...")
time.sleep(0.2)
os.system(f'{adb} connect {ip_address}')
except:
print(f"Unable to connect to device {ip_address}")
print(f"Unable to connect to device: {ip_address}")
time.sleep(0.5)
sys.exit(0)

"""
Disconnect from the Android device
"""
def disconnect_ip(self):
try:
ip_address = args.ip_address
print("Disconnecting...")
time.sleep(0.2)
os.system(f'{adb} disconnect {ip_address}')
except:
print(f"Unable to connect to device {ip_address}")
print(f"Unable to disconnect from device: {ip_address}")
time.sleep(0.5)
sys.exit(0)


"""
Allows you to remove an apk from the Android device
"""
def remove_apk(self):
try:
package_name = args.package # Package Name
os.system(f'{adb} uninstall {package_name}')
print(f"{package_name} successfully removed")
except:
print(f"Unable to locate {package_name}")

print(f"Unable to locate: {package_name}")

"""
Allows you to upload an apk from the Android device
"""
def upload_apk(self):
try:
name_of_apk = args.upload
os.system(f'{adb} install -r {name_of_apk}')
print(f"{name_of_apk} successfully uploaded")
except:
print(f"{name_of_apk} upload unsuccessful")
print(f"Unable to upload apk: {name_of_apk}")

"""
Allows you to upload a file to the Android device
"""
def upload_file(self):
try:
name_of_file = args.push
name_of_file = args.file
location_to_push = args.location
os.system(f'{adb} push {name_of_file} {location_to_push}')
print(f"{name_of_file} successfully uploaded")
except:
print(f"{name_of_file} upload unsuccessful")
print(f"Unable to upload file: {name_of_file}")

"""
Allows you to remove a file from the Android device
"""
def remove_file(self):
try:
location_to_remove = args.location
os.system(f'{adb} shell rm -rf {location_to_remove}')
print(f"{location_to_remove} successfully removed")
except:
print(f"{location_to_remove} removal unsuccessful")
print(f"Unable to remove: {location_to_remove}")

if args.package == False and args.remove == True:
print("A package name is required to remove an APK")
if args.package == False and args.remove:
print("A package name is required to remove an apk")
sys.exit(0)


"""
Reboots the Android device
"""
def reboot(self):
try:
ip_address = args.ip_address
os.system(f"{adb} reboot {ip_address}")
except:
print("Device is unresponsive. Please check the connection")

print("Device is unresponsive. Please check connection")

"""
Downloads a file from the Android device
"""
def download(self):
try:
file_location = args.download
os.system(f"{adb} pull {file_location}")
except:
print(f"Unable to locate {file_location}")
print(f"Unable to locate file: {file_location}")

"""
Controls the bluetooth service on the Android device
"""
def bluetooth(self):
if args.bluetooth == 'start':
try:
os.system(f'{adb} root')
os.system(f'{adb} shell service call bluetooth_manager 6') # Starts bluetooth service
except:
print("Unable to start bluetooth service")
elif args.bluetooth == 'stop':
try:
os.system(f'{adb} root')
os.system(f'{adb} shell service call bluetooth_manager 8') # Stops bluetooth service
except:
print("Unable to stop bluetooth service")
else:
print("Please set to either start or stop for your desired response")

"""
Controls the wifi service on the Android device
"""
def wifi(self):
if args.wifi == 'start':
try:
os.system(f'{adb} root')
os.system(f"{adb} shell 'svc wifi enable'") # Starts wifi service
except:
print("Unable to start wifi service")
elif args.wifi == 'stop':
try:
os.system(f'{adb} root')
os.system(f"{adb} shell 'svc wifi disable'") # Stops wifi service
except:
print("Unable to stop wifi service")
else:
print("Please set to either start or stop for your desired response")

if __name__ == '__main__':
D = Droid()
Expand All @@ -125,10 +191,10 @@ def download(self):
if args.remove and args.package:
D.remove_apk()

if args.push and args.location:
if args.file and args.location:
D.upload_file()

if args.file and args.location:
if args.rmfile and args.location:
D.remove_file()

if args.upload:
Expand All @@ -142,3 +208,9 @@ def download(self):

if args.disconnect:
D.disconnect_ip()

if args.bluetooth:
D.bluetooth()

if args.wifi:
D.wifi()

0 comments on commit 703979a

Please sign in to comment.