Sometimes for security, we can implement machine self-destruct, for example, I want to implement an app, after running can make Android system damage, unable to reboot, unless the system is re-written.
The first step is to hack the phone to enable root access. The flags are placed in the System/app folder into a single SU command that can be called.
push su /systempush SuperUser.apk /systemchmod4755 /system/bin/su
The second step is to get root
The principle is to modify the permissions of the APK itself to 777
public static Boolean isRoot (String pkgcodepath) {ProcessProcess=NULL; DataOutputStream OS =NULL;Try{String cmd ="chmod 777"+ Pkgcodepath;Process= Runtime.getruntime (). EXEC ("Su"); OS =NewDataOutputStream (Process. Getoutputstream ()); Os.writebytes (cmd +"\ n"); Os.writebytes ("exit\n"); Os.flush ();Process. WaitFor (); }Catch(Exception e) {return false; }finally{Try{if(OS! =NULL) {OS.Close(); }Process. Destroy (); }Catch(Exception e) { } }return true; }
If the mobile phone has installed superuser.apk, there will be a hint that there is an application to apply for super permissions, then click OK.
Step three, using a forced restart
public static Boolean reboot () {ProcessProcess=NULL; DataOutputStream OS =NULL;Try{String cmd ="reboot";Process= Runtime.getruntime (). EXEC ("Su"); OS =NewDataOutputStream (Process. Getoutputstream ()); Os.writebytes (cmd +"\ n"); Os.writebytes ("exit\n"); Os.flush ();Process. WaitFor (); }Catch(Exception e) {return false; }finally{Try{if(OS! =NULL) {OS.Close(); }Process. Destroy (); }Catch(Exception e) { } }return true; }
If you set up a service, then boot up, execute the above statement, is the infinite power-on restart. Can execute shutdown, is shutdown.
Finally, we have a tough trick, is to make Android unable to boot
public static Boolean Destroymachine () {ProcessProcess=NULL; DataOutputStream OS =NULL;Try{String cmd ="rm System/lib/*.jar";Process= Runtime.getruntime (). EXEC ("Su"); OS =NewDataOutputStream (Process. Getoutputstream ()); Os.writebytes (cmd +"\ n"); Os.writebytes ("exit\n"); Os.flush ();Process. WaitFor (); }Catch(Exception e) {return false; }finally{Try{if(OS! =NULL) {OS.Close(); }Process. Destroy (); }Catch(Exception e) { } }return true; }
Execute this command, delete the system library, and then execute the restart command, the machine becomes a brick. Unless the machine is brushed.
So how to achieve the entire business? Can do this: do a boot-start system service running in the background, and can be connected in the background. When our phone is lost, we send a command through the network, the phone backend service received instructions to self-destruct. Of course, we can also use the SMS business to achieve, but, the general mobile phone is stolen, SIM card is also naturally replaced, the phone may also be restored to the factory settings, so the network is more reliable.
How Android achieves self-destruct