-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
171 lines (148 loc) · 4.4 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
const { spawn } = require('child_process');
const express = require('express');
const path = require('path');
const app = require('express')();
const http = require('http').createServer(app);
const io = require('socket.io')(http);
const fs = require('fs');
const ga_token = 'Hit delivery requested: ';
const firebase_token = 'Logging event';
const instances = {};
app.use(express.static(path.join(__dirname, '/src')));
app.get('/', (_, res) => {
res.sendFile(__dirname + '/src/panel.html');
});
http.listen(3000, () => {
console.log('listening on port 3000.');
});
io.on('create_connection', ({ tool, app }) => {
if (tool === 'universal_analytics') return startGA();
if (tool === 'firebase_analytics') return startFirebase(app);
});
io.on('end_connection', ({ tool }) => {
if (tool === 'universal_analytics') return endGA();
if (tool === 'firebase_analytics') return endFirebase();
});
function startGA() {
endInstance('ga-debug', 'ga-logcat');
createADBInstance({
name: 'ga-debug',
params: ['shell', 'setprop', 'log.tag.GAv4-SVC', 'DEBUG'],
handler: console.log,
});
createADBInstance({
name: 'ga-logcat',
params: ['logcat', '-v', 'time', '-s', 'GAv4-SVC'],
handler: (data) => {
const hits = String(data)
.split('\n')
.filter((txt) => txt.indexOf(ga_token) >= 0)
.map((txt) => {
//console.log(txt);
return txt
.split(ga_token)
.pop()
.split(', ')
.reduce((acc, cur) => {
const [key, value] = cur.split('=');
acc[key] = value;
return acc;
}, {});
});
hits.forEach((hit) => {
io.emit('hit sent', { data: hit, tool: 'google_analytics' });
//console.table(hit);
});
},
});
}
function endGA() {
endInstance('ga-debug-end');
createADBInstance({
name: 'ga-debug-end',
params: ['shell', 'setprop', 'log.tag.GAv4', 'DEBUG'],
handler: console.log,
});
}
function startFirebase(app) {
endInstance('fa-debug', 'fa-verbose', 'fa-verbose-svc', 'fa-main');
console.log('oi');
createADBInstance({
name: 'fa-debug',
params: ['shell', 'setprop', 'debug.firebase.analytics.app', app],
handler: console.log,
});
createADBInstance({
name: 'fa-verbose',
params: ['shell', 'setprop', 'log.tag.FA', 'VERBOSE'],
handler: console.log,
});
createADBInstance({
name: 'fa-verbose-svc',
params: ['shell', 'setprop', 'log.tag.FA-SVC', 'VERBOSE'],
handler: console.log,
});
createADBInstance({
name: 'fa-main',
//params: ['logcat'],
params: ['logcat', '-v', 'time', '-e', '"Logging event:"'],
handler: (data) => {
const hits = String(data)
.split('\n')
.filter((txt) => txt.match(firebase_token))
.map((txt) => {
//console.log(txt);
const event = txt.split(firebase_token).pop().slice(6, -2);
const [, bundle] = event.match(/Bundle\[\{(.*)\}\]/);
const data = event.replace(`Bundle[{${bundle}}]`, '[]');
const res = { ...parse(data), ...parse(bundle) };
return res;
});
hits.forEach((data) => {
io.emit('hit sent', { data, tool: 'firebase_analytics' });
console.table(hit);
});
},
});
}
function parse(txt) {
return txt.split(', ').reduce((acc, next) => {
const [key, val] = next.split('=');
acc[key] = val.replace(/^'|'$/g, '');
return acc;
}, {});
}
function endFirebase() {
endInstance('fa-debug-end');
createADBInstance({
name: 'fa-debug-end',
params: ['shell', 'setprop', 'debug.firebase.analytics.app', '.none.'],
handler: console.log,
});
}
function createADBInstance({ name, params, handler }) {
const instance = spawn('adb', params);
instances[name] = instance;
console.log(`Creating instance for ${name}`);
instance.stdout.on('data', handler);
instance.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
instance.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
}
function endInstance(...names) {
names.forEach((name) => {
const instance = instances[name];
if (!instance) return;
console.log(`Killing ${name}...`);
instance.stdin.pause();
instance.kill();
delete instances[name];
console.log(`${name} killed`);
});
}
//startFirebase('com.itaucard.activity');
startGA();
startFirebase('com.itau.pers');