-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathagent.js
214 lines (182 loc) · 6.99 KB
/
agent.js
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
'use strict';
let printBacktrace=function (){
Java.perform(function() {
let android_util_Log = Java.use('android.util.Log'), java_lang_Exception = Java.use('java.lang.Exception');
let exc = android_util_Log.getStackTraceString(java_lang_Exception.$new());
colorLog(exc, { c: Color.Green });
});
};
function dumpIntent(intent){
try{
if(!intent.hasExtra("marked_as_dumped")){
sendIntentToMonitor(intent)
intent.putExtra("marked_as_dumped","marked");
}
} catch(error){
console.log(error);
}
}
function sendIntentToMonitor(intent){
try{
let bundle_clz = intent.getExtras();
let data = intent.getData();
let action = intent.getAction();
let flags = intent.getFlags();
let exported = isActivityExported(intent);
let component = intent.getComponent();
let itype = intent.getType();
let targetPackage = "";
let targetClassName = "";
let dataToString ="";
let extras = "";
let type = "";
if(data != null){
dataToString = data.toString();
}
if(component != null){
targetPackage = component.getPackageName();
targetClassName = component.getClassName();
}
if(itype != null){
type = itype.toString();
}
if(bundle_clz != null){
let keySet = bundle_clz.keySet();
let iter = keySet.iterator();
while(iter.hasNext()) {
let currentKey = iter.next();
let currentValue = bundle_clz.get(currentKey);
if (currentValue!=null)
type = currentValue.getClass().toString();
else type = 'undefined'
let t = type.substring(type.lastIndexOf('.')+1,type.length)
if(currentKey!='marked_as_dumped'){
extras += '\t('+t+ ') '+ currentKey + ' = ' + currentValue+'\n'
}
}
extras+='\n\n'
}
let sentData = JSON.stringify({"description":intent.toString(), "targetPackageName":targetPackage,
"targetClassName":targetClassName, "action":action, "data":dataToString, "type":type, "flags":flags,
"extras":extras, "targetIsExported":exported});
send('IntentMsg|'+sentData);
} catch(e){
throw e;
}
}
function getApplicationContext(){
return Java.use('android.app.ActivityThread').currentApplication().getApplicationContext();
}
function isActivityExported(intent){
try{
const context = getApplicationContext();
const packageManager = context.getPackageManager();
let resolveInfo = packageManager.resolveActivity(intent, 0);
if(resolveInfo != null)
return resolveInfo.activityInfo.value.exported.value;
else return null;
} catch(error){
console.log(error)
}
}
Java.perform(function() {
let activity = Java.use('android.app.Activity');
activity.onNewIntent.overload('android.content.Intent').implementation = function(intent){
dumpIntent(intent);
this.onNewIntent(intent);
}
activity.startActivity.overload('android.content.Intent', 'android.os.Bundle').implementation = function(intent, bundle){
dumpIntent(intent);
this.startActivity(intent, bundle);
}
activity.startActivities.overload('[Landroid.content.Intent;', 'android.os.Bundle').implementation = function(intents, bundle){
for (let i = 0; i < intents.length; i++) {
dumpIntent(intents[i]);
}
this.startActivities(intents, bundle);
}
activity.startActivityForResult.overload('android.content.Intent', 'int', 'android.os.Bundle').implementation = function(intent, requestCode, bundle){
if( requestCode != -1){
dumpIntent(intent);
}
this.startActivityForResult(intent,requestCode, bundle);
}
activity.startActivityIfNeeded.overload('android.content.Intent', 'int', 'android.os.Bundle').implementation = function(intent, requestCode, bundle){
dumpIntent(intent);
this.startActivityIfNeeded(intent, requestCode, bundle);
}
activity.setResult.overload('int','android.content.Intent').implementation = function(requestCode,intent){
dumpIntent(intent);
this.setResult(requestCode,intent);
}
let hook_1703927890 = Java.use('android.content.Intent');
let interestingMethodNames = [
'getBundleExtra',
'hasExtra',
'getAction',
'getClipData',
'getDataString',
'getData',
'getBooleanArrayExtra',
'getBooleanExtra',
'getByteArrayExtra',
'getByteExtra',
'getCharArrayExtra',
'getCharExtra',
'getCharSequenceArrayExtra',
'getCharSequenceArrayListExtra',
'getCharSequenceExtra',
'getDoubleArrayExtra',
'getDoubleExtra',
'getFloatArrayExtra',
'getFloatExtra',
'getIntArrayExtra',
'getIntExtra',
'getIntegerArrayListExtra',
'getLongArrayExtra',
'getShortArrayExtra',
'getShortExtra',
'getStringArrayExtra',
'getStringArrayListExtra',
'getStringExtra',
'getExtras',
'getSerializableExtra',
'getParcelableExtra',
'getParcelableArrayListExtra',
'getParcelableArrayExtra'
];
let isDumping = false;
function hookIntentGetMethod(methodName) {
try {
if (hook_1703927890[methodName]) { // Ensure the method exists
let overloadCount_1703927890 = hook_1703927890[methodName].overloads.length;
for (let i = 0; i < overloadCount_1703927890; i++) {
hook_1703927890[methodName].overloads[i].implementation = function() {
let result = this[methodName].apply(this, arguments);
// Avoid re-entrancy
if (!isDumping && !this.hasExtra("marked_as_dumped")) {
try {
isDumping = true;
dumpIntent(this);
this.putExtra("marked_as_dumped", "marked");
} catch (copyError) {
console.log("Error creating or dumping Intent copy: " + copyError);
} finally {
isDumping = false;
}
}
return result;
};
}
} else {
console.log('Method ' + methodName + ' does not exist on android.content.Intent');
}
} catch (error) {
console.log("Error in hookIntentGetMethod: " + error);
}
}
for (var i = 0; i < interestingMethodNames.length; i++) {
var methodName = interestingMethodNames[i];
hookIntentGetMethod(methodName);
}
});