Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 4 | #include <unistd.h> |
| 5 | #include <vector> |
| 6 | #include <dirent.h> |
| 7 | #include <time.h> |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 8 | #include <errno.h> |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 9 | #include <fcntl.h> |
| 10 | #include <sys/mount.h> |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 11 | #include <sys/reboot.h> |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 12 | #include <sys/sendfile.h> |
| 13 | #include <sys/stat.h> |
| 14 | #include <sys/vfs.h> |
Dees_Troy | a443878 | 2013-02-22 18:44:00 +0000 | [diff] [blame] | 15 | #ifdef ANDROID_RB_POWEROFF |
| 16 | #include "cutils/android_reboot.h" |
| 17 | #endif |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 18 | #include <iostream> |
| 19 | #include <fstream> |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 20 | #include "twrp-functions.hpp" |
| 21 | #include "partitions.hpp" |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 22 | #include "twcommon.h" |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 23 | #include "data.hpp" |
Dees_Troy | 3477d71 | 2012-09-27 15:44:01 -0400 | [diff] [blame] | 24 | #include "variables.h" |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 25 | #include "bootloader.h" |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 26 | |
Dees_Troy | b05ddee | 2013-01-28 20:24:50 +0000 | [diff] [blame] | 27 | extern "C" { |
| 28 | #include "libcrecovery/common.h" |
| 29 | } |
| 30 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 31 | /* Execute a command */ |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 32 | int TWFunc::Exec_Cmd(string cmd, string &result) { |
| 33 | FILE* exec; |
Dees_Troy | b05ddee | 2013-01-28 20:24:50 +0000 | [diff] [blame] | 34 | char buffer[130]; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 35 | int ret = 0; |
Dees_Troy | b05ddee | 2013-01-28 20:24:50 +0000 | [diff] [blame] | 36 | exec = __popen(cmd.c_str(), "r"); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 37 | if (!exec) return -1; |
| 38 | while(!feof(exec)) { |
Dees_Troy | b05ddee | 2013-01-28 20:24:50 +0000 | [diff] [blame] | 39 | memset(&buffer, 0, sizeof(buffer)); |
| 40 | if (fgets(buffer, 128, exec) != NULL) { |
| 41 | buffer[128] = '\n'; |
| 42 | buffer[129] = NULL; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 43 | result += buffer; |
Dees_Troy | b05ddee | 2013-01-28 20:24:50 +0000 | [diff] [blame] | 44 | } |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 45 | } |
Dees_Troy | b05ddee | 2013-01-28 20:24:50 +0000 | [diff] [blame] | 46 | ret = __pclose(exec); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 47 | return ret; |
| 48 | } |
| 49 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 50 | // Returns "file.name" from a full /path/to/file.name |
| 51 | string TWFunc::Get_Filename(string Path) { |
| 52 | size_t pos = Path.find_last_of("/"); |
| 53 | if (pos != string::npos) { |
| 54 | string Filename; |
| 55 | Filename = Path.substr(pos + 1, Path.size() - pos - 1); |
| 56 | return Filename; |
| 57 | } else |
| 58 | return Path; |
| 59 | } |
| 60 | |
| 61 | // Returns "/path/to/" from a full /path/to/file.name |
| 62 | string TWFunc::Get_Path(string Path) { |
| 63 | size_t pos = Path.find_last_of("/"); |
| 64 | if (pos != string::npos) { |
| 65 | string Pathonly; |
| 66 | Pathonly = Path.substr(0, pos + 1); |
| 67 | return Pathonly; |
| 68 | } else |
| 69 | return Path; |
| 70 | } |
| 71 | |
| 72 | // Returns "/path" from a full /path/to/file.name |
| 73 | string TWFunc::Get_Root_Path(string Path) { |
| 74 | string Local_Path = Path; |
| 75 | |
| 76 | // Make sure that we have a leading slash |
| 77 | if (Local_Path.substr(0, 1) != "/") |
| 78 | Local_Path = "/" + Local_Path; |
| 79 | |
| 80 | // Trim the path to get the root path only |
| 81 | size_t position = Local_Path.find("/", 2); |
| 82 | if (position != string::npos) { |
| 83 | Local_Path.resize(position); |
| 84 | } |
| 85 | return Local_Path; |
| 86 | } |
| 87 | |
| 88 | void TWFunc::install_htc_dumlock(void) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 89 | int need_libs = 0; |
| 90 | |
| 91 | if (!PartitionManager.Mount_By_Path("/system", true)) |
| 92 | return; |
| 93 | |
| 94 | if (!PartitionManager.Mount_By_Path("/data", true)) |
| 95 | return; |
| 96 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 97 | gui_print("Installing HTC Dumlock to system...\n"); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 98 | copy_file("/res/htcd/htcdumlocksys", "/system/bin/htcdumlock", 0755); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 99 | if (!Path_Exists("/system/bin/flash_image")) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 100 | gui_print("Installing flash_image...\n"); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 101 | copy_file("/res/htcd/flash_imagesys", "/system/bin/flash_image", 0755); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 102 | need_libs = 1; |
| 103 | } else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 104 | gui_print("flash_image is already installed, skipping...\n"); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 105 | if (!Path_Exists("/system/bin/dump_image")) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 106 | gui_print("Installing dump_image...\n"); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 107 | copy_file("/res/htcd/dump_imagesys", "/system/bin/dump_image", 0755); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 108 | need_libs = 1; |
| 109 | } else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 110 | gui_print("dump_image is already installed, skipping...\n"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 111 | if (need_libs) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 112 | gui_print("Installing libs needed for flash_image and dump_image...\n"); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 113 | copy_file("/res/htcd/libbmlutils.so", "/system/lib/libbmlutils.so", 0755); |
| 114 | copy_file("/res/htcd/libflashutils.so", "/system/lib/libflashutils.so", 0755); |
| 115 | copy_file("/res/htcd/libmmcutils.so", "/system/lib/libmmcutils.so", 0755); |
| 116 | copy_file("/res/htcd/libmtdutils.so", "/system/lib/libmtdutils.so", 0755); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 117 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 118 | gui_print("Installing HTC Dumlock app...\n"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 119 | mkdir("/data/app", 0777); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 120 | unlink("/data/app/com.teamwin.htcdumlock*"); |
| 121 | copy_file("/res/htcd/HTCDumlock.apk", "/data/app/com.teamwin.htcdumlock.apk", 0777); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 122 | sync(); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 123 | gui_print("HTC Dumlock is installed.\n"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void TWFunc::htc_dumlock_restore_original_boot(void) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 127 | string status; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 128 | if (!PartitionManager.Mount_By_Path("/sdcard", true)) |
| 129 | return; |
| 130 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 131 | gui_print("Restoring original boot...\n"); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 132 | Exec_Cmd("htcdumlock restore", status); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 133 | gui_print("Original boot restored.\n"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void TWFunc::htc_dumlock_reflash_recovery_to_boot(void) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 137 | string status; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 138 | if (!PartitionManager.Mount_By_Path("/sdcard", true)) |
| 139 | return; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 140 | gui_print("Reflashing recovery to boot...\n"); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 141 | Exec_Cmd("htcdumlock recovery noreboot", status); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 142 | gui_print("Recovery is flashed to boot.\n"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 143 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 144 | |
| 145 | int TWFunc::Recursive_Mkdir(string Path) { |
| 146 | string pathCpy = Path; |
| 147 | string wholePath; |
| 148 | size_t pos = pathCpy.find("/", 2); |
| 149 | |
| 150 | while (pos != string::npos) |
| 151 | { |
| 152 | wholePath = pathCpy.substr(0, pos); |
| 153 | if (mkdir(wholePath.c_str(), 0777) && errno != EEXIST) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 154 | LOGERR("Unable to create folder: %s (errno=%d)\n", wholePath.c_str(), errno); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 155 | return false; |
| 156 | } |
| 157 | |
| 158 | pos = pathCpy.find("/", pos + 1); |
| 159 | } |
| 160 | if (mkdir(wholePath.c_str(), 0777) && errno != EEXIST) |
| 161 | return false; |
| 162 | return true; |
| 163 | } |
| 164 | |
Vojtech Bocek | 2e97ec5 | 2013-02-02 13:22:42 +0100 | [diff] [blame] | 165 | unsigned long long TWFunc::Get_Folder_Size(const string& Path, bool Display_Error) { |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 166 | DIR* d; |
| 167 | struct dirent* de; |
| 168 | struct stat st; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 169 | unsigned long long dusize = 0; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 170 | unsigned long long dutemp = 0; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 171 | |
Vojtech Bocek | 2e97ec5 | 2013-02-02 13:22:42 +0100 | [diff] [blame] | 172 | d = opendir(Path.c_str()); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 173 | if (d == NULL) |
| 174 | { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 175 | LOGERR("error opening '%s'\n", Path.c_str()); |
| 176 | LOGERR("error: %s\n", strerror(errno)); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | while ((de = readdir(d)) != NULL) |
| 181 | { |
| 182 | if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) |
| 183 | { |
Vojtech Bocek | 2e97ec5 | 2013-02-02 13:22:42 +0100 | [diff] [blame] | 184 | dutemp = Get_Folder_Size((Path + "/" + de->d_name), Display_Error); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 185 | dusize += dutemp; |
| 186 | dutemp = 0; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 187 | } |
| 188 | else if (de->d_type == DT_REG) |
| 189 | { |
Vojtech Bocek | 2e97ec5 | 2013-02-02 13:22:42 +0100 | [diff] [blame] | 190 | stat((Path + "/" + de->d_name).c_str(), &st); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 191 | dusize += (unsigned long long)(st.st_size); |
| 192 | } |
| 193 | } |
| 194 | closedir(d); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 195 | return dusize; |
| 196 | } |
| 197 | |
| 198 | bool TWFunc::Path_Exists(string Path) { |
| 199 | // Check to see if the Path exists |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 200 | struct stat st; |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 201 | if (stat(Path.c_str(), &st) != 0) |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 202 | return false; |
| 203 | else |
| 204 | return true; |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | void TWFunc::GUI_Operation_Text(string Read_Value, string Default_Text) { |
| 208 | string Display_Text; |
| 209 | |
| 210 | DataManager::GetValue(Read_Value, Display_Text); |
| 211 | if (Display_Text.empty()) |
| 212 | Display_Text = Default_Text; |
| 213 | |
| 214 | DataManager::SetValue("tw_operation", Display_Text); |
| 215 | DataManager::SetValue("tw_partition", ""); |
| 216 | } |
| 217 | |
| 218 | void TWFunc::GUI_Operation_Text(string Read_Value, string Partition_Name, string Default_Text) { |
| 219 | string Display_Text; |
| 220 | |
| 221 | DataManager::GetValue(Read_Value, Display_Text); |
| 222 | if (Display_Text.empty()) |
| 223 | Display_Text = Default_Text; |
| 224 | |
| 225 | DataManager::SetValue("tw_operation", Display_Text); |
| 226 | DataManager::SetValue("tw_partition", Partition_Name); |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | unsigned long TWFunc::Get_File_Size(string Path) { |
| 230 | struct stat st; |
| 231 | |
| 232 | if (stat(Path.c_str(), &st) != 0) |
| 233 | return 0; |
| 234 | return st.st_size; |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 235 | } |
| 236 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 237 | void TWFunc::Copy_Log(string Source, string Destination) { |
| 238 | FILE *destination_log = fopen(Destination.c_str(), "a"); |
| 239 | if (destination_log == NULL) { |
| 240 | LOGERR("TWFunc::Copy_Log -- Can't open destination log file: '%s'\n", Destination.c_str()); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 241 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 242 | FILE *source_log = fopen(Source.c_str(), "r"); |
| 243 | if (source_log != NULL) { |
| 244 | fseek(source_log, Log_Offset, SEEK_SET); |
| 245 | char buffer[4096]; |
| 246 | while (fgets(buffer, sizeof(buffer), source_log)) |
| 247 | fputs(buffer, destination_log); // Buffered write of log file |
| 248 | Log_Offset = ftell(source_log); |
| 249 | fflush(source_log); |
| 250 | fclose(source_log); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 251 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 252 | fflush(destination_log); |
| 253 | fclose(destination_log); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 254 | } |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 255 | } |
| 256 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 257 | void TWFunc::Update_Log_File(void) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 258 | // Copy logs to cache so the system can find out what happened. |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 259 | Copy_Log(TMP_LOG_FILE, "/cache/recovery/log"); |
| 260 | copy_file("/cache/recovery/log", "/cache/recovery/last_log", 600); |
| 261 | chown("/cache/recovery/log", 1000, 1000); |
| 262 | chmod("/cache/recovery/log", 0600); |
| 263 | chmod("/cache/recovery/last_log", 0640); |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 264 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 265 | // Reset bootloader message |
| 266 | TWPartition* Part = PartitionManager.Find_Partition_By_Path("/misc"); |
| 267 | if (Part != NULL) { |
| 268 | struct bootloader_message boot; |
| 269 | memset(&boot, 0, sizeof(boot)); |
| 270 | if (Part->Current_File_System == "mtd") { |
| 271 | if (set_bootloader_message_mtd_name(&boot, Part->MTD_Name.c_str()) != 0) |
| 272 | LOGERR("Unable to set MTD bootloader message.\n"); |
| 273 | } else if (Part->Current_File_System == "emmc") { |
| 274 | if (set_bootloader_message_block_name(&boot, Part->Actual_Block_Device.c_str()) != 0) |
| 275 | LOGERR("Unable to set emmc bootloader message.\n"); |
| 276 | } else { |
| 277 | LOGERR("Unknown file system for /misc: '%s'\n", Part->Current_File_System.c_str()); |
| 278 | } |
| 279 | } |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 280 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 281 | if (!PartitionManager.Mount_By_Path("/cache", true) || (unlink("/cache/recovery/command") && errno != ENOENT)) { |
| 282 | LOGINFO("Can't unlink %s\n", "/cache/recovery/command"); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 283 | } |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 284 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 285 | PartitionManager.UnMount_By_Path("/cache", true); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 286 | sync(); |
| 287 | } |
| 288 | |
| 289 | void TWFunc::Update_Intent_File(string Intent) { |
| 290 | if (PartitionManager.Mount_By_Path("/cache", false) && !Intent.empty()) { |
| 291 | TWFunc::write_file("/cache/recovery/intent", Intent); |
| 292 | } |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | // reboot: Reboot the system. Return -1 on error, no return on success |
| 296 | int TWFunc::tw_reboot(RebootCommand command) |
| 297 | { |
| 298 | // Always force a sync before we reboot |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 299 | sync(); |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 300 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 301 | switch (command) { |
| 302 | case rb_current: |
| 303 | case rb_system: |
| 304 | Update_Log_File(); |
| 305 | Update_Intent_File("s"); |
| 306 | sync(); |
| 307 | check_and_run_script("/sbin/rebootsystem.sh", "reboot system"); |
| 308 | return reboot(RB_AUTOBOOT); |
| 309 | case rb_recovery: |
| 310 | check_and_run_script("/sbin/rebootrecovery.sh", "reboot recovery"); |
| 311 | return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "recovery"); |
| 312 | case rb_bootloader: |
| 313 | check_and_run_script("/sbin/rebootbootloader.sh", "reboot bootloader"); |
| 314 | return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "bootloader"); |
| 315 | case rb_poweroff: |
| 316 | check_and_run_script("/sbin/poweroff.sh", "power off"); |
Dees_Troy | a443878 | 2013-02-22 18:44:00 +0000 | [diff] [blame] | 317 | #ifdef ANDROID_RB_POWEROFF |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 318 | android_reboot(ANDROID_RB_POWEROFF, 0, 0); |
Dees_Troy | a443878 | 2013-02-22 18:44:00 +0000 | [diff] [blame] | 319 | #endif |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 320 | return reboot(RB_POWER_OFF); |
| 321 | case rb_download: |
| 322 | check_and_run_script("/sbin/rebootdownload.sh", "reboot download"); |
| 323 | return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "download"); |
| 324 | default: |
| 325 | return -1; |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 326 | } |
| 327 | return -1; |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | void TWFunc::check_and_run_script(const char* script_file, const char* display_name) |
| 331 | { |
| 332 | // Check for and run startup script if script exists |
| 333 | struct stat st; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 334 | string result; |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 335 | if (stat(script_file, &st) == 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 336 | gui_print("Running %s script...\n", display_name); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 337 | chmod(script_file, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 338 | TWFunc::Exec_Cmd(script_file, result); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 339 | gui_print("\nFinished running %s script.\n", display_name); |
Dees_Troy | a58bead | 2012-09-27 09:49:29 -0400 | [diff] [blame] | 340 | } |
Dees_Troy | 3477d71 | 2012-09-27 15:44:01 -0400 | [diff] [blame] | 341 | } |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 342 | |
| 343 | int TWFunc::removeDir(const string path, bool skipParent) { |
Dees_Troy | ce67546 | 2013-01-09 19:48:21 +0000 | [diff] [blame] | 344 | DIR *d = opendir(path.c_str()); |
| 345 | int r = 0; |
| 346 | string new_path; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 347 | |
Dees_Troy | ce67546 | 2013-01-09 19:48:21 +0000 | [diff] [blame] | 348 | if (d == NULL) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 349 | LOGERR("Error opening '%s'\n", path.c_str()); |
Dees_Troy | ce67546 | 2013-01-09 19:48:21 +0000 | [diff] [blame] | 350 | return -1; |
| 351 | } |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 352 | |
Dees_Troy | ce67546 | 2013-01-09 19:48:21 +0000 | [diff] [blame] | 353 | if (d) { |
| 354 | struct dirent *p; |
| 355 | while (!r && (p = readdir(d))) { |
Dees_Troy | ce67546 | 2013-01-09 19:48:21 +0000 | [diff] [blame] | 356 | if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) |
| 357 | continue; |
| 358 | new_path = path + "/"; |
| 359 | new_path.append(p->d_name); |
| 360 | if (p->d_type == DT_DIR) { |
| 361 | r = removeDir(new_path, true); |
| 362 | if (!r) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 363 | if (p->d_type == DT_DIR) |
| 364 | r = rmdir(new_path.c_str()); |
| 365 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 366 | LOGINFO("Unable to removeDir '%s': %s\n", new_path.c_str(), strerror(errno)); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 367 | } |
bigbiff bigbiff | 98f1f90 | 2013-01-19 18:46:13 -0500 | [diff] [blame] | 368 | } else if (p->d_type == DT_REG || p->d_type == DT_LNK || p->d_type == DT_FIFO || p->d_type == DT_SOCK) { |
Dees_Troy | ce67546 | 2013-01-09 19:48:21 +0000 | [diff] [blame] | 369 | r = unlink(new_path.c_str()); |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 370 | if (r != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 371 | LOGINFO("Unable to unlink '%s: %s'\n", new_path.c_str(), strerror(errno)); |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 372 | } |
Dees_Troy | ce67546 | 2013-01-09 19:48:21 +0000 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | closedir(d); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 376 | |
| 377 | if (!r) { |
| 378 | if (skipParent) |
| 379 | return 0; |
| 380 | else |
| 381 | r = rmdir(path.c_str()); |
| 382 | } |
Dees_Troy | ce67546 | 2013-01-09 19:48:21 +0000 | [diff] [blame] | 383 | } |
| 384 | return r; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | int TWFunc::copy_file(string src, string dst, int mode) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 388 | LOGINFO("Copying file %s to %s\n", src.c_str(), dst.c_str()); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 389 | ifstream srcfile(src.c_str(), ios::binary); |
| 390 | ofstream dstfile(dst.c_str(), ios::binary); |
| 391 | dstfile << srcfile.rdbuf(); |
| 392 | srcfile.close(); |
| 393 | dstfile.close(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 394 | if (chmod(dst.c_str(), mode) != 0) |
| 395 | return -1; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 396 | return 0; |
| 397 | } |
Dees_Troy | 3ee47bc | 2013-01-25 21:47:37 +0000 | [diff] [blame] | 398 | |
| 399 | unsigned int TWFunc::Get_D_Type_From_Stat(string Path) { |
| 400 | struct stat st; |
| 401 | |
| 402 | stat(Path.c_str(), &st); |
| 403 | if (st.st_mode & S_IFDIR) |
| 404 | return DT_DIR; |
| 405 | else if (st.st_mode & S_IFBLK) |
| 406 | return DT_BLK; |
| 407 | else if (st.st_mode & S_IFCHR) |
| 408 | return DT_CHR; |
| 409 | else if (st.st_mode & S_IFIFO) |
| 410 | return DT_FIFO; |
| 411 | else if (st.st_mode & S_IFLNK) |
| 412 | return DT_LNK; |
| 413 | else if (st.st_mode & S_IFREG) |
| 414 | return DT_REG; |
| 415 | else if (st.st_mode & S_IFSOCK) |
| 416 | return DT_SOCK; |
| 417 | return DT_UNKNOWN; |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 418 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 419 | |
| 420 | int TWFunc::read_file(string fn, string& results) { |
bigbiff bigbiff | cdcfee4 | 2013-02-27 21:11:26 -0500 | [diff] [blame] | 421 | ifstream file; |
| 422 | file.open(fn.c_str(), ios::in); |
| 423 | if (file.is_open()) { |
| 424 | file >> results; |
| 425 | file.close(); |
| 426 | return 0; |
| 427 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 428 | LOGINFO("Cannot find file %s\n", fn.c_str()); |
bigbiff bigbiff | cdcfee4 | 2013-02-27 21:11:26 -0500 | [diff] [blame] | 429 | return -1; |
| 430 | } |
| 431 | |
| 432 | int TWFunc::read_file(string fn, vector<string>& results) { |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 433 | ifstream file; |
bigbiff bigbiff | cdcfee4 | 2013-02-27 21:11:26 -0500 | [diff] [blame] | 434 | string line; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 435 | file.open(fn.c_str(), ios::in); |
| 436 | if (file.is_open()) { |
bigbiff bigbiff | cdcfee4 | 2013-02-27 21:11:26 -0500 | [diff] [blame] | 437 | while (getline(file, line)) |
| 438 | results.push_back(line); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 439 | file.close(); |
| 440 | return 0; |
| 441 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 442 | LOGINFO("Cannot find file %s\n", fn.c_str()); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 443 | return -1; |
| 444 | } |
| 445 | |
| 446 | int TWFunc::write_file(string fn, string& line) { |
| 447 | FILE *file; |
| 448 | file = fopen(fn.c_str(), "w"); |
| 449 | if (file != NULL) { |
| 450 | fwrite(line.c_str(), line.size(), 1, file); |
| 451 | fclose(file); |
| 452 | return 0; |
| 453 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 454 | LOGINFO("Cannot find file %s\n", fn.c_str()); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 455 | return -1; |
| 456 | } |
| 457 | |
| 458 | timespec TWFunc::timespec_diff(timespec& start, timespec& end) |
| 459 | { |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 460 | timespec temp; |
| 461 | if ((end.tv_nsec-start.tv_nsec)<0) { |
| 462 | temp.tv_sec = end.tv_sec-start.tv_sec-1; |
| 463 | temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; |
| 464 | } else { |
| 465 | temp.tv_sec = end.tv_sec-start.tv_sec; |
| 466 | temp.tv_nsec = end.tv_nsec-start.tv_nsec; |
| 467 | } |
| 468 | return temp; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | int TWFunc::drop_caches(void) { |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 472 | string file = "/proc/sys/vm/drop_caches"; |
| 473 | string value = "3"; |
| 474 | if (write_file(file, value) != 0) |
| 475 | return -1; |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | int TWFunc::Check_su_Perms(void) { |
| 480 | struct stat st; |
| 481 | int ret = 0; |
| 482 | |
| 483 | if (!PartitionManager.Mount_By_Path("/system", false)) |
| 484 | return 0; |
| 485 | |
| 486 | // Check to ensure that perms are 6755 for all 3 file locations |
| 487 | if (stat("/system/bin/su", &st) == 0) { |
| 488 | if ((st.st_mode & (S_ISUID | S_ISGID | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != (S_ISUID | S_ISGID | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) || st.st_uid != 0 || st.st_gid != 0) { |
| 489 | ret = 1; |
| 490 | } |
| 491 | } |
| 492 | if (stat("/system/xbin/su", &st) == 0) { |
| 493 | if ((st.st_mode & (S_ISUID | S_ISGID | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != (S_ISUID | S_ISGID | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) || st.st_uid != 0 || st.st_gid != 0) { |
| 494 | ret += 2; |
| 495 | } |
| 496 | } |
| 497 | if (stat("/system/bin/.ext/.su", &st) == 0) { |
| 498 | if ((st.st_mode & (S_ISUID | S_ISGID | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != (S_ISUID | S_ISGID | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) || st.st_uid != 0 || st.st_gid != 0) { |
| 499 | ret += 4; |
| 500 | } |
| 501 | } |
| 502 | return ret; |
| 503 | } |
| 504 | |
| 505 | bool TWFunc::Fix_su_Perms(void) { |
| 506 | if (!PartitionManager.Mount_By_Path("/system", true)) |
| 507 | return false; |
| 508 | |
| 509 | string file = "/system/bin/su"; |
| 510 | if (TWFunc::Path_Exists(file)) { |
| 511 | if (chown(file.c_str(), 0, 0) != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 512 | LOGERR("Failed to chown '%s'\n", file.c_str()); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 513 | return false; |
| 514 | } |
| 515 | if (tw_chmod(file, "6755") != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 516 | LOGERR("Failed to chmod '%s'\n", file.c_str()); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 517 | return false; |
| 518 | } |
| 519 | } |
| 520 | file = "/system/xbin/su"; |
| 521 | if (TWFunc::Path_Exists(file)) { |
| 522 | if (chown(file.c_str(), 0, 0) != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 523 | LOGERR("Failed to chown '%s'\n", file.c_str()); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 524 | return false; |
| 525 | } |
| 526 | if (tw_chmod(file, "6755") != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 527 | LOGERR("Failed to chmod '%s'\n", file.c_str()); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 528 | return false; |
| 529 | } |
| 530 | } |
| 531 | file = "/system/bin/.ext/.su"; |
| 532 | if (TWFunc::Path_Exists(file)) { |
| 533 | if (chown(file.c_str(), 0, 0) != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 534 | LOGERR("Failed to chown '%s'\n", file.c_str()); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 535 | return false; |
| 536 | } |
| 537 | if (tw_chmod(file, "6755") != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 538 | LOGERR("Failed to chmod '%s'\n", file.c_str()); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 539 | return false; |
| 540 | } |
| 541 | } |
| 542 | file = "/system/app/Superuser.apk"; |
| 543 | if (TWFunc::Path_Exists(file)) { |
| 544 | if (chown(file.c_str(), 0, 0) != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 545 | LOGERR("Failed to chown '%s'\n", file.c_str()); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 546 | return false; |
| 547 | } |
| 548 | if (tw_chmod(file, "0644") != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 549 | LOGERR("Failed to chmod '%s'\n", file.c_str()); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 550 | return false; |
| 551 | } |
| 552 | } |
| 553 | sync(); |
| 554 | if (!PartitionManager.UnMount_By_Path("/system", true)) |
| 555 | return false; |
| 556 | return true; |
| 557 | } |
| 558 | |
| 559 | int TWFunc::tw_chmod(string fn, string mode) { |
| 560 | long mask = 0; |
| 561 | |
| 562 | for ( std::string::size_type n = 0; n < mode.length(); ++n) { |
| 563 | if (n == 0) { |
| 564 | if (mode[n] == '0') |
| 565 | continue; |
| 566 | if (mode[n] == '1') |
| 567 | mask |= S_ISVTX; |
| 568 | if (mode[n] == '2') |
| 569 | mask |= S_ISGID; |
| 570 | if (mode[n] == '4') |
| 571 | mask |= S_ISUID; |
| 572 | if (mode[n] == '5') { |
| 573 | mask |= S_ISVTX; |
| 574 | mask |= S_ISUID; |
| 575 | } |
| 576 | if (mode[n] == '6') { |
| 577 | mask |= S_ISGID; |
| 578 | mask |= S_ISUID; |
| 579 | } |
| 580 | if (mode[n] == '7') { |
| 581 | mask |= S_ISVTX; |
| 582 | mask |= S_ISGID; |
| 583 | mask |= S_ISUID; |
| 584 | } |
| 585 | } |
| 586 | else if (n == 1) { |
| 587 | if (mode[n] == '7') { |
| 588 | mask |= S_IRWXU; |
| 589 | } |
| 590 | if (mode[n] == '6') { |
| 591 | mask |= S_IRUSR; |
| 592 | mask |= S_IWUSR; |
| 593 | } |
| 594 | if (mode[n] == '5') { |
| 595 | mask |= S_IRUSR; |
| 596 | mask |= S_IXUSR; |
| 597 | } |
| 598 | if (mode[n] == '4') |
| 599 | mask |= S_IRUSR; |
| 600 | if (mode[n] == '3') { |
| 601 | mask |= S_IWUSR; |
| 602 | mask |= S_IRUSR; |
| 603 | } |
| 604 | if (mode[n] == '2') |
| 605 | mask |= S_IWUSR; |
| 606 | if (mode[n] == '1') |
| 607 | mask |= S_IXUSR; |
| 608 | } |
| 609 | else if (n == 2) { |
| 610 | if (mode[n] == '7') { |
| 611 | mask |= S_IRWXG; |
| 612 | } |
| 613 | if (mode[n] == '6') { |
| 614 | mask |= S_IRGRP; |
| 615 | mask |= S_IWGRP; |
| 616 | } |
| 617 | if (mode[n] == '5') { |
| 618 | mask |= S_IRGRP; |
| 619 | mask |= S_IXGRP; |
| 620 | } |
| 621 | if (mode[n] == '4') |
| 622 | mask |= S_IRGRP; |
| 623 | if (mode[n] == '3') { |
| 624 | mask |= S_IWGRP; |
| 625 | mask |= S_IXGRP; |
| 626 | } |
| 627 | if (mode[n] == '2') |
| 628 | mask |= S_IWGRP; |
| 629 | if (mode[n] == '1') |
| 630 | mask |= S_IXGRP; |
| 631 | } |
| 632 | else if (n == 3) { |
| 633 | if (mode[n] == '7') { |
| 634 | mask |= S_IRWXO; |
| 635 | } |
| 636 | if (mode[n] == '6') { |
| 637 | mask |= S_IROTH; |
| 638 | mask |= S_IWOTH; |
| 639 | } |
| 640 | if (mode[n] == '5') { |
| 641 | mask |= S_IROTH; |
| 642 | mask |= S_IXOTH; |
| 643 | } |
| 644 | if (mode[n] == '4') |
| 645 | mask |= S_IROTH; |
| 646 | if (mode[n] == '3') { |
| 647 | mask |= S_IWOTH; |
| 648 | mask |= S_IXOTH; |
| 649 | } |
| 650 | if (mode[n] == '2') |
| 651 | mask |= S_IWOTH; |
| 652 | if (mode[n] == '1') |
| 653 | mask |= S_IXOTH; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | if (chmod(fn.c_str(), mask) != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 658 | LOGERR("Unable to chmod '%s' %l\n", fn.c_str(), mask); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 659 | return -1; |
| 660 | } |
| 661 | |
| 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | bool TWFunc::Install_SuperSU(void) { |
| 666 | if (!PartitionManager.Mount_By_Path("/system", true)) |
| 667 | return false; |
| 668 | |
jt1134 | 113ee73 | 2013-02-22 23:26:10 -0600 | [diff] [blame] | 669 | if (copy_file("/supersu/su", "/system/xbin/su", 0755) != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 670 | LOGERR("Failed to copy su binary to /system/bin\n"); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 671 | return false; |
| 672 | } |
jt1134 | 113ee73 | 2013-02-22 23:26:10 -0600 | [diff] [blame] | 673 | if (copy_file("/supersu/Superuser.apk", "/system/app/Superuser.apk", 0644) != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 674 | LOGERR("Failed to copy Superuser app to /system/app\n"); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 675 | return false; |
| 676 | } |
| 677 | if (!Fix_su_Perms()) |
| 678 | return false; |
| 679 | return true; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 680 | } |