Untitled

mail@pastecode.io avatar
unknown
plain_text
23 days ago
1.9 kB
2
Indexable
Never
import subprocess
import csv

# Hàm lấy danh sách các package đã cài
def get_installed_packages():
    result = subprocess.run(['adb', 'shell', 'pm', 'list', 'packages'], stdout=subprocess.PIPE)
    packages = result.stdout.decode('utf-8').splitlines()
    return [pkg.split(":")[1] for pkg in packages]

# Hàm lấy thông tin về các activity từ dumpsys
def get_activity_info(package_name):
    result = subprocess.run(['adb', 'shell', 'dumpsys', 'package', package_name], stdout=subprocess.PIPE)
    return result.stdout.decode('utf-8')

# Hàm phân tích các activity có exported=false
def parse_exported_activities(package_name, dumpsys_output):
    activities = []
    lines = dumpsys_output.splitlines()
    app_name = ""
    for i, line in enumerate(lines):
        # Tìm appName (nếu có trong dump)
        if "application-label" in line:
            app_name = line.split("=")[1]

        # Tìm các activity có exported=false
        if "Activity" in line and "exported=false" in lines[i + 1]:
            activity_name = line.split("Activity")[1].strip().split(" ")[0]
            activities.append((app_name, package_name, activity_name))

    return activities

# Hàm xuất dữ liệu ra file CSV
def export_to_csv(data, filename="exported_activities.csv"):
    with open(filename, mode='w', newline='', encoding='utf-8') as file:
        writer = csv.writer(file)
        writer.writerow(["App Name", "Package Name", "Activity (exported=false)"])
        writer.writerows(data)

def main():
    packages = get_installed_packages()
    all_activities = []
    
    for package in packages:
        dumpsys_output = get_activity_info(package)
        activities = parse_exported_activities(package, dumpsys_output)
        all_activities.extend(activities)
    
    export_to_csv(all_activities)

if __name__ == "__main__":
    main()
Leave a Comment