Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function start(Path, Args) {
// Exit on process termination
process.on('SIGTERM', stop);
process.on('SIGINT', stop);
// Attach and load script
device = await frida.getDevice(deviceId);
if (!Args || 0 === Args.length) {
procID = await device.spawn(Path);
} else {
procID = await device.spawn([Path,Args]);
}
session = await device.attach(procID);
session.detached.connect(onDetached);
script = await session.createScript(MonacoCodeEditor.getValue());
// For performance we can't update the text area all the time
// it will lock the UI on big volumes of data. Instead we append
// to an array using a mutex and every X ms we flush the array
// to the text area
script.message.connect(message => {
ChangeLogExclusive(logMutex, 'Append', message.payload);
setTimeout(function () {
async function inject(AttachTo) {
// Exit on process termination
process.on('SIGTERM', stop);
process.on('SIGINT', stop);
// Attach and load script
device = await frida.getDevice(deviceId);
session = await device.attach(AttachTo);
session.detached.connect(onDetached);
script = await session.createScript(MonacoCodeEditor.getValue());
// For performance we can't update the text area all the time
// it will lock the UI on big volumes of data. Instead we append
// to an array using a mutex and every X ms we flush the array
// to the text area
script.message.connect(message => {
ChangeLogExclusive(logMutex, 'Append', message.payload);
setTimeout(function () {
if (RunningLog.length > 0) {
ChangeLogExclusive(logMutex, 'Write', message.payload);
}
}, 500);
});
async function getProcList() {
// Make sure the device list has updated
if (atob(deviceId) != "local") {
for (i = 0; i < 3; i++) {
var dev = await getDeviceList();
if (dev.length > 2) {
break;
}
await sleep(1000);
}
}
let currentDevice = await frida.getDevice(atob(deviceId));
let Applications = await currentDevice.enumerateProcesses();
return Applications;
}
getProcList().then(data => {
channels.session.on('connection', async(socket) => {
const { device, bundle } = socket.handshake.query
let dev, session, app
if (!device || !bundle) {
socket.emit('err', 'invalid parameters')
socket.disconnect(true)
return
}
try {
dev = await frida.getDevice(device)
if (!FridaUtil.isUSB(dev)) throw new Error('device not found')
const apps = await dev.enumerateApplications()
app = apps.find(item => item.identifier === bundle)
if (!app) throw new Error('app not installed')
socket.emit('app', {
device: serializeDevice(dev),
app: serializeApp(app),
})
if (app.pid) {
const front = await dev.getFrontmostApplication()
if (front && front.pid === app.pid) {
session = await dev.attach(app.name)
} else {
async run(target) {
const device = await frida.getDevice(target.device);
this._device = device;
const onOutput = this._onOutput.bind(this);
device.output.connect(onOutput);
try {
const spawn = target.hasOwnProperty('argv');
let pid;
if (spawn)
pid = await device.spawn(target.argv);
else
pid = target.pid;
this._pid = pid;
const session = await device.attach(pid);
switch (targetDevice.kind) {
case "local":
device = await frida.getLocalDevice();
break;
case "usb":
device = await frida.getUsbDevice();
break;
case "remote":
device = await frida.getRemoteDevice();
break;
case "by-host":
device = await frida.getDeviceManager().addRemoteDevice(targetDevice.host);
break;
case "by-id":
device = await frida.getDevice(targetDevice.id);
break;
default:
throw new Error("Invalid target device");
}
return device;
});
}
return this.scheduler.perform("Getting device", async (): Promise => {
let device: frida.Device;
switch (targetDevice.kind) {
case "local":
device = await frida.getLocalDevice();
break;
case "usb":
device = await frida.getUsbDevice();
break;
case "remote":
device = await frida.getRemoteDevice();
break;
case "by-id":
device = await frida.getDevice(targetDevice.id);
break;
default:
throw new Error("Invalid target device");
}
return device;
});
}
async function getProcList() {
let currentDevice = await frida.getDevice(deviceId);
let Applications = await currentDevice.enumerateProcesses();
return Applications;
}