Skip to content

Commit

Permalink
feat: allow unmounting disk images (#454)
Browse files Browse the repository at this point in the history
New command to remove developer disk images
- ios image unmount
  • Loading branch information
nicolasbouffard authored Aug 19, 2024
1 parent 27ad5e0 commit c2832f0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ios/imagemounter/imagemounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type DeveloperDiskImageMounter struct {
type ImageMounter interface {
ListImages() ([][]byte, error)
MountImage(imagePath string) error
UnmountImage() error
io.Closer
}

Expand Down Expand Up @@ -95,6 +96,19 @@ func (conn *DeveloperDiskImageMounter) MountImage(imagePath string) error {
return hangUp(conn.plistRw)
}

func (conn *DeveloperDiskImageMounter) UnmountImage() error {
req := map[string]interface{}{
"Command": "UnmountImage",
"MountPath": "/Developer",
}
log.Debugf("sending: %+v", req)
err := conn.plistRw.Write(req)
if err != nil {
return err
}
return nil
}

func (conn *DeveloperDiskImageMounter) mountImage(signatureBytes []byte) error {
req := map[string]interface{}{
"Command": "MountImage",
Expand Down Expand Up @@ -189,6 +203,16 @@ func MountImage(device ios.DeviceEntry, path string) error {
return conn.MountImage(path)
}

func UnmountImage(device ios.DeviceEntry) error {
conn, err := NewImageMounter(device)
if err != nil {
return fmt.Errorf("failed connecting to image mounter: %v", err)
}
defer conn.Close()

return conn.UnmountImage()
}

func listImages(prw ios.PlistCodecReadWriter, imageType string, v *semver.Version) ([][]byte, error) {
err := prw.Write(map[string]interface{}{
"Command": "LookupImage",
Expand Down
13 changes: 13 additions & 0 deletions ios/imagemounter/personalized_image_mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ func (p PersonalizedDeveloperDiskImageMounter) MountImage(imagePath string) erro
return nil
}

func (p PersonalizedDeveloperDiskImageMounter) UnmountImage() error {
req := map[string]interface{}{
"Command": "UnmountImage",
"MountPath": "/System/Developer",
}
log.Debugf("sending: %+v", req)
err := p.plistRw.Write(req)
if err != nil {
return err
}
return nil
}

func (p PersonalizedDeveloperDiskImageMounter) queryPersonalizedImageNonce() ([]byte, error) {
err := p.plistRw.Write(map[string]interface{}{
"Command": "QueryNonce",
Expand Down
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Usage:
ios info [display | lockdown] [options]
ios image list [options]
ios image mount [--path=<imagepath>] [options]
ios image unmount [options]
ios image auto [--basedir=<where_dev_images_are_stored>] [options]
ios syslog [options]
ios screenshot [options] [--output=<outfile>] [--stream] [--port=<port>]
Expand Down Expand Up @@ -160,6 +161,7 @@ The commands work as following:
ios image list [options] List currently mounted developers images' signatures
ios image mount [--path=<imagepath>] [options] Mount a image from <imagepath>
> For iOS 17+ (personalized developer disk images) <imagepath> must point to the "Restore" directory inside the developer disk
ios image unmount [options] Unmount developer disk image
ios image auto [--basedir=<where_dev_images_are_stored>] [options] Automatically download correct dev image from the internets and mount it.
> You can specify a dir where images should be cached.
> The default is the current dir.
Expand Down Expand Up @@ -1139,6 +1141,17 @@ func imageCommand1(device ios.DeviceEntry, arguments docopt.Opts) bool {
}
log.WithFields(log.Fields{"image": path, "udid": device.Properties.SerialNumber}).Info("success mounting image")
}

unmount, _ := arguments.Bool("unmount")
if unmount {
err := imagemounter.UnmountImage(device)
if err != nil {
log.WithFields(log.Fields{"udid": device.Properties.SerialNumber, "err": err}).
Error("error unmounting image")
return true
}
log.WithFields(log.Fields{"udid": device.Properties.SerialNumber}).Info("success unmounting image")
}
}
return b
}
Expand Down

0 comments on commit c2832f0

Please sign in to comment.