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> {
...
@@ -168,19 +168,18 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
shell
=
Shell
.
getShell
();
shell
=
Shell
.
getShell
();
// Patch boot image
// Patch boot image
shell
.
run
(
mList
,
shell
.
run
(
mList
,
null
,
"cd "
+
install
,
"cd "
+
install
,
"KEEPFORCEENCRYPT="
+
mKeepEnc
+
" KEEPVERITY="
+
mKeepVerity
+
" sh "
+
"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!"
))
if
(
TextUtils
.
equals
(
mList
.
get
(
mList
.
size
()
-
1
),
"Failed!"
))
return
false
;
return
false
;
shell
.
run
(
mList
,
shell
.
run
(
null
,
null
,
"mv -f new-boot.img ../
2>/dev/null
"
,
"mv -f new-boot.img ../"
,
"mv bin/busybox busybox
2>/dev/null
"
,
"mv bin/busybox busybox"
,
"rm -rf bin *.img update-binary
2>/dev/null
"
,
"rm -rf bin *.img update-binary"
,
"cd /"
);
"cd /"
);
File
patched_boot
=
new
File
(
install
.
getParent
(),
"new-boot.img"
);
File
patched_boot
=
new
File
(
install
.
getParent
(),
"new-boot.img"
);
...
@@ -197,7 +196,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
...
@@ -197,7 +196,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
)
{
)
{
SignBoot
.
doSignature
(
"/boot"
,
in
,
out
,
keyIn
,
certIn
);
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
)
{
switch
(
mode
)
{
...
@@ -206,7 +205,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
...
@@ -206,7 +205,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
dest
.
getParentFile
().
mkdirs
();
dest
.
getParentFile
().
mkdirs
();
switch
(
mm
.
bootFormat
)
{
switch
(
mm
.
bootFormat
)
{
case
".img"
:
case
".img"
:
shell
.
run_raw
(
false
,
"cp -f "
+
patched_boot
+
" "
+
dest
);
shell
.
run_raw
(
false
,
false
,
"cp -f "
+
patched_boot
+
" "
+
dest
);
break
;
break
;
case
".img.tar"
:
case
".img.tar"
:
try
(
try
(
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Const.java
View file @
49c672ac
...
@@ -24,7 +24,7 @@ public class Const {
...
@@ -24,7 +24,7 @@ public class Const {
public
static
final
String
MAGISK_DISABLE_FILE
=
"/cache/.disable_magisk"
;
public
static
final
String
MAGISK_DISABLE_FILE
=
"/cache/.disable_magisk"
;
public
static
final
String
TMP_FOLDER_PATH
=
"/dev/tmp"
;
public
static
final
String
TMP_FOLDER_PATH
=
"/dev/tmp"
;
public
static
final
String
MAGISK_LOG
=
"/cache/magisk.log"
;
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
final
File
EXTERNAL_PATH
=
new
File
(
Environment
.
getExternalStorageDirectory
(),
"MagiskManager"
);
public
static
String
MAGISK_PATH
()
{
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 {
...
@@ -25,6 +25,7 @@ public class Shell {
private
final
Process
process
;
private
final
Process
process
;
private
final
OutputStream
STDIN
;
private
final
OutputStream
STDIN
;
private
final
InputStream
STDOUT
;
private
final
InputStream
STDOUT
;
private
final
InputStream
STDERR
;
private
static
void
testRootShell
(
Shell
shell
)
throws
IOException
{
private
static
void
testRootShell
(
Shell
shell
)
throws
IOException
{
shell
.
STDIN
.
write
((
"id\n"
).
getBytes
(
"UTF-8"
));
shell
.
STDIN
.
write
((
"id\n"
).
getBytes
(
"UTF-8"
));
...
@@ -41,6 +42,7 @@ public class Shell {
...
@@ -41,6 +42,7 @@ public class Shell {
process
=
Runtime
.
getRuntime
().
exec
(
command
);
process
=
Runtime
.
getRuntime
().
exec
(
command
);
STDIN
=
process
.
getOutputStream
();
STDIN
=
process
.
getOutputStream
();
STDOUT
=
process
.
getInputStream
();
STDOUT
=
process
.
getInputStream
();
STDERR
=
process
.
getErrorStream
();
}
}
public
static
Shell
getShell
()
{
public
static
Shell
getShell
()
{
...
@@ -87,12 +89,11 @@ public class Shell {
...
@@ -87,12 +89,11 @@ public class Shell {
}
}
// Root shell initialization
// Root shell initialization
mm
.
shell
.
run_raw
(
false
,
mm
.
shell
.
run_raw
(
false
,
false
,
"export PATH="
+
Const
.
BUSYBOXPATH
+
":$PATH"
,
"export PATH="
+
Const
.
BUSYBOX
_
PATH
+
":$PATH"
,
"mount_partitions"
,
"mount_partitions"
,
"find_boot_image"
,
"find_boot_image"
,
"migrate_boot_backup"
"migrate_boot_backup"
);
);
}
}
}
}
...
@@ -104,16 +105,20 @@ public class Shell {
...
@@ -104,16 +105,20 @@ public class Shell {
return
status
>
0
;
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
)
{
synchronized
(
process
)
{
try
{
try
{
StreamGobbler
out
=
new
StreamGobbler
(
STDOUT
,
output
);
out
=
new
StreamGobbler
(
STDOUT
,
output
);
err
=
new
StreamGobbler
(
STDERR
,
error
);
out
.
start
();
out
.
start
();
run_raw
(
true
,
commands
);
err
.
start
();
STDIN
.
write
(
"echo \'-shell-done-\'\n"
.
getBytes
(
"UTF-8"
));
run_raw
(
output
!=
null
,
error
!=
null
,
commands
);
STDIN
.
write
(
"echo \'-shell-done-\'\necho \'-shell-done-\' >&2\n"
.
getBytes
(
"UTF-8"
));
STDIN
.
flush
();
STDIN
.
flush
();
try
{
try
{
out
.
join
();
out
.
join
();
err
.
join
();
}
catch
(
InterruptedException
ignored
)
{}
}
catch
(
InterruptedException
ignored
)
{}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -122,12 +127,15 @@ public class Shell {
...
@@ -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
)
{
synchronized
(
process
)
{
try
{
try
{
for
(
String
command
:
commands
)
{
for
(
String
command
:
commands
)
{
Logger
.
shell
(
true
,
command
);
Logger
.
shell
(
true
,
command
);
STDIN
.
write
((
command
+
(
stdout
?
"\n"
:
" >/dev/null\n"
)
).
getBytes
(
"UTF-8"
));
STDIN
.
write
((
command
+
suffix
).
getBytes
(
"UTF-8"
));
STDIN
.
flush
();
STDIN
.
flush
();
}
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -140,12 +148,7 @@ public class Shell {
...
@@ -140,12 +148,7 @@ public class Shell {
public
void
loadInputStream
(
InputStream
in
)
{
public
void
loadInputStream
(
InputStream
in
)
{
synchronized
(
process
)
{
synchronized
(
process
)
{
try
{
try
{
int
read
;
Utils
.
inToOut
(
in
,
STDIN
);
byte
[]
bytes
=
new
byte
[
4096
];
while
((
read
=
in
.
read
(
bytes
))
!=
-
1
)
{
STDIN
.
write
(
bytes
,
0
,
read
);
}
STDIN
.
flush
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -162,14 +165,14 @@ public class Shell {
...
@@ -162,14 +165,14 @@ public class Shell {
Shell
shell
=
getShell
();
Shell
shell
=
getShell
();
if
(
shell
==
null
)
if
(
shell
==
null
)
return
;
return
;
shell
.
run
(
output
,
commands
);
shell
.
run
(
output
,
null
,
commands
);
}
}
public
static
void
sh_raw
(
String
...
commands
)
{
public
static
void
sh_raw
(
String
...
commands
)
{
Shell
shell
=
getShell
();
Shell
shell
=
getShell
();
if
(
shell
==
null
)
if
(
shell
==
null
)
return
;
return
;
shell
.
run_raw
(
false
,
commands
);
shell
.
run_raw
(
false
,
false
,
commands
);
}
}
public
static
List
<
String
>
su
(
String
...
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;
...
@@ -7,6 +7,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Collections
;
/**
/**
* Modified by topjohnwu, based on Chainfire's libsuperuser
* Modified by topjohnwu, based on Chainfire's libsuperuser
...
@@ -14,8 +15,8 @@ import java.util.Collection;
...
@@ -14,8 +15,8 @@ import java.util.Collection;
public
class
StreamGobbler
extends
Thread
{
public
class
StreamGobbler
extends
Thread
{
private
BufferedReader
reader
=
null
;
private
BufferedReader
reader
;
private
Collection
<
String
>
writer
=
null
;
private
Collection
<
String
>
writer
;
/**
/**
* <p>StreamGobbler constructor</p>
* <p>StreamGobbler constructor</p>
...
@@ -24,17 +25,17 @@ public class StreamGobbler extends Thread {
...
@@ -24,17 +25,17 @@ public class StreamGobbler extends Thread {
* possible to prevent a deadlock from occurring, or Process.waitFor() never
* possible to prevent a deadlock from occurring, or Process.waitFor() never
* returning (as the buffer is full, pausing the native process)</p>
* returning (as the buffer is full, pausing the native process)</p>
*
*
* @param in
putStream
InputStream to read from
* @param in InputStream to read from
* @param out
putList
{@literal List<String>} to write to, or null
* @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
{
try
{
while
(
in
putStream
.
available
()
!=
0
)
{
while
(
in
.
available
()
!=
0
)
{
in
putStream
.
skip
(
inputStream
.
available
());
in
.
skip
(
in
.
available
());
}
}
}
catch
(
IOException
ignored
)
{}
}
catch
(
IOException
ignored
)
{}
reader
=
new
BufferedReader
(
new
InputStreamReader
(
in
putStream
));
reader
=
new
BufferedReader
(
new
InputStreamReader
(
in
));
writer
=
out
putList
;
writer
=
out
==
null
?
null
:
Collections
.
synchronizedCollection
(
out
)
;
}
}
@Override
@Override
...
@@ -45,7 +46,7 @@ public class StreamGobbler extends Thread {
...
@@ -45,7 +46,7 @@ public class StreamGobbler extends Thread {
while
((
line
=
reader
.
readLine
())
!=
null
)
{
while
((
line
=
reader
.
readLine
())
!=
null
)
{
if
(
TextUtils
.
equals
(
line
,
"-shell-done-"
))
if
(
TextUtils
.
equals
(
line
,
"-shell-done-"
))
return
;
return
;
writer
.
add
(
line
);
if
(
writer
!=
null
)
writer
.
add
(
line
);
Logger
.
shell
(
false
,
line
);
Logger
.
shell
(
false
,
line
);
}
}
}
catch
(
IOException
e
)
{
}
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