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
d3ade064
Commit
d3ade064
authored
Dec 14, 2021
by
vvb2060
Committed by
John Wu
Dec 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use InputStream transfer
parent
f1a3ef95
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
30 deletions
+21
-30
DownloadActivity.java
.../src/main/java/com/topjohnwu/magisk/DownloadActivity.java
+1
-4
DynLoad.java
stub/src/main/java/com/topjohnwu/magisk/DynLoad.java
+13
-14
Request.java
stub/src/main/java/com/topjohnwu/magisk/net/Request.java
+7
-12
No files found.
stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java
View file @
d3ade064
...
...
@@ -140,10 +140,7 @@ public class DownloadActivity extends Activity {
var
is
=
new
CipherInputStream
(
new
ByteArrayInputStream
(
Bytes
.
res
()),
cipher
);
var
out
=
new
FileOutputStream
(
apk
);
try
(
is
;
out
)
{
byte
[]
buf
=
new
byte
[
4096
];
for
(
int
read
;
(
read
=
is
.
read
(
buf
))
>=
0
;)
{
out
.
write
(
buf
,
0
,
read
);
}
APKInstall
.
transfer
(
is
,
out
);
}
DynAPK
.
addAssetPath
(
getResources
().
getAssets
(),
apk
.
getPath
());
}
catch
(
Exception
ignored
)
{
...
...
stub/src/main/java/com/topjohnwu/magisk/DynLoad.java
View file @
d3ade064
...
...
@@ -12,33 +12,24 @@ import android.net.Uri;
import
android.os.Build
;
import
android.util.Log
;
import
com.topjohnwu.magisk.utils.APKInstall
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.lang.reflect.Field
;
import
io.michaelrocks.paranoid.Obfuscate
;
@Obfuscate
@SuppressWarnings
(
"ResultOfMethodCallIgnored"
)
public
class
DynLoad
{
static
Object
componentFactory
;
static
final
DynAPK
.
Data
apkData
=
createApkData
();
private
static
void
copy
(
InputStream
src
,
OutputStream
dest
)
throws
IOException
{
try
(
InputStream
s
=
src
)
{
try
(
OutputStream
o
=
dest
)
{
byte
[]
buf
=
new
byte
[
8192
];
for
(
int
read
;
(
read
=
s
.
read
(
buf
))
>=
0
;)
{
o
.
write
(
buf
,
0
,
read
);
}
}
}
}
// Dynamically load APK, inject ClassLoader into ContextImpl, then
// create the actual Application instance from the loaded APK
static
Application
inject
(
Context
context
)
{
...
...
@@ -55,7 +46,11 @@ public class DynLoad {
File
external
=
new
File
(
context
.
getExternalFilesDir
(
null
),
"magisk.apk"
);
if
(
external
.
exists
())
{
try
{
copy
(
new
FileInputStream
(
external
),
new
FileOutputStream
(
apk
));
var
in
=
new
FileInputStream
(
external
);
var
out
=
new
FileOutputStream
(
apk
);
try
(
in
;
out
)
{
APKInstall
.
transfer
(
in
,
out
);
}
}
catch
(
IOException
e
)
{
Log
.
e
(
DynLoad
.
class
.
getSimpleName
(),
""
,
e
);
apk
.
delete
();
...
...
@@ -74,7 +69,10 @@ public class DynLoad {
try
{
InputStream
src
=
resolver
.
openInputStream
(
uri
);
if
(
src
!=
null
)
{
copy
(
src
,
new
FileOutputStream
(
apk
));
var
out
=
new
FileOutputStream
(
apk
);
try
(
src
;
out
)
{
APKInstall
.
transfer
(
src
,
out
);
}
}
}
catch
(
IOException
e
)
{
Log
.
e
(
DynLoad
.
class
.
getSimpleName
(),
""
,
e
);
...
...
@@ -148,6 +146,7 @@ public class DynLoad {
Field
mInfo
=
context
.
getClass
().
getDeclaredField
(
"mPackageInfo"
);
mInfo
.
setAccessible
(
true
);
Object
loadedApk
=
mInfo
.
get
(
context
);
assert
loadedApk
!=
null
;
Field
mcl
=
loadedApk
.
getClass
().
getDeclaredField
(
"mClassLoader"
);
mcl
.
setAccessible
(
true
);
mcl
.
set
(
loadedApk
,
cl
);
...
...
stub/src/main/java/com/topjohnwu/magisk/net/Request.java
View file @
d3ade064
...
...
@@ -2,6 +2,8 @@ package com.topjohnwu.magisk.net;
import
android.os.AsyncTask
;
import
com.topjohnwu.magisk.utils.APKInstall
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -24,7 +26,7 @@ import io.michaelrocks.paranoid.Obfuscate;
@Obfuscate
public
class
Request
implements
Closeable
{
private
HttpURLConnection
conn
;
private
final
HttpURLConnection
conn
;
private
Executor
executor
=
null
;
private
int
code
=
-
1
;
...
...
@@ -192,13 +194,9 @@ public class Request implements Closeable {
}
private
File
dlFile
(
File
f
)
throws
IOException
{
try
(
InputStream
in
=
getInputStream
();
try
(
InputStream
in
=
getInputStream
();
OutputStream
out
=
new
BufferedOutputStream
(
new
FileOutputStream
(
f
)))
{
int
len
;
byte
[]
buf
=
new
byte
[
4096
];
while
((
len
=
in
.
read
(
buf
))
!=
-
1
)
{
out
.
write
(
buf
,
0
,
len
);
}
APKInstall
.
transfer
(
in
,
out
);
}
return
f
;
}
...
...
@@ -207,11 +205,8 @@ public class Request implements Closeable {
int
len
=
conn
.
getContentLength
();
len
=
len
>
0
?
len
:
32
;
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
(
len
);
try
(
InputStream
in
=
getInputStream
())
{
byte
[]
buf
=
new
byte
[
4096
];
while
((
len
=
in
.
read
(
buf
))
!=
-
1
)
{
out
.
write
(
buf
,
0
,
len
);
}
try
(
InputStream
in
=
getInputStream
())
{
APKInstall
.
transfer
(
in
,
out
);
}
return
out
.
toByteArray
();
}
...
...
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