-
-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathDialogHook.js
More file actions
159 lines (146 loc) · 5.52 KB
/
Copy pathDialogHook.js
File metadata and controls
159 lines (146 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
Frida script to auto-kill annoying popups and alerts.
Checks the text inside dialogs against a blocklist (root detection, force updates, etc.)
and closes them automatically so the app keeps running.
*/
Java.performNow(function () {
// Popups containing these phrases will get nuked
let blacklist = new Set([
"rooting detected",
"Detected!!!",
"Hooking",
"force update",
"upgrade now",
"buy now",
]);
function extractDialogText(dialog) {
let texts = [];
try {
let window = dialog.getWindow();
if (window === null) return texts;
let decorView = window.getDecorView();
if (decorView === null) return texts;
let TextView = Java.use("android.widget.TextView");
let ViewGroup = Java.use("android.view.ViewGroup");
function walkViews(view) {
try {
if (TextView.class.isInstance(view)) {
let text = Java.cast(view, TextView).getText();
if (text !== null && text.toString().trim().length > 0) {
texts.push(text.toString().trim());
}
}
if (ViewGroup.class.isInstance(view)) {
let group = Java.cast(view, ViewGroup);
for (let i = 0; i < group.getChildCount(); i++) {
walkViews(group.getChildAt(i));
}
}
} catch (e) { }
}
walkViews(decorView);
} catch (e) {
console.error("Error scraping dialog text:", e);
}
return texts;
}
function isBlacklisted(texts) {
let combined = texts.join(" ").toLowerCase();
for (let word of blacklist) {
if (combined.indexOf(word.toLowerCase()) !== -1) {
return word;
}
}
return null;
}
function autoDismiss(dialog) {
let retained = Java.retain(dialog); // Hold reference so it doesn't get GC'd. wasted lot of time to understand why app crashed. lol
Java.scheduleOnMainThread(function () {
try {
let texts = extractDialogText(retained);
let matched = isBlacklisted(texts);
if (matched !== null) {
console.log("Dismissing dialog! Caught keyword: '" + matched + "' | Full text: " + JSON.stringify(texts));
retained.dismiss();
} else {
console.log("Dialog looks clean, letting it stay. Text: " + JSON.stringify(texts));
}
} catch (e) {
console.error("Failed to dismiss dialog:", e);
}
});
}
try {
let Dialog = Java.use("android.app.Dialog");
Dialog.show.implementation = function () {
console.warn("Hit Dialog.show()");
this.show();
this.setCancelable(true);
this.setCanceledOnTouchOutside(true);
autoDismiss(this);
}
} catch (error) {
console.error("Standard Dialog class missing or changed");
}
try {
let AlertDialog = Java.use("android.app.AlertDialog");
AlertDialog.show.implementation = function () {
console.warn("Hit AlertDialog.show()");
this.show();
this.setCancelable(true);
this.setCanceledOnTouchOutside(true);
autoDismiss(this);
}
} catch (error) {
console.error("Standard AlertDialog missing or changed");
}
try {
let AppCompatAlertDialog = Java.use("androidx.appcompat.app.AlertDialog");
AppCompatAlertDialog.show.implementation = function () {
console.warn("Hit AndroidX AlertDialog.show()");
this.show();
this.setCancelable(true);
this.setCanceledOnTouchOutside(true);
autoDismiss(this);
}
} catch (error) {
console.error("AndroidX AlertDialog not found in this app");
}
try {
let DialogFragment = Java.use("androidx.fragment.app.DialogFragment");
DialogFragment.onCreateDialog.implementation = function (savedState) {
console.warn("Hit DialogFragment.onCreateDialog()");
let dlg = this.onCreateDialog(savedState);
dlg.setCancelable(true);
dlg.setCanceledOnTouchOutside(true);
autoDismiss(dlg);
return dlg;
}
} catch (error) {
console.error("AndroidX DialogFragment not found");
}
try {
let SupportAlertDialog = Java.use("android.support.v7.app.AlertDialog");
SupportAlertDialog.show.implementation = function () {
console.warn("Hit SupportV7 AlertDialog.show()");
this.show();
this.setCancelable(true);
this.setCanceledOnTouchOutside(true);
autoDismiss(this);
}
} catch (error) {
console.error("Legacy Support V7 AlertDialog not found");
}
try {
let MaterialAlertDialog = Java.use("com.google.android.material.dialog.MaterialAlertDialog");
MaterialAlertDialog.show.implementation = function () {
console.warn("Hit MaterialAlertDialog.show()");
this.show();
this.setCancelable(true);
this.setCanceledOnTouchOutside(true);
autoDismiss(this);
}
} catch (error) {
console.error("Material Components Dialog missing");
}
})