Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * TikTok Event Logger
- * This file fetches the frida event and eventv3 logs and outputs each event as JSON + \n to ./output.txt
- * It hookes com.ss.android.common.applog.g.insertEvent and sends it to the onMessage listener which does the actual I/O
- *
- * Prerequisites:
- * Have frida-server installed
- * Make sure you've run have setenforce 0 via adb shell
- * Run frida -U -n com.zhiliaoapp.musically -l ./index.js
- *
- */
- 'use strict'
- const fs = require('fs')
- const frida = require('frida')
- const current = {
- device: null,
- pid: null,
- script: null
- };
- async function main() {
- process.on('SIGTERM', stop);
- process.on('SIGINT', stop);
- const device = await frida.getUsbDevice();
- current.device = device;
- device.output.connect(onOutput);
- console.log(device)
- const application = await device.getFrontmostApplication();
- console.log('[*] Frontmost application:', application);
- console.log('[*] spawn()');
- const pid = application.pid
- if (application.identifier !== 'com.zhiliaoapp.musically') {
- console.error('TikTok isnt the active app. Ending.')
- stop()
- }
- // let pid = 'com.zhiliaoapp.musically' // await device.spawn(['com.zhiliaoapp.musically'])
- console.log('PID is: ', pid)
- current.pid = pid;
- console.log(`[*] attach(${pid})`);
- const session = await device.attach(pid);
- session.detached.connect(onDetached);
- console.log(`[*] createScript()`);
- const script = await session.createScript(`
- if (Java.available) {
- Java.perform(function () {
- var EventLogger = Java.use('com.ss.android.common.applog.g');
- EventLogger.insertEvent.implementation = function (m) {
- var event = {
- category: m.category.value,
- ext_json: m.ext_json.value,
- ext_value: m.ext_value.value,
- id: m.id.value,
- instant_only: m.instant_only.value,
- label: m.label.value,
- mHasTimelySend: m.mHasTimelySend.value,
- session_id: m.session_id.value,
- tag: m.tag.value,
- teaEventIndex: m.teaEventIndex.value,
- timestamp: m.timestamp.value,
- user_id: m.user_id.value,
- value: m.value.value,
- }
- send(event)
- return this.insertEvent(m)
- }
- })
- }
- `);
- current.script = script;
- script.message.connect(onMessage);
- await script.load();
- }
- function stop() {
- const { device, script } = current;
- if (script !== null) {
- script.unload();
- current.script = null;
- }
- if (device !== null) {
- device.output.disconnect(onOutput);
- current.device = null;
- }
- }
- function onOutput(pid, fd, data) {
- if (pid !== current.pid)
- return;
- let description;
- if (data.length > 0)
- description = '"' + data.toString().replace(/\n/g, '\\n') + '"';
- else
- description = '<EOF>';
- console.log(`[*] onOutput(pid=${pid}, fd=${fd}, data=${description})`);
- }
- function onDetached(reason) {
- console.log(`[*] onDetached(reason='${reason}')`);
- current.device.output.disconnect(onOutput);
- }
- function onMessage(message, data) {
- console.log('[*] onMessage() message:', message, 'data:', data);
- fs.appendFileSync('output-fresh.txt', `\n${JSON.stringify(message.payload)}`, 'utf8')
- }
- main()
- .catch(e => {
- console.error(e);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement