Skip to content

Commit

Permalink
v0.8.0
Browse files Browse the repository at this point in the history
export modules and classes to editor
  • Loading branch information
ChiChou committed Dec 23, 2023
1 parent b4d72dd commit 646da02
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 39 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"displayName": "frida Workbench",
"description": "Unofficial frida workbench for VSCode",
"version": "0.7.7",
"version": "0.8.0",
"engines": {
"vscode": "^1.69.1"
},
Expand Down Expand Up @@ -141,6 +141,16 @@
"title": "Close All Console",
"category": "Frida"
},
{
"command": "frida.print.modules",
"title": "Export All Modules To Editor",
"category": "Frida"
},
{
"command": "frida.print.classes",
"title": "Export All Classes To Editor",
"category": "Frida"
},
{
"command": "frida.external.objection",
"title": "Objection",
Expand Down Expand Up @@ -274,6 +284,14 @@
"command": "frida.syslog",
"when": "false"
},
{
"command": "frida.print.modules",
"when": "false"
},
{
"command": "frida.print.classes",
"when": "false"
},
{
"command": "frida.attach",
"when": "false"
Expand Down Expand Up @@ -416,6 +434,26 @@
"when": "view == fridaPs && viewItem =~ /^process\\|/",
"group": "3_frida_logger@1"
},
{
"command": "frida.print.modules",
"when": "view == fridaApps && viewItem =~ /^app\\|/",
"group": "3_frida_logger@2"
},
{
"command": "frida.print.modules",
"when": "view == fridaPs && viewItem =~ /^process\\|/",
"group": "3_frida_logger@2"
},
{
"command": "frida.print.classes",
"when": "view == fridaApps && viewItem =~ /^app\\|/",
"group": "3_frida_logger@3"
},
{
"command": "frida.print.classes",
"when": "view == fridaPs && viewItem =~ /^process\\|/",
"group": "3_frida_logger@3"
},
{
"command": "frida.external.objection",
"when": "view == fridaApps && viewItem =~ /^app\\|/",
Expand Down
39 changes: 39 additions & 0 deletions src/commands/print.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Uri, window } from "vscode";
import { rpc } from "../driver/backend";
import { TargetItem } from "../providers/devices";

interface Module {
name: string;
base: string;
size: number;
path: string;
};

type ClassesResult = string[];
type ModulesResult = Module[];

function create(name: string, content: string) {
window.showTextDocument(Uri.parse(`untitled:${encodeURIComponent(name)}`)).then((editor) => {
editor.edit((editBuilder) => {
editBuilder.insert(editor.selection.active, content);
});
});
}

export function classes(target: TargetItem) {
rpc(target, 'classes')
.then((result: ClassesResult) => {
const text = result.join('\n');
create(`classes - ${target.label}.txt`, text);
})
.catch(err => window.showErrorMessage(err.message));
}

export function modules(target: TargetItem) {
rpc(target, 'modules')
.then((modules: ModulesResult) => {
const text = modules.map(m => `${m.base} ${m.name} ${m.size} ${m.path}`).join('\n');
create(`modules - ${target.label}.txt`, text);
})
.catch(err => window.showErrorMessage(err.message));
}
6 changes: 2 additions & 4 deletions src/commands/syslog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function vacuum() {
}
}

export async function show(node?: TargetItem) {
export async function show(node: TargetItem) {
function cmdChannel(name: string, bin: string, args: string[]) {
if (name in active) {
return active[name];
Expand Down Expand Up @@ -43,9 +43,7 @@ export async function show(node?: TargetItem) {
} else if (node instanceof ProcessItem) {
bundleOrPid = ['--pid', node.data.pid.toString()];
} else {
if (node) {
window.showErrorMessage(`Invalid target "${node.label}"`);
}
window.showErrorMessage(`Invalid target "${node.label}"`);
return;
}

Expand Down
27 changes: 14 additions & 13 deletions src/driver/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ const py = join(base, 'driver.py');

export const driverScript = () => py;

export function flags(node: TargetItem) {
if (node instanceof DeviceItem) {
return ['--device', node.data.id];
} else if (node instanceof AppItem) {
return ['--app', node.data.identifier];
} else if (node instanceof ProcessItem) {
return ['--pid', node.data.pid.toString()];
}

throw new Error(`Invalid target "${node}"`);
}

function askInstallFrida() {
window.showErrorMessage(`Frida python module not detected. Please check your Python interpreter setting,
or pip install frida-tools. Do you want to install now?`, 'Install', 'Cancel')
Expand All @@ -42,7 +30,7 @@ or pip install frida-tools. Do you want to install now?`, 'Install', 'Cancel')
export function exec(...args: string[]): Promise<any> {
const remoteDevices = asParam();
return new Promise((resolve, reject) => {
execFile(python3Path(), [py, ...remoteDevices, ...args], {}, (err, stdout, stderr) => {
execFile(python3Path(), [py, ...remoteDevices, ...args], { maxBuffer: 1024 * 1024 * 20}, (err, stdout, stderr) => {
if (err) {
if (stderr.includes('Unable to import frida')) {
askInstallFrida();
Expand Down Expand Up @@ -87,6 +75,19 @@ export function location(id: string, bundle: string) {
return exec('location', id, bundle);
}

export function rpc(target: TargetItem, method: string, ...args: string[]) {
let bundleOrPid: string[];
if (target instanceof AppItem) {
bundleOrPid = ['--app', target.data.identifier];
} else if (target instanceof ProcessItem) {
bundleOrPid = ['--pid', target.data.pid.toString()];
} else {
throw new Error(`Invalid target "${target}"`);
}

return exec('rpc', '--device', target.device.id, ...bundleOrPid, method, ...args);
}

export function lockdownSyslog(id: string, bundleOrPid: string[]) {
return run({
name: `Syslog: ${bundleOrPid}`,
Expand Down
4 changes: 4 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as rootless from './commands/rootless';
import * as ssh from './commands/ssh';
import * as syslog from './commands/syslog';
import * as typing from './commands/typing';
import * as print from './commands/print';

export function activate(context: vscode.ExtensionContext) {
const register = (cmd: string, cb: (...args: any[]) => any) => vscode.commands.registerCommand(cmd, cb);
Expand Down Expand Up @@ -61,6 +62,9 @@ export function activate(context: vscode.ExtensionContext) {
push(register('frida.debug.setup', boilerplate.debug));

push(register('frida.typing.init', typing.init));

push(register('frida.print.classes', print.classes));
push(register('frida.print.modules', print.modules));
}

// this method is called when your extension is deactivated
Expand Down

0 comments on commit 646da02

Please sign in to comment.