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

I am developing a jailbreak application, and I donโ€™t care if it is rejected by the app store. I found a way to completely erase my iPhone using this method. Is there a way to completely erase iPhone data programmatically? However, there is a problem with this method. This makes my iphone useless, and I have to restore it using itunes. I just want to restore the factory settings of my iphone programmatically.

+4
source share
1 answer

The private SpringboardServices structure has a private SBDataReset API. He wipes all the data.

You can check the following code , for example, how to use it.

An application using this API must be allowed to use "com.apple.springboard.wipedevice".

BTW. Another alternative is to use the MDM protocol. He has a cleaning team. However, this requires more mechanisms (MDM server, user registration).

Update 1

Looks like the sample code is missing from the link. I looked at Preferences and a couple of other pieces of iOS software that uses SBDataReset, and it looks like a new argument has been introduced into SBDataReset.

Try using the following code (sorry, I donโ€™t have a jailbroken iOS device right now, so I canโ€™t try it myself)

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

Note that there is a second parameter for the SBDataReset function.

It appears that 4 is the normal cleaning mode, and 6 is the brick cleaning mode.

DISCLAIMER This code is provided AS IS. I have no idea what will happen if the device is wiped in brick mode.

+10
source

All Articles