简体   繁体   English

从Mac命令行访问iOS应用程序目录(沙箱)

[英]Command line access to iOS app directory (sandbox) from Mac

I need to access the sandbox directory for an application installed on an iOS device, using the command line (non-gui) from a Mac or Linux. 我需要使用Mac或Linux上的命令行(non-gui)访问安装在iOS设备上的应用程序的沙箱目录。 This is to help with development and testing automation. 这有助于开发和测试自动化。 Dropping a json file into the sandbox lets me set parameters like extra debug messages and smaller refresh intervals. 将json文件放入沙箱可以让我设置额外的调试消息和更小的刷新间隔等参数。

A tool like iFunBox works perfectly but is graphical only, requiring numerous clicks to do this. 像iFunBox这样的工具可以很好地工作,但只是图形化,需要多次点击才能完成。 Emails to the developers were unanswered. 发给开发人员的电子邮件没有得到答复。 It also does not support AppleScript. 它也不支持AppleScript。 I did find another app that provided a Fuse module, but it turned out buggy especially if the app was uninstalled and then reinstalled (in order to reset back to first time user experience). 我确实找到了另一个提供Fuse模块的应用程序,但是如果应用程序被卸载然后重新安装(以便重置为第一次用户体验),它就变成了错误。 I reported the problems to the developer but there is no fix on the horizon. 我向开发人员报告了这些问题,但没有解决问题。

The things I need to do are: 我需要做的事情是:

  • Test if an app with a specific bundle id is installed 测试是否安装了具有特定软件包ID的应用程序
  • Create Library/Caches/MYLIBNAME directory if it doesn't exist 创建Library / Caches / MYLIBNAME目录(如果它不存在)
  • Copy a ~100 byte json file from the Mac to that directory 将一个~100字节的json文件从Mac复制到该目录
  • Get a copy of that file 获取该文件的副本
  • A solution that only works from Linux is acceptable too 只能在Linux上运行的解决方案也是可以接受的
  • Devices are not jailbroken and I would prefer not to need that as a requirement 设备没有越狱,我宁愿不要求这样做

In some cases I do not have the source code to the app since it is a third party using my library, so compiling different versions of the app isn't practical. 在某些情况下,我没有应用程序的源代码,因为它是使用我的库的第三方,因此编译应用程序的不同版本是不切实际的。

Answer is below in many comments thanks to lxt. 由于lxt,许多评论中的答案如下。 Summary is: 总结是:

  • Various libraries and programs associated with libimobiledevice can solve the problems 与libimobiledevice相关的各种库和程序可以解决这些问题
    • Use patched iFuse to mount an application sandbox 使用修补的 iFuse安装应用程序沙箱
    • Use idevicesyslog to see the console log 使用idevicesyslog查看控制台日志
    • Use ideviceinstaller to install/uninstall apps 使用ideviceinstaller安装/卸载应用程序
  • The various libraries and programs associated with libimobiledevice are incredibly difficult if not impossible to compile as is on Linux or Mac, and there is no unified distribution of the source or binaries 与libimobiledevice相关的各种库和程序即使不是不可能在Linux或Mac上编译也是非常困难的,并且没有统一分发源或二进制文件
    • For Ubuntu try libimobiledevice (may have 3 suffix), ideviceinstaller and libimobiledevice-utils packages 对于Ubuntu,请尝试libimobiledevice(可能有3个后缀),ideviceinstaller和libimobiledevice-utils包
    • For Mac a search for libimobiledevice-macosx may get you some of the way there 对于Mac,搜索libimobiledevice-macosx可能会让你获得一些方法

This is going to be a little tricky, because as I think you've found out the application name is randomly generated on every install. 这有点棘手,因为我认为您已经发现应用程序名称是在每次安装时随机生成的。 I don't think there is a way past that, certainly that I know of. 我不认为有过这样的方式,当然我知道。 This explains the problems you're running into when simulating a new install (...the app directory name changes to a new, random hash, and then you're stuck). 这解释了您在模拟新安装时遇到的问题(...应用程序目录名称更改为新的随机哈希,然后您被卡住了)。

Although my preference would be to access this config file in some other way (perhaps over a network, and have some code that only executes on debug/test builds check for it), if you did want to do this then I'd suggest trying something like writing a script that when you want to simulate a new install chooses the app directory that's most recently modified. 虽然我倾向于以其他方式访问此配置文件(可能通过网络,并且只有一些代码只能在调试/测试版本上执行检查),如果你确实想要这样做,那么我建议你尝试类似于编写脚本,当您想要模拟新安装时,选择最近修改过的应用程序目录。 But this is very hacky. 但这非常hacky。

If you're not able to insert conditional code that only executes on debug/ test builds then I think the random app naming schema that iOS uses at a file system level is going to be problematic for you whatever approach you take. 如果您无法插入仅在调试/测试版本上执行的条件代码,那么我认为iOS在文件系统级别使用的随机应用程序命名架构对您采取的任何方法都会有问题。

Update : Regarding iFuse and libimobiledevice - out of the box it limits you to the documents directory. 更新 :关于iFuse和libimobiledevice - 开箱即用它限制你到文档目录。 This is because the authors of iFuse don't entry-level users to be confused, and also because the structure is a little different depending on iOS version. 这是因为iFuse的作者不会让入门级用户感到困惑,也因为结构因iOS版本而略有不同。 You can comment out the lines in the iFuse source - fuse_opt_add_arg(&args, "-osubdir=Documents"); 你可以注释掉iFuse源代码中的行 - fuse_opt_add_arg(&args, "-osubdir=Documents"); - to get access to the library directory through the mount. - 通过mount访问库目录。 You will obviously need to re-compile iFuse yourself if doing this. 如果这样做,你显然需要自己重新编译iFuse。

您可以使用MobileDevice Library

I know this is an old question and I doubt anyone is looking here anymore, but I thought I'd mention that you can use 'brew install libimobiledevice' to compile on the mac. 我知道这是一个老问题,我怀疑任何人都在这里看,但我想我会提到你可以使用'brew install libimobiledevice'在mac上编译。 There are a lot of dependencies and Homebrew really helps make it an easy process by installing them for you. 有许多依赖项,Homebrew真的有助于通过为您安装它们来使它成为一个简单的过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM