Skip to content

Commit

Permalink
Added option for removing files on the Android device
Browse files Browse the repository at this point in the history
  • Loading branch information
Hifumi committed Jun 6, 2022
1 parent 5926ce0 commit 186e5a4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ python3 droid.py -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
-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)
-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 the selected file
-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
-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)
-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
```

I would recommend running this command before doing anything else to confirm you can successfully connect to the Android device on your network
Expand Down
20 changes: 16 additions & 4 deletions droid.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
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('-loc', '--location', help="Location on the Android device to push the selected file", 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)

args = parser.parse_args()

author = "Hifumi1337"
version = "0.2.6"
version = "0.2.7"

if platform.system() == 'Darwin':
adb = "$HOME/Library/Android/sdk/platform-tools/adb"
Expand Down Expand Up @@ -79,7 +80,7 @@ def upload_apk(self):
except:
print(f"{name_of_apk} upload unsuccessful")

def push(self):
def upload_file(self):
try:
name_of_file = args.push
location_to_push = args.location
Expand All @@ -88,6 +89,14 @@ def push(self):
except:
print(f"{name_of_file} upload unsuccessful")

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")

if args.package == False and args.remove == True:
print("A package name is required to remove an APK")
sys.exit(0)
Expand Down Expand Up @@ -117,7 +126,10 @@ def download(self):
D.remove_apk()

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

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

if args.upload:
D.upload_apk()
Expand Down

0 comments on commit 186e5a4

Please sign in to comment.