Skip to content

Commit 26edc66

Browse files
author
Your Name
committed
Support loading multiple cmdlets in single script
1 parent c3353ab commit 26edc66

38 files changed

Lines changed: 220 additions & 142 deletions

.cshellrc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ v p ret
44
d p
55

66
# load a new commandlet from a script file and execute
7-
js src.js
8-
test malloc
7+
js cmdlet.js
8+
test1 malloc
99

1010
# show the first instruction of exit
1111
l exit 1
1212

1313
# set up a macro
14-
m test2
14+
m test3
1515
l main
1616
q
1717

18+
!test3
19+
1820
# set up a breakpoint
1921
@f malloc 1 ?
2022
!= $eip 0

cmdlet.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function dumpStuff(tokens, name, length) {
2+
if (tokens.length !== 1) throw new Error("expected 1 argument");
3+
const address = tokens[0].toVar().toPointer();
4+
Output.writeln(`${name}: ${address}`);
5+
6+
const bytes = Mem.readBytes(address, length);
7+
const dump = hexdump(bytes.buffer, {
8+
length: length,
9+
header: true,
10+
ansi: true,
11+
address: address,
12+
});
13+
const prefixed = dump.split('\n').join(`\n${Output.green("0x")}`);
14+
Output.writeln(` ${prefixed}`);
15+
}
16+
17+
return [
18+
{
19+
name: "test1",
20+
21+
runSync: function(tokens) {
22+
try {
23+
dumpStuff(tokens, "test1", 16);
24+
return Var.ZERO;
25+
} catch {
26+
return this.usage();
27+
}
28+
},
29+
},
30+
{
31+
name: "test2",
32+
33+
runSync: function(tokens) {
34+
try {
35+
dumpStuff(tokens, "test2", 32);
36+
return Var.ZERO;
37+
} catch {
38+
return this.usage();
39+
}
40+
},
41+
},
42+
]

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.6.4",
3+
"version": "1.6.5",
44
"description": "Frida's CShell",
55
"scripts": {
66
"prepare": "npm run build && npm run version && npm run package && npm run copy",

src.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/cmdlets/breakpoints/bp.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Bp, BpType } from '../../breakpoints/bp.js';
22
import { Bps } from '../../breakpoints/bps.js';
3-
import { CmdLet } from '../../commands/cmdlet.js';
3+
import { CmdLetBase } from '../../commands/cmdlet.js';
44
import { Input, InputInterceptLine } from '../../io/input.js';
55
import { Output } from '../../io/output.js';
66
import { Token } from '../../io/token.js';
@@ -11,7 +11,7 @@ enum InputMode {
1111
Commands = 'commands',
1212
}
1313

14-
abstract class TypedBpCmdLet extends CmdLet implements InputInterceptLine {
14+
abstract class TypedBpCmdLet extends CmdLetBase implements InputInterceptLine {
1515
protected static readonly CONDITIONAL_CHAR: string = '?';
1616
public abstract readonly bpType: BpType;
1717
protected abstract runCreate(tokens: Token[]): Var | null;
@@ -82,8 +82,8 @@ ${Output.bold('show:')}
8282
8383
${this.name} - show all ${this.bpType} breakpoints
8484
85-
${this.name} ${CmdLet.NUM_CHAR}n - show a ${this.bpType} breakpoint
86-
${CmdLet.NUM_CHAR}n the number of the breakpoint to show
85+
${this.name} ${CmdLetBase.NUM_CHAR}n - show a ${this.bpType} breakpoint
86+
${CmdLetBase.NUM_CHAR}n the number of the breakpoint to show
8787
8888
${Output.bold('create:')}
8989
${create}
@@ -93,8 +93,8 @@ ${modify}
9393
9494
${Output.bold('delete:')}
9595
96-
${this.name} ${CmdLet.NUM_CHAR}n # - delete a ${this.bpType} breakpoint
97-
${CmdLet.NUM_CHAR}n the number of the breakpoint to delete
96+
${this.name} ${CmdLetBase.NUM_CHAR}n # - delete a ${this.bpType} breakpoint
97+
${CmdLetBase.NUM_CHAR}n the number of the breakpoint to delete
9898
9999
${Output.bold('NOTE:')} Set hits to '*' for unlimited breakpoint.`;
100100

@@ -329,17 +329,17 @@ ${this.name} addr hits ${TypedBpCmdLet.CONDITIONAL_CHAR} - create ${this.bpType}
329329

330330
protected override usageModify(): string {
331331
const usage: string = `
332-
${this.name} ${CmdLet.NUM_CHAR}n addr - modify a ${this.bpType} breakpoint without a hit limit
333-
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
332+
${this.name} ${CmdLetBase.NUM_CHAR}n addr - modify a ${this.bpType} breakpoint without a hit limit
333+
${CmdLetBase.NUM_CHAR}n the number of the breakpoint to modify
334334
addr the address to move the breakpoint
335335
336-
${this.name} ${CmdLet.NUM_CHAR}n addr hits - modify a ${this.bpType} breakpoint
337-
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
336+
${this.name} ${CmdLetBase.NUM_CHAR}n addr hits - modify a ${this.bpType} breakpoint
337+
${CmdLetBase.NUM_CHAR}n the number of the breakpoint to modify
338338
addr the address to move the breakpoint
339339
hits the number of times the breakpoint should fire
340340
341-
${this.name} ${CmdLet.NUM_CHAR}n addr hits ${TypedBpCmdLet.CONDITIONAL_CHAR} - modify a ${this.bpType} breakpoint with conditions
342-
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
341+
${this.name} ${CmdLetBase.NUM_CHAR}n addr hits ${TypedBpCmdLet.CONDITIONAL_CHAR} - modify a ${this.bpType} breakpoint with conditions
342+
${CmdLetBase.NUM_CHAR}n the number of the breakpoint to modify
343343
addr the address to move the breakpoint
344344
hits the number of times the breakpoint should fire`;
345345
return usage;
@@ -464,19 +464,19 @@ ${this.name} addr len hits ${TypedBpCmdLet.CONDITIONAL_CHAR} - create ${this.bpT
464464

465465
protected override usageModify(): string {
466466
const usage: string = `
467-
${this.name} ${CmdLet.NUM_CHAR}n addr len - modify a ${this.bpType} breakpoint without a hit limit
468-
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
467+
${this.name} ${CmdLetBase.NUM_CHAR}n addr len - modify a ${this.bpType} breakpoint without a hit limit
468+
${CmdLetBase.NUM_CHAR}n the number of the breakpoint to modify
469469
addr the address to move the breakpoint
470470
len the length of the memory region to watch
471471
472-
${this.name} ${CmdLet.NUM_CHAR}n addr len hits - modify a ${this.bpType} breakpoint
473-
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
472+
${this.name} ${CmdLetBase.NUM_CHAR}n addr len hits - modify a ${this.bpType} breakpoint
473+
${CmdLetBase.NUM_CHAR}n the number of the breakpoint to modify
474474
addr the address to move the breakpoint
475475
len the length of the memory region to watch
476476
hits the number of times the breakpoint should fire
477477
478-
${this.name} ${CmdLet.NUM_CHAR}n addr len hits ${TypedBpCmdLet.CONDITIONAL_CHAR} - modify a ${this.bpType} breakpoint with conditions
479-
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
478+
${this.name} ${CmdLetBase.NUM_CHAR}n addr len hits ${TypedBpCmdLet.CONDITIONAL_CHAR} - modify a ${this.bpType} breakpoint with conditions
479+
${CmdLetBase.NUM_CHAR}n the number of the breakpoint to modify
480480
addr the address to move the breakpoint
481481
len the length of the memory region to watch
482482
hits the number of times the breakpoint should fire`;
@@ -611,19 +611,19 @@ ${this.name} addr depth hits ${TypedBpCmdLet.CONDITIONAL_CHAR} - create ${this.b
611611

612612
protected override usageModify(): string {
613613
const usage: string = `
614-
${this.name} ${CmdLet.NUM_CHAR}n addr depth - modify a ${this.bpType} breakpoint without a hit limit
615-
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
614+
${this.name} ${CmdLetBase.NUM_CHAR}n addr depth - modify a ${this.bpType} breakpoint without a hit limit
615+
${CmdLetBase.NUM_CHAR}n the number of the breakpoint to modify
616616
addr the address to move the breakpoint
617617
depth the maximum depth of callstack to follow
618618
619-
${this.name} ${CmdLet.NUM_CHAR}n addr depth hits - modify a ${this.bpType} breakpoint
620-
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
619+
${this.name} ${CmdLetBase.NUM_CHAR}n addr depth hits - modify a ${this.bpType} breakpoint
620+
${CmdLetBase.NUM_CHAR}n the number of the breakpoint to modify
621621
addr the address to move the breakpoint
622622
depth the maximum depth of callstack to follow
623623
hits the number of times the breakpoint should fire
624624
625-
${this.name} ${CmdLet.NUM_CHAR}n addr depth hits ${TypedBpCmdLet.CONDITIONAL_CHAR} - modify a ${this.bpType} breakpoint with conditions
626-
${CmdLet.NUM_CHAR}n the number of the breakpoint to modify
625+
${this.name} ${CmdLetBase.NUM_CHAR}n addr depth hits ${TypedBpCmdLet.CONDITIONAL_CHAR} - modify a ${this.bpType} breakpoint with conditions
626+
${CmdLetBase.NUM_CHAR}n the number of the breakpoint to modify
627627
addr the address to move the breakpoint
628628
depth the maximum depth of callstack to follow
629629
hits the number of times the breakpoint should fire`;

src/cmdlets/breakpoints/reg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { CmdLet } from '../../commands/cmdlet.js';
1+
import { CmdLetBase } from '../../commands/cmdlet.js';
22
import { Output } from '../../io/output.js';
33
import { Vars } from '../../vars/vars.js';
44
import { Token } from '../../io/token.js';
55
import { Var } from '../../vars/var.js';
66
import { Regs } from '../../breakpoints/regs.js';
77

8-
export class RegCmdLet extends CmdLet {
8+
export class RegCmdLet extends CmdLetBase {
99
name = 'R';
1010
category = 'breakpoints';
1111
help = 'register management';

src/cmdlets/data/assembly.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { CmdLet } from '../../commands/cmdlet.js';
1+
import { CmdLetBase } from '../../commands/cmdlet.js';
22
import { Output } from '../../io/output.js';
33
import { Format } from '../../misc/format.js';
44
import { Token } from '../../io/token.js';
55
import { Var } from '../../vars/var.js';
66
import { Mem } from '../../memory/mem.js';
77
import { Overlay } from '../../memory/overlay.js';
88

9-
export class AssemblyCmdLet extends CmdLet {
9+
export class AssemblyCmdLet extends CmdLetBase {
1010
name = 'l';
1111
category = 'data';
1212
help = 'disassembly listing';

src/cmdlets/data/copy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { CmdLet } from '../../commands/cmdlet.js';
1+
import { CmdLetBase } from '../../commands/cmdlet.js';
22
import { Output } from '../../io/output.js';
33
import { Format } from '../../misc/format.js';
44
import { Token } from '../../io/token.js';
55
import { Var } from '../../vars/var.js';
66
import { Mem } from '../../memory/mem.js';
77

8-
export class CopyCmdLet extends CmdLet {
8+
export class CopyCmdLet extends CmdLetBase {
99
name = 'cp';
1010
category = 'data';
1111
help = 'copy data in memory';

src/cmdlets/data/dump.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { CmdLet } from '../../commands/cmdlet.js';
1+
import { CmdLetBase } from '../../commands/cmdlet.js';
22
import { Output } from '../../io/output.js';
33
import { Format } from '../../misc/format.js';
44
import { Token } from '../../io/token.js';
55
import { Var } from '../../vars/var.js';
66
import { Mem } from '../../memory/mem.js';
77

8-
export class DumpCmdLet extends CmdLet {
8+
export class DumpCmdLet extends CmdLetBase {
99
name = 'd';
1010
category = 'data';
1111
help = 'dump data from memory';

0 commit comments

Comments
 (0)