Skip to content

Commit

Permalink
Mtk Easy Su
Browse files Browse the repository at this point in the history
  • Loading branch information
JunioJsv committed Feb 4, 2020
0 parents commit 1c2c338
Show file tree
Hide file tree
Showing 44 changed files with 1,190 additions and 0 deletions.
24 changes: 24 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Mtk Easy Su
- This app set up bootless root access with [Magisk](https://github.com/topjohnwu/Magisk) and Mtk-su (by [Diplomatic](https://forum.xda-developers.com/member.php?u=8132642)@Xda) on MediaTek Android devices.
- Download the latest version [here](https://github.com/JunioJsv/mediatek-easy-root/releases/latest)

### Notes :memo:
- (:warning:__Required__) To manage root access for each application, you must download [Magisk manager](https://github.com/topjohnwu/Magisk/releases/tag/manager-v7.1.1) (__v7.1.1__)
- (:warning:__Required__) Before installing the app make sure that **google play protect is disabled**, in recent weeks the play store has marked the app as harmful for no reason.
- To check if you have been granted root access, check the value returned by the log, when it is 0 is because it worked and you have root access, the log below is of a mediatek that this app was successful.
```sh
param1: 0x1000, param2: 0x8040, type: 4
Building symbol table
kallsyms_addresses pa 0x40e81240
kallsyms_num_syms 81314, addr_count 81314
kallsyms_names pa 0x40ed08e0, size 1013690
kallsyms_markers pa 0x40fc80a0
kallsyms_token_table pa 0x40fc85a0
kallsyms_token_index pa 0x40fc8950
Patching credentials
Parsing current_is_single_threaded
c0478518: MOVW R0, #0x8d60
c047851c: MOVT R0, #0xc162
init_task VA: 0xc1628d60
Potential list_head tasks at offset 0x2b0
comm swapper/0 at offset 0x430
Found own task_struct at node 1
cred VA: 0xcdf01480
Parsing avc_denied
c0cdea6c: MOVW R12, #0x77e4
c0cdea70: MOVT R12, #0xc190
selinux_enforcing VA: 0xc19077e4
Setting selinux_enforcing
Switched selinux to permissivearmv7l machine
starting /system/bin/sh
UID: 0 cap: 3fffffffff selinux: permissive
returned 0
```
> _If for some reason the script fails on the first attempt, try again. The second attempt is sometimes successful._
### Tested devices :heavy_check_mark:
| Device | Model | Chipset | Result |
|-----------------|:-------:|:----------------:|:-------:|
| Lg K10 | M250DS | MediaTek MT6750 | Success |
| Lg K10 Power | M320TV | MediaTek MT6750 | Success |
| Lg K10 TV | K430DSF | MediaTek MT6753 | Success |
| Lg K8 | K350 | Mediatek MT6735 | Fail |
| Lg K4 | X230DS | MediaTek MT6737M | Success |
| Motorola Moto C | XT1756 | Mediatek MT6737M | Success |
| Motorola Moto E4| XT1773 | Mediatek MT6737 | Success |
| Alcatel A3 LX | 9008X | Mediatek MT8735B | Success |
| Alcatel 1 | 5033T | Mediatek MT6739 | Success |
| Alcatel U5 3G | 4047A | Mediatek MT6580M | Fail |
| Blu Studio X8 HD| S532 | Mediatek MT6580 | Fail |
| Nook Tablet 10.1|BNTV650|Mediatek A35-MT8167A| Success |
|ZTE Blade A7 Prime| OEM |Mediatek A22-MT6761| Success |

### Acknowledgments :handshake:
- This app was based on [this](https://forum.xda-developers.com/showpost.php?p=79626434&postcount=135) tutorial.
- Thanks to [Diplomatic](https://forum.xda-developers.com/member.php?u=8132642) for writing the script that makes this app possible.
- Thanks to everyone on the LG K10 XDA Forum.
- Thanks to John Wu for Magisk Manager. [@topjohnwu](https://twitter.com/topjohnwu)

### Warning :warning:
WARNING: DO NOT UPDATE MAGISK THROUGH MAGISK MANAGER ON A LOCKED BOOTLOADER OR YOU WILL BRICK YOUR DEVICE.
<p align=center>I'm not responsible for anything '_'</p>
2 changes: 2 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/release
32 changes: 32 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
defaultConfig {
applicationId 'juniojsv.mtk.easy.su'
minSdkVersion 21
targetSdkVersion 29
versionCode 5
versionName "1.0.5"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'androidx.cardview:cardview:1.0.0'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
32 changes: 32 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="juniojsv.mtk.easy.su">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<receiver android:name=".RunOnBoot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>

<activity android:name=".MainActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
Binary file added app/src/main/assets/magiskinit
Binary file not shown.
Binary file added app/src/main/assets/mtk-su
Binary file not shown.
102 changes: 102 additions & 0 deletions app/src/main/assets/suboot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/system/bin/sh
#
# Updated: Out 10, 2019
# by diplomatic and JunioJsv
#
# WARNING: DO NOT UPDATE MAGISK THROUGH MAGISK MANAGER OR YOU WILL BRICK YOUR
# DEVICE ON A LOCKED BOOTLOADER
#

HOMEDIR=$1

SU_MINISCRIPT='
# Magisk function to find boot partition and prevent the installer from finding
# it again
toupper() {
echo "$@" | tr "[:lower:]" "[:upper:]"
}
grep_prop() {
local REGEX="s/^$1=//p"
shift
local FILES=$@
sed -n "$REGEX" $FILES 2>/dev/null | head -n 1
}
find_block() {
for BLOCK in "$@"; do
DEVICES=`find /dev/block -type l -iname $BLOCK` 2>/dev/null
for DEVICE in $DEVICES; do
if [ -h "$DEVICE" ]; then
cd ${DEVICE%/*}
BASENAME="${DEVICE##*/}"
mv "$BASENAME" ".$BASENAME"
cd -
fi
done
done
# Fallback by parsing sysfs uevents
for uevent in /sys/dev/block/*/uevent; do
local PARTNAME=`grep_prop PARTNAME $uevent`
for BLOCK in "$@"; do
if [ "`toupper $BLOCK`" = "`toupper $PARTNAME`" ]; then
#echo /dev/block/$DEVNAME
#return 0
chmod 0 $uevent
fi
done
done
return 1
}
# Root only at this point; hoping selinux is permissive
if [ $(id -u) != 0 ] || [ "$(getenforce)" != "Permissive" ]; then
echo "Root user only" >&2
exit 1
fi
cd $HOMEDIR
# Patch selinux policy -- error messages here are normal
./magiskpolicy --live --magisk "allow magisk * * *"
if [ ! -f /sbin/.init-stamp ]; then
# Create tmpfs /xbin overlay
./magisk --startup
if [ ! -f /sbin/magiskinit ] || [ ! -f /sbin/magisk.bin ]; then
echo "Bad /sbin mount?" >&2
setenforce 1
exit 1
fi
# Copy binaries
cp magiskinit /sbin/
export PATH=/sbin:$PATH
magiskinit -x magisk /sbin/magisk.bin
# Finish startup calls
magisk --post-fs-data
magisk --service
magisk --boot-complete
touch /sbin/.init-stamp
fi
# Disaster prevention
SLOT=$(getprop ro.boot.slot_suffix)
find_block boot$SLOT
setenforce 1
'

mkdir -p $HOMEDIR
cd $HOMEDIR || exit 1

./magiskinit -x magisk ./magisk || exit 1
chmod 755 magisk
ln -fs magiskinit magiskpolicy

# start SU daemon
export HOMEDIR
echo "$SU_MINISCRIPT" | ./mtk-su -v
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions app/src/main/java/juniojsv/mtk/easy/su/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package juniojsv.mtk.easy.su

import android.content.ClipData
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
import java.lang.ref.WeakReference

// JunioJsv 04/02/2020

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
supportActionBar?.elevation = 0.0f

val preferences = getSharedPreferences("preferences", Context.MODE_PRIVATE)

version_text.text = String.format("Version %s",
BuildConfig.VERSION_NAME
)

switch_run_on_boot.apply {
isChecked = preferences.getBoolean("run_on_boot", false)
setOnCheckedChangeListener { _, isChecked ->
preferences.edit().apply {
putBoolean("run_on_boot", isChecked).commit()
}.apply()
}
}

button_github.setOnClickListener {
startActivity(Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(
"https://github.com/JunioJsv/mtk-easy-su"
)
})
}

button_xda.setOnClickListener {
startActivity(Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(
"https://forum.xda-developers.com/android/development/amazing-temp-root-mediatek-armv8-t3922213/post79626434#post79626434"
)
})
}

button_try_root.setOnClickListener {
button_try_root.isEnabled = false
TryRoot(WeakReference(applicationContext)) { success, log ->
button_try_root.isEnabled = success == false
this.log.text = log
button_copy.visibility = View.VISIBLE
}.execute()
}

button_copy.setOnClickListener {
(getSystemService(Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager)
.setPrimaryClip(ClipData.newPlainText("log", log.text))

}
}
}
23 changes: 23 additions & 0 deletions app/src/main/java/juniojsv/mtk/easy/su/RunOnBoot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package juniojsv.mtk.easy.su

import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.widget.Toast
import java.lang.ref.WeakReference

// JunioJsv 04/02/2020

class RunOnBoot : BroadcastReceiver() {

@SuppressLint("UnsafeProtectedBroadcastReceiver")
override fun onReceive(context: Context?, intent: Intent?) {
context?.apply {
if (getSharedPreferences("preferences", Context.MODE_PRIVATE).getBoolean("run_on_boot", false)) {
Toast.makeText(this, "Trying to ensure root access", Toast.LENGTH_SHORT).show()
TryRoot(WeakReference(this)).execute()
}
}
}
}
Loading

0 comments on commit 1c2c338

Please sign in to comment.