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
4c1ea0e4
Commit
4c1ea0e4
authored
Apr 18, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update stub implementation
Prevent some potential issues
parent
7e01f9c9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
25 deletions
+34
-25
ClassLoaders.java
stub/src/main/java/com/topjohnwu/magisk/ClassLoaders.java
+4
-2
DelegateComponentFactory.java
...n/java/com/topjohnwu/magisk/DelegateComponentFactory.java
+1
-3
InjectAPK.java
stub/src/main/java/com/topjohnwu/magisk/InjectAPK.java
+29
-17
Mapping.java
stub/src/main/java/com/topjohnwu/magisk/Mapping.java
+0
-3
No files found.
stub/src/main/java/com/topjohnwu/magisk/ClassLoaders.java
View file @
4c1ea0e4
...
...
@@ -4,10 +4,12 @@ import com.topjohnwu.magisk.utils.DynamicClassLoader;
import
java.io.File
;
class
InjectedClassLoader
extends
DynamicClassLoader
{
// Wrap the actual classloader as we only want to resolve classname
// mapping when loading from platform (via LoadedApk.mClassLoader)
class
InjectedClassLoader
extends
ClassLoader
{
InjectedClassLoader
(
File
apk
)
{
super
(
apk
);
super
(
new
DynamicClassLoader
(
apk
)
);
}
@Override
...
...
stub/src/main/java/com/topjohnwu/magisk/DelegateComponentFactory.java
View file @
4c1ea0e4
...
...
@@ -12,12 +12,11 @@ import android.content.Intent;
@SuppressLint
(
"NewApi"
)
public
class
DelegateComponentFactory
extends
AppComponentFactory
{
static
DelegateComponentFactory
INSTANCE
;
ClassLoader
loader
;
AppComponentFactory
receiver
;
public
DelegateComponentFactory
()
{
I
NSTANCE
=
this
;
I
njectAPK
.
componentFactory
=
this
;
}
@Override
...
...
@@ -53,7 +52,6 @@ public class DelegateComponentFactory extends AppComponentFactory {
@Override
public
ContentProvider
instantiateProvider
(
ClassLoader
cl
,
String
className
)
throws
ClassNotFoundException
,
IllegalAccessException
,
InstantiationException
{
if
(
loader
==
null
)
loader
=
cl
;
if
(
receiver
!=
null
)
return
receiver
.
instantiateProvider
(
loader
,
className
);
return
create
(
className
);
...
...
stub/src/main/java/com/topjohnwu/magisk/InjectAPK.java
View file @
4c1ea0e4
...
...
@@ -5,6 +5,8 @@ import android.app.Application;
import
android.content.ContentResolver
;
import
android.content.Context
;
import
android.content.ContextWrapper
;
import
android.content.pm.ApplicationInfo
;
import
android.content.pm.PackageManager
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.util.Log
;
...
...
@@ -17,6 +19,12 @@ import java.lang.reflect.Field;
public
class
InjectAPK
{
static
Object
componentFactory
;
private
static
DelegateComponentFactory
getComponentFactory
()
{
return
(
DelegateComponentFactory
)
componentFactory
;
}
@SuppressWarnings
(
"ResultOfMethodCallIgnored"
)
static
Application
setup
(
Context
context
)
{
// Get ContextImpl
...
...
@@ -28,7 +36,6 @@ public class InjectAPK {
File
update
=
DynAPK
.
update
(
context
);
if
(
update
.
exists
())
update
.
renameTo
(
apk
);
Application
result
=
null
;
if
(!
apk
.
exists
())
{
// Try copying APK
Uri
uri
=
new
Uri
.
Builder
().
scheme
(
"content"
)
...
...
@@ -48,42 +55,47 @@ public class InjectAPK {
}
if
(
apk
.
exists
())
{
ClassLoader
cl
=
new
InjectedClassLoader
(
apk
);
PackageManager
pm
=
context
.
getPackageManager
();
ApplicationInfo
info
=
pm
.
getPackageArchiveInfo
(
apk
.
getPath
(),
0
).
applicationInfo
;
try
{
// Create the receiver Application
Object
app
=
cl
.
loadClass
(
Mapping
.
get
(
"APP"
)).
getConstructor
(
Object
.
class
)
Object
app
=
cl
.
loadClass
(
info
.
className
)
.
getConstructor
(
Object
.
class
)
.
newInstance
(
DynAPK
.
pack
(
dynData
()));
// Create the receiver component factory
Object
factory
=
null
;
if
(
Build
.
VERSION
.
SDK_INT
>=
28
)
{
factory
=
cl
.
loadClass
(
Mapping
.
get
(
"ACF"
)
).
newInstance
();
factory
=
cl
.
loadClass
(
info
.
appComponentFactory
).
newInstance
();
}
setClassLoader
(
context
,
cl
);
// Finally, set variables
result
=
(
Application
)
app
;
if
(
Build
.
VERSION
.
SDK_INT
>=
28
)
{
DelegateComponentFactory
.
INSTANCE
.
loader
=
cl
;
DelegateComponentFactory
.
INSTANCE
.
receiver
=
(
AppComponentFactory
)
factory
;
getComponentFactory
()
.
loader
=
cl
;
getComponentFactory
()
.
receiver
=
(
AppComponentFactory
)
factory
;
}
return
(
Application
)
app
;
}
catch
(
Exception
e
)
{
Log
.
e
(
InjectAPK
.
class
.
getSimpleName
(),
""
,
e
);
apk
.
delete
();
}
}
else
{
// fallthrough
}
ClassLoader
cl
=
new
RedirectClassLoader
();
try
{
setClassLoader
(
context
,
cl
);
if
(
Build
.
VERSION
.
SDK_INT
>=
28
)
{
DelegateComponentFactory
.
INSTANCE
.
loader
=
cl
;
getComponentFactory
()
.
loader
=
cl
;
}
}
catch
(
Exception
e
)
{
// Should never happen
Log
.
e
(
InjectAPK
.
class
.
getSimpleName
(),
""
,
e
);
}
}
return
result
;
return
null
;
}
// Replace LoadedApk mClassLoader
...
...
stub/src/main/java/com/topjohnwu/magisk/Mapping.java
View file @
4c1ea0e4
...
...
@@ -34,9 +34,6 @@ public class Mapping {
for
(
Map
.
Entry
<
String
,
String
>
e
:
map
.
entrySet
())
{
inverseMap
.
put
(
e
.
getValue
(),
e
.
getKey
());
}
map
.
put
(
"APP"
,
"com.topjohnwu.magisk.core.App"
);
map
.
put
(
"ACF"
,
"androidx.core.app.CoreComponentFactory"
);
}
public
static
String
get
(
String
name
)
{
...
...
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