Skip to content

Commit

Permalink
fix: issue with permission denied on files
Browse files Browse the repository at this point in the history
  • Loading branch information
JunioJsv committed Apr 10, 2021
1 parent f3b4c5b commit bd57a04
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
applicationId 'juniojsv.mtk.easy.su'
minSdkVersion 21
targetSdkVersion 30
versionCode 205
versionName "2.0.5"
versionCode 206
versionName "2.0.6"
}

buildTypes {
Expand Down
49 changes: 27 additions & 22 deletions app/src/main/java/juniojsv/mtk/easy/su/ExploitHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,14 @@ class ExploitHandler(

override fun doInBackground(): ExploitResult {
val log = StringBuilder("Mtk-easy-su ${BuildConfig.VERSION_NAME}\n")
val files = arrayListOf<File>()
with(context) {
if (filesDir.absoluteFile.listFiles()?.isEmpty() == true ||
preferences.getString(
PREF_EXTRACTED_BY_VERSION,
String()
) != BuildConfig.VERSION_NAME ||
BuildConfig.DEBUG
) {

preferences.edit(true) {
putString(PREF_EXTRACTED_BY_VERSION, BuildConfig.VERSION_NAME)
}

File(filesDir.absoluteFile, "64").mkdir()
File(filesDir.absoluteFile, "32").mkdir()
assets?.list("")?.forEach { name ->
when (name) {
"magisk-boot.sh", "magiskinit32", "magiskinit64", "mtk-su32", "mtk-su64" -> {
File(filesDir.absoluteFile, "64").mkdir()
File(filesDir.absoluteFile, "32").mkdir()
assets?.list("")?.forEach { name ->
when (name) {
"magisk-boot.sh", "magiskinit32", "magiskinit64", "mtk-su32", "mtk-su64" -> {
try {
val file: File =
when {
name.endsWith("32") -> File(
Expand All @@ -55,12 +45,15 @@ class ExploitHandler(
val output = FileOutputStream(file)
assets.open(name).copyTo(output, 512)
output.close()
try {
Runtime.getRuntime().exec("chmod 700 ${file.absolutePath}")
.waitFor()
} catch (e: Exception) {
log.append(e.message)
Runtime.getRuntime().exec("chmod 510 ${file.absolutePath}")
.waitFor()
files.add(file)
file.exists().let { success ->
if (success)
log.append("extracted ${file.toRelativeString(context.filesDir)}\n")
}
} catch (e: Exception) {
log.append(e.message)
}
}
}
Expand All @@ -71,6 +64,7 @@ class ExploitHandler(

arrayOf(
"getprop ro.vendor.product.model",
"getprop ro.build.version.release",
"date",
"ls -R -1 -h -g ${context.filesDir.absolutePath}",
"cat /proc/cpuinfo", "cat /proc/meminfo",
Expand All @@ -86,6 +80,17 @@ class ExploitHandler(

val wasSucceeded = File("/sbin/su").exists()

try {
files.forEach { file ->
file.deleteRecursively().let { success ->
if (success)
log.append("deleted ${file.toRelativeString(context.filesDir)}\n")
}
}
} catch (e: Exception) {
log.append(e.message)
}

return ExploitResult(wasSucceeded, log.toString())
}

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/juniojsv/mtk/easy/su/Keys.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ const val PREF_SECURITY_PATCH_IGNORED = "security_patch_warning_ignored"
const val PREF_STARTUP_WARNING = "startup_warning"
const val PREF_RUN_AS_64_BITS = "run_as_64"
const val PREF_AUTO_SEND_LOGS = "auto_send_logs"
const val PREF_EXTRACTED_BY_VERSION = "extracted_by_version"
const val LOG_ADMOB_INITIALIZATION = "admob_initialization"
const val LOG_VERITY_UPDATE = "verity_update"

0 comments on commit bd57a04

Please sign in to comment.