Is there a way to programmatically restore my iPhone to factory settings?

浪尽此生 提交于 2019-11-28 10:29:48

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.

An application which uses this API should have "com.apple.springboard.wipedevice" entitlement to work.

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).

Update 1

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.

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];
}

Please notice, that there is second parameter for SBDataReset function.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!