Skip to content

Commit

Permalink
Add support for filtering output
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Sep 18, 2024
1 parent c8eb66a commit 5170625
Show file tree
Hide file tree
Showing 34 changed files with 399 additions and 237 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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frida-cshell",
"version": "1.4.1",
"version": "1.4.2",
"description": "Frida's CShell",
"scripts": {
"prepare": "npm run build && npm run version && npm run package && npm run copy",
Expand Down
71 changes: 41 additions & 30 deletions src/breakpoints/bp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,16 @@ export class Bp {
private startCoverage(threadId: ThreadId, ctx: CpuContext) {
Output.clearLine();
Output.writeln(Output.yellow('-'.repeat(80)));
Output.write(`${Output.yellow('|')} Start Trace `);
Output.write(`${Output.green(`#${this._idx}`)} `);
Output.write(`[${this._type}] `);
Output.write(`${Output.yellow(this.literal)} `);
Output.write(`@ $pc=${Output.blue(Format.toHexString(ctx.pc))} `);
Output.write(`$tid=${threadId}, depth=${this._depth}`);
Output.writeln();
Output.writeln(
[
`${Output.yellow('|')} Start Trace`,
Output.green(`#${this._idx}`),
`[${this._type}]`,
Output.yellow(this.literal),
`@ $pc=${Output.blue(Format.toHexString(ctx.pc))}`,
`$tid=${threadId}, depth=${this._depth}`,
].join(' '),
);
Output.writeln(Output.yellow('-'.repeat(80)));
}

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

Output.writeln(Output.yellow('-'.repeat(80)));
Output.write(`${Output.yellow('|')} Stop Trace `);
Output.write(`${Output.green(`#${this._idx}`)} `);
Output.write(`[${this._type}] `);
Output.write(`${Output.yellow(this.literal)} `);
Output.write(`@ $pc=${Output.blue(Format.toHexString(ctx.pc))} `);
Output.write(`$tid=${threadId}`);
Output.writeln();
Output.writeln(
[
`${Output.yellow('|')} Stop Trace`,
Output.green(`#${this._idx}`),
`[${this._type}]`,
Output.yellow(this.literal),
`@ $pc=${Output.blue(Format.toHexString(ctx.pc))}`,
`$tid=${threadId}, depth=${this._depth}`,
].join(' '),
);
Output.writeln(Output.yellow('-'.repeat(80)));

Traces.delete(threadId);
Expand All @@ -239,13 +244,16 @@ export class Bp {
else if (this._hits > 0) this._hits--;
Output.clearLine();
Output.writeln(Output.yellow('-'.repeat(80)));
Output.write(`${Output.yellow('|')} Break `);
Output.write(`${Output.green(`#${this._idx}`)} `);
Output.write(`[${this._type}] `);
Output.write(`${Output.yellow(this.literal)} `);
Output.write(`@ $pc=${Output.blue(Format.toHexString(ctx.pc))} `);
Output.write(`$tid=${threadId}`);
Output.writeln();
Output.writeln(
[
`${Output.yellow('|')} Break`,
Output.green(`#${this._idx}`),
`[${this._type}]`,
Output.yellow(this.literal),
`@ $pc=${Output.blue(Format.toHexString(ctx.pc))}`,
`$tid=${threadId}`,
].join(' '),
);
Output.writeln(Output.yellow('-'.repeat(80)));
Regs.setThreadId(threadId);
Regs.setContext(ctx);
Expand Down Expand Up @@ -275,7 +283,7 @@ export class Bp {
} catch (error) {
if (error instanceof Error) {
Output.writeln(`ERROR: ${error.message}`);
Output.writeln(`${error.stack}`, true);
Output.verboseWriteln(`${error.stack}`);
} else {
Output.writeln(`ERROR: Unknown error`);
}
Expand Down Expand Up @@ -325,13 +333,16 @@ export class Bp {

Output.clearLine();
Output.writeln(Output.yellow('-'.repeat(80)));
Output.write(`${Output.yellow('|')} Break `);
Output.write(`${Output.green(`#${this._idx}`)} `);
Output.write(`[${this._type}] `);
Output.write(`${Output.yellow(this.literal)} `);
Output.write(`@ $pc=${Output.blue(Format.toHexString(details.from))} `);
Output.write(`$addr=${Output.blue(Format.toHexString(details.address))}`);
Output.writeln();
Output.writeln(
[
`${Output.yellow('|')} Break`,
Output.green(`#${this._idx}`),
`[${this._type}]`,
Output.yellow(this.literal),
`@ $pc=${Output.blue(Format.toHexString(details.from))}`,
`$addr=${Output.blue(Format.toHexString(details.address))}`,
].join(' '),
);
Output.writeln(Output.yellow('-'.repeat(80)));
Regs.setAddress(details.address);
Regs.setPc(details.from);
Expand Down
6 changes: 3 additions & 3 deletions src/cmdlets/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const USAGE: string = `Usage: l
l address <bytes> - show disassembly listing
address the address/symbol to disassemble
bytes the number of instructions to disassemble (default ${DEFAULT_LENGTH})
`;
bytes the number of instructions to disassemble (default ${DEFAULT_LENGTH})`;

export class AssemblyCmdLet extends CmdLet {
name = 'l';
Expand Down Expand Up @@ -72,6 +71,7 @@ export class AssemblyCmdLet extends CmdLet {

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

cursor = cursor.add(insn.size);
Expand Down Expand Up @@ -125,7 +125,7 @@ export class AssemblyCmdLet extends CmdLet {
}

public usage(): Var {
Output.write(USAGE);
Output.writeln(USAGE);
return Var.ZERO;
}
}
10 changes: 5 additions & 5 deletions src/cmdlets/bp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ abstract class TypedBpCmdLet extends CmdLet implements InputInterceptLine {
);
Bps.all()
.filter(bp => bp.type === this.bpType)
.forEach(bp => Output.writeln(bp.toString()));
.forEach(bp => Output.writeln(bp.toString(), true));
return Var.ZERO;
} else {
const bp = Bps.get(this.bpType, index);
Expand All @@ -90,7 +90,7 @@ abstract class TypedBpCmdLet extends CmdLet implements InputInterceptLine {
public usage(): Var {
const create = this.usageCreate();
const modify = this.usageModify();
const INSN_BP_USAGE: string = `Usage: ${this.name}
const USAGE: string = `Usage: ${this.name}
${Output.bold('show:')}
${this.name} - show all ${this.bpType} breakpoints
Expand All @@ -109,9 +109,9 @@ ${Output.bold('delete:')}
${this.name} ${NUM_CHAR}n # - delete a ${this.bpType} breakpoint
${NUM_CHAR}n the number of the breakpoint to delete
${Output.bold('NOTE:')} Set hits to '*' for unlimited breakpoint.
`;
Output.write(INSN_BP_USAGE);
${Output.bold('NOTE:')} Set hits to '*' for unlimited breakpoint.`;

Output.writeln(USAGE);
return Var.ZERO;
}

Expand Down
22 changes: 12 additions & 10 deletions src/cmdlets/bt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const USAGE: string = `Usage: bt
bt - show the backtrace for the current thread in a breakpoint
bt name - show backtrace for thread
thread the name of the thread to show backtrace for
`;
thread the name of the thread to show backtrace for`;

export class BtCmdLet extends CmdLet {
name = 'bt';
Expand Down Expand Up @@ -51,17 +50,20 @@ export class BtCmdLet extends CmdLet {
.forEach(s => {
const prefix = s.moduleName === null ? '' : `${s.moduleName}!`;
const name = `${prefix}${s.name}`;
Output.write(
`${Output.green(name.padEnd(40, '.'))} ${Output.yellow(Format.toHexString(s.address))}`,
);
let fileInfo = '';
if (s.fileName !== null && s.lineNumber !== null) {
if (s.fileName.length !== 0 && s.lineNumber !== 0) {
Output.write(
`\t${Output.blue(s.fileName)}:${Output.blue(s.lineNumber.toString())} `,
);
fileInfo = `\t${Output.blue(s.fileName)}:${Output.blue(s.lineNumber.toString())}`;
}
}
Output.writeln();
Output.writeln(
[
Output.green(name.padEnd(40, '.')),
Output.yellow(Format.toHexString(s.address)),
fileInfo,
].join(' '),
true,
);
});
}

Expand Down Expand Up @@ -100,7 +102,7 @@ export class BtCmdLet extends CmdLet {
}

public usage(): Var {
Output.write(USAGE);
Output.writeln(USAGE);
return Var.ZERO;
}
}
5 changes: 2 additions & 3 deletions src/cmdlets/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const USAGE: string = `Usage: cp
cp dest src bytes - copy data
dest the address/symbol to write to
src the address/symbol to read from
bytes the numer of bytes to read
`;
bytes the numer of bytes to read`;

export class CopyCmdLet extends CmdLet {
name = 'cp';
Expand Down Expand Up @@ -43,7 +42,7 @@ export class CopyCmdLet extends CmdLet {
}

public usage(): Var {
Output.write(USAGE);
Output.writeln(USAGE);
return Var.ZERO;
}
}
Loading

0 comments on commit 5170625

Please sign in to comment.