Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 755
zzzzz Avatar asked Mar 04 '13 13:03

zzzzz


People also ask

How do I force my iPhone to factory reset?

Tap Settings > General > Transfer or Reset [Device]Then tap Erase All Content and Settings.

How do I reset my iPhone to factory settings without passcode?

Simply press and hold the Volume buttons and Home button at the same time. iPhone X, 8 & Newer: Press and hold the Volume up button, then the Volume Down button, and the side button at the same time. iPhone 7 / 7 Plus: Press and hold the Volume Down and the side button at the same time.

Can you reset iPhone from computer?

You can use a Mac or Windows PC to erase all data and settings from your iPhone, restore iPhone to factory settings, and install the latest version of iOS. Connect your iPhone to your computer with a USB or USB-C cable. You may also need an adapter.


1 Answers

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.

like image 198
Victor Ronin Avatar answered Sep 19 '22 13:09

Victor Ronin