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
0c9feedb
Commit
0c9feedb
authored
Nov 03, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support restarting app when obfuscated
parent
14ba002c
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
46 additions
and
57 deletions
+46
-57
Hacks.kt
app/src/main/java/com/topjohnwu/magisk/Hacks.kt
+5
-10
DownloadService.kt
...va/com/topjohnwu/magisk/model/download/DownloadService.kt
+1
-1
ManagerUpgrade.kt
...ava/com/topjohnwu/magisk/model/download/ManagerUpgrade.kt
+1
-1
GeneralReceiver.kt
...va/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt
+1
-1
MainActivity.kt
app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt
+1
-1
SplashActivity.kt
app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt
+3
-4
FlashActivity.kt
.../main/java/com/topjohnwu/magisk/ui/flash/FlashActivity.kt
+1
-1
ModulesFragment.kt
...in/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt
+1
-1
Notifications.kt
app/src/main/java/com/topjohnwu/magisk/view/Notifications.kt
+3
-3
Shortcuts.kt
app/src/main/java/com/topjohnwu/magisk/view/Shortcuts.kt
+3
-2
DynAPK.java
shared/src/main/java/com/topjohnwu/magisk/DynAPK.java
+1
-1
ProcessPhoenix.java
...ed/src/main/java/com/topjohnwu/magisk/ProcessPhoenix.java
+6
-25
DownloadActivity.java
.../src/main/java/com/topjohnwu/magisk/DownloadActivity.java
+8
-1
Mapping.java
...src/main/java/com/topjohnwu/magisk/obfuscate/Mapping.java
+11
-5
No files found.
app/src/main/java/com/topjohnwu/magisk/Hacks.kt
View file @
0c9feedb
...
...
@@ -53,18 +53,12 @@ fun Context.wrapJob(): Context = object : GlobalResContext(this) {
}
}
fun
Class
<*>.
cmp
(
pkg
:
String
=
BuildConfig
.
APPLICATION_ID
):
ComponentName
{
fun
Class
<*>.
cmp
(
pkg
:
String
):
ComponentName
{
val
name
=
ClassMap
[
this
].
name
return
ComponentName
(
pkg
,
Info
.
stub
?.
componentMap
?.
get
(
name
)
?:
name
)
}
fun
Context
.
intent
(
c
:
Class
<
*
>):
Intent
{
val
cls
=
ClassMap
[
c
]
return
Info
.
stub
?.
let
{
val
className
=
it
.
componentMap
.
getOrElse
(
cls
.
name
)
{
cls
.
name
}
Intent
().
setComponent
(
ComponentName
(
this
,
className
))
}
?:
Intent
(
this
,
cls
)
}
inline
fun
<
reified
T
>
Context
.
intent
()
=
Intent
().
setComponent
(
T
::
class
.
java
.
cmp
(
packageName
))
private
open
class
GlobalResContext
(
base
:
Context
)
:
ContextWrapper
(
base
)
{
open
val
mRes
:
Resources
get
()
=
ResourceMgr
.
resource
...
...
@@ -192,8 +186,9 @@ object ClassMap {
UpdateCheckService
::
class
.
java
to
a
.
g
::
class
.
java
,
GeneralReceiver
::
class
.
java
to
a
.
h
::
class
.
java
,
DownloadService
::
class
.
java
to
a
.
j
::
class
.
java
,
SuRequestActivity
::
class
.
java
to
a
.
m
::
class
.
java
SuRequestActivity
::
class
.
java
to
a
.
m
::
class
.
java
,
ProcessPhoenix
::
class
.
java
to
a
.
r
::
class
.
java
)
operator
fun
get
(
c
:
Class
<
*
>)
=
map
.
getOrElse
(
c
)
{
throw
IllegalArgumentException
()
}
operator
fun
get
(
c
:
Class
<
*
>)
=
map
.
getOrElse
(
c
)
{
c
}
}
app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt
View file @
0c9feedb
...
...
@@ -140,7 +140,7 @@ open class DownloadService : RemoteFileService() {
inline
operator
fun
invoke
(
context
:
Context
,
argBuilder
:
Builder
.()
->
Unit
)
{
val
app
=
context
.
applicationContext
val
builder
=
Builder
().
apply
(
argBuilder
)
val
intent
=
app
.
intent
(
DownloadService
::
class
.
java
).
putExtra
(
ARG_URL
,
builder
.
subject
)
val
intent
=
app
.
intent
<
DownloadService
>(
).
putExtra
(
ARG_URL
,
builder
.
subject
)
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
app
.
startForegroundService
(
intent
)
...
...
app/src/main/java/com/topjohnwu/magisk/model/download/ManagerUpgrade.kt
View file @
0c9feedb
...
...
@@ -38,7 +38,7 @@ private fun RemoteFileService.upgrade(apk: File, id: Int) {
patch
(
apk
,
id
)
}
else
{
// Simply relaunch the app
ProcessPhoenix
.
triggerRebirth
(
this
)
ProcessPhoenix
.
triggerRebirth
(
this
,
intent
<
ProcessPhoenix
>()
)
}
}
else
{
patch
(
apk
,
id
)
...
...
app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt
View file @
0c9feedb
...
...
@@ -63,7 +63,7 @@ open class GeneralReceiver : BaseReceiver() {
}
when
(
action
)
{
REQUEST
->
{
val
i
=
context
.
intent
(
SuRequestActivity
::
class
.
java
)
val
i
=
context
.
intent
<
SuRequestActivity
>(
)
.
setAction
(
action
)
.
putExtra
(
"socket"
,
intent
.
getStringExtra
(
"socket"
))
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
...
...
app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt
View file @
0c9feedb
...
...
@@ -60,7 +60,7 @@ open class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Na
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
if
(!
SplashActivity
.
DONE
)
{
startActivity
(
intent
(
SplashActivity
::
class
.
java
))
startActivity
(
intent
<
SplashActivity
>(
))
finish
()
}
...
...
app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt
View file @
0c9feedb
...
...
@@ -40,7 +40,7 @@ open class SplashActivity : Activity() {
Config
.
suManager
=
""
Shell
.
su
(
"pm uninstall $pkg"
).
submit
()
}
if
(
TextUtils
.
equals
(
pkg
,
packageName
)
)
{
if
(
pkg
==
packageName
)
{
runCatching
{
// We are the manager, remove com.topjohnwu.magisk as it could be malware
packageManager
.
getApplicationInfo
(
BuildConfig
.
APPLICATION_ID
,
0
)
...
...
@@ -60,10 +60,9 @@ open class SplashActivity : Activity() {
// Setup shortcuts
Shortcuts
.
setup
(
this
)
val
intent
=
intent
(
MainActivity
::
class
.
java
)
intent
.
putExtra
(
Const
.
Key
.
OPEN_SECTION
,
getIntent
().
getStringExtra
(
Const
.
Key
.
OPEN_SECTION
))
DONE
=
true
startActivity
(
intent
)
startActivity
(
intent
<
MainActivity
>().
apply
{
intent
?.
also
{
putExtras
(
it
)
}
})
finish
()
}
...
...
app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashActivity.kt
View file @
0c9feedb
...
...
@@ -60,7 +60,7 @@ open class FlashActivity : BaseActivity<FlashViewModel, ActivityFlashBinding>()
companion
object
{
private
fun
intent
(
context
:
Context
)
=
context
.
intent
(
FlashActivity
::
class
.
java
)
private
fun
intent
(
context
:
Context
)
=
context
.
intent
<
FlashActivity
>(
)
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
private
fun
intent
(
context
:
Context
,
file
:
File
)
=
intent
(
context
).
setData
(
file
.
toUri
())
...
...
app/src/main/java/com/topjohnwu/magisk/ui/module/ModulesFragment.kt
View file @
0c9feedb
...
...
@@ -28,7 +28,7 @@ class ModulesFragment : BaseFragment<ModuleViewModel, FragmentModulesBinding>()
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?)
{
if
(
requestCode
==
Const
.
ID
.
FETCH_ZIP
&&
resultCode
==
Activity
.
RESULT_OK
&&
data
!=
null
)
{
// Get the URI of the selected file
val
intent
=
activity
.
intent
(
FlashActivity
::
class
.
java
)
val
intent
=
activity
.
intent
<
FlashActivity
>(
)
intent
.
setData
(
data
.
data
).
putExtra
(
Const
.
Key
.
FLASH_ACTION
,
Const
.
Value
.
FLASH_ZIP
)
startActivity
(
intent
)
}
...
...
app/src/main/java/com/topjohnwu/magisk/view/Notifications.kt
View file @
0c9feedb
...
...
@@ -47,7 +47,7 @@ object Notifications {
}
fun
magiskUpdate
(
context
:
Context
)
{
val
intent
=
context
.
intent
(
SplashActivity
::
class
.
java
)
val
intent
=
context
.
intent
<
SplashActivity
>(
)
.
putExtra
(
Const
.
Key
.
OPEN_SECTION
,
"magisk"
)
val
stackBuilder
=
TaskStackBuilder
.
create
(
context
)
stackBuilder
.
addParentStack
(
SplashActivity
::
class
.
java
.
cmp
(
context
.
packageName
))
...
...
@@ -65,7 +65,7 @@ object Notifications {
}
fun
managerUpdate
(
context
:
Context
)
{
val
intent
=
context
.
intent
(
GeneralReceiver
::
class
.
java
)
val
intent
=
context
.
intent
<
GeneralReceiver
>(
)
.
setAction
(
Const
.
Key
.
BROADCAST_MANAGER_UPDATE
)
.
putExtra
(
Const
.
Key
.
INTENT_SET_APP
,
Info
.
remote
.
app
)
...
...
@@ -82,7 +82,7 @@ object Notifications {
}
fun
dtboPatched
(
context
:
Context
)
{
val
intent
=
context
.
intent
(
GeneralReceiver
::
class
.
java
)
val
intent
=
context
.
intent
<
GeneralReceiver
>(
)
.
setAction
(
Const
.
Key
.
BROADCAST_REBOOT
)
val
pendingIntent
=
PendingIntent
.
getBroadcast
(
context
,
Const
.
ID
.
DTBO_NOTIFICATION_ID
,
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
)
...
...
app/src/main/java/com/topjohnwu/magisk/view/Shortcuts.kt
View file @
0c9feedb
...
...
@@ -7,6 +7,7 @@ import android.content.pm.ShortcutManager
import
android.graphics.drawable.Icon
import
android.os.Build
import
androidx.annotation.RequiresApi
import
androidx.core.content.getSystemService
import
androidx.core.graphics.drawable.toAdaptiveIcon
import
androidx.core.graphics.drawable.toIcon
import
com.topjohnwu.magisk.*
...
...
@@ -19,7 +20,7 @@ object Shortcuts {
fun
setup
(
context
:
Context
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
25
)
{
val
manager
=
context
.
getSystemService
(
ShortcutManager
::
class
.
java
)
val
manager
=
context
.
getSystemService
<
ShortcutManager
>(
)
manager
?.
dynamicShortcuts
=
getShortCuts
(
context
)
}
}
...
...
@@ -28,7 +29,7 @@ object Shortcuts {
private
fun
getShortCuts
(
context
:
Context
):
List
<
ShortcutInfo
>
{
val
shortCuts
=
mutableListOf
<
ShortcutInfo
>()
val
root
=
Shell
.
rootAccess
()
val
intent
=
context
.
intent
(
SplashActivity
::
class
.
java
)
val
intent
=
context
.
intent
<
SplashActivity
>(
)
fun
getIcon
(
id
:
Int
):
Icon
{
return
if
(
Build
.
VERSION
.
SDK_INT
>=
26
)
...
...
shared/src/main/java/com/topjohnwu/magisk/DynAPK.java
View file @
0c9feedb
...
...
@@ -11,7 +11,7 @@ import static android.os.Build.VERSION.SDK_INT;
public
class
DynAPK
{
private
static
final
int
STUB_VERSION
=
3
;
private
static
final
int
STUB_VERSION
=
4
;
// Indices of the object array
private
static
final
int
STUB_VERSION_ENTRY
=
0
;
...
...
shared/src/main/java/com/topjohnwu/magisk/ProcessPhoenix.java
View file @
0c9feedb
...
...
@@ -22,7 +22,6 @@ import android.content.Intent;
import
android.os.Bundle
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
static
android
.
content
.
Intent
.
FLAG_ACTIVITY_CLEAR_TASK
;
import
static
android
.
content
.
Intent
.
FLAG_ACTIVITY_NEW_TASK
;
...
...
@@ -37,27 +36,11 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
* Trigger process recreation by calling {@link #triggerRebirth} with a {@link Context} instance.
*/
public
class
ProcessPhoenix
extends
Activity
{
private
static
final
String
KEY_RESTART_INTENT
S
=
"phoenix_restart_intents
"
;
private
static
final
String
KEY_RESTART_INTENT
=
"phoenix_restart_intent
"
;
/**
* Call to restart the application process using the {@linkplain Intent#CATEGORY_DEFAULT default}
* activity as an intent.
* <p>
* Behavior of the current process after invoking this method is undefined.
*/
public
static
void
triggerRebirth
(
Context
context
)
{
triggerRebirth
(
context
,
getRestartIntent
(
context
));
}
/**
* Call to restart the application process using the specified intents.
* <p>
* Behavior of the current process after invoking this method is undefined.
*/
public
static
void
triggerRebirth
(
Context
context
,
Intent
...
nextIntents
)
{
Intent
intent
=
new
Intent
(
context
,
a
.
r
.
class
);
public
static
void
triggerRebirth
(
Context
context
,
Intent
intent
)
{
intent
.
addFlags
(
FLAG_ACTIVITY_NEW_TASK
);
// In case we are called with non-Activity context.
intent
.
put
ParcelableArrayListExtra
(
KEY_RESTART_INTENTS
,
new
ArrayList
<>(
Arrays
.
asList
(
nextIntents
)
));
intent
.
put
Extra
(
KEY_RESTART_INTENT
,
getRestartIntent
(
context
));
context
.
startActivity
(
intent
);
if
(
context
instanceof
Activity
)
{
((
Activity
)
context
).
finish
();
...
...
@@ -73,17 +56,15 @@ public class ProcessPhoenix extends Activity {
return
defaultIntent
;
}
throw
new
IllegalStateException
(
"Unable to determine default activity for "
+
packageName
+
". Does an activity specify the DEFAULT category in its intent filter?"
);
throw
new
IllegalStateException
();
}
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
ArrayList
<
Intent
>
intents
=
getIntent
().
getParcelableArrayListExtra
(
KEY_RESTART_INTENTS
);
startActivit
ies
(
intents
.
toArray
(
new
Intent
[
0
])
);
Intent
intent
=
getIntent
().
getParcelableExtra
(
KEY_RESTART_INTENT
);
startActivit
y
(
intent
);
finish
();
Runtime
.
getRuntime
().
exit
(
0
);
}
...
...
stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java
View file @
0c9feedb
...
...
@@ -4,6 +4,8 @@ import android.app.Activity;
import
android.app.AlertDialog
;
import
android.app.Application
;
import
android.app.ProgressDialog
;
import
android.content.ComponentName
;
import
android.content.Intent
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.util.Log
;
...
...
@@ -11,6 +13,7 @@ import android.util.Log;
import
com.topjohnwu.magisk.net.ErrorHandler
;
import
com.topjohnwu.magisk.net.Networking
;
import
com.topjohnwu.magisk.net.ResponseListener
;
import
com.topjohnwu.magisk.obfuscate.Mapping
;
import
com.topjohnwu.magisk.obfuscate.RawData
;
import
com.topjohnwu.magisk.utils.APKInstall
;
...
...
@@ -48,7 +51,11 @@ public class DownloadActivity extends Activity {
// Download and relaunch the app
Networking
.
get
(
apkLink
)
.
setErrorHandler
(
err
)
.
getAsFile
(
MANAGER_APK
,
f
->
ProcessPhoenix
.
triggerRebirth
(
this
));
.
getAsFile
(
MANAGER_APK
,
apk
->
{
Intent
intent
=
new
Intent
()
.
setComponent
(
new
ComponentName
(
this
,
Mapping
.
inverse
(
"a.r"
)));
ProcessPhoenix
.
triggerRebirth
(
this
,
intent
);
});
}
else
{
// Download and upgrade the app
Application
app
=
getApplication
();
...
...
stub/src/main/java/com/topjohnwu/magisk/obfuscate/Mapping.java
View file @
0c9feedb
...
...
@@ -7,9 +7,14 @@ import static com.topjohnwu.magisk.DynAPK.Data;
public
class
Mapping
{
private
static
Map
<
String
,
String
>
map
=
new
HashMap
<>();
private
static
Map
<
String
,
String
>
inverseMap
;
static
{
map
.
put
(
"a.x"
,
"androidx.work.impl.background.systemjob.SystemJobService"
);
inverseMap
=
new
HashMap
<>(
map
.
size
());
for
(
Map
.
Entry
<
String
,
String
>
e
:
map
.
entrySet
())
{
inverseMap
.
put
(
e
.
getValue
(),
e
.
getKey
());
}
}
public
static
String
get
(
String
name
)
{
...
...
@@ -17,13 +22,14 @@ public class Mapping {
return
n
!=
null
?
n
:
name
;
}
public
static
String
inverse
(
String
name
)
{
String
n
=
inverseMap
.
get
(
name
);
return
n
!=
null
?
n
:
name
;
}
public
static
Data
data
()
{
Map
<
String
,
String
>
componentMap
=
new
HashMap
<>(
map
.
size
());
for
(
Map
.
Entry
<
String
,
String
>
e
:
map
.
entrySet
())
{
componentMap
.
put
(
e
.
getValue
(),
e
.
getKey
());
}
Data
data
=
new
Data
();
data
.
componentMap
=
component
Map
;
data
.
componentMap
=
inverse
Map
;
return
data
;
}
...
...
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