Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
UxHarshit committed Dec 10, 2022
0 parents commit 3cdd32d
Show file tree
Hide file tree
Showing 55 changed files with 1,653 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
67 changes: 67 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'com.teamuxh.uxh_toolkit'
compileSdk 32

defaultConfig {
applicationId "com.teamuxh.uxh_toolkit"
minSdk 23
targetSdk 32
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ''
}
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.18.1'
}
}
}

dependencies {
def libsuVersion = '5.0.3'

// The core module that provides APIs to a shell
implementation "com.github.topjohnwu.libsu:core:${libsuVersion}"

// Optional: APIs for creating root services. Depends on ":core"
implementation "com.github.topjohnwu.libsu:service:${libsuVersion}"

// Optional: Provides remote file system support
implementation "com.github.topjohnwu.libsu:nio:${libsuVersion}"

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.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">
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:extractNativeLibs="true"
android:theme="@style/Theme.UxH_ToolKit"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>

</manifest>
14 changes: 14 additions & 0 deletions app/src/main/aidl/com/teamuxh/uxh_toolkit/ITestRoot.aidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// ITestRoot.aidl
package com.teamuxh.uxh_toolkit;

// Declare any non-default types here with import statements

interface ITestRoot {
/** * Demonstrates some basic types that you can use as parameters
* and return values in AIDL.
*/
int getUid();
int getAppPid(String packageName);
int getLibAddress(int pid,String libName);
String[] getLoadedLibrary(int pid);
}
26 changes: 26 additions & 0 deletions app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.18.1)


project("uxh_toolkit")

add_library(uxh_toolkit
SHARED
main.cpp)

find_library(log-lib
log)

target_link_libraries(
uxh_toolkit
${log-lib})

add_library(
root
SHARED
rootMain.cpp
)
find_library(log-lib
log)
target_link_libraries(
root
${log-lib})
3 changes: 3 additions & 0 deletions app/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <jni.h>
#include <dirent.h>
#include <fstream>
126 changes: 126 additions & 0 deletions app/src/main/cpp/rootMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include <jni.h>
#include <dirent.h>
#include <fstream>
#include <iostream>
#include <string>
#include <unistd.h>
#include <list>
#include <vector>
#include <android/log.h>
#include <unordered_set>
#include <sstream>
#include <set>
#include <algorithm>
#include <map>

//
// Created by hurri on 23-11-2022.
//


extern "C"
JNIEXPORT jint JNICALL
Java_com_teamuxh_uxh_1toolkit_constant_NativeRoot_00024Companion_nativeGetUid(JNIEnv *env,
jobject thiz) {
return (int) getuid();
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_teamuxh_uxh_1toolkit_constant_NativeRoot_00024Companion_nativeGetPid(JNIEnv *env,
jobject thiz,
jstring package_name) {
const char *packagename = env->GetStringUTFChars(package_name, nullptr);
int id = -1;
DIR *dir;
FILE *fp;
char filename[512];
char cmdline[256];
struct dirent *entry;
dir = opendir("/proc");
while ((entry = readdir(dir)) != NULL) {
id = atoi(entry->d_name);
if (id != 0) {
sprintf(filename, "/proc/%d/cmdline", id);
fp = fopen(filename, "r");
if (fp) {
fgets(cmdline, sizeof(cmdline), fp);
fclose(fp);

if (strcmp(packagename, cmdline) == 0) {
return id;
}
}
}
}
closedir(dir);
return -1;
}




extern "C"
JNIEXPORT jint JNICALL
Java_com_teamuxh_uxh_1toolkit_constant_NativeRoot_00024Companion_getModuleAddress(JNIEnv *env,
jobject thiz,
jint pid,
jstring lib_name) {
const char *module_name = env->GetStringUTFChars(lib_name, 0);
FILE *fp;
long addr = 0;
char *pch;
char filename[32];
char line[1024];
snprintf(filename, sizeof(filename), "/proc/%d/maps", pid);
fp = fopen(filename, "r");
if (fp != NULL) {
while (fgets(line, sizeof(line), fp)) {
if (strstr(line, module_name)) {
pch = strtok(line, "-");
addr = strtoul(pch, NULL, 16);
if (addr == 0x8000)
addr = 0;
break;
}
}
fclose(fp);

}
return addr;
}

void test() {

}

extern "C"
JNIEXPORT jobjectArray JNICALL
Java_com_teamuxh_uxh_1toolkit_constant_NativeRoot_00024Companion_getLoadedLibraries(JNIEnv *env,
jobject thiz,
jint pid) {
jobjectArray pArray = nullptr;
char filename[32];
snprintf(filename, sizeof(filename), "/proc/%d/maps", pid);
std::ifstream file(filename);
std::unordered_set<std::string> values;
std::string line;
while (std::getline(file, line)) {
std::istringstream iss(line);
std::string word;
for (int i = 0; i < 6; ++i) {
iss >> word;
if (i == 5 && word.find(".so") != std::string::npos)
values.insert(word);
}
}
file.close();
std::vector<std::string> vecValues(values.begin(), values.end());
std::sort(vecValues.begin(), vecValues.end());
pArray = env->NewObjectArray(vecValues.size(), env->FindClass("java/lang/String"),
nullptr);
for (int i = 0; i < vecValues.size(); i++) {
env->SetObjectArrayElement(pArray, i, env->NewStringUTF(vecValues[i].c_str()));
}

return pArray;
}
30 changes: 30 additions & 0 deletions app/src/main/java/com/teamuxh/uxh_toolkit/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.teamuxh.uxh_toolkit

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.teamuxh.uxh_toolkit.ui.main.MainFragment
import com.topjohnwu.superuser.Shell

class MainActivity : AppCompatActivity() {

companion object{
init {
Shell.enableVerboseLogging = true
Shell.setDefaultBuilder(
Shell.Builder.create()
.setFlags(Shell.FLAG_REDIRECT_STDERR)
.setTimeout(10)
)
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.replace(R.id.container, MainFragment())
.commitNow()
}

}
}
Loading

0 comments on commit 3cdd32d

Please sign in to comment.