Commit Graph

29 Commits

Author SHA1 Message Date
topjohnwu 40eda05a30 Make main app fully independent from the stub
- Skip 0x7f01XXXX - 0x7f05XXXX resource IDs in the main app; they are
reserved for stub resources
- Support sending additional data from host to guest
- Use resource mapping passed from host when they are being sent
to the system framework (notifications and shortcuts)
2019-10-17 02:55:42 -04:00
topjohnwu 9f9de8c43b Obfuscate WorkManager components
Remove unused components and hack the context sent into WorkManager
2019-10-16 17:03:55 -04:00
topjohnwu 43bda2d4a4 Allow component classname obfuscation 2019-10-16 04:38:31 -04:00
topjohnwu 5ffb9eaa5b Support loading Magisk Manager from stub on 9.0+
In the effort of preventing apps from crawling APK contents across the
whole installed app list to detect Magisk Manager, the solution here
is to NOT install the actual APK into the system, but instead
dynamically load the full app at runtime by a stub app. The full APK
will be stored in the application's private internal data where
non-root processes cannot read or scan.

The basis of this implementation is the class "AppComponentFactory"
that is introduced in API 28. If assigned, the system framework will
delegate app component instantiation to our custom implementation,
which allows us to do all sorts of crazy stuffs, in our case dynamically
load classes and create objects that does not exist in our APK.

There are a few challenges to achieve our goal though. First, Java
ClassLoaders follow the "delegation pattern", which means class loading
resolution will first be delegated to the parent loader before we get
a chance to do anything. This includes DexClassLoader, which is what
we will be using to load DEX files at runtime. This is a problem
because our stub app and full app share quite a lot of class names.
A custom ClassLoader, DynamicClassLoader, is created to overcome this
issue: it will always load classes in its current dex path before
delegating it to the parent.

Second, all app components (with the exception of runtime
BroadcastReceivers) are required to be declared in AndroidManifest.xml.
The full Magisk Manager has quite a lot of components (including
those from WorkManager and Room). The solution is to copy the complete
AndroidManifest.xml from the full app to the stub, and our
AppComponentFactory is responsible to construct the proper objects or
return dummy implementations in case the full APK isn't downloaded yet.

Third, other than classes, all resources required to run the full app
are also not bundled with the stub APK. We have to call an internal API
`AssetManager.addAssetPath(String)` to add our downloaded full APK into
AssetManager in order to access resources within our full app. That
internal API has existed forever, and is whitelisted from restricted
API access on modern Android versions, so it is pretty safe to use.

Fourth, on the subject of resources, some resources are not just being
used by our app at runtime. Resources such as the app icon, app label,
launch theme, basically everything referred in AndroidManifest.xml,
are used by the system to display the app properly. The system get these
resources via resource IDs and direct loading from the installed APK.
This subset of resources would have to be copied into the stub to make
the app work properly.

Fifth, resource IDs are used all over the place in XMLs and Java code.
The resource IDs in the stub and full app cannot missmatch, or
somewhere, either it be the system or AssetManager, will refer to the
incorrect resource. The full app will have to include all resources in
the stub, and all of them have to be assigned to the exact same IDs in
both APKs. To achieve this, we use AAPT2's "--emit-ids" option to dump
the resource ID mapping when building the stub, and "--stable-ids" when
building the full APK to make sure all overlapping resources in full
and stub are always assigned to the same ID.

Finally, both stub and full app have to work properly independently.
On 9.0+, the stub will have to first launch an Activity to download
the full APK before it can relaunch into the full app. On pre-9.0, the
stub should behave as it always did: download and prompt installation
to upgrade itself to full Magisk Manager. In the full app, the goal
is to introduce minimal intrusion to the code base to make sure this
whole thing is maintainable in the future. Fortunately, the solution
ends up pretty slick: all ContextWrappers in the app will be injected
with custom Contexts. The custom Contexts will return our patched
Resources object and the ClassLoader that loads itself, which will be
DynamicClassLoader in the case of running as a delegate app.
By directly patching the base Context of ContextWrappers (which covers
tons of app components) and in the Koin DI, the effect propagates deep
into every aspect of the code, making this change basically fully
transparent to almost every piece of code in full Magisk Manager.

After this commit, the stub app is able to properly download and launch
the full app, with most basic functionalities working just fine.
Do not expect Magisk Manager upgrades and hiding (repackaging) to
work properly, and some other minor issues might pop up.
This feature is still in the early WIP stages.
2019-10-14 03:49:17 -04:00
topjohnwu 674d272eaa Support pre-5.0 without GMS
Fix #1912
2019-10-11 01:46:15 -04:00
topjohnwu 5fa452aa74 Multiple minor changes 2019-08-12 01:54:33 -07:00
topjohnwu 8f07747452 Remove net module 2019-08-04 18:33:20 -07:00
topjohnwu 71d855e836 Cleanup more code 2019-08-04 13:47:14 -07:00
topjohnwu 33b7ab593c Migrate PatchAPK to Kotlin 2019-08-04 13:00:27 -07:00
topjohnwu 9784353223 Fix ActivityTracker
Koin does not support nullable types
2019-07-29 04:18:05 -07:00
topjohnwu 7d93ca5c73 Modernize MagiskInstaller 2019-07-29 04:05:54 -07:00
topjohnwu 9adfb382e8 Only launch FlashActivity if app is foreground 2019-07-28 03:38:27 -07:00
topjohnwu d1ff7e0ffe Move extensions to its own package 2019-07-28 02:10:22 -07:00
topjohnwu 42e7db8d13 Modernize Repo class for Magisk modules
- Use Kotlin
- Use Room database
- Use retrofit for networking
- Use RxJava pipeline for repo updating
2019-07-28 01:54:34 -07:00
topjohnwu caa9df86bc Switch to R8 friendly room-runtime 2019-06-07 00:17:00 -07:00
Viktor De Pasquale d1dfda405f Removed Kotpref and replaced it with PreferenceModel 2019-06-04 00:59:57 -07:00
Viktor De Pasquale d546733287 Removed direct static usages of database from app 2019-05-12 17:25:26 +02:00
Viktor De Pasquale c275326d59 Removed direct static usages of database from app 2019-05-12 16:56:56 +02:00
Viktor De Pasquale d4561507b8 Raised deprecation level on old database 2019-05-12 14:37:24 +02:00
Viktor De Pasquale d39d885ec2 Removed repo db helper 2019-05-10 18:21:07 +02:00
Viktor De Pasquale 10e903c9fc Added direct fetch from network and fixed build issues 2019-05-06 20:12:31 +02:00
topjohnwu d1ed502e03 Multidex debug only 2019-05-02 14:06:08 -04:00
Viktor De Pasquale a9b00dd537 Updated deprecation statements and moved components init after attaching base context
This needed to be done in order to get the Koin working as it requires injection before calling onCreate
2019-04-27 11:27:42 +02:00
Viktor De Pasquale 52c83b2916 Updated su screen with new arch
Added new Dialog for further use
2019-04-26 21:23:58 +02:00
Viktor De Pasquale 11d716a3c8 Updated splash screen with new arch 2019-04-22 16:00:48 +02:00
topjohnwu 71ce0de606 Make debug buildable 2019-04-19 02:11:22 -04:00
Viktor De Pasquale 15aa813416 Migrated to compat shared prefs and fixed it not reacting to changes
Added back dark theme
2019-04-17 14:03:25 +02:00
Viktor De Pasquale 9bb4dfad13 Added back version checking (and version boxes) after transitioning homepage to MVVM
Fixed several errors caused along the way
2019-04-14 11:00:29 +02:00
Viktor De Pasquale 2d58c725e0 Added koin, databinding and navigation components
Converted App class and Main activity to Kotlin. With that refactored fields within App class to allow lazy initialization

BEWARE: at this point the navigation is very much broken, won't let you anywhere beyond home screen
2019-04-11 20:01:49 +02:00