-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
720 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/src/main/java/moe/fuqiuluo/portal/android/root/ShellUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package moe.fuqiuluo.portal.android.root | ||
|
||
object ShellUtils { | ||
fun hasRoot(): Boolean { | ||
val runtime = Runtime.getRuntime() | ||
try { | ||
val process = runtime.exec("su") | ||
process.outputStream.write("exit\n".toByteArray()) | ||
process.outputStream.flush() | ||
process.waitFor() | ||
return process.exitValue() == 0 | ||
} catch (e: Exception) { | ||
return false | ||
} | ||
} | ||
|
||
fun setEnforceMode(enabled: Boolean) { | ||
val runtime = Runtime.getRuntime() | ||
try { | ||
val process = runtime.exec("su") | ||
process.outputStream.write("setenforce ${if (enabled) "1" else "0"}\n".toByteArray()) | ||
process.outputStream.write("exit\n".toByteArray()) | ||
process.outputStream.flush() | ||
process.waitFor() | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
|
||
fun executeCommand(command: String): String { | ||
val runtime = Runtime.getRuntime() | ||
try { | ||
val process = runtime.exec("su") | ||
process.outputStream.write("$command\n".toByteArray()) | ||
process.outputStream.write("exit\n".toByteArray()) | ||
process.outputStream.flush() | ||
process.waitFor() | ||
if (process.exitValue() != 0) { | ||
return process.errorStream.bufferedReader().readText() | ||
} | ||
return process.inputStream.bufferedReader().readText() | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
return "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
cmake_minimum_required(VERSION 3.22.1) | ||
|
||
project("Portal") | ||
|
||
set(CMAKE_CXX_STANDARD 23) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
# MumuEmulator crash? if enable x86_64 | ||
|
||
#find_package(lsplant REQUIRED CONFIG) | ||
find_package(dobby REQUIRED CONFIG) | ||
|
||
add_library(portal SHARED | ||
main.cpp | ||
elf_util.cpp | ||
sensor_hook.cpp) | ||
|
||
target_link_libraries(portal android log) | ||
target_link_libraries(portal dobby::dobby) | ||
#target_link_libraries(${CMAKE_PROJECT_NAME} lsplant::lsplant) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef PORTAL_DOBBY_HOOK_H | ||
#define PORTAL_DOBBY_HOOK_H | ||
|
||
#include <unistd.h> | ||
#include <dobby.h> | ||
|
||
#endif //PORTAL_DOBBY_HOOK_H |
Oops, something went wrong.