Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...