Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
49c672ac
Commit
49c672ac
authored
Nov 17, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add STDERR support
parent
b570cb5b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
38 deletions
+41
-38
InstallMagisk.java
.../main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
+8
-9
Const.java
app/src/main/java/com/topjohnwu/magisk/utils/Const.java
+1
-1
Shell.java
app/src/main/java/com/topjohnwu/magisk/utils/Shell.java
+21
-18
StreamGobbler.java
...c/main/java/com/topjohnwu/magisk/utils/StreamGobbler.java
+11
-10
No files found.
app/src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
View file @
49c672ac
...
...
@@ -168,19 +168,18 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
shell
=
Shell
.
getShell
();
// Patch boot image
shell
.
run
(
mList
,
shell
.
run
(
mList
,
null
,
"cd "
+
install
,
"KEEPFORCEENCRYPT="
+
mKeepEnc
+
" KEEPVERITY="
+
mKeepVerity
+
" sh "
+
"update-binary indep boot_patch.sh "
+
boot
+
" || echo 'Failed!'"
);
"update-binary indep boot_patch.sh "
+
boot
+
" || echo 'Failed!'"
);
if
(
TextUtils
.
equals
(
mList
.
get
(
mList
.
size
()
-
1
),
"Failed!"
))
return
false
;
shell
.
run
(
mList
,
"mv -f new-boot.img ../
2>/dev/null
"
,
"mv bin/busybox busybox
2>/dev/null
"
,
"rm -rf bin *.img update-binary
2>/dev/null
"
,
shell
.
run
(
null
,
null
,
"mv -f new-boot.img ../"
,
"mv bin/busybox busybox"
,
"rm -rf bin *.img update-binary"
,
"cd /"
);
File
patched_boot
=
new
File
(
install
.
getParent
(),
"new-boot.img"
);
...
...
@@ -197,7 +196,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
)
{
SignBoot
.
doSignature
(
"/boot"
,
in
,
out
,
keyIn
,
certIn
);
}
shell
.
run_raw
(
false
,
"mv -f "
+
signed
+
" "
+
patched_boot
);
shell
.
run_raw
(
false
,
false
,
"mv -f "
+
signed
+
" "
+
patched_boot
);
}
switch
(
mode
)
{
...
...
@@ -206,7 +205,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
dest
.
getParentFile
().
mkdirs
();
switch
(
mm
.
bootFormat
)
{
case
".img"
:
shell
.
run_raw
(
false
,
"cp -f "
+
patched_boot
+
" "
+
dest
);
shell
.
run_raw
(
false
,
false
,
"cp -f "
+
patched_boot
+
" "
+
dest
);
break
;
case
".img.tar"
:
try
(
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Const.java
View file @
49c672ac
...
...
@@ -24,7 +24,7 @@ public class Const {
public
static
final
String
MAGISK_DISABLE_FILE
=
"/cache/.disable_magisk"
;
public
static
final
String
TMP_FOLDER_PATH
=
"/dev/tmp"
;
public
static
final
String
MAGISK_LOG
=
"/cache/magisk.log"
;
public
static
final
String
BUSYBOXPATH
=
"/dev/magisk/bin"
;
public
static
final
String
BUSYBOX
_
PATH
=
"/dev/magisk/bin"
;
public
static
final
File
EXTERNAL_PATH
=
new
File
(
Environment
.
getExternalStorageDirectory
(),
"MagiskManager"
);
public
static
String
MAGISK_PATH
()
{
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Shell.java
View file @
49c672ac
...
...
@@ -25,6 +25,7 @@ public class Shell {
private
final
Process
process
;
private
final
OutputStream
STDIN
;
private
final
InputStream
STDOUT
;
private
final
InputStream
STDERR
;
private
static
void
testRootShell
(
Shell
shell
)
throws
IOException
{
shell
.
STDIN
.
write
((
"id\n"
).
getBytes
(
"UTF-8"
));
...
...
@@ -41,6 +42,7 @@ public class Shell {
process
=
Runtime
.
getRuntime
().
exec
(
command
);
STDIN
=
process
.
getOutputStream
();
STDOUT
=
process
.
getInputStream
();
STDERR
=
process
.
getErrorStream
();
}
public
static
Shell
getShell
()
{
...
...
@@ -87,12 +89,11 @@ public class Shell {
}
// Root shell initialization
mm
.
shell
.
run_raw
(
false
,
"export PATH="
+
Const
.
BUSYBOXPATH
+
":$PATH"
,
mm
.
shell
.
run_raw
(
false
,
false
,
"export PATH="
+
Const
.
BUSYBOX
_
PATH
+
":$PATH"
,
"mount_partitions"
,
"find_boot_image"
,
"migrate_boot_backup"
);
"migrate_boot_backup"
);
}
}
...
...
@@ -104,16 +105,20 @@ public class Shell {
return
status
>
0
;
}
public
void
run
(
Collection
<
String
>
output
,
String
...
commands
)
{
public
void
run
(
Collection
<
String
>
output
,
Collection
<
String
>
error
,
String
...
commands
)
{
StreamGobbler
out
,
err
;
synchronized
(
process
)
{
try
{
StreamGobbler
out
=
new
StreamGobbler
(
STDOUT
,
output
);
out
=
new
StreamGobbler
(
STDOUT
,
output
);
err
=
new
StreamGobbler
(
STDERR
,
error
);
out
.
start
();
run_raw
(
true
,
commands
);
STDIN
.
write
(
"echo \'-shell-done-\'\n"
.
getBytes
(
"UTF-8"
));
err
.
start
();
run_raw
(
output
!=
null
,
error
!=
null
,
commands
);
STDIN
.
write
(
"echo \'-shell-done-\'\necho \'-shell-done-\' >&2\n"
.
getBytes
(
"UTF-8"
));
STDIN
.
flush
();
try
{
out
.
join
();
err
.
join
();
}
catch
(
InterruptedException
ignored
)
{}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
...
...
@@ -122,12 +127,15 @@ public class Shell {
}
}
public
void
run_raw
(
boolean
stdout
,
String
...
commands
)
{
public
void
run_raw
(
boolean
stdout
,
boolean
stderr
,
String
...
commands
)
{
String
suffix
=
"\n"
;
if
(!
stderr
)
suffix
=
" 2>/dev/null"
+
suffix
;
if
(!
stdout
)
suffix
=
" >/dev/null"
+
suffix
;
synchronized
(
process
)
{
try
{
for
(
String
command
:
commands
)
{
Logger
.
shell
(
true
,
command
);
STDIN
.
write
((
command
+
(
stdout
?
"\n"
:
" >/dev/null\n"
)
).
getBytes
(
"UTF-8"
));
STDIN
.
write
((
command
+
suffix
).
getBytes
(
"UTF-8"
));
STDIN
.
flush
();
}
}
catch
(
IOException
e
)
{
...
...
@@ -140,12 +148,7 @@ public class Shell {
public
void
loadInputStream
(
InputStream
in
)
{
synchronized
(
process
)
{
try
{
int
read
;
byte
[]
bytes
=
new
byte
[
4096
];
while
((
read
=
in
.
read
(
bytes
))
!=
-
1
)
{
STDIN
.
write
(
bytes
,
0
,
read
);
}
STDIN
.
flush
();
Utils
.
inToOut
(
in
,
STDIN
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -162,14 +165,14 @@ public class Shell {
Shell
shell
=
getShell
();
if
(
shell
==
null
)
return
;
shell
.
run
(
output
,
commands
);
shell
.
run
(
output
,
null
,
commands
);
}
public
static
void
sh_raw
(
String
...
commands
)
{
Shell
shell
=
getShell
();
if
(
shell
==
null
)
return
;
shell
.
run_raw
(
false
,
commands
);
shell
.
run_raw
(
false
,
false
,
commands
);
}
public
static
List
<
String
>
su
(
String
...
commands
)
{
...
...
app/src/main/java/com/topjohnwu/magisk/utils/StreamGobbler.java
View file @
49c672ac
...
...
@@ -7,6 +7,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.util.Collection
;
import
java.util.Collections
;
/**
* Modified by topjohnwu, based on Chainfire's libsuperuser
...
...
@@ -14,8 +15,8 @@ import java.util.Collection;
public
class
StreamGobbler
extends
Thread
{
private
BufferedReader
reader
=
null
;
private
Collection
<
String
>
writer
=
null
;
private
BufferedReader
reader
;
private
Collection
<
String
>
writer
;
/**
* <p>StreamGobbler constructor</p>
...
...
@@ -24,17 +25,17 @@ public class StreamGobbler extends Thread {
* possible to prevent a deadlock from occurring, or Process.waitFor() never
* returning (as the buffer is full, pausing the native process)</p>
*
* @param in
putStream
InputStream to read from
* @param out
putList
{@literal List<String>} to write to, or null
* @param in InputStream to read from
* @param out {@literal List<String>} to write to, or null
*/
public
StreamGobbler
(
InputStream
in
putStream
,
Collection
<
String
>
outputLis
t
)
{
public
StreamGobbler
(
InputStream
in
,
Collection
<
String
>
ou
t
)
{
try
{
while
(
in
putStream
.
available
()
!=
0
)
{
in
putStream
.
skip
(
inputStream
.
available
());
while
(
in
.
available
()
!=
0
)
{
in
.
skip
(
in
.
available
());
}
}
catch
(
IOException
ignored
)
{}
reader
=
new
BufferedReader
(
new
InputStreamReader
(
in
putStream
));
writer
=
out
putList
;
reader
=
new
BufferedReader
(
new
InputStreamReader
(
in
));
writer
=
out
==
null
?
null
:
Collections
.
synchronizedCollection
(
out
)
;
}
@Override
...
...
@@ -45,7 +46,7 @@ public class StreamGobbler extends Thread {
while
((
line
=
reader
.
readLine
())
!=
null
)
{
if
(
TextUtils
.
equals
(
line
,
"-shell-done-"
))
return
;
writer
.
add
(
line
);
if
(
writer
!=
null
)
writer
.
add
(
line
);
Logger
.
shell
(
false
,
line
);
}
}
catch
(
IOException
e
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment