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
Hide 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;
...
@@ -4,10 +4,12 @@ import com.topjohnwu.magisk.utils.DynamicClassLoader;
import
java.io.File
;
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
)
{
InjectedClassLoader
(
File
apk
)
{
super
(
apk
);
super
(
new
DynamicClassLoader
(
apk
)
);
}
}
@Override
@Override
...
...
stub/src/main/java/com/topjohnwu/magisk/DelegateComponentFactory.java
View file @
4c1ea0e4
...
@@ -12,12 +12,11 @@ import android.content.Intent;
...
@@ -12,12 +12,11 @@ import android.content.Intent;
@SuppressLint
(
"NewApi"
)
@SuppressLint
(
"NewApi"
)
public
class
DelegateComponentFactory
extends
AppComponentFactory
{
public
class
DelegateComponentFactory
extends
AppComponentFactory
{
static
DelegateComponentFactory
INSTANCE
;
ClassLoader
loader
;
ClassLoader
loader
;
AppComponentFactory
receiver
;
AppComponentFactory
receiver
;
public
DelegateComponentFactory
()
{
public
DelegateComponentFactory
()
{
I
NSTANCE
=
this
;
I
njectAPK
.
componentFactory
=
this
;
}
}
@Override
@Override
...
@@ -53,7 +52,6 @@ public class DelegateComponentFactory extends AppComponentFactory {
...
@@ -53,7 +52,6 @@ public class DelegateComponentFactory extends AppComponentFactory {
@Override
@Override
public
ContentProvider
instantiateProvider
(
ClassLoader
cl
,
String
className
)
public
ContentProvider
instantiateProvider
(
ClassLoader
cl
,
String
className
)
throws
ClassNotFoundException
,
IllegalAccessException
,
InstantiationException
{
throws
ClassNotFoundException
,
IllegalAccessException
,
InstantiationException
{
if
(
loader
==
null
)
loader
=
cl
;
if
(
receiver
!=
null
)
if
(
receiver
!=
null
)
return
receiver
.
instantiateProvider
(
loader
,
className
);
return
receiver
.
instantiateProvider
(
loader
,
className
);
return
create
(
className
);
return
create
(
className
);
...
...
stub/src/main/java/com/topjohnwu/magisk/InjectAPK.java
View file @
4c1ea0e4
...
@@ -5,6 +5,8 @@ import android.app.Application;
...
@@ -5,6 +5,8 @@ import android.app.Application;
import
android.content.ContentResolver
;
import
android.content.ContentResolver
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.ContextWrapper
;
import
android.content.ContextWrapper
;
import
android.content.pm.ApplicationInfo
;
import
android.content.pm.PackageManager
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Build
;
import
android.util.Log
;
import
android.util.Log
;
...
@@ -17,6 +19,12 @@ import java.lang.reflect.Field;
...
@@ -17,6 +19,12 @@ import java.lang.reflect.Field;
public
class
InjectAPK
{
public
class
InjectAPK
{
static
Object
componentFactory
;
private
static
DelegateComponentFactory
getComponentFactory
()
{
return
(
DelegateComponentFactory
)
componentFactory
;
}
@SuppressWarnings
(
"ResultOfMethodCallIgnored"
)
@SuppressWarnings
(
"ResultOfMethodCallIgnored"
)
static
Application
setup
(
Context
context
)
{
static
Application
setup
(
Context
context
)
{
// Get ContextImpl
// Get ContextImpl
...
@@ -28,7 +36,6 @@ public class InjectAPK {
...
@@ -28,7 +36,6 @@ public class InjectAPK {
File
update
=
DynAPK
.
update
(
context
);
File
update
=
DynAPK
.
update
(
context
);
if
(
update
.
exists
())
if
(
update
.
exists
())
update
.
renameTo
(
apk
);
update
.
renameTo
(
apk
);
Application
result
=
null
;
if
(!
apk
.
exists
())
{
if
(!
apk
.
exists
())
{
// Try copying APK
// Try copying APK
Uri
uri
=
new
Uri
.
Builder
().
scheme
(
"content"
)
Uri
uri
=
new
Uri
.
Builder
().
scheme
(
"content"
)
...
@@ -48,42 +55,47 @@ public class InjectAPK {
...
@@ -48,42 +55,47 @@ public class InjectAPK {
}
}
if
(
apk
.
exists
())
{
if
(
apk
.
exists
())
{
ClassLoader
cl
=
new
InjectedClassLoader
(
apk
);
ClassLoader
cl
=
new
InjectedClassLoader
(
apk
);
PackageManager
pm
=
context
.
getPackageManager
();
ApplicationInfo
info
=
pm
.
getPackageArchiveInfo
(
apk
.
getPath
(),
0
).
applicationInfo
;
try
{
try
{
// Create the receiver Application
// 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
()));
.
newInstance
(
DynAPK
.
pack
(
dynData
()));
// Create the receiver component factory
// Create the receiver component factory
Object
factory
=
null
;
Object
factory
=
null
;
if
(
Build
.
VERSION
.
SDK_INT
>=
28
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
28
)
{
factory
=
cl
.
loadClass
(
Mapping
.
get
(
"ACF"
)
).
newInstance
();
factory
=
cl
.
loadClass
(
info
.
appComponentFactory
).
newInstance
();
}
}
setClassLoader
(
context
,
cl
);
setClassLoader
(
context
,
cl
);
// Finally, set variables
// Finally, set variables
result
=
(
Application
)
app
;
if
(
Build
.
VERSION
.
SDK_INT
>=
28
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
28
)
{
DelegateComponentFactory
.
INSTANCE
.
loader
=
cl
;
getComponentFactory
()
.
loader
=
cl
;
DelegateComponentFactory
.
INSTANCE
.
receiver
=
(
AppComponentFactory
)
factory
;
getComponentFactory
()
.
receiver
=
(
AppComponentFactory
)
factory
;
}
}
return
(
Application
)
app
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
InjectAPK
.
class
.
getSimpleName
(),
""
,
e
);
Log
.
e
(
InjectAPK
.
class
.
getSimpleName
(),
""
,
e
);
apk
.
delete
();
apk
.
delete
();
}
}
}
else
{
// fallthrough
ClassLoader
cl
=
new
RedirectClassLoader
();
}
try
{
setClassLoader
(
context
,
cl
);
ClassLoader
cl
=
new
RedirectClassLoader
();
if
(
Build
.
VERSION
.
SDK_INT
>=
28
)
{
try
{
DelegateComponentFactory
.
INSTANCE
.
loader
=
cl
;
setClassLoader
(
context
,
cl
);
}
if
(
Build
.
VERSION
.
SDK_INT
>=
28
)
{
}
catch
(
Exception
e
)
{
getComponentFactory
().
loader
=
cl
;
// Should never happen
Log
.
e
(
InjectAPK
.
class
.
getSimpleName
(),
""
,
e
);
}
}
}
catch
(
Exception
e
)
{
Log
.
e
(
InjectAPK
.
class
.
getSimpleName
(),
""
,
e
);
}
}
return
result
;
return
null
;
}
}
// Replace LoadedApk mClassLoader
// Replace LoadedApk mClassLoader
...
...
stub/src/main/java/com/topjohnwu/magisk/Mapping.java
View file @
4c1ea0e4
...
@@ -34,9 +34,6 @@ public class Mapping {
...
@@ -34,9 +34,6 @@ public class Mapping {
for
(
Map
.
Entry
<
String
,
String
>
e
:
map
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
String
>
e
:
map
.
entrySet
())
{
inverseMap
.
put
(
e
.
getValue
(),
e
.
getKey
());
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
)
{
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