File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 12
12
import java .io .InputStreamReader ;
13
13
import java .io .OutputStreamWriter ;
14
14
15
+ import xzr .hkf .utils .AssetsUtil ;
16
+
15
17
public class Worker extends MainActivity .fileWorker {
16
18
Activity activity ;
17
19
String file_path ;
@@ -67,6 +69,11 @@ public void run() {
67
69
return ;
68
70
}
69
71
72
+ try {
73
+ patch ();
74
+ } catch (IOException ignored ) {
75
+ }
76
+
70
77
try {
71
78
flash (activity );
72
79
} catch (IOException ioException ) {
@@ -116,6 +123,13 @@ void getBinary() throws IOException {
116
123
throw new IOException ();
117
124
}
118
125
126
+ void patch () throws IOException {
127
+ final String mkbootfs_path = activity .getFilesDir ().getAbsolutePath () + "/mkbootfs" ;
128
+ AssetsUtil .exportFiles (activity , "mkbootfs" , mkbootfs_path );
129
+
130
+ runWithNewProcessNoReturn (false , "sed -i '/$BB chmod -R 755 tools bin;/i cp -f " + mkbootfs_path + " $AKHOME/tools;' " + binary_path );
131
+ }
132
+
119
133
void flash (Activity activity ) throws IOException {
120
134
Process process = new ProcessBuilder ("su" ).redirectErrorStream (true ).start ();
121
135
OutputStreamWriter outputStreamWriter = new OutputStreamWriter (process .getOutputStream ());
Original file line number Diff line number Diff line change
1
+ package xzr .hkf .utils ;
2
+
3
+ import android .content .Context ;
4
+
5
+ import java .io .File ;
6
+ import java .io .FileOutputStream ;
7
+ import java .io .IOException ;
8
+ import java .io .InputStream ;
9
+
10
+ public class AssetsUtil {
11
+ public static void exportFiles (Context context , String src , String out ) throws IOException {
12
+ String [] fileNames = context .getAssets ().list (src );
13
+ if (fileNames .length > 0 ) {
14
+ File file = new File (out );
15
+ file .mkdirs ();
16
+ for (String fileName : fileNames ) {
17
+ exportFiles (context , src + "/" + fileName , out + "/" + fileName );
18
+ }
19
+ } else {
20
+ InputStream is = context .getAssets ().open (src );
21
+ FileOutputStream fos = new FileOutputStream (new File (out ));
22
+ byte [] buffer = new byte [1024 ];
23
+ int byteCount = 0 ;
24
+ while ((byteCount = is .read (buffer )) != -1 ) {
25
+ fos .write (buffer , 0 , byteCount );
26
+ }
27
+ fos .flush ();
28
+ is .close ();
29
+ fos .close ();
30
+ }
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments