Skip to content

Commit 9c778d7

Browse files
author
Your Name
committed
Add support for dumping data to file
1 parent 7f1f42a commit 9c778d7

File tree

5 files changed

+55
-3
lines changed

5 files changed

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

src/cmdlets/data/dumpfile.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { CmdLetBase } from '../../commands/cmdlet.js';
2+
import { Output } from '../../io/output.js';
3+
import { Format } from '../../misc/format.js';
4+
import { Token } from '../../io/token.js';
5+
import { Var } from '../../vars/var.js';
6+
import { Mem } from '../../memory/mem.js';
7+
8+
export class DumpFileCmdLet extends CmdLetBase {
9+
name = 'df';
10+
category = 'data';
11+
help = 'dump data to file';
12+
13+
private static readonly USAGE: string = `Usage: df
14+
15+
df filename address bytes - show data
16+
filename the name of the file to dump to
17+
adress the address/symbol to dump from
18+
count the count of fields to dump`;
19+
20+
public runSync(tokens: Token[]): Var {
21+
const vars = this.transform(tokens, [
22+
this.parseString,
23+
this.parseVar,
24+
this.parseVar,
25+
]);
26+
if (vars === null) return this.usage();
27+
const [filename, address, length] = vars as [string, Var, Var];
28+
this.dump(filename, address.toPointer(), length.toU64().toNumber());
29+
return new Var(filename);
30+
}
31+
32+
private dump(filename: string, address: NativePointer, length: number) {
33+
try {
34+
const bytes = Mem.readBytes(address, length);
35+
Output.debug(`writing ${length} bytes from ${address} to ${filename}`);
36+
File.writeAllBytes(filename, bytes.buffer as ArrayBuffer);
37+
} catch (error) {
38+
throw new Error(
39+
`failed to dump ${Format.toHexString(length)} bytes from ${Format.toHexString(address)} to ${filename}, ${error}`,
40+
);
41+
}
42+
}
43+
44+
public usage(): Var {
45+
Output.writeln(DumpFileCmdLet.USAGE);
46+
return Var.ZERO;
47+
}
48+
}

src/cmdlets/development/js.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import { ErrnoCmdLet } from '../misc/errno.js';
8686
import { SzCmdLet } from '../files/sz.js';
8787
import { TlsCmdLet } from '../thread/tls.js';
8888
import { TmpCmdLet } from '../files/tmp.js';
89+
import { DumpFileCmdLet } from '../data/dumpfile.js';
8990

9091
export class JsCmdLet extends CmdLetBase {
9192
name = 'js';
@@ -124,6 +125,7 @@ js path - load commandlet JS script
124125
CoverageBpCmdLet: CoverageBpCmdLet,
125126
DivCmdLet: DivCmdLet,
126127
DumpCmdLet: DumpCmdLet,
128+
DumpFileCmdLet: DumpFileCmdLet,
127129
EchoCmdLet: EchoCmdLet,
128130
EqCmdLet: EqCmdLet,
129131
ErrnoCmdLet: ErrnoCmdLet,

src/commands/cmdlets.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import { ErrnoCmdLet } from '../cmdlets/misc/errno.js';
7373
import { SzCmdLet } from '../cmdlets/files/sz.js';
7474
import { TlsCmdLet } from '../cmdlets/thread/tls.js';
7575
import { TmpCmdLet } from '../cmdlets/files/tmp.js';
76+
import { DumpFileCmdLet } from '../cmdlets/data/dumpfile.js';
7677

7778
export class CmdLets {
7879
private static byName: Map<string, CmdLet> = new Map<string, CmdLet>();
@@ -91,6 +92,7 @@ export class CmdLets {
9192
this.registerCmdletType(CoverageBpCmdLet);
9293
this.registerCmdletType(DivCmdLet);
9394
this.registerCmdletType(DumpCmdLet);
95+
this.registerCmdletType(DumpFileCmdLet);
9496
this.registerCmdletType(DumpStringCmdLet);
9597
this.registerCmdletType(EchoCmdLet);
9698
this.registerCmdletType(EndianCmdLet);

0 commit comments

Comments
 (0)