Skip to content

Commit 079cd29

Browse files
author
Your Name
committed
Add support for generating coverage data
1 parent 9fe6b6a commit 079cd29

File tree

9 files changed

+654
-22
lines changed

9 files changed

+654
-22
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "frida-cshell",
3-
"version": "1.2.1",
3+
"version": "1.3.0",
44
"description": "Frida's CShell",
55
"scripts": {
66
"prepare": "npm run build && npm run version && npm run package && npm run copy",
@@ -16,8 +16,8 @@
1616
"@typescript-eslint/eslint-plugin": "^7.1.1",
1717
"@typescript-eslint/parser": "^7.1.1",
1818
"eslint": "^8.57.0",
19-
"frida-compile": "^16.2.1",
19+
"frida-compile": "^16.4.1",
2020
"replace": "^1.2.2",
21-
"prettier": "^3.2.5"
21+
"prettier": "^3.3.3"
2222
}
2323
}

src/breakpoints/bp.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Trace, Traces } from '../traces/trace.js';
1111
import { Var } from '../vars/var.js';
1212
import { Vars } from '../vars/vars.js';
1313
import { CallTrace } from '../traces/call.js';
14+
import { CoverageTrace } from '../traces/coverage/trace.js';
1415

1516
export const BP_LENGTH: number = 16;
1617

@@ -26,6 +27,7 @@ export enum BpType {
2627
BlockTrace = 'block trace',
2728
CallTrace = 'call trace',
2829
UniqueBlockTrace = 'unique block trace',
30+
Coverage = 'coverage',
2931
MemoryRead = 'memory read',
3032
MemoryWrite = 'memory write',
3133
}
@@ -87,6 +89,7 @@ export class Bp {
8789
case BpType.BlockTrace:
8890
case BpType.CallTrace:
8991
case BpType.UniqueBlockTrace:
92+
case BpType.Coverage:
9093
return BpKind.Code;
9194
case BpType.MemoryRead:
9295
case BpType.MemoryWrite:
@@ -167,6 +170,19 @@ export class Bp {
167170
},
168171
});
169172
break;
173+
case BpType.Coverage:
174+
this._listener = Interceptor.attach(addr.toPointer(), {
175+
onEnter() {
176+
if (bp._hits === 0) return;
177+
bp._trace = CoverageTrace.create(this.threadId);
178+
bp.startCoverage(this.threadId, this.context);
179+
},
180+
onLeave(_retVal) {
181+
if (bp._hits === 0) return;
182+
bp.stopCoverage(this.threadId, this.context);
183+
},
184+
});
185+
break;
170186
default:
171187
throw new Error(`unknown code breakpoint type: ${this._type}`);
172188
}

src/cmdlets/bp.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ abstract class TypedBpCmdLet extends CmdLet implements InputInterceptLine {
4444
switch (this.bpType) {
4545
case BpType.Instruction:
4646
case BpType.FunctionEntry:
47-
case BpType.FunctionExit: {
47+
case BpType.FunctionExit:
48+
case BpType.Coverage: {
4849
if (tokens.length !== 3) return null;
4950
const [a0, a1, a2] = tokens;
5051
const [t0, t1, t2] = [a0 as Token, a1 as Token, a2 as Token];
@@ -146,6 +147,7 @@ abstract class TypedBpCmdLet extends CmdLet implements InputInterceptLine {
146147
case BpType.BlockTrace:
147148
case BpType.CallTrace:
148149
case BpType.UniqueBlockTrace:
150+
case BpType.Coverage:
149151
this.done();
150152
break;
151153
default:
@@ -235,7 +237,8 @@ abstract class TypedBpCmdLet extends CmdLet implements InputInterceptLine {
235237
switch (this.bpType) {
236238
case BpType.Instruction:
237239
case BpType.FunctionEntry:
238-
case BpType.FunctionExit: {
240+
case BpType.FunctionExit:
241+
case BpType.Coverage: {
239242
if (tokens.length !== 2) return null;
240243
const [a0, a1] = tokens;
241244
const [t0, t1] = [a0 as Token, a1 as Token];
@@ -453,3 +456,9 @@ export class UniqueBlockTraceBpCmdLet extends TypedBpCmdLet {
453456
bpType = BpType.UniqueBlockTrace;
454457
help = `${this.bpType} breakpoint`;
455458
}
459+
460+
export class CoverageBpCmdLet extends TypedBpCmdLet {
461+
name = '@c';
462+
bpType = BpType.Coverage;
463+
help = `${this.bpType} breakpoint`;
464+
}

src/commands/cmdlets.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
BlockTraceBpCmdLet,
3333
CallTraceBpCmdLet,
3434
UniqueBlockTraceBpCmdLet,
35+
CoverageBpCmdLet,
3536
InsnBpCmdLet,
3637
ReadBpCmdLet,
3738
WriteBpCmdLet,
@@ -56,6 +57,7 @@ export class CmdLets {
5657
this.registerCmdletType(BtCmdLet);
5758
this.registerCmdletType(CallTraceBpCmdLet);
5859
this.registerCmdletType(CopyCmdLet);
60+
this.registerCmdletType(CoverageBpCmdLet);
5961
this.registerCmdletType(DivCmdLet);
6062
this.registerCmdletType(DumpCmdLet);
6163
this.registerCmdletType(EndianCmdLet);

src/traces/block.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ export class BlockTrace implements Trace {
6363
currentDepth = 0;
6464
first = false;
6565
}
66-
if (numOutput >= BlockTrace.MAX_BLOCKS) return;
66+
if (numOutput >= BlockTrace.MAX_BLOCKS) {
67+
Output.writeln(Output.red(`TRACE TRUNCATED`));
68+
return;
69+
}
6770
numOutput += 1;
71+
const idx = `${numOutput.toString().padStart(4, ' ')}. `;
72+
Output.write(Output.bold(idx));
6873
if (currentDepth > 0) {
6974
Output.write('\t'.repeat(currentDepth));
7075
}

src/traces/call.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ export class CallTrace implements Trace {
6060
currentDepth = 1;
6161
first = false;
6262
}
63-
if (numOutput >= CallTrace.MAX_CALLS) return;
63+
if (numOutput >= CallTrace.MAX_CALLS) {
64+
Output.writeln(Output.red(`TRACE TRUNCATED`));
65+
return;
66+
}
6467
numOutput += 1;
68+
const idx = `${numOutput.toString().padStart(4, ' ')}. `;
69+
Output.write(Output.bold(idx));
6570
if (currentDepth > 0) {
6671
Output.write('\t'.repeat(currentDepth));
6772
}

0 commit comments

Comments
 (0)