@@ -26,17 +26,22 @@ import (
26
26
"os"
27
27
"os/signal"
28
28
"path/filepath"
29
+ "regexp"
30
+ "strings"
29
31
"syscall"
30
32
31
33
"github.com/apex/log"
32
34
"github.com/blacktop/ipsw/internal/commands/mount"
35
+ "github.com/blacktop/ipsw/internal/download"
33
36
"github.com/blacktop/ipsw/internal/utils"
34
37
"github.com/spf13/cobra"
35
38
)
36
39
37
40
func init () {
38
41
rootCmd .AddCommand (mountCmd )
39
42
43
+ mountCmd .Flags ().StringP ("key" , "k" , "" , "DMG key" )
44
+ mountCmd .Flags ().Bool ("lookup" , false , "Lookup DMG keys on theapplewiki.com" )
40
45
mountCmd .Flags ().String ("pem-db" , "" , "AEA pem DB JSON file" )
41
46
}
42
47
@@ -54,15 +59,60 @@ var mountCmd = &cobra.Command{
54
59
}
55
60
return []string {"ipsw" }, cobra .ShellCompDirectiveFilterFileExt
56
61
},
57
- RunE : func (cmd * cobra.Command , args []string ) error {
58
-
62
+ RunE : func (cmd * cobra.Command , args []string ) ( err error ) {
63
+ // set log level
59
64
if Verbose {
60
65
log .SetLevel (log .DebugLevel )
61
66
}
62
67
68
+ // flags
69
+ key , _ := cmd .Flags ().GetString ("key" )
70
+ lookupKeys , _ := cmd .Flags ().GetBool ("lookup" )
63
71
pemDB , _ := cmd .Flags ().GetString ("pem-db" )
72
+ // validate flags
73
+ if len (key ) > 0 && lookupKeys {
74
+ return fmt .Errorf ("cannot use --key AND --lookup flags together" )
75
+ }
76
+
77
+ var keys any
78
+ if lookupKeys {
79
+ var (
80
+ device string
81
+ version string
82
+ build string
83
+ )
84
+ re := regexp .MustCompile (`^.*/(?P<device>.+)_(?P<version>.+)_(?P<build>.+)_(?i)Restore\.ipsw$` )
85
+ if re .MatchString (args [1 ]) {
86
+ matches := re .FindStringSubmatch (args [1 ])
87
+ if len (matches ) < 4 {
88
+ return fmt .Errorf ("failed to parse IPSW filename: %s" , args [1 ])
89
+ }
90
+ device = matches [1 ]
91
+ version = matches [2 ]
92
+ build = matches [3 ]
93
+ } else {
94
+ return fmt .Errorf ("failed to parse IPSW filename: %s" , args [1 ])
95
+ }
96
+ if device == "" || build == "" {
97
+ return fmt .Errorf ("device or build information is missing from IPSW filename (required for key lookup)" )
98
+ }
99
+ log .Info ("Downloading Keys..." )
100
+ wikiKeys , err := download .GetWikiFirmwareKeys (& download.WikiConfig {
101
+ Keys : true ,
102
+ Device : strings .Replace (device , "ip" , "iP" , 1 ),
103
+ Version : version ,
104
+ Build : strings .ToUpper (build ),
105
+ // Beta: viper.GetBool("download.key.beta"),
106
+ }, "" , false )
107
+ if err != nil {
108
+ return fmt .Errorf ("failed querying theapplewiki.com: %v" , err )
109
+ }
110
+ keys = wikiKeys
111
+ } else if len (key ) > 0 {
112
+ keys = key
113
+ }
64
114
65
- mctx , err := mount .DmgInIPSW (args [1 ], args [0 ], pemDB )
115
+ mctx , err := mount .DmgInIPSW (args [1 ], args [0 ], pemDB , keys )
66
116
if err != nil {
67
117
return fmt .Errorf ("failed to mount %s DMG: %v" , args [0 ], err )
68
118
}
0 commit comments