aman-e9 commited on
Commit
31ee30c
·
verified ·
1 Parent(s): e639dd1

Upload apk_modder_advanced (1).py

Browse files
Files changed (1) hide show
  1. apk_modder_advanced (1).py +88 -0
apk_modder_advanced (1).py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import os
3
+ import shutil
4
+ import subprocess
5
+
6
+ APKTOOL_PATH = "apktool" # Ensure this is in your system path
7
+ SIGNED_APK = "signed_output.apk"
8
+ TRACKER_LOG = "detected_trackers.txt"
9
+
10
+ def mod_apk(apk_path):
11
+ app_name = "decompiled_app"
12
+ cleaned_apk = "recompiled.apk"
13
+
14
+ # Step 1: Decompile APK
15
+ if os.path.exists(app_name):
16
+ shutil.rmtree(app_name)
17
+ subprocess.run([APKTOOL_PATH, "d", apk_path, "-o", app_name, "-f"], check=True)
18
+
19
+ # Step 2: Clean the Manifest (remove bad permissions)
20
+ manifest_path = os.path.join(app_name, "AndroidManifest.xml")
21
+ if os.path.exists(manifest_path):
22
+ with open(manifest_path, "r") as f:
23
+ content = f.read()
24
+ bad_permissions = [
25
+ "RECORD_AUDIO", "READ_CONTACTS", "WRITE_CONTACTS", "ACCESS_FINE_LOCATION",
26
+ "ACCESS_COARSE_LOCATION", "READ_SMS", "SEND_SMS", "RECEIVE_SMS"
27
+ ]
28
+ for perm in bad_permissions:
29
+ content = content.replace(f'android.permission.{perm}', "REMOVED_BY_MAJDOOR")
30
+ with open(manifest_path, "w") as f:
31
+ f.write(content)
32
+
33
+ # Step 3: Scan and remove ad SDK & tracker references
34
+ ad_keywords = ["admob", "facebook.ads", "chartboost", "unityads", "startapp"]
35
+ tracker_keywords = ["track", "analytics", "crashlytics", "adjust", "flurry", "firebase", "segment"]
36
+ found_trackers = []
37
+
38
+ for root, _, files in os.walk(app_name):
39
+ for file in files:
40
+ if file.endswith(".smali"):
41
+ path = os.path.join(root, file)
42
+ with open(path, "r") as f:
43
+ lines = f.readlines()
44
+ new_lines = []
45
+ for line in lines:
46
+ if any(ad in line.lower() for ad in ad_keywords):
47
+ continue # Remove ads
48
+ if any(tk in line.lower() for tk in tracker_keywords):
49
+ found_trackers.append(line.strip())
50
+ new_lines.append(line)
51
+ with open(path, "w") as f:
52
+ f.writelines(new_lines)
53
+
54
+ # Write found trackers to file
55
+ with open(TRACKER_LOG, "w") as f:
56
+ if found_trackers:
57
+ f.write("Detected tracker-related code:\n")
58
+ for tracker in found_trackers:
59
+ f.write(tracker + "\n")
60
+ else:
61
+ f.write("No trackers found.")
62
+
63
+ # Step 4: Inject branding into app_name in strings.xml
64
+ strings_xml_path = os.path.join(app_name, "res", "values", "strings.xml")
65
+ if os.path.exists(strings_xml_path):
66
+ with open(strings_xml_path, "r", encoding="utf-8") as f:
67
+ strings_content = f.read()
68
+ strings_content = strings_content.replace("<string name=\"app_name\">", "<string name=\"app_name\">Majdoor_")
69
+ with open(strings_xml_path, "w", encoding="utf-8") as f:
70
+ f.write(strings_content)
71
+
72
+ # Step 5: Rebuild APK
73
+ subprocess.run([APKTOOL_PATH, "b", app_name, "-o", cleaned_apk], check=True)
74
+
75
+ # Step 6: Sign APK
76
+ try:
77
+ subprocess.run([
78
+ "apksigner", "sign",
79
+ "--ks", "debug.keystore",
80
+ "--ks-pass", "pass:android",
81
+ "--key-pass", "pass:android",
82
+ "--out", SIGNED_APK,
83
+ cleaned_apk
84
+ ], check=True)
85
+ return SIGNED_APK
86
+ except Exception as e:
87
+ print("Signing failed. Returning unsigned APK.")
88
+ return cleaned_apk