Skip to content

Commit

Permalink
fix: mount DeveloperDiskImage
Browse files Browse the repository at this point in the history
  • Loading branch information
bitxeno committed Jul 4, 2023
1 parent e188fba commit 9e9241e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 51 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ atvloadly 是一个支持在 AppleTV 上侧载应用的 web 服务。底层通

> 每个 Apple ID 最多可以同时激活 3 个应用,安装超过 3 个后,会导致前面已安装的 App 变为不可用
2、密码可以使用App-specific password吗,这样安全些
2、升级系统后安装失败

> 升级系统后需要重新配对,一般新出的系统都不支持,建议关闭系统自动更新
3、密码可以使用App-specific password吗,这样安全些

> AltServer 目前不支持
Expand Down
11 changes: 6 additions & 5 deletions manager/device_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package manager

import (
"encoding/json"
"fmt"
"sync"

"github.com/bitxeno/atvloadly/config"
Expand Down Expand Up @@ -83,7 +84,7 @@ func (dm *DeviceManager) ReloadDevices() {

// 获取DeveloperDiskImage绑定信息,install/screenshot等功能
// 都需要先绑定DeveloperDiskImage才有权限操作
func (dm *DeviceManager) GetMountImageInfo(udid string) (*model.UsbmuxdDevice, error) {
func (dm *DeviceManager) GetMountImageInfo(udid string) (*model.UsbmuxdImage, error) {
usbmux, err := gidevice.NewUsbmux()
if err != nil {
log.Err(err).Msg("Cannot get image signatures: ")
Expand Down Expand Up @@ -114,11 +115,11 @@ func (dm *DeviceManager) GetMountImageInfo(udid string) (*model.UsbmuxdDevice, e
return nil, err
}

devInfo.ImageMounted = len(imageSignatures) > 0
devInfo.SetDeveloperDiskImageUrl(config.Settings.DeveloperDiskImage.ImageSource)
return devInfo, nil
imageInfo := model.NewUsbmuxdImage(*devInfo, config.Settings.DeveloperDiskImage.ImageSource)
imageInfo.ImageMounted = len(imageSignatures) > 0
return imageInfo, nil
}
}

return nil, nil
return nil, fmt.Errorf("Device pairing state not valid. Please try to pair again.")
}
2 changes: 1 addition & 1 deletion manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func GetDeviceByID(id string) (*model.Device, bool) {
return deviceManager.GetDeviceByID(id)
}

func GetDeviceMountImageInfo(udid string) (*model.UsbmuxdDevice, error) {
func GetDeviceMountImageInfo(udid string) (*model.UsbmuxdImage, error) {
return deviceManager.GetMountImageInfo(udid)
}

Expand Down
23 changes: 0 additions & 23 deletions model/usbmuxd_device.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package model

import (
"fmt"
"strings"
)

type UsbmuxdDevice struct {
DeviceName string `json:"DeviceName,omitempty"`
ProductVersion string `json:"ProductVersion,omitempty"`
Expand All @@ -24,22 +19,4 @@ type UsbmuxdDevice struct {
BasebandVersion string `json:"BasebandVersion,omitempty"`
DeviceColor string `json:"DeviceColor,omitempty"`
DeviceClass string `json:"DeviceClass,omitempty"`

// custom
ImageMounted bool `json:"ImageMounted,omitempty"`
DeveloperDiskImageUrl string `json:"DeveloperDiskImageUrl,omitempty"`
DeveloperDiskImageVersion string `json:"DeveloperDiskImageVersion,omitempty"`
}

func (ud *UsbmuxdDevice) SetDeveloperDiskImageUrl(imageSource string) {
arr := strings.Split(ud.ProductVersion, ".")
tvOSVersion := ""
if len(arr) < 2 {
tvOSVersion = fmt.Sprintf("%s.0", arr[0])
} else {
tvOSVersion = fmt.Sprintf("%s.%s", arr[0], arr[1])
}

ud.DeveloperDiskImageVersion = tvOSVersion
ud.DeveloperDiskImageUrl = strings.Replace(imageSource, "{0}", tvOSVersion, -1)
}
31 changes: 31 additions & 0 deletions model/usbmuxd_image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package model

import (
"fmt"
"strings"
)

type UsbmuxdImage struct {
Device UsbmuxdDevice

ImageMounted bool `json:"ImageMounted,omitempty"`
DeveloperDiskImageUrl string `json:"DeveloperDiskImageUrl,omitempty"`
DeveloperDiskImageVersion string `json:"DeveloperDiskImageVersion,omitempty"`
}

func NewUsbmuxdImage(device UsbmuxdDevice, imageSource string) *UsbmuxdImage {
arr := strings.Split(device.ProductVersion, ".")
tvOSVersion := ""
if len(arr) < 2 {
tvOSVersion = fmt.Sprintf("%s.0", arr[0])
} else {
tvOSVersion = fmt.Sprintf("%s.%s", arr[0], arr[1])
}

return &UsbmuxdImage{
Device: device,
ImageMounted: false,
DeveloperDiskImageUrl: strings.Replace(imageSource, "{0}", tvOSVersion, -1),
DeveloperDiskImageVersion: tvOSVersion,
}
}
25 changes: 15 additions & 10 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,40 @@ func MountDeveloperDiskImage(ctx context.Context, id string) error {

// 尝试挂载
// 对应版本的DeveloperDiskImage不存在的话,尝试下载
imageDir := filepath.Join(cfg.Server.WorkDir, "DeveloperDiskImage", imageInfo.DeveloperDiskImageVersion)
if _, err := os.Stat(imageDir); os.IsNotExist(err) {
imageDir := filepath.Join(cfg.Server.WorkDir, "DeveloperDiskImage")
imageVersionDir := filepath.Join(cfg.Server.WorkDir, "DeveloperDiskImage", imageInfo.DeveloperDiskImageVersion)
if _, err := os.Stat(imageVersionDir); os.IsNotExist(err) {
tmpPath := filepath.Join(cfg.Server.WorkDir, "tmp", "DeveloperDiskImage.zip")
if _, err = http.NewClient().SetDoNotParseResponse(true).R().SetOutput(tmpPath).Get(imageInfo.DeveloperDiskImageUrl); err != nil {
log.Err(err).Msg("Download DeveloperDiskImage error: ")
resp, err := http.NewClient().R().SetOutput(tmpPath).Get(imageInfo.DeveloperDiskImageUrl)
if err != nil {
log.Err(err).Msg("Download Developer disk image error: ")
return err
}
if !resp.IsSuccess() {
return fmt.Errorf("Developer disk image could not found. os: tvOS %s url: %s status: %d", imageInfo.Device.ProductVersion, imageInfo.DeveloperDiskImageUrl, resp.StatusCode())
}

// unzip
uz := unzip.New()
if _, err = uz.Extract(tmpPath, imageDir); err != nil {
log.Err(err).Msg("Unzip DeveloperDiskImage error: ")
log.Err(err).Msg("Unzip Developer disk image error: ")
return err
}
}

// 开始执行挂载
dmg := filepath.Join(imageDir, "DeveloperDiskImage.dmg")
signature := filepath.Join(imageDir, "DeveloperDiskImage.dmg.signature")
dmg := filepath.Join(imageVersionDir, "DeveloperDiskImage.dmg")
signature := filepath.Join(imageVersionDir, "DeveloperDiskImage.dmg.signature")
cmd := exec.CommandContext(ctx, "ideviceimagemounter", "-u", device.UDID, "-n", dmg, signature)
data, err := cmd.Output()
data, err := cmd.CombinedOutput()
if err != nil {
log.Err(err).Msg("Run ideviceimagemounter error: ")
return err
return fmt.Errorf("%s%s", string(data), err.Error())
}

output := string(data)
if strings.Contains(output, "ERROR") {
return fmt.Errorf(output)
return fmt.Errorf("%s\n%s", "Run ideviceimagemounter error: ", output)
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion view/src/page/install/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default {
_this.log.output += "Prepare to mount DeveloperDiskImage...\n";
let data = await api.mountDeviceImageAsync(_this.id);
if (data != "success") {
_this.log.output += resp.data;
_this.log.output += data;
_this.cmd.output = "";
_this.loading = false;
toast.error("安装失败,请查看日志了解详细信息");
Expand All @@ -190,6 +190,7 @@ export default {
let file = _this.files[i];
formData.append("files", file);
}
_this.log.output += "IPA uploading...\n";
api.upload(formData).then((res) => {
let ipa = res.data[0];
_this.ipa = ipa;
Expand Down
10 changes: 0 additions & 10 deletions view/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,6 @@ entities@^4.2.0:
resolved "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz"
integrity sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==

[email protected]:
version "0.14.54"
resolved "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.54.tgz"
integrity sha512-jtdKWV3nBviOd5v4hOpkVmpxsBy90CGzebpbO9beiqUYVMBtSc0AL9zGftFuBon7PNDcdvNCEuQqw2x0wP9yug==

esbuild@^0.14.27:
version "0.14.54"
resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.14.54.tgz"
Expand Down Expand Up @@ -602,11 +597,6 @@ fs.realpath@^1.0.0:
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fsevents@~2.3.2:
version "2.3.2"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

function-bind@^1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"
Expand Down

0 comments on commit 9e9241e

Please sign in to comment.