packages/apps/Superuser
修訂 | dba07fba0fabad10322ccbb5e3f7623e41c074d0 (tree) |
---|---|
時間 | 2010-08-17 09:33:15 |
作者 | ChainsDD <chainsdd@gmai...> |
Commiter | ChainsDD |
Use su -v instead of checksums to determine if su binary is up to date.
@@ -3,8 +3,6 @@ | ||
3 | 3 | <string name="app_name">Superuser</string> |
4 | 4 | <string name="app_name_request">Superuser Request</string> |
5 | 5 | <string name="app_name_perms">Superuser Permissions</string> |
6 | - <string name="su_md5_cd">0ae93ca7bc600cd2379d5fe9fa71d0a0</string> | |
7 | - <string name="su_md5_ef">eb1d831e9d3be6ca90a9e47ee5935e04</string> | |
8 | 6 | |
9 | 7 | <string name="permlab_respond">respond to superuser requests</string> |
10 | 8 | <string name="permdesc_respond">Allows the application to respond to requests for superuser access.</string> |
@@ -61,7 +61,6 @@ public class Su extends TabActivity { | ||
61 | 61 | } |
62 | 62 | |
63 | 63 | private void firstRun() { |
64 | - int sdkVersion = Integer.parseInt(VERSION.SDK); | |
65 | 64 | int versionCode = 0; |
66 | 65 | try { |
67 | 66 | versionCode = getPackageManager() |
@@ -79,43 +78,13 @@ public class Su extends TabActivity { | ||
79 | 78 | } |
80 | 79 | Log.d(TAG, "First run for version " + versionCode); |
81 | 80 | |
82 | - InputStream fileInput = null; | |
83 | - FileOutputStream fileOutput = null; | |
84 | - int zipFile, binFile; | |
85 | - Log.d(TAG, "sdkVersion = " + sdkVersion); | |
86 | - if (sdkVersion < 5) { | |
87 | - Log.d(TAG, "Copying files for cupcake/donut"); | |
88 | - zipFile = R.raw.su_2_3_bin_cd_signed; | |
89 | - binFile = R.raw.su_cd; | |
90 | - } else { | |
91 | - Log.d(TAG, "Copying files for eclair/froyo"); | |
92 | - zipFile = R.raw.su_2_3_bin_ef_signed; | |
93 | - binFile = R.raw.su_ef; | |
94 | - } | |
95 | - try { | |
96 | - fileInput = getResources().openRawResource(zipFile); | |
97 | - byte[] zipReader = new byte[fileInput.available()]; | |
98 | - while (fileInput.read(zipReader) != -1); | |
99 | - fileInput.close(); | |
100 | - fileOutput = openFileOutput("su-2.3-bin.zip", MODE_WORLD_READABLE); | |
101 | - fileOutput.write(zipReader); | |
102 | - fileOutput.close(); | |
103 | - | |
104 | - fileInput = getResources().openRawResource(binFile); | |
105 | - byte[] binReader = new byte[fileInput.available()]; | |
106 | - while (fileInput.read(binReader) != -1); | |
107 | - fileInput.close(); | |
108 | - fileOutput = openFileOutput("su", MODE_WORLD_READABLE); | |
109 | - fileOutput.write(binReader); | |
110 | - fileOutput.close(); | |
111 | - } catch (IOException e) { | |
112 | - e.printStackTrace(); | |
113 | - } finally { | |
114 | - } | |
81 | + copyNewFiles(); | |
115 | 82 | |
116 | - String suMd5 = getSuMd5(); | |
117 | - String expectedSuMd5 = getString((versionCode < 5)?R.string.su_md5_cd:R.string.su_md5_ef); | |
118 | - if (suMd5 == null || !suMd5.equals(expectedSuMd5)) { | |
83 | + String suVer = getSuVersion(); | |
84 | + String expectedSuVer = (versionCode < 5)?"2.3-cd":"2.3-ef"; | |
85 | + Log.d(TAG, "Actual su version: " + suVer); | |
86 | + Log.d(TAG, "Expected su version: " + expectedSuVer); | |
87 | + if (suVer == null || !suVer.equals(expectedSuVer)) { | |
119 | 88 | Log.d(TAG, "System has outdated su, attempting to copy new version"); |
120 | 89 | // TODO: find a way to automatically update su, use recovery mode method if that fails |
121 | 90 | File sdDir = new File(Environment.getExternalStorageDirectory().getPath()); |
@@ -159,38 +128,90 @@ public class Su extends TabActivity { | ||
159 | 128 | editor.commit(); |
160 | 129 | } |
161 | 130 | |
162 | - private String getSuMd5() { | |
163 | - Process process; | |
164 | - BufferedReader stdInput; | |
165 | - String binSuMd5, xbinSuMd5; | |
131 | + private String getSuVersion() | |
132 | + { | |
133 | + String suVersion = ""; | |
134 | + Process process = null; | |
166 | 135 | |
167 | - try { | |
168 | - process = Runtime.getRuntime().exec("md5sum /system/bin/su"); | |
169 | - stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); | |
170 | - if (stdInput != null) { | |
171 | - binSuMd5 = stdInput.readLine().split(" ")[0]; | |
172 | - stdInput.close(); | |
173 | - } else { | |
174 | - return null; | |
175 | - } | |
176 | - process = Runtime.getRuntime().exec("md5sum /system/xbin/su"); | |
177 | - stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); | |
178 | - if (stdInput != null) { | |
179 | - xbinSuMd5 = stdInput.readLine().split(" ")[0]; | |
180 | - stdInput.close(); | |
181 | - } else { | |
182 | - return null; | |
183 | - } | |
184 | - } catch (IOException e) { | |
185 | - Log.e(TAG, "Failed to gather MD5 sums", e); | |
186 | - return null; | |
187 | - } | |
136 | + try { | |
137 | + process = Runtime.getRuntime().exec("su -v"); | |
138 | + BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); | |
139 | + suVersion = stdInput.readLine(); | |
140 | + } catch (IOException e) { | |
141 | + Log.e(TAG, "Call to su failed. Perhaps the wrong version of su is present", e); | |
142 | + return null; | |
143 | + } | |
188 | 144 | |
189 | - if (!binSuMd5.equals(xbinSuMd5)) { | |
190 | - Log.e(TAG, "/system/bin/su does not match /system/xbin/su. Possible symlink problem."); | |
191 | - return null; | |
192 | - } else { | |
193 | - return binSuMd5; | |
194 | - } | |
145 | + return suVersion; | |
195 | 146 | } |
147 | + | |
148 | + private void copyNewFiles() { | |
149 | + int sdkVersion = Integer.parseInt(VERSION.SDK); | |
150 | + InputStream fileInput = null; | |
151 | + FileOutputStream fileOutput = null; | |
152 | + int zipFile, binFile; | |
153 | + Log.d(TAG, "sdkVersion = " + sdkVersion); | |
154 | + if (sdkVersion < 5) { | |
155 | + Log.d(TAG, "Copying files for cupcake/donut"); | |
156 | + zipFile = R.raw.su_2_3_bin_cd_signed; | |
157 | + binFile = R.raw.su_cd; | |
158 | + } else { | |
159 | + Log.d(TAG, "Copying files for eclair/froyo"); | |
160 | + zipFile = R.raw.su_2_3_bin_ef_signed; | |
161 | + binFile = R.raw.su_ef; | |
162 | + } | |
163 | + try { | |
164 | + fileInput = getResources().openRawResource(zipFile); | |
165 | + byte[] zipReader = new byte[fileInput.available()]; | |
166 | + while (fileInput.read(zipReader) != -1); | |
167 | + fileInput.close(); | |
168 | + fileOutput = openFileOutput("su-2.3-bin.zip", MODE_WORLD_READABLE); | |
169 | + fileOutput.write(zipReader); | |
170 | + fileOutput.close(); | |
171 | + | |
172 | + fileInput = getResources().openRawResource(binFile); | |
173 | + byte[] binReader = new byte[fileInput.available()]; | |
174 | + while (fileInput.read(binReader) != -1); | |
175 | + fileInput.close(); | |
176 | + fileOutput = openFileOutput("su", MODE_WORLD_READABLE); | |
177 | + fileOutput.write(binReader); | |
178 | + fileOutput.close(); | |
179 | + } catch (IOException e) { | |
180 | + e.printStackTrace(); | |
181 | + } finally { | |
182 | + } | |
183 | + | |
184 | + } | |
185 | + | |
186 | +// private boolean remount(boolean writeable) { | |
187 | +// String device = null; | |
188 | +// String type = null; | |
189 | +// try { | |
190 | +// Process process = Runtime.getRuntime().exec("mount"); | |
191 | +// BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); | |
192 | +// String line; | |
193 | +// while ((line = stdInput.readLine()) != null) { | |
194 | +// String[] array = line.split(" "); | |
195 | +// device = array[0]; | |
196 | +// if (array[1].equals("on") && array[2].equals("/system")) { | |
197 | +// type = array[4]; | |
198 | +// break; | |
199 | +// } else if (array[1].equals("/system")) { | |
200 | +// type = array[2]; | |
201 | +// break; | |
202 | +// } | |
203 | +// } | |
204 | +// if (type != null) { | |
205 | +// String mode = writeable?"rw ":"ro "; | |
206 | +// String mountStr = "su -c mount -o remount," + mode + device + " /system"; | |
207 | +// Log.d(TAG, mountStr); | |
208 | +// process = Runtime.getRuntime().exec(mountStr); | |
209 | +// } | |
210 | +// } catch (IOException e) { | |
211 | +// // TODO Auto-generated catch block | |
212 | +// e.printStackTrace(); | |
213 | +// return false; | |
214 | +// } | |
215 | +// return true; | |
216 | +// } | |
196 | 217 | } |