PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Android Phone Recovery Tool By J~Net

Go down

Android Phone Recovery Tool By J~Net Empty Android Phone Recovery Tool By J~Net

Post by jamied_uk 29th January 2024, 11:44

Code:
#
#File Recovery Tool By (c)J~Net 2024
# https://jnet.forumotion.com/t1997-android-phone-recovery-tool-by-jnet#3076
#
# python3 run.py
import os
import shutil
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox

class FileRecoveryApp:
    def __init__(self, root):
        self.root = root
        self.root.title("File Recovery Tool")
        self.selected_folders = []
        self.output_folder = None  # New variable to store the output folder
        self.file_type_var = tk.StringVar()
        self.file_type_var.set(".mp4")

        # UI Elements
        self.folder_listbox = tk.Listbox(root, selectmode=tk.MULTIPLE)
        self.folder_listbox.pack(pady=10)

        self.add_phone_folder_button = tk.Button(root, text="Add Phone Folder", command=self.add_phone_folder)
        self.add_phone_folder_button.pack(pady=5)

        self.output_folder_button = tk.Button(root, text="Choose Output Folder", command=self.choose_output_folder)
        self.output_folder_button.pack(pady=5)

        self.file_type_label = tk.Label(root, text="File Type:")
        self.file_type_label.pack(pady=5)
        self.file_type_entry = tk.Entry(root, textvariable=self.file_type_var)
        self.file_type_entry.pack(pady=5)

        self.recover_button = tk.Button(root, text="Recover Selected Files", command=self.recover_files)
        self.recover_button.pack(pady=10)

    def add_phone_folder(self):
        # Check if ADB is installed
        if not self.is_adb_installed():
            self.install_adb()

        # Use ADB to list folders on the phone and dynamically add them to the listbox
        phone_folders = self.get_phone_folders()
        if phone_folders:
            phone_folder_selected = filedialog.askdirectory(title="Select Phone Folder", initialdir=phone_folders[0])
            if phone_folder_selected:
                self.selected_folders.append(phone_folder_selected)
                self.folder_listbox.insert(tk.END, phone_folder_selected)
        else:
            tk.messagebox.showwarning("Phone Not Connected", "Phone not connected. Press Enter to try again.")

    def choose_output_folder(self):
        # Open a file dialog to select the output folder for recovered files
        self.output_folder = filedialog.askdirectory()

    def recover_files(self):
        file_type = self.file_type_var.get()

        if not self.output_folder:
            # If output folder is not selected, prompt the user to choose one
            tk.messagebox.showwarning("Output Folder", "Please choose an output folder.")
            return

        for folder_path in self.selected_folders:
            self.recover_files_in_folder(folder_path, file_type)

    def recover_files_in_folder(self, folder_path, file_type):
        # Check if the phone folder exists
        if not os.path.exists(folder_path):
            print(f"Folder does not exist: {folder_path}")
            return

        # Create a temporary directory to store recovered files
        temp_output_folder = os.path.join(os.getcwd(), "recovered_files")
        os.makedirs(temp_output_folder, exist_ok=True)

        # Traverse the folder and its subdirectories
        for root_folder, subfolders, files in os.walk(folder_path):
            for file_name in files:
                if file_name.endswith(file_type):
                    file_path = os.path.join(root_folder, file_name)

                    # Check if the file is deleted
                    if not os.path.exists(file_path):
                        # Use ADB to pull the file from the phone
                        adb_pull_command = f"adb pull {os.path.join('.trash', file_name)} {temp_output_folder}"
                        os.system(adb_pull_command)

        # Move recovered files to the selected output folder
        for recovered_file_name in os.listdir(temp_output_folder):
            recovered_file_path = os.path.join(temp_output_folder, recovered_file_name)
            shutil.move(recovered_file_path, os.path.join(self.output_folder, recovered_file_name))
            print(f"Recovered: {os.path.join(self.output_folder, recovered_file_name)}")

        # Remove the temporary directory
        shutil.rmtree(temp_output_folder)

    def get_phone_folders(self):
        try:
            # Run ADB command to list folders on the phone
            result = os.popen("adb shell ls -d /storage/emulated/0/*/").read()
            folders = result.splitlines()
            return folders
        except Exception as e:
            print(f"Error getting phone folders: {e}")
            return []

    def is_adb_installed(self):
        try:
            # Check if ADB is in the system's PATH
            result = os.system("adb version")
            return result == 0
        except Exception as e:
            print(f"Error checking ADB installation: {e}")
            return False

    def install_adb(self):
        try:
            # Install ADB based on the operating system
            if os.name == 'posix':  # Linux
                os.system("sudo apt-get install adb")
            elif os.name == 'nt':  # Windows
                # Download ADB for Windows and extract it to a directory in the system's PATH
                adb_download_url = "https://dl.google.com/android/repository/platform-tools-latest-windows.zip"
                adb_zip_path = os.path.join(os.getcwd(), "platform-tools.zip")
                os.system(f"curl -o {adb_zip_path} {adb_download_url}")
                os.system(f"unzip {adb_zip_path} -d {os.getcwd()}")
                os.remove(adb_zip_path)
            else:
                print("Unsupported operating system. Please install ADB manually.")
        except Exception as e:
            print(f"Error installing ADB: {e}")

if __name__ == "__main__":
    # Create the main tkinter window
    root = tk.Tk()

    # Instantiate the FileRecoveryApp class with the main window
    app = FileRecoveryApp(root)

    # Run the tkinter main loop
    root.mainloop()
jamied_uk
jamied_uk
Admin

Posts : 2950
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum