Skip to content

Commit 5170625

Browse files
author
Your Name
committed
Add support for filtering output
1 parent c8eb66a commit 5170625

34 files changed

+399
-237
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "frida-cshell",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"description": "Frida's CShell",
55
"scripts": {
66
"prepare": "npm run build && npm run version && npm run package && npm run copy",

src/breakpoints/bp.ts

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,16 @@ export class Bp {
191191
private startCoverage(threadId: ThreadId, ctx: CpuContext) {
192192
Output.clearLine();
193193
Output.writeln(Output.yellow('-'.repeat(80)));
194-
Output.write(`${Output.yellow('|')} Start Trace `);
195-
Output.write(`${Output.green(`#${this._idx}`)} `);
196-
Output.write(`[${this._type}] `);
197-
Output.write(`${Output.yellow(this.literal)} `);
198-
Output.write(`@ $pc=${Output.blue(Format.toHexString(ctx.pc))} `);
199-
Output.write(`$tid=${threadId}, depth=${this._depth}`);
200-
Output.writeln();
194+
Output.writeln(
195+
[
196+
`${Output.yellow('|')} Start Trace`,
197+
Output.green(`#${this._idx}`),
198+
`[${this._type}]`,
199+
Output.yellow(this.literal),
200+
`@ $pc=${Output.blue(Format.toHexString(ctx.pc))}`,
201+
`$tid=${threadId}, depth=${this._depth}`,
202+
].join(' '),
203+
);
201204
Output.writeln(Output.yellow('-'.repeat(80)));
202205
}
203206

@@ -212,14 +215,16 @@ export class Bp {
212215
Output.writeln(Output.blue('-'.repeat(80)));
213216
Output.clearLine();
214217

215-
Output.writeln(Output.yellow('-'.repeat(80)));
216-
Output.write(`${Output.yellow('|')} Stop Trace `);
217-
Output.write(`${Output.green(`#${this._idx}`)} `);
218-
Output.write(`[${this._type}] `);
219-
Output.write(`${Output.yellow(this.literal)} `);
220-
Output.write(`@ $pc=${Output.blue(Format.toHexString(ctx.pc))} `);
221-
Output.write(`$tid=${threadId}`);
222-
Output.writeln();
218+
Output.writeln(
219+
[
220+
`${Output.yellow('|')} Stop Trace`,
221+
Output.green(`#${this._idx}`),
222+
`[${this._type}]`,
223+
Output.yellow(this.literal),
224+
`@ $pc=${Output.blue(Format.toHexString(ctx.pc))}`,
225+
`$tid=${threadId}, depth=${this._depth}`,
226+
].join(' '),
227+
);
223228
Output.writeln(Output.yellow('-'.repeat(80)));
224229

225230
Traces.delete(threadId);
@@ -239,13 +244,16 @@ export class Bp {
239244
else if (this._hits > 0) this._hits--;
240245
Output.clearLine();
241246
Output.writeln(Output.yellow('-'.repeat(80)));
242-
Output.write(`${Output.yellow('|')} Break `);
243-
Output.write(`${Output.green(`#${this._idx}`)} `);
244-
Output.write(`[${this._type}] `);
245-
Output.write(`${Output.yellow(this.literal)} `);
246-
Output.write(`@ $pc=${Output.blue(Format.toHexString(ctx.pc))} `);
247-
Output.write(`$tid=${threadId}`);
248-
Output.writeln();
247+
Output.writeln(
248+
[
249+
`${Output.yellow('|')} Break`,
250+
Output.green(`#${this._idx}`),
251+
`[${this._type}]`,
252+
Output.yellow(this.literal),
253+
`@ $pc=${Output.blue(Format.toHexString(ctx.pc))}`,
254+
`$tid=${threadId}`,
255+
].join(' '),
256+
);
249257
Output.writeln(Output.yellow('-'.repeat(80)));
250258
Regs.setThreadId(threadId);
251259
Regs.setContext(ctx);
@@ -275,7 +283,7 @@ export class Bp {
275283
} catch (error) {
276284
if (error instanceof Error) {
277285
Output.writeln(`ERROR: ${error.message}`);
278-
Output.writeln(`${error.stack}`, true);
286+
Output.verboseWriteln(`${error.stack}`);
279287
} else {
280288
Output.writeln(`ERROR: Unknown error`);
281289
}
@@ -325,13 +333,16 @@ export class Bp {
325333

326334
Output.clearLine();
327335
Output.writeln(Output.yellow('-'.repeat(80)));
328-
Output.write(`${Output.yellow('|')} Break `);
329-
Output.write(`${Output.green(`#${this._idx}`)} `);
330-
Output.write(`[${this._type}] `);
331-
Output.write(`${Output.yellow(this.literal)} `);
332-
Output.write(`@ $pc=${Output.blue(Format.toHexString(details.from))} `);
333-
Output.write(`$addr=${Output.blue(Format.toHexString(details.address))}`);
334-
Output.writeln();
336+
Output.writeln(
337+
[
338+
`${Output.yellow('|')} Break`,
339+
Output.green(`#${this._idx}`),
340+
`[${this._type}]`,
341+
Output.yellow(this.literal),
342+
`@ $pc=${Output.blue(Format.toHexString(details.from))}`,
343+
`$addr=${Output.blue(Format.toHexString(details.address))}`,
344+
].join(' '),
345+
);
335346
Output.writeln(Output.yellow('-'.repeat(80)));
336347
Regs.setAddress(details.address);
337348
Regs.setPc(details.from);

src/cmdlets/assembly.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const USAGE: string = `Usage: l
1010
1111
l address <bytes> - show disassembly listing
1212
address the address/symbol to disassemble
13-
bytes the number of instructions to disassemble (default ${DEFAULT_LENGTH})
14-
`;
13+
bytes the number of instructions to disassemble (default ${DEFAULT_LENGTH})`;
1514

1615
export class AssemblyCmdLet extends CmdLet {
1716
name = 'l';
@@ -72,6 +71,7 @@ export class AssemblyCmdLet extends CmdLet {
7271

7372
Output.writeln(
7473
`${Output.bold(idx)}: ${Output.green(Format.toHexString(cursor))}: ${Output.yellow(insn.toString().padEnd(40))} ${Output.blue(bytesStr)}`,
74+
true,
7575
);
7676

7777
cursor = cursor.add(insn.size);
@@ -125,7 +125,7 @@ export class AssemblyCmdLet extends CmdLet {
125125
}
126126

127127
public usage(): Var {
128-
Output.write(USAGE);
128+
Output.writeln(USAGE);
129129
return Var.ZERO;
130130
}
131131
}

src/cmdlets/bp.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ abstract class TypedBpCmdLet extends CmdLet implements InputInterceptLine {
7676
);
7777
Bps.all()
7878
.filter(bp => bp.type === this.bpType)
79-
.forEach(bp => Output.writeln(bp.toString()));
79+
.forEach(bp => Output.writeln(bp.toString(), true));
8080
return Var.ZERO;
8181
} else {
8282
const bp = Bps.get(this.bpType, index);
@@ -90,7 +90,7 @@ abstract class TypedBpCmdLet extends CmdLet implements InputInterceptLine {
9090
public usage(): Var {
9191
const create = this.usageCreate();
9292
const modify = this.usageModify();
93-
const INSN_BP_USAGE: string = `Usage: ${this.name}
93+
const USAGE: string = `Usage: ${this.name}
9494
${Output.bold('show:')}
9595
9696
${this.name} - show all ${this.bpType} breakpoints
@@ -109,9 +109,9 @@ ${Output.bold('delete:')}
109109
${this.name} ${NUM_CHAR}n # - delete a ${this.bpType} breakpoint
110110
${NUM_CHAR}n the number of the breakpoint to delete
111111
112-
${Output.bold('NOTE:')} Set hits to '*' for unlimited breakpoint.
113-
`;
114-
Output.write(INSN_BP_USAGE);
112+
${Output.bold('NOTE:')} Set hits to '*' for unlimited breakpoint.`;
113+
114+
Output.writeln(USAGE);
115115
return Var.ZERO;
116116
}
117117

src/cmdlets/bt.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const USAGE: string = `Usage: bt
99
bt - show the backtrace for the current thread in a breakpoint
1010
1111
bt name - show backtrace for thread
12-
thread the name of the thread to show backtrace for
13-
`;
12+
thread the name of the thread to show backtrace for`;
1413

1514
export class BtCmdLet extends CmdLet {
1615
name = 'bt';
@@ -51,17 +50,20 @@ export class BtCmdLet extends CmdLet {
5150
.forEach(s => {
5251
const prefix = s.moduleName === null ? '' : `${s.moduleName}!`;
5352
const name = `${prefix}${s.name}`;
54-
Output.write(
55-
`${Output.green(name.padEnd(40, '.'))} ${Output.yellow(Format.toHexString(s.address))}`,
56-
);
53+
let fileInfo = '';
5754
if (s.fileName !== null && s.lineNumber !== null) {
5855
if (s.fileName.length !== 0 && s.lineNumber !== 0) {
59-
Output.write(
60-
`\t${Output.blue(s.fileName)}:${Output.blue(s.lineNumber.toString())} `,
61-
);
56+
fileInfo = `\t${Output.blue(s.fileName)}:${Output.blue(s.lineNumber.toString())}`;
6257
}
6358
}
64-
Output.writeln();
59+
Output.writeln(
60+
[
61+
Output.green(name.padEnd(40, '.')),
62+
Output.yellow(Format.toHexString(s.address)),
63+
fileInfo,
64+
].join(' '),
65+
true,
66+
);
6567
});
6668
}
6769

@@ -100,7 +102,7 @@ export class BtCmdLet extends CmdLet {
100102
}
101103

102104
public usage(): Var {
103-
Output.write(USAGE);
105+
Output.writeln(USAGE);
104106
return Var.ZERO;
105107
}
106108
}

src/cmdlets/copy.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const USAGE: string = `Usage: cp
1010
cp dest src bytes - copy data
1111
dest the address/symbol to write to
1212
src the address/symbol to read from
13-
bytes the numer of bytes to read
14-
`;
13+
bytes the numer of bytes to read`;
1514

1615
export class CopyCmdLet extends CmdLet {
1716
name = 'cp';
@@ -43,7 +42,7 @@ export class CopyCmdLet extends CmdLet {
4342
}
4443

4544
public usage(): Var {
46-
Output.write(USAGE);
45+
Output.writeln(USAGE);
4746
return Var.ZERO;
4847
}
4948
}

0 commit comments

Comments
 (0)