Created
April 16, 2023 09:28
-
-
Save OctoNezd/ccb31d9def9860bcf5e22135dd747cfd to your computer and use it in GitHub Desktop.
Script to recover files from android phones using adb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requirements: | |
# pip install adbutils tqdm | |
# Tested on Huawei STF-L09 that randomly reboots when screen is on | |
import os | |
from tqdm import tqdm | |
import adbutils | |
adb = adbutils.AdbClient(host="127.0.0.1", port=5037) | |
adb.wait_for(state="device") | |
device = adb.device_list()[0] | |
dev_name = device.serial | |
DATA_TYPES = { | |
"images": ["*.jpg", "*.png", "*.bmp", "*.tiff", "*.tif", "*.gif", "*.jpeg"], | |
"documents": ["*.pdf", "*.docx", "*.doc", "*.xls", "*.xlsx", "*.ppt", "*.pptx"], | |
"audio": ["*.mp3", "*.wav", "*.ogg", "*.m4a", "*.aac"] | |
} | |
BLOCK_LIST = ["/Android", "/.", "com.mojang", | |
"/games", "Kwai", "Huawei", "mobotex", "VideoShowPro", "1VideoMaker"] | |
for data_type, extensions in DATA_TYPES.items(): | |
command = ["find", "/sdcard/"] | |
for extension in extensions: | |
command += ["-name", extension, "-o"] | |
command = command[:-1] | |
print("Running", command) | |
file_list = device.shell(command).split("\n") | |
file_list_filtered = [] | |
for file in file_list: | |
skip = False | |
for blocked_word in BLOCK_LIST: | |
if blocked_word.lower() in file.lower(): | |
# print(f"Skipping {file} because it contains {blocked_word}") | |
skip = True | |
break | |
if not skip: | |
print("Adding", file) | |
file_list_filtered.append(file) | |
if len(file_list_filtered) == 0: | |
print("No files found") | |
continue | |
print("Gonna pull", len(file_list_filtered), "files") | |
for file in tqdm(file_list_filtered): | |
parent_fldr = file.split("/")[-2] | |
final_path = f"extracted/{dev_name}/{data_type}/{parent_fldr}/" | |
os.makedirs(final_path, exist_ok=True) | |
device.sync.pull(file, final_path + "/" + file.split("/")[-1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment