卸載App在theos導入private framework MobileInstallation無法成功

各位大大下午好,小弟在實作這位大神給的demo code。

自己研究大約三天了,主要卡在以下問題:

第一個問題,在theos make package的時候出現ld: framework not found MobileInstallation錯誤:
按照書本上的指導得知,若要引用私用框架需要寫上MyProject_PRIVATE_FRAMEWORKS = MobileInstallation
但是在mack package的時候始終顯示not found。
我去過/opt/theos底下找的到

~/opt/theos/include/PrivateFrameworks/MobileInstallation:
CDStructures.h                             MobileInstallerDelegateProtocol-Protocol.h
MIInstallerClient.h                        MobileInstallerProtocol-Protocol.h

我去過iphone 8.1.2手機上用openssh看過也有:

/System/Library/PrivateFrameworks/MobileInstallation.framework
/System/Library/PrivateFrameworks/MobileInstallation.framework/Info.plist
/System/Library/PrivateFrameworks/MobileInstallation.framework/_CodeSignature
/System/Library/PrivateFrameworks/MobileInstallation.framework/_CodeSignature/CodeResources
/private/var/mobile/Library/Logs/MobileInstallation
/private/var/mobile/Library/Logs/MobileInstallation/mobile_installation.log.0
/private/var/mobile/Library/Logs/MobileInstallation/mobile_installation.log.1
/private/var/mobile/Library/MobileInstallation
/private/var/mobile/Library/MobileInstallation/AppMigratorLastSystemVersion.plist
/private/var/mobile/Library/MobileInstallation/DiskImagesInfo.plist
/private/var/mobile/Library/MobileInstallation/LastBuildInfo.plist
/private/var/mobile/Library/MobileInstallation/LastLaunchServicesMap.plist
/private/var/mobile/Library/MobileInstallation/UninstalledApplications.plist

我也去過電腦上的xcode底下也找得到~/Library/Developer/Xcode/iOS DeviceSupport/8.1.2 (12B440)/Symbols/System/Library/PrivateFrameworks/MobileInstallation.framework

所以我可以斷定這個框架他是存在的,但書上第33頁也有提到該如何導入私用框架,因此想請問大大,哪個地方我做錯了?該怎麼修正錯誤?

第二個問題就是以下這段程式碼是我參考原文作者和網上其他資料的,執行上始終死在 if (mobileInstallationUninstallForLaunchServices)這邊,所以我判定是私用框架沒有成功導入,無法呼叫MobileInstallationUninstall這個方法,或者另一個可能是iOS8.1.2已經沒有這個方法?我在想第一個問題解決了,或許第二個問題也會有頭緒。因為這兩個問題是連貫的所以放在一起,如不符合發帖規則,此無視第二問題,專注第一問題。

typedef void (*MobileInstallationCallback)(CFDictionaryRef information);
typedef int (* MobileInstallationUninstallForLaunchServices)(CFStringRef bundleIdentifier, CFDictionaryRef parameters, MobileInstallationCallback callback, void *unknown);
- (void)unInstallTap:(id)sender
{
    NSLog(@"uninstalling...");
    void *lib = dlopen("/System/Library/PrivateFrameworks/MobileInstallation.framework/MobileInstallation", RTLD_LAZY);
    if (lib)
    {
        MobileInstallationUninstallForLaunchServices mobileInstallationUninstallForLaunchServices = (MobileInstallationUninstallForLaunchServices)dlsym(lib, "MobileInstallationUninstall");
        
        if (mobileInstallationUninstallForLaunchServices)
        {
            CFStringRef identifier = CFStringCreateWithCString(kCFAllocatorDefault, [BundleID UTF8String], kCFStringEncodingUTF8);
            int ret = mobileInstallationUninstallForLaunchServices(identifier, NULL, NULL, NULL);
            CFRelease(identifier);
            // return ret;
            NSLog(@"iOSRE Uninstall: %d", ret);
        } else {
            NSLog(@"iOSRE mobileInstallationUninstallForLaunchServices nil");
        }
    } else {
        NSLog(@"iOSRE lib nil");
    }
}

感謝大大們撥空解答!

有crashlog啥的吗

我后来在努力查到了theos github的开发者的回答:

他说某版本以后原本的xcode sdk位置无不存在,要自己去下载对应版本的sdk放到该位置。我放完之后,第一个问题就消失了,算是成功消除错误讯息,可是依然无法成功。

我把程式码又改回更简单的方式参照原文作者:

typedef void (*MobileInstallationCallback)(CFDictionaryRef information);
extern int MobileInstallationUninstallForLaunchServices(CFStringRef bundleIdentifier, CFDictionaryRef parameters, MobileInstallationCallback callback, void *unknown) NS_AVAILABLE_IOS(8_0);
        CFStringRef identifier = CFStringCreateWithCString(kCFAllocatorDefault, "com.mixerbox.mb3", kCFStringEncodingUTF8);
        if (identifier != NULL) {
            MobileInstallationUninstallForLaunchServices(identifier, NULL, NULL, NULL);
            CFRelease(identifier);
        }

之后运行得到了更精确的错误讯息:

Process Myproject (pid 7949) is required to have an entitlement named "com.apple.private.mobileinstall.allowedSPI" with an array containing "UninstallForLaunchServices" to call the MobileInstallation SPI.

这是我的makefile:

include $(THEOS)/makefiles/common.mk
ARCHS = armv7 arm64
TARGET = iphone:latest:8.1
THEOS_DEVICE_IP=127.0.0.1
THEOS_DEVICE_PORT=2222

APPLICATION_NAME = MyProject
MyProject_FILES = main.m ZRAppDelegate.m ZRRootViewController.m AppsCleaner.m
MyProject_FRAMEWORKS = UIKit CoreGraphics
MyProject_PRIVATE_FRAMEWORKS = MobileInstallation
MyProject_LIBRARIES = applist
MyProject_LDFLAGS = -lsqlite3
MyProject_CODESIGN_FLAGS = -Sentitlements.xml

include $(THEOS_MAKE_PATH)/application.mk

after-stage::
	$(ECHO_NOTHING)chmod +s $(THEOS_STAGING_DIR)/Applications/MyProject.app/MyProject$(ECHO_END)

after-install::
	install.exec "killall -9 SpringBoard"

我是把entitlements.xml放在project root:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>com.apple.private.mobileinstall.allowedSPI</key>
        <array>
            <string>Install</string>
            <string>Browse</string>
            <string>Uninstall</string>
            <string>Archive</string>
            <string>RemoveArchive</string>
            <string>UninstallForLaunchServices</string>
        </array>
        <key>com.apple.springboard.launchapplications</key>
        <true/>
        <key>com.apple.springboard.openapplications</key>
        <true/>
    </dict>
</plist>

我在跑make package install没有错误,但是安装上去后,再去查看log依然没有成功授权UninstallForLaunchServices。我知道这最新的error log裡面的内容已经跟帖子无关,但又是连贯性的,大大是否我另外发帖?

自己解答,又再折腾了一天后,困在theos 用codesign_flags失败下,决定自己打包deb,重新添加授权,我是按照下面两篇文章得到解答:
http://lazy-blog.logdown.com/posts/1529215-deb-production-process
上面这篇只要做到重新签名和chown, chmod档桉夹之后,就可以了。再按照下一篇:

裡面提到因为自从1.17.0版本的dpkg-deb开始, 默认使用xz格式来压缩data.tar文件
但是,cydia在ios提供的dpkg是1.14版本, 还没有支持xz这种压缩格式
所以我们需要设置”-Zgzip”参数给dpkg-deb 进行打包, 类似命令:
dpkg-deb -Zgzip -b tmp game.deb
使用上面这行-Zgzip去打包后的deb,用iFunBox上传到/var/mobile底下,在使用iFile去安装这个deb, uicache重刷icons介面后就会跳出你的app了。在执行解除安装的代码就成功囉!

以上的解决方桉我不是很满意,因为这样一来每次修改程式码都要来走一次重签名。而没办法使用theos简单来make package会很麻烦的。所以大大们如果有关于theos修正的解法还请告知小弟。

在此与同好分享我的次等解决方桉。