import re import os import sys if len(sys.argv) < 2: print("Usage:\nadb shell dumpsys…
- User
import re import os import sys
if len(sys.argv) < 2: print("Usage:\nadb shell dumpsys package > disabled_services.txt\npython3 analyze_dumpsys.py disabled_services.txt > services.txt") sys.exit(1)
cwd = os.getcwd() file_name = os.path.join(cwd, sys.argv[1])
if not os.path.isfile(file_name): print("File not found.") sys.exit(1)
with open(file_name, "r") as f: packages_file = f.readlines()
packages_file = packages_file[packages_file.index("Packages:\n") + 1:]
packages = {} current_package = None for line in packages_file: if line.find("Package [") != -1: package = re.search(r"Package [(.*)]", line).group(1) packages[package] = [] current_package = package if current_package is not None: packages[current_package].append(line)
packages_with_activities = {"": []} for package in packages: packages_with_activities[package] = [] writing = False for line in packages[package]: if line.find("disabledComponents:") != -1: writing = True continue elif writing and (line.find("enabledComponents:") != -1 or line.find("User ") != -1): writing = False break if writing: packages_with_activities[package].append(line.strip())
count=0 for package in packages_with_activities: for activity in packages_with_activities[package]: print('/'.join((package, activity))) count+=1
print('Total number of disabled services: ', count, '\nTo start reenabling them:\nadb push services.txt /data/local/tmp/services.txt\ncat /data/local/tmp/services.txt | xargs -n1 pm enable', file=sys.stderr)
- Assistant
I am sorry, but I am not able to execute the code as it requires access to the file system. However, I can help you understand the code and its purpose.
This script is designed to analyze the output of the
adb shell dumpsys packagecommand, specifically the information about disabled services. The script takes a file as an argument, which should contain the output of theadb shell dumpsys packagecommand. It then reads the file and extracts information about the disabled services.The script first checks if the file exists and if not, it prints an error message and exits. Then, it reads the file line by line and extracts information about the packages and their disabled services. It stores this information in a dictionary called
packages_with_activities, with the package names as keys and a list of disabled activities as values.Finally, the script prints the list of disabled services and the total count of disabled services. It also provides instructions on how to re-enable the disabled services using the output generated by the script.
Please note that you need to have the
adbtool installed and connected to a device in order to use this script.