-
Notifications
You must be signed in to change notification settings - Fork 10
/
cmd_mse.go
58 lines (49 loc) · 1.18 KB
/
cmd_mse.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
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/freemyipod/wInd3x/pkg/mse"
)
var extractDir string
var mseCmd = &cobra.Command{
Use: "mse",
Short: "Manipulate .mse firmware files",
}
var mseExtractCmd = &cobra.Command{
Use: "extract [Firmware.mse]",
Short: "Extract an .mse firmware flie into images",
Long: "Split an .mse file into individual images like osos, disk, etc.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
f, err := os.Open(args[0])
if err != nil {
return fmt.Errorf("could not read input: %w", err)
}
defer f.Close()
m, err := mse.Parse(f)
if err != nil {
return fmt.Errorf("could not parse .mse: %w", err)
}
dir := extractDir
if dir == "" {
dir, err = os.Getwd()
if err != nil {
return fmt.Errorf("could not get working directory: %w", err)
}
}
for _, file := range m.Files {
if !file.Header.Valid() {
continue
}
path := filepath.Join(dir, file.Header.Name.String())
glog.Infof("Extracting %s ...", path)
if err := os.WriteFile(path, file.Data, 0666); err != nil {
return err
}
}
return nil
},
}