有没有办法以编程方式将我的iPhone恢复为出厂设置? [英] Is there a way to programmatically restore my iPhone to factory settings?
问题描述
我正在为越狱的应用程序开发程序,我不在乎它是否被App Store拒绝.我找到了一种使用这种方法完全擦掉iPhone的方法
I am developing for a jailbroken app and I don't care if it's rejected by the App store. I have found a way to completely wipe out my iPhone using this way Is there a way to completely wipe out iPhone data programatically?. There is a problem with this method however. It makes my iphone worthless and I have to recover it using itunes. I just want to factory restore my iphone programmatically.
推荐答案
SpringboardServices私有框架中有一个私有API SBDataReset.它会擦除所有数据.
There is a private API SBDataReset in SpringboardServices private framework. It wipes all data.
您可以查看以下代码,例如如何使用它.
You can check the following code for example how to use it.
使用此API的应用程序应具有"com.apple.springboard.wipedevice"权利.
An application which uses this API should have "com.apple.springboard.wipedevice" entitlement to work.
顺便说一句.另一种选择是使用MDM协议.它具有擦除命令.但是,这需要更多的机制(MDM服务器,注册用户).
BTW. One more alternative is to use MDM protocol. It has a wipe command. However, it requires way more machinery (MDM server, enroll a user).
链接中的示例代码似乎已过期.我研究了Preferences和使用SBDataReset的其他几款iOS软件,看来SBDataReset引入了新的论点.
It looks like sample code in the link is out date. I looked into Preferences and couple of other pieces of iOS software which uses SBDataReset and it looks like new argument was introduced to SBDataReset.
尝试下面的代码(对不起,我现在没有越狱的iOS设备,所以我不能自己尝试)
Try following code (sorry, I don't have jailbroken iOS device right now, so I can't try it on my own)
#import <UIKit/UIKit.h>
#import <UIKit/UIApplication.h>
#include <dlfcn.h>
#include <stdio.h>
// Framework Paths
#define SBSERVPATH "/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices"
#define UIKITPATH "/System/Library/Framework/UIKit.framework/UIKit"
#define WIPE_MODE_NORMAL 4
int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Fetch the SpringBoard server port
mach_port_t *p;
void *uikit = dlopen(UIKITPATH, RTLD_LAZY);
int (*SBSSpringBoardServerPort)() =
dlsym(uikit, "SBSSpringBoardServerPort");
p = SBSSpringBoardServerPort();
dlclose(uikit);
// Getting DataReset proc
void *sbserv = dlopen(SBSERVPATH, RTLD_LAZY);
int (*dataReset)(mach_port_t* port, int wipeMode) = dlsym(sbserv, "SBDataReset");
dataReset(p, WIPE_MODE_NORMAL);
dlclose(sbserv);
[pool release];
}
请注意,SBDataReset函数有第二个参数.
Please notice, that there is second parameter for SBDataReset function.
看起来4是普通擦拭模式,6是砖擦拭模式.
It looks like 4 is normal wipe mode and 6 is brick wipe mode.
免责声明该代码按原样提供.我不知道如果以砖块模式擦除设备会发生什么情况.
DISCLAIMER This code is provided AS IS. I have no idea what will happen if device will be wiped in brick mode.
这篇关于有没有办法以编程方式将我的iPhone恢复为出厂设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!