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
65224ed2
Commit
65224ed2
authored
Nov 25, 2021
by
vvb2060
Committed by
John Wu
Nov 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix NPE when apk could not be parsed
parent
0a28dfe1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
21 deletions
+27
-21
InjectAPK.java
stub/src/main/java/com/topjohnwu/magisk/InjectAPK.java
+27
-21
No files found.
stub/src/main/java/com/topjohnwu/magisk/InjectAPK.java
View file @
65224ed2
...
@@ -6,6 +6,7 @@ import android.content.ContentResolver;
...
@@ -6,6 +6,7 @@ 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.ApplicationInfo
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageManager
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Build
;
...
@@ -59,8 +60,31 @@ public class InjectAPK {
...
@@ -59,8 +60,31 @@ public class InjectAPK {
if
(
apk
.
exists
())
{
if
(
apk
.
exists
())
{
ClassLoader
cl
=
new
InjectedClassLoader
(
apk
);
ClassLoader
cl
=
new
InjectedClassLoader
(
apk
);
PackageManager
pm
=
context
.
getPackageManager
();
PackageManager
pm
=
context
.
getPackageManager
();
ApplicationInfo
info
=
pm
.
getPackageArchiveInfo
(
apk
.
getPath
(),
0
).
applicationInfo
;
PackageInfo
pkgInfo
=
pm
.
getPackageArchiveInfo
(
apk
.
getPath
(),
0
)
;
try
{
try
{
return
createApp
(
context
,
cl
,
pkgInfo
.
applicationInfo
);
}
catch
(
Exception
e
)
{
Log
.
e
(
InjectAPK
.
class
.
getSimpleName
(),
""
,
e
);
apk
.
delete
();
}
// fallthrough
}
ClassLoader
cl
=
new
RedirectClassLoader
();
try
{
setClassLoader
(
context
,
cl
);
if
(
Build
.
VERSION
.
SDK_INT
>=
28
)
{
getComponentFactory
().
loader
=
cl
;
}
}
catch
(
Exception
e
)
{
Log
.
e
(
InjectAPK
.
class
.
getSimpleName
(),
""
,
e
);
}
return
null
;
}
private
static
Application
createApp
(
Context
context
,
ClassLoader
cl
,
ApplicationInfo
info
)
throws
ReflectiveOperationException
{
// Create the receiver Application
// Create the receiver Application
Object
app
=
cl
.
loadClass
(
info
.
className
)
Object
app
=
cl
.
loadClass
(
info
.
className
)
.
getConstructor
(
Object
.
class
)
.
getConstructor
(
Object
.
class
)
...
@@ -81,24 +105,6 @@ public class InjectAPK {
...
@@ -81,24 +105,6 @@ public class InjectAPK {
}
}
return
(
Application
)
app
;
return
(
Application
)
app
;
}
catch
(
Exception
e
)
{
Log
.
e
(
InjectAPK
.
class
.
getSimpleName
(),
""
,
e
);
apk
.
delete
();
}
// fallthrough
}
ClassLoader
cl
=
new
RedirectClassLoader
();
try
{
setClassLoader
(
context
,
cl
);
if
(
Build
.
VERSION
.
SDK_INT
>=
28
)
{
getComponentFactory
().
loader
=
cl
;
}
}
catch
(
Exception
e
)
{
Log
.
e
(
InjectAPK
.
class
.
getSimpleName
(),
""
,
e
);
}
return
null
;
}
}
// Replace LoadedApk mClassLoader
// Replace LoadedApk mClassLoader
...
...
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