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
010e4de4
Commit
010e4de4
authored
Aug 05, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce DynamicClassLoader
parent
41134466
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
5 deletions
+65
-5
ManagerUpgrade.kt
...ava/com/topjohnwu/magisk/model/download/ManagerUpgrade.kt
+2
-2
HomeFragment.kt
...rc/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt
+2
-3
DynamicClassLoader.kt
...ain/java/com/topjohnwu/magisk/utils/DynamicClassLoader.kt
+61
-0
No files found.
app/src/main/java/com/topjohnwu/magisk/model/download/ManagerUpgrade.kt
View file @
010e4de4
...
@@ -9,10 +9,10 @@ import com.topjohnwu.magisk.model.entity.internal.Configuration.APK.Restore
...
@@ -9,10 +9,10 @@ import com.topjohnwu.magisk.model.entity.internal.Configuration.APK.Restore
import
com.topjohnwu.magisk.model.entity.internal.Configuration.APK.Upgrade
import
com.topjohnwu.magisk.model.entity.internal.Configuration.APK.Upgrade
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import
com.topjohnwu.magisk.ui.SplashActivity
import
com.topjohnwu.magisk.ui.SplashActivity
import
com.topjohnwu.magisk.utils.DynamicClassLoader
import
com.topjohnwu.magisk.utils.PatchAPK
import
com.topjohnwu.magisk.utils.PatchAPK
import
com.topjohnwu.magisk.utils.RootUtils
import
com.topjohnwu.magisk.utils.RootUtils
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
dalvik.system.DexClassLoader
import
timber.log.Timber
import
timber.log.Timber
import
java.io.File
import
java.io.File
...
@@ -27,7 +27,7 @@ private fun RemoteFileService.patchPackage(apk: File, id: Int): File {
...
@@ -27,7 +27,7 @@ private fun RemoteFileService.patchPackage(apk: File, id: Int): File {
val
patched
=
File
(
apk
.
parent
,
"patched.apk"
)
val
patched
=
File
(
apk
.
parent
,
"patched.apk"
)
try
{
try
{
// Try using the new APK to patch itself
// Try using the new APK to patch itself
val
loader
=
D
exClassLoader
(
apk
.
path
,
apk
.
parent
,
null
,
ClassLoader
.
getSystemClassLoader
()
)
val
loader
=
D
ynamicClassLoader
(
apk
)
loader
.
loadClass
(
"a.a"
)
loader
.
loadClass
(
"a.a"
)
.
getMethod
(
"patchAPK"
,
String
::
class
.
java
,
String
::
class
.
java
,
String
::
class
.
java
)
.
getMethod
(
"patchAPK"
,
String
::
class
.
java
,
String
::
class
.
java
,
String
::
class
.
java
)
.
invoke
(
null
,
apk
.
path
,
patched
.
path
,
packageName
)
.
invoke
(
null
,
apk
.
path
,
patched
.
path
,
packageName
)
...
...
app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt
View file @
010e4de4
...
@@ -18,10 +18,10 @@ import com.topjohnwu.magisk.model.events.*
...
@@ -18,10 +18,10 @@ import com.topjohnwu.magisk.model.events.*
import
com.topjohnwu.magisk.ui.base.MagiskActivity
import
com.topjohnwu.magisk.ui.base.MagiskActivity
import
com.topjohnwu.magisk.ui.base.MagiskFragment
import
com.topjohnwu.magisk.ui.base.MagiskFragment
import
com.topjohnwu.magisk.utils.ISafetyNetHelper
import
com.topjohnwu.magisk.utils.ISafetyNetHelper
import
com.topjohnwu.magisk.utils.DynamicClassLoader
import
com.topjohnwu.magisk.view.MarkDownWindow
import
com.topjohnwu.magisk.view.MarkDownWindow
import
com.topjohnwu.magisk.view.dialogs.*
import
com.topjohnwu.magisk.view.dialogs.*
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
dalvik.system.DexClassLoader
import
org.koin.androidx.viewmodel.ext.android.viewModel
import
org.koin.androidx.viewmodel.ext.android.viewModel
import
java.io.File
import
java.io.File
...
@@ -97,8 +97,7 @@ class HomeFragment : MagiskFragment<HomeViewModel, FragmentMagiskBinding>(),
...
@@ -97,8 +97,7 @@ class HomeFragment : MagiskFragment<HomeViewModel, FragmentMagiskBinding>(),
private
fun
updateSafetyNet
(
dieOnError
:
Boolean
)
{
private
fun
updateSafetyNet
(
dieOnError
:
Boolean
)
{
try
{
try
{
val
loader
=
DexClassLoader
(
EXT_APK
.
path
,
EXT_APK
.
parent
,
null
,
val
loader
=
DynamicClassLoader
(
EXT_APK
)
ISafetyNetHelper
::
class
.
java
.
classLoader
)
val
clazz
=
loader
.
loadClass
(
"com.topjohnwu.snet.Snet"
)
val
clazz
=
loader
.
loadClass
(
"com.topjohnwu.snet.Snet"
)
val
helper
=
clazz
.
getMethod
(
"newHelper"
,
val
helper
=
clazz
.
getMethod
(
"newHelper"
,
Class
::
class
.
java
,
String
::
class
.
java
,
Activity
::
class
.
java
,
Any
::
class
.
java
)
Class
::
class
.
java
,
String
::
class
.
java
,
Activity
::
class
.
java
,
Any
::
class
.
java
)
...
...
app/src/main/java/com/topjohnwu/magisk/utils/DynamicClassLoader.kt
0 → 100644
View file @
010e4de4
package
com.topjohnwu.magisk.utils
import
dalvik.system.DexClassLoader
import
java.io.File
import
java.io.IOException
import
java.net.URL
import
java.util.*
@Suppress
(
"FunctionName"
)
inline
fun
<
reified
T
>
T
.
DynamicClassLoader
(
apk
:
File
)
=
DynamicClassLoader
(
apk
,
T
::
class
.
java
.
classLoader
)
class
DynamicClassLoader
(
apk
:
File
,
parent
:
ClassLoader
?)
:
DexClassLoader
(
apk
.
path
,
apk
.
parent
,
null
,
parent
)
{
private
val
base
by
lazy
{
Any
::
class
.
java
.
classLoader
!!
}
@Throws
(
ClassNotFoundException
::
class
)
override
fun
loadClass
(
name
:
String
,
resolve
:
Boolean
)
:
Class
<
*
>
=
findLoadedClass
(
name
)
?:
runCatching
{
base
.
loadClass
(
name
)
}.
getOrElse
{
runCatching
{
findClass
(
name
)
}.
getOrElse
{
err
->
runCatching
{
parent
.
loadClass
(
name
)
}.
getOrElse
{
throw
err
}
}
}
override
fun
getResource
(
name
:
String
)
=
base
.
getResource
(
name
)
?:
findResource
(
name
)
?:
parent
?.
getResource
(
name
)
@Throws
(
IOException
::
class
)
override
fun
getResources
(
name
:
String
):
Enumeration
<
URL
>
{
val
resources
=
mutableListOf
(
base
.
getResources
(
name
),
findResources
(
name
),
parent
.
getResources
(
name
))
return
object
:
Enumeration
<
URL
>
{
override
fun
hasMoreElements
():
Boolean
{
while
(
true
)
{
if
(
resources
.
isEmpty
())
return
false
if
(!
resources
[
0
].
hasMoreElements
())
{
resources
.
removeAt
(
0
)
}
else
{
return
true
}
}
}
override
fun
nextElement
():
URL
{
if
(!
hasMoreElements
())
throw
NoSuchElementException
()
return
resources
[
0
].
nextElement
()
}
}
}
}
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