Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
allow remote device
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiChou committed Mar 20, 2020
1 parent bc6dbaf commit 16b1014
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 38 deletions.
28 changes: 26 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ const router = new Router({ prefix: '/api' })

router
.get('/devices', async (ctx) => {
const list = await frida.enumerateDevices()
const mgr = await frida.getDeviceManager()
const list = await mgr.enumerateDevices()
ctx.body = {
version: FRIDA_VERSION,
list: list.filter(FridaUtil.isUSB).map(serializeDevice),
list: list.map(serializeDevice),
}
})
.get('/device/:device/apps', async (ctx) => {
Expand All @@ -54,6 +55,29 @@ router
await dev.resume(pid)
ctx.body = { status: 'ok', pid }
})
.put('/device/add', async (ctx) => {
const ip = ctx.request.rawBody
const mgr = await frida.getDeviceManager()
try {
mgr.addRemoteDevice(ip)
} catch(e) {
ctx.status = 400
ctx.body = { status: 'failed', error: e.message }
return
}
ctx.body = { status: 'ok' }
})
.delete('/device/:device', async (ctx) => {
const mgr = await frida.getDeviceManager()
try {
await mgr.removeRemoteDevice(ctx.params.device)
} catch(e) {
ctx.status = 404
ctx.body = { status: 'failed', error: e.message }
return
}
ctx.body = { status: 'ok' }
})

app
.use(compress({
Expand Down
8 changes: 4 additions & 4 deletions gui/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import RPC from '~/lib/wsrpc'

import 'material-design-icons/iconfont/material-icons.css'

import { ADD_DEVICE, REMOVE_DEVICE } from '~/vuex/types'
import { LOAD_DEVICES } from '~/vuex/types'

//
require('promise.prototype.finally').shim()
Expand All @@ -36,12 +36,12 @@ const v = new Vue({
const socket = io('/devices', { path: '/msg' })
socket
.on('deviceRemove', (dev) => {
store.commit(REMOVE_DEVICE, dev)
store.dispatch(LOAD_DEVICES)
v.$toast.open(`${dev.name} has been removed`)
})
.on('deviceAdd', (dev) => {
store.commit(ADD_DEVICE, dev)
v.$toast.open(`New device ${dev.name} has been connected`)
store.dispatch(LOAD_DEVICES)
v.$toast.open(`New device ${dev.name}`)

if (v.$route.name === 'welcome')
v.$router.push({ name: 'apps', params: { device: dev.id }})
Expand Down
13 changes: 3 additions & 10 deletions gui/src/vuex/mods/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,13 @@ export const getters = {


export const mutations = {
[types.ADD_DEVICE]: (state, device) => state.list.push(device),
[types.REMOVE_DEVICE]: (state, device) => {
if (device.id == state.selected.id) {
state.selected = {}
}
state.list = state.list.filter(dev => dev.id !== device.id)
},
[types.DEVICES_LOADING]: (state, loading) => state.loading = loading,
[types.UPDATE_DEVICES]: (state, { list, version }) => {
state.list = list
state.version = version
if (!state.list.find(dev => dev.id === state.selected.id)) {
state.selected = {}
}
},
[types.STORE_DEVICE]: (state, device) => {
state.selected = device
Expand Down Expand Up @@ -80,9 +76,6 @@ export const mutations = {

export const actions = {
[types.LOAD_DEVICES]({ commit, state }) {
if (state.list.length)
return

commit(types.DEVICES_LOADING, true)
axios.get('/devices')
.then(({ data }) => commit(types.UPDATE_DEVICES, data))
Expand Down
15 changes: 2 additions & 13 deletions gui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,12 @@ module.exports = {
devServer: {
historyApiFallback: {
rewrites: [{
from: /^\/app\/.*$/,
from: /^\/(apps?|welcome|url)\/.*$/,
to: function () {
return 'index.html'
}
},
{
from: /^\/welcome\/.*$/,
to: function () {
return 'index.html'
}
},
{
from: /^\/url\/.*$/,
to: function () {
return 'index.html'
}
}]
]
},
noInfo: true,
proxy: {
Expand Down
2 changes: 0 additions & 2 deletions lib/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ channels.session.on('connection', async(socket) => {

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')
Expand Down
8 changes: 1 addition & 7 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,10 @@ async function retry(operation, options) {


class FridaUtil {
static isUSB(dev) {
return dev && ['tether', 'usb'].indexOf(dev.type) > -1
}

static async getDevice(id) {
const list = await frida.enumerateDevices()
const dev = list.find(d => d.id === id && FridaUtil.isUSB(d))

const dev = list.find(d => d.id === id)
if (dev) return dev

throw new DeviceNotFoundError(id)
}

Expand Down

0 comments on commit 16b1014

Please sign in to comment.