Skip to content

Commit

Permalink
Added trace support
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Sep 20, 2024
1 parent 328b613 commit ea0ecf2
Show file tree
Hide file tree
Showing 15 changed files with 836 additions and 215 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.6",
"version": "1.5.0",
"description": "Frida's CShell",
"scripts": {
"prepare": "npm run build && npm run version && npm run package && npm run copy",
Expand Down
8 changes: 5 additions & 3 deletions src/breakpoints/bp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class Bp {
this._listener = Interceptor.attach(addr.toPointer(), {
onEnter() {
if (bp._hits === 0) return;
bp._trace = BlockTrace.create(this.threadId, bp._depth);
bp._trace = BlockTrace.create(this.threadId, bp._depth, false);
bp.startCoverage(this.threadId, this.context);
},
onLeave(_retVal) {
Expand Down Expand Up @@ -172,7 +172,7 @@ export class Bp {
this._listener = Interceptor.attach(addr.toPointer(), {
onEnter() {
if (bp._hits === 0) return;
bp._trace = CoverageTrace.create(this.threadId);
bp._trace = CoverageTrace.create(this.threadId, null, null);
bp.startCoverage(this.threadId, this.context);
},
onLeave(_retVal) {
Expand Down Expand Up @@ -243,7 +243,9 @@ export class Bp {
Output.setIndent(true);
Output.writeln();
try {
trace.display();
trace.lines().forEach(l => {
Output.writeln(l);
});
Output.writeln();
} finally {
Output.setIndent(false);
Expand Down
45 changes: 16 additions & 29 deletions src/cmdlets/breakpoints/bp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Output } from '../../io/output.js';
import { Token } from '../../io/token.js';
import { Var } from '../../vars/var.js';

const NUM_CHAR: string = '#';

abstract class TypedBpCmdLet extends CmdLet implements InputInterceptLine {
public abstract readonly bpType: BpType;
protected abstract runCreate(tokens: Token[]): Var | null;
Expand All @@ -33,17 +31,6 @@ abstract class TypedBpCmdLet extends CmdLet implements InputInterceptLine {
return this.usage();
}

protected parseIndex(token: Token): number | null {
const literal = token.getLiteral();
if (!literal.startsWith(NUM_CHAR)) return null;

const numStr = literal.slice(1);
const val = parseInt(numStr);

if (isNaN(val)) return null;
return val;
}

private runDelete(tokens: Token[]): Var | null {
const vars = this.transform(tokens, [this.parseIndex, this.parseDelete]);
if (vars === null) return null;
Expand Down Expand Up @@ -84,8 +71,8 @@ ${Output.bold('show:')}
${this.name} - show all ${this.bpType} breakpoints
${this.name} ${NUM_CHAR}n - show a ${this.bpType} breakpoint
${NUM_CHAR}n the number of the breakpoint to show
${this.name} ${CmdLet.NUM_CHAR}n - show a ${this.bpType} breakpoint
${CmdLet.NUM_CHAR}n the number of the breakpoint to show
${Output.bold('create:')}
${create}
Expand All @@ -95,8 +82,8 @@ ${modify}
${Output.bold('delete:')}
${this.name} ${NUM_CHAR}n # - delete a ${this.bpType} breakpoint
${NUM_CHAR}n the number of the breakpoint to delete
${this.name} ${CmdLet.NUM_CHAR}n # - delete a ${this.bpType} breakpoint
${CmdLet.NUM_CHAR}n the number of the breakpoint to delete
${Output.bold('NOTE:')} Set hits to '*' for unlimited breakpoint.`;

Expand Down Expand Up @@ -193,12 +180,12 @@ ${this.name} addr hits - create ${this.bpType} breakpoint

protected override usageModify(): string {
const USAGE: string = `
${this.name} ${NUM_CHAR}n addr - modify a ${this.bpType} breakpoint without a hit limit
${NUM_CHAR}n the number of the breakpoint to modify
${this.name} ${CmdLet.NUM_CHAR}n addr - modify a ${this.bpType} breakpoint without a hit limit
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
addr the address to move the breakpoint
${this.name} ${NUM_CHAR}n addr hits - modify a ${this.bpType} breakpoint
${NUM_CHAR}n the number of the breakpoint to modify
${this.name} ${CmdLet.NUM_CHAR}n addr hits - modify a ${this.bpType} breakpoint
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
addr the address to move the breakpoint
hits the number of times the breakpoint should fire`;
return USAGE;
Expand Down Expand Up @@ -292,13 +279,13 @@ ${this.name} addr len hits - create ${this.bpType} breakpoint without a hit limi

protected override usageModify(): string {
const USAGE: string = `
${this.name} ${NUM_CHAR}n addr len - modify a ${this.bpType} breakpoint without a hit limit
${NUM_CHAR}n the number of the breakpoint to modify
${this.name} ${CmdLet.NUM_CHAR}n addr len - modify a ${this.bpType} breakpoint without a hit limit
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
addr the address to move the breakpoint
len the length of the memory region to watch
${this.name} ${NUM_CHAR}n addr len hits - modify a ${this.bpType} breakpoint
${NUM_CHAR}n the number of the breakpoint to modify
${this.name} ${CmdLet.NUM_CHAR}n addr len hits - modify a ${this.bpType} breakpoint
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
addr the address to move the breakpoint
len the length of the memory region to watch
hits the number of times the breakpoint should fire`;
Expand Down Expand Up @@ -402,13 +389,13 @@ ${this.name} addr depth hits - create ${this.bpType} breakpoint

protected override usageModify(): string {
const USAGE: string = `
${this.name} ${NUM_CHAR}n addr depth - modify a ${this.bpType} breakpoint without a hit limit
${NUM_CHAR}n the number of the breakpoint to modify
${this.name} ${CmdLet.NUM_CHAR}n addr depth - modify a ${this.bpType} breakpoint without a hit limit
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
addr the address to move the breakpoint
depth the maximum depth of callstack to follow
${this.name} ${NUM_CHAR}n addr depth hits - modify a ${this.bpType} breakpoint
${NUM_CHAR}n the number of the breakpoint to modify
${this.name} ${CmdLet.NUM_CHAR}n addr depth hits - modify a ${this.bpType} breakpoint
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
addr the address to move the breakpoint
depth the maximum depth of callstack to follow
hits the number of times the breakpoint should fire`;
Expand Down
10 changes: 10 additions & 0 deletions src/cmdlets/development/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ import { GrepCmdLet } from '../misc/grep.js';
import { CatCmdLet } from '../files/cat.js';
import { LogCmdLet } from '../misc/log.js';
import { HotCmdLet } from '../thread/hot.js';
import {
TraceCallCmdLet,
TraceBlockCmdLet,
TraceUniqueBlockCmdLet,
TraceCoverageCmdLet,
} from '../trace/trace.js';

const USAGE: string = `Usage: js
Expand Down Expand Up @@ -131,6 +137,10 @@ export class JsCmdLet extends CmdLet {
SubCmdLet: SubCmdLet,
SymCmdLet: SymCmdLet,
ThreadCmdLet: ThreadCmdLet,
TraceBlockCmdLet: TraceBlockCmdLet,
TraceCallCmdLet: TraceCallCmdLet,
TraceCoverageCmdLet: TraceCoverageCmdLet,
TraceUniqueBlockCmdLet: TraceUniqueBlockCmdLet,
Token: Token,
Var: Var,
VarCmdLet: VarCmdLet,
Expand Down
4 changes: 1 addition & 3 deletions src/cmdlets/misc/var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { Vars } from '../../vars/vars.js';
import { Token } from '../../io/token.js';
import { Var } from '../../vars/var.js';

const DELETE_CHAR: string = '#';

const USAGE: string = `Usage: v
v - show the values of all variables
Expand All @@ -16,7 +14,7 @@ v name value - assign a value to a variable
name the name of the variable to assign
value the value to assign
v name ${DELETE_CHAR} - delete a variable
v name ${CmdLet.DELETE_CHAR} - delete a variable
name the name of the variable to delete`;

export class VarCmdLet extends CmdLet {
Expand Down
Loading

0 comments on commit ea0ecf2

Please sign in to comment.