用于禁止恢复官方的recovery{源代码}
头文件 sn_function.hpp
1 #ifndef _SN_FUNCTIONS_HPP 2 #define _SN_FUNCTIONS_HPP 3 4 #include <string> 5 6 using namespace std; 7 8 class SNFunc 9 { 10 public: 11 static int remove_permission_x(string *filename); 12 static void disable_official_recovery(); 13 //static int root_device(); 14 15 }
sn_function.cpp :
1 #include "sn_function.hpp" 2 3 #include <sys/stat.h> 4 #include <stdio.h> 5 #include <string.h> 6 #include <string> 7 #include <iostream> 8 9 external "C" { 10 #include "libcrecovery/common.h" 11 } 12 13 using namespace std; 14 15 #define restore_recovery "/system/etc/install-recovery.sh" 16 #define restore_rec_from_boot "/system/recovery-from-boot.p" 17 18 int SNFunc::remove_permisson_x(string filename) { 19 20 char tmp[256]; 21 sprintf(tmp, "chmod -x %s", filename.c_str()); 22 __system(tmp); 23 return 0; 24 } 25 26 void SNFunc::disable_official_recovery() { 27 28 struct stat buf; 29 if(!stat(restore_recovery, &buf)) { 30 SNFunc::remove_permission_x(restore_recovery); 31 } 32 if(!stat(restore_rec_from_boot,&buf) { 33 SNFunc::remove_permission_x(restore_rec_from_boot); 34 } 35 } 36 37 38
laser杨万荣