-
Notifications
You must be signed in to change notification settings - Fork 10
/
cmd_dump.go
59 lines (51 loc) · 1.38 KB
/
cmd_dump.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"os"
"time"
"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/freemyipod/wInd3x/pkg/app"
"github.com/freemyipod/wInd3x/pkg/exploit/dumpmem"
)
var dumpCmd = &cobra.Command{
Use: "dump [offset] [size] [file]",
Short: "Dump memory to file",
Long: "Read memory from a connected device and write results to a file. Not very fast.",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
app, err := app.New()
if err != nil {
return err
}
defer app.Close()
offset, err := parseNumber(args[0])
if err != nil {
return fmt.Errorf("invalid offset")
}
size, err := parseNumber(args[1])
if err != nil {
return fmt.Errorf("invalid size")
}
f, err := os.Create(args[2])
if err != nil {
return fmt.Errorf("could not open file for writing: %w", err)
}
defer f.Close()
start := time.Now()
for i := uint32(0); i < size; i += 0x40 {
o := offset + i
glog.Infof("Dumping %x...", o)
data, err := dumpmem.Trigger(app.Usb, app.Ep, o)
if err != nil {
return fmt.Errorf("failed to run wInd3x exploit: %w", err)
}
if _, err := f.Write(data); err != nil {
return fmt.Errorf("failed to write: %w", err)
}
}
took := time.Since(start)
glog.Infof("Done! %d bytes in %d seconds (%d bytes per second)", size, int(took.Seconds()), int(float64(size)/took.Seconds()))
return nil
},
}