-
Notifications
You must be signed in to change notification settings - Fork 10
/
cmd_run.go
42 lines (36 loc) · 1014 Bytes
/
cmd_run.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
package main
import (
"fmt"
"os"
"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/freemyipod/wInd3x/pkg/app"
"github.com/freemyipod/wInd3x/pkg/dfu"
)
var runCmd = &cobra.Command{
Use: "run [dfu image path]",
Short: "Run a DFU image on a device",
Long: "Run a DFU image (signed/encrypted or unsigned) on a connected device, starting haxed dfu mode first if necessary.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
app, err := app.New()
if err != nil {
return err
}
defer app.Close()
path := args[0]
glog.Infof("Uploading %s...", path)
data, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("Failed to read image: %w", err)
}
if err := dfu.Clean(app.Usb); err != nil {
return fmt.Errorf("Failed to clean: %w", err)
}
if err := dfu.SendImage(app.Usb, data, app.Desc.Kind.DFUVersion()); err != nil {
return fmt.Errorf("Failed to send image: %w", err)
}
glog.Infof("Image sent.")
return nil
},
}