├── PermissionManager
├── .gitignore
├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── gradle.xml
│ └── misc.xml
├── app
│ ├── .gitignore
│ ├── appKey.jks
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── linux
│ │ │ └── permissionmanager
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── cpp
│ │ │ ├── CMakeLists.txt
│ │ │ ├── cJSON.cpp
│ │ │ ├── cJSON.h
│ │ │ ├── native-lib.cpp
│ │ │ ├── root.cpp
│ │ │ └── urlEncodeUtils.h
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── linux
│ │ │ │ └── permissionmanager
│ │ │ │ ├── Adapter
│ │ │ │ ├── SelectAppRecyclerAdapter.java
│ │ │ │ └── SelectFileRecyclerAdapter.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── Model
│ │ │ │ ├── PopupWindowOnTouchClose.java
│ │ │ │ ├── SelectAppRecyclerItem.java
│ │ │ │ └── SelectFileRecyclerItem.java
│ │ │ │ └── Utils
│ │ │ │ ├── DialogUtils.java
│ │ │ │ └── ScreenInfoUtils.java
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── line.xml
│ │ │ ├── line_drawable.xml
│ │ │ ├── ripple_grey.xml
│ │ │ ├── shape_wnd_grey_corner.xml
│ │ │ ├── thumb.xml
│ │ │ └── thumb_drawable.xml
│ │ │ ├── layout
│ │ │ ├── activity_main.xml
│ │ │ ├── select_app_recycler_item.xml
│ │ │ ├── select_app_wnd.xml
│ │ │ ├── select_file_recycler_item.xml
│ │ │ └── select_file_wnd.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── values-night
│ │ │ └── themes.xml
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── themes.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── linux
│ │ └── permissionmanager
│ │ └── ExampleUnitTest.java
├── build.gradle
├── build_apk
│ └── PermissionManager.apk
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── README.md
├── ScreenCap
├── 1.png
├── 3.png
└── 4.png
├── patch_kernel_root
├── 3rdparty
│ ├── capstone-4.0.2-win64
│ │ ├── CREDITS.TXT
│ │ ├── ChangeLog
│ │ ├── LICENSE.TXT
│ │ ├── LICENSE_LLVM.TXT
│ │ ├── README.md
│ │ ├── RELEASE_NOTES
│ │ ├── SPONSORS.TXT
│ │ ├── capstone.dll
│ │ ├── capstone.lib
│ │ ├── capstone_dll.lib
│ │ ├── cstool.exe
│ │ └── include
│ │ │ ├── capstone
│ │ │ ├── arm.h
│ │ │ ├── arm64.h
│ │ │ ├── capstone.h
│ │ │ ├── evm.h
│ │ │ ├── m680x.h
│ │ │ ├── m68k.h
│ │ │ ├── mips.h
│ │ │ ├── platform.h
│ │ │ ├── ppc.h
│ │ │ ├── sparc.h
│ │ │ ├── systemz.h
│ │ │ ├── tms320c64x.h
│ │ │ ├── x86.h
│ │ │ └── xcore.h
│ │ │ ├── platform.h
│ │ │ └── windowsce
│ │ │ ├── intrin.h
│ │ │ └── stdint.h
│ └── find_mrs_register.h
├── analyze
│ ├── ARM_asm.h
│ ├── base_func.h
│ ├── kallsyms_lookup_name.cpp
│ ├── kallsyms_lookup_name.h
│ ├── kallsyms_lookup_name_4_6_0.cpp
│ ├── kallsyms_lookup_name_4_6_0.h
│ ├── kallsyms_lookup_name_6_1_42.cpp
│ ├── kallsyms_lookup_name_6_1_42.h
│ ├── kallsyms_lookup_name_6_1_60.cpp
│ ├── kallsyms_lookup_name_6_1_60.h
│ ├── kallsyms_lookup_name_6_6_30.cpp
│ ├── kallsyms_lookup_name_6_6_30.h
│ ├── kernel_symbol_parser.cpp
│ ├── kernel_symbol_parser.h
│ ├── kernel_version_parser.cpp
│ ├── kernel_version_parser.h
│ ├── symbol_analyze.cpp
│ └── symbol_analyze.h
├── exe
│ ├── aarch64-linux-android-as.exe
│ ├── arm-linux-androideabi-as.exe
│ ├── patch_kernel_root.exe
│ └── 快速扩充文件体积工具
│ │ ├── QuicklyExpandFileSize.cpp
│ │ ├── QuicklyExpandFileSize128M.exe
│ │ ├── QuicklyExpandFileSize192M.exe
│ │ ├── QuicklyExpandFileSize64.exe
│ │ ├── QuicklyExpandFileSize96.exe
│ │ └── 用法:将kernel文件拖拽至exe
├── patch_avc_denied.cpp
├── patch_avc_denied.h
├── patch_base.cpp
├── patch_base.h
├── patch_do_execve.cpp
├── patch_do_execve.h
├── patch_filldir64.cpp
├── patch_filldir64.h
├── patch_freeze_task.cpp
├── patch_freeze_task.h
├── patch_kernel_root.cpp
├── patch_kernel_root.h
├── patch_kernel_root.vcxproj
├── patch_kernel_root.vcxproj.filters
└── patch_kernel_root.vcxproj.user
└── testRoot
└── jni
├── Android.mk
├── Application.mk
├── Build.bat
├── Clean.bat
├── kernel_root_kit
├── file_convert_to_source_tools
│ ├── file_convert_to_source_tools.cpp
│ └── file_convert_to_source_tools.exe
├── kernel_root_kit_command.h
├── kernel_root_kit_elf64_symbol_parser.h
├── kernel_root_kit_err_def.h
├── kernel_root_kit_exec_process.h
├── kernel_root_kit_fork_helper.h
├── kernel_root_kit_lib_root_server_data.h
├── kernel_root_kit_lib_su_env_data.h
├── kernel_root_kit_log.h
├── kernel_root_kit_maps_helper.h
├── kernel_root_kit_parasite_app.cpp
├── kernel_root_kit_parasite_app.h
├── kernel_root_kit_parasite_elf_def.h
├── kernel_root_kit_parasite_patch_elf.cpp
├── kernel_root_kit_parasite_patch_elf.h
├── kernel_root_kit_process64_inject.cpp
├── kernel_root_kit_process64_inject.h
├── kernel_root_kit_process_cmdline_utils.h
├── kernel_root_kit_ptrace_arm64_utils.cpp
├── kernel_root_kit_ptrace_arm64_utils.h
├── kernel_root_kit_random.h
├── kernel_root_kit_su_exec_data.h
├── kernel_root_kit_su_install_helper.cpp
├── kernel_root_kit_su_install_helper.h
├── kernel_root_kit_umbrella.h
├── kernel_root_kit_upx_data.h
├── kernel_root_kit_upx_helper.cpp
└── kernel_root_kit_upx_helper.h
├── lib_root_server
├── file_to_gzip
│ ├── file_to_gzip.cpp
│ ├── file_to_gzip.exe
│ ├── file_to_gzip.sln
│ ├── file_to_gzip.vcxproj
│ ├── file_to_gzip.vcxproj.filters
│ ├── file_to_gzip.vcxproj.user
│ └── zlib-1.3.1
│ │ ├── adler32.c
│ │ ├── compress.c
│ │ ├── crc32.c
│ │ ├── crc32.h
│ │ ├── deflate.c
│ │ ├── deflate.h
│ │ ├── gzclose.c
│ │ ├── gzguts.h
│ │ ├── gzlib.c
│ │ ├── gzread.c
│ │ ├── gzwrite.c
│ │ ├── infback.c
│ │ ├── inffast.c
│ │ ├── inffast.h
│ │ ├── inffixed.h
│ │ ├── inflate.c
│ │ ├── inflate.h
│ │ ├── inftrees.c
│ │ ├── inftrees.h
│ │ ├── trees.c
│ │ ├── trees.h
│ │ ├── uncompr.c
│ │ ├── zconf.h
│ │ ├── zlib.h
│ │ ├── zutil.c
│ │ └── zutil.h
├── generate_source_lib_root_server_data.bat
├── generate_source_lib_root_server_html_data.bat
├── index.html
├── index_html_gz_data.h
├── jni
│ ├── Android.mk
│ └── Application.mk
├── lib_root_server.cpp
├── lib_root_server.h
└── lib_root_server_inline.h
├── lib_su_env
├── generate_source_lib_su_env_data.bat
├── jni
│ ├── Android.mk
│ └── Application.mk
├── lib_su_env.cpp
└── lib_su_env_inline.h
├── su
├── generate_source_su_exec_data.bat
├── jni
│ ├── Android.mk
│ └── Application.mk
├── su.cpp
├── su.h
├── su_encryptor.h
├── su_hide_path_utils.h
└── su_log.h
├── testRoot.cpp
├── testRoot.h
├── upx
├── generate_source_upx_data.bat
└── upx-5.0.1-arm64_linux
│ ├── COPYING
│ ├── LICENSE
│ ├── NEWS
│ ├── README
│ ├── THANKS.txt
│ ├── upx
│ ├── upx-doc.html
│ ├── upx-doc.txt
│ └── upx.1
├── utils
├── cJSON.cpp
├── cJSON.h
├── jsonUtils.h
├── randomData.h
└── stringUtils.h
└── 编译流程.txt
/PermissionManager/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/PermissionManager/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/PermissionManager/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/PermissionManager/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
19 |
20 |
--------------------------------------------------------------------------------
/PermissionManager/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/PermissionManager/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/PermissionManager/app/appKey.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/app/appKey.jks
--------------------------------------------------------------------------------
/PermissionManager/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | compileSdk 31
7 |
8 | defaultConfig {
9 | applicationId "com.linux.permissionmanager"
10 | minSdk 26
11 | targetSdk 31
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | externalNativeBuild {
17 | cmake {
18 | cppFlags '-std=c++17'
19 | abiFilters "arm64-v8a" //需要什么构架的so,就在这边添加即
20 | }
21 | }
22 | }
23 |
24 | buildTypes {
25 | release {
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
28 | }
29 | }
30 | compileOptions {
31 | sourceCompatibility JavaVersion.VERSION_1_8
32 | targetCompatibility JavaVersion.VERSION_1_8
33 | }
34 | externalNativeBuild {
35 | cmake {
36 | path file('src/main/cpp/CMakeLists.txt')
37 | version '3.18.1'
38 | }
39 | }
40 | buildFeatures {
41 | viewBinding true
42 | }
43 | }
44 |
45 | dependencies {
46 |
47 | implementation 'androidx.appcompat:appcompat:1.4.1'
48 | implementation 'com.google.android.material:material:1.5.0'
49 | implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
50 | testImplementation 'junit:junit:4.13.2'
51 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
52 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
53 | }
--------------------------------------------------------------------------------
/PermissionManager/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/PermissionManager/app/src/androidTest/java/com/linux/permissionmanager/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.linux.permissionmanager;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.linux.permissionmanager", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # For more information about using CMake with Android Studio, read the
2 | # documentation: https://d.android.com/studio/projects/add-native-code.html
3 |
4 | # Sets the minimum version of CMake required to build the native library.
5 |
6 | cmake_minimum_required(VERSION 3.18.1)
7 |
8 | # Declares and names the project.
9 |
10 | project("permissionmanager")
11 |
12 | # Creates and names a library, sets it as either STATIC
13 | # or SHARED, and provides the relative paths to its source code.
14 | # You can define multiple libraries, and CMake builds them for you.
15 | # Gradle automatically packages shared libraries with your APK.
16 |
17 | add_library( # Sets the name of the library.
18 | permissionmanager
19 |
20 | # Sets the library as a shared library.
21 | SHARED
22 |
23 | # Provides a relative path to your source file(s).
24 | ../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_process64_inject.cpp
25 | ../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_ptrace_arm64_utils.cpp
26 | ../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_su_install_helper.cpp
27 | ../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_upx_helper.cpp
28 | ../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_parasite_app.cpp
29 | ../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_parasite_patch_elf.cpp
30 | cJSON.cpp
31 | native-lib.cpp)
32 |
33 | # Searches for a specified prebuilt library and stores the path as a
34 | # variable. Because CMake includes system libraries in the search path by
35 | # default, you only need to specify the name of the public NDK library
36 | # you want to add. CMake verifies that the library exists before
37 | # completing its build.
38 |
39 | find_library( # Sets the name of the path variable.
40 | log-lib
41 |
42 | # Specifies the name of the NDK library that
43 | # you want CMake to locate.
44 | log)
45 |
46 | # Specifies libraries CMake should link to your target library. You
47 | # can link multiple libraries, such as libraries you define in this
48 | # build script, prebuilt third-party libraries, or system libraries.
49 |
50 | target_link_libraries( # Specifies the target library.
51 | permissionmanager
52 |
53 | # Links the target library to the log library
54 | # included in the NDK.
55 | ${log-lib})
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/cpp/urlEncodeUtils.h:
--------------------------------------------------------------------------------
1 | #ifndef URL_ENCODE_UTILS_H_
2 | #define URL_ENCODE_UTILS_H_
3 | #include
4 | #include
5 |
6 | static inline char to_hex(char code) {
7 | static char hex[] = "0123456789ABCDEF";
8 | return hex[code & 15];
9 | }
10 | static inline char from_hex(char ch) {
11 | return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
12 | }
13 |
14 | /*
15 | //使用例子
16 | int main() {
17 | char str[] = "你好,世界";
18 | char encoded_str[256];
19 | url_encode(str, encoded_str);
20 | printf("Encoded URL: %s\n", encoded_str);
21 | return 0;
22 | }
23 | */
24 | static void url_encode(char *str, char *encoded_str) {
25 | char *pstr = str, *buf = encoded_str;
26 | while (*pstr) {
27 | unsigned char c = *pstr;
28 | if (c <= 0x7F) { // ASCII
29 | if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
30 | *buf++ = c;
31 | } else if (c == ' ') {
32 | *buf++ = '+';
33 | } else {
34 | *buf++ = '%', *buf++ = to_hex(c >> 4), *buf++ = to_hex(c & 15);
35 | }
36 | } else { // Non-ASCII
37 | while (c) {
38 | *buf++ = '%', *buf++ = to_hex(c >> 4), *buf++ = to_hex(c & 15);
39 | c = *(++pstr);
40 | }
41 | continue;
42 | }
43 | pstr++;
44 | }
45 | *buf = '\0';
46 | }
47 | /*
48 | //使用例子
49 | int main() {
50 | char url[] = "%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C"; // "你好,世界"的URL编码
51 | char decoded_str[256];
52 | url_decode(url, decoded_str);
53 | printf("Decoded URL: %s\n", decoded_str);
54 | return 0;
55 | }
56 | */
57 | static void url_decode(char *str, char *decoded_str) {
58 | char *pstr = str, *buf = decoded_str;
59 | while (*pstr) {
60 | if (*pstr == '%') {
61 | if (pstr[1] && pstr[2]) {
62 | *buf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]);
63 | pstr += 2;
64 | }
65 | } else if (*pstr == '+') {
66 | *buf++ = ' ';
67 | } else {
68 | *buf++ = *pstr;
69 | }
70 | pstr++;
71 | }
72 | *buf = '\0';
73 | }
74 | #endif
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/java/com/linux/permissionmanager/Adapter/SelectFileRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.linux.permissionmanager.Adapter;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.os.Handler;
6 | import android.os.Message;
7 | import android.text.Html;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ImageView;
12 | import android.widget.PopupWindow;
13 | import android.widget.TextView;
14 |
15 | import androidx.annotation.NonNull;
16 | import androidx.recyclerview.widget.RecyclerView;
17 |
18 | import com.linux.permissionmanager.Model.SelectFileRecyclerItem;
19 | import com.linux.permissionmanager.R;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 | public class SelectFileRecyclerAdapter extends RecyclerView.Adapter {
24 | public static class ViewHolder extends RecyclerView.ViewHolder {
25 | public View v;
26 | public TextView select_file_name;
27 | public TextView select_file_desc;
28 | public ViewHolder(View v) {
29 | super(v);
30 | this.v = v;
31 | }
32 | }
33 | private int resourceId;
34 | private List objects;
35 | private PopupWindow popupWindow;
36 | private Handler selectFileCallback;
37 | private Context ctx;
38 | public SelectFileRecyclerAdapter(Context ctx, int textViewResourceId, List objects, PopupWindow popupWindow, Handler selectFileCallback) {
39 | this.resourceId = textViewResourceId;
40 | this.objects = new ArrayList<>(objects);
41 | this. popupWindow = popupWindow;
42 | this. selectFileCallback = selectFileCallback;
43 | this. ctx = ctx;
44 | }
45 |
46 | public void updateList(List newList) {
47 | objects.clear();
48 | objects.addAll(newList);
49 | notifyDataSetChanged();
50 | }
51 |
52 |
53 | public List getList() {
54 | return objects;
55 | }
56 |
57 |
58 | @NonNull
59 | @Override
60 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
61 | View v =LayoutInflater.from(parent.getContext()).inflate(resourceId,parent,false);
62 | SelectFileRecyclerAdapter.ViewHolder holder = new SelectFileRecyclerAdapter.ViewHolder(v);
63 |
64 | holder.select_file_name=v.findViewById(R.id.select_file_name) ;
65 | holder.select_file_desc=v.findViewById(R.id.select_file_desc) ;
66 | return holder;
67 | }
68 |
69 | @Override
70 | public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
71 | SelectFileRecyclerItem fileItem=objects.get(position);
72 | String fileName = fileItem.getFileName();
73 | String fileDesc = fileItem.getFileDesc();
74 | Color fileDescColor = fileItem.getFileDescColor();
75 | String hexColor = String.format("#%06X", (0xFFFFFF & fileDescColor.toArgb()));
76 |
77 | String showText=""+fileName +" ";
78 | String showDesc=""+fileDesc +" ";
79 | holder.select_file_name.setText(Html.fromHtml(showText));
80 | holder.select_file_desc.setText(Html.fromHtml(showDesc));
81 |
82 | holder.v.setOnClickListener(new ClickRecyclerItemListener(fileItem));
83 | }
84 |
85 | @Override
86 | public int getItemCount() {
87 | return objects.size();
88 | }
89 |
90 | @Override
91 | public int getItemViewType(int position) {
92 | return position;
93 | }
94 |
95 |
96 | class ClickRecyclerItemListener implements View.OnClickListener {
97 | SelectFileRecyclerItem fileItem;
98 | public ClickRecyclerItemListener(SelectFileRecyclerItem fileItem){
99 | this.fileItem =fileItem;
100 | }
101 | @Override
102 | public void onClick(View v) {
103 | popupWindow.dismiss();
104 | Message msg = new Message();
105 | msg.obj = (SelectFileRecyclerItem)fileItem;
106 | selectFileCallback.sendMessage(msg);
107 | }
108 | }
109 | }
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/PopupWindowOnTouchClose.java:
--------------------------------------------------------------------------------
1 | package com.linux.permissionmanager.Model;
2 |
3 | import android.view.MotionEvent;
4 | import android.view.View;
5 | import android.widget.PopupWindow;
6 |
7 | public class PopupWindowOnTouchClose implements View.OnTouchListener {
8 | private boolean lastVailedDown = true;
9 | private int screenWidth, screenHeight, centerWidth, centerHeight;
10 | private PopupWindow popupWindow;
11 |
12 | public PopupWindowOnTouchClose(PopupWindow popupWindow, int screenWidth, int screenHeight, int centerWidth, int centerHeight) {
13 | this.popupWindow = popupWindow;
14 | this.screenWidth = screenWidth;
15 | this.screenHeight = screenHeight;
16 | this.centerWidth = centerWidth;
17 | this.centerHeight = centerHeight;
18 | }
19 |
20 | private boolean isValiedRegion(View v, MotionEvent event) {
21 | int x = (int) event.getX();
22 | int y = (int) event.getY();
23 | double wndLeft = (screenWidth - centerWidth) / 2;
24 | double wndTop = (screenHeight - centerHeight) / 2;
25 | if (x < wndLeft || x > wndLeft + centerWidth || y < wndTop || y > wndTop + centerHeight) {
26 | return false;
27 | }
28 | return true;
29 | }
30 |
31 | @Override
32 | public boolean onTouch(View v, MotionEvent event) {
33 |
34 | if (event.getAction() == MotionEvent.ACTION_DOWN) {
35 | lastVailedDown = isValiedRegion(v, event);
36 | } else if (event.getAction() == MotionEvent.ACTION_UP) {
37 | if (!lastVailedDown) {
38 | if (!isValiedRegion(v, event)) {
39 | popupWindow.dismiss();
40 | }
41 | }
42 | }
43 | return false;
44 | }
45 | }
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/SelectAppRecyclerItem.java:
--------------------------------------------------------------------------------
1 | package com.linux.permissionmanager.Model;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageInfo;
5 | import android.graphics.drawable.Drawable;
6 |
7 | public class SelectAppRecyclerItem {
8 | private PackageInfo packageInfo;
9 |
10 | public SelectAppRecyclerItem(PackageInfo packageInfo){
11 | this.packageInfo = packageInfo;
12 | }
13 |
14 | public PackageInfo getPackageInfo() {
15 | return packageInfo;
16 | }
17 |
18 | public String getShowName(Context ctx) {
19 | String showName = this.packageInfo.applicationInfo.loadLabel(ctx.getPackageManager()).toString();
20 | return showName;
21 | }
22 | public String getPackageName() {
23 | String packageName = this.packageInfo.applicationInfo.packageName;
24 | return packageName;
25 | }
26 | public Drawable getDrawable(Context ctx) {
27 | Drawable icon = this.packageInfo.applicationInfo.loadIcon(ctx.getPackageManager());
28 | return icon;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/SelectFileRecyclerItem.java:
--------------------------------------------------------------------------------
1 | package com.linux.permissionmanager.Model;
2 |
3 | import android.graphics.Color;
4 | import android.os.Build;
5 |
6 | import androidx.annotation.RequiresApi;
7 |
8 | import java.nio.file.Path;
9 | import java.nio.file.Paths;
10 |
11 | public class SelectFileRecyclerItem {
12 | private String filePath;
13 | private String fileDesc;
14 | private Color fileDescColor;
15 |
16 | public SelectFileRecyclerItem(String filePath, String fileDesc, Color fileDescColor){
17 | this.filePath = filePath;
18 | this.fileDesc = fileDesc;
19 | this.fileDescColor = fileDescColor;
20 | }
21 |
22 | public String getFilePath() {
23 | return this.filePath;
24 | }
25 |
26 | public String getFileName() {
27 | Path path = Paths.get(filePath);
28 | Path fileName = path.getFileName();
29 | return fileName.toString();
30 | }
31 | public String getFileDesc() {
32 | return this.fileDesc;
33 | }
34 | public Color getFileDescColor() {
35 | return this.fileDescColor;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/java/com/linux/permissionmanager/Utils/DialogUtils.java:
--------------------------------------------------------------------------------
1 | package com.linux.permissionmanager.Utils;
2 |
3 | import android.content.Context;
4 | import android.content.DialogInterface;
5 | import android.graphics.drawable.Drawable;
6 | import android.os.Handler;
7 | import android.os.Message;
8 | import android.widget.EditText;
9 |
10 | import androidx.appcompat.app.AlertDialog;
11 |
12 | public class DialogUtils {
13 |
14 | /**
15 | * 显示带有消息的对话框。
16 | *
17 | * @param context 上下文
18 | * @param title 对话框标题
19 | * @param msg 对话框内容
20 | * @param icon 对话框图标(可为 null)
21 | */
22 | public static void showMsgDlg(Context context, String title, String msg, Drawable icon) {
23 | AlertDialog.Builder builder = new AlertDialog.Builder(context);
24 | builder.setTitle(title);
25 | builder.setMessage(msg);
26 | if (icon != null) {
27 | builder.setIcon(icon);
28 | }
29 | builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
30 | public void onClick(DialogInterface dialog, int id) {
31 | dialog.dismiss();
32 | }
33 | });
34 | AlertDialog dialog = builder.create();
35 | dialog.show();
36 | }
37 |
38 | /**
39 | * 显示带有三个按钮的输入对话框。
40 | *
41 | * @param context 上下文
42 | * @param defaultText 默认文本
43 | * @param title 对话框标题
44 | * @param thirdButtonText 第三个按钮的文本
45 | * @param confirmCallback 点击确定按钮时的回调
46 | * @param thirdButtonCallback 第三个按钮的回调
47 | */
48 | public static void showInputDlg(Context context, String defaultText, String title, final String thirdButtonText,
49 | final Handler confirmCallback, final Handler thirdButtonCallback) {
50 | final EditText inputTxt = new EditText(context);
51 | inputTxt.setText(defaultText);
52 | inputTxt.setFocusable(true);
53 | inputTxt.setSelection(defaultText.length(), 0);
54 |
55 | AlertDialog.Builder builder = new AlertDialog.Builder(context);
56 | builder.setTitle(title)
57 | .setIcon(android.R.drawable.ic_dialog_info)
58 | .setView(inputTxt)
59 | .setNegativeButton("取消", new DialogInterface.OnClickListener() {
60 | @Override
61 | public void onClick(DialogInterface dialog, int which) {
62 | dialog.dismiss();
63 | }
64 | })
65 | .setPositiveButton("确定", new DialogInterface.OnClickListener() {
66 | public void onClick(DialogInterface dialog, int which) {
67 | String text = inputTxt.getText().toString();
68 | Message msg = new Message();
69 | msg.obj = text;
70 | confirmCallback.sendMessage(msg);
71 | }
72 | });
73 |
74 | // 添加第三个按钮
75 | if (thirdButtonText != null && !thirdButtonText.isEmpty()) {
76 | builder.setNeutralButton(thirdButtonText, new DialogInterface.OnClickListener() {
77 | @Override
78 | public void onClick(DialogInterface dialog, int which) {
79 | // 自定义回调
80 | if (thirdButtonCallback != null) {
81 | thirdButtonCallback.sendMessage(new Message());
82 | }
83 | }
84 | });
85 | }
86 |
87 | AlertDialog dialog = builder.create();
88 | dialog.show();
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/drawable/line.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/drawable/line_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
9 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/drawable/ripple_grey.xml:
--------------------------------------------------------------------------------
1 |
2 | //点击时波纹的颜色
5 | //未点击时控件的背景(可以是图片,可以是颜色,也可以是drawable里的xml背景(比如圆角))
6 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/drawable/shape_wnd_grey_corner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/drawable/thumb.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/drawable/thumb_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
9 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/layout/select_app_recycler_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
16 |
17 |
24 |
29 |
30 |
31 |
32 |
33 |
43 |
44 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/layout/select_file_recycler_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
16 |
17 |
27 |
28 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/layout/select_file_wnd.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
12 |
13 |
22 |
23 |
31 |
32 |
33 |
40 |
41 |
42 |
43 |
47 |
48 |
49 |
58 |
59 |
60 |
70 |
71 |
72 |
73 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 | #424242
11 | #FF767676
12 | #00000000
13 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PermissionManager
3 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
19 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/PermissionManager/app/src/test/java/com/linux/permissionmanager/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.linux.permissionmanager;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/PermissionManager/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | task clean(type: Delete) {
4 | delete rootProject.buildDir
5 | }
--------------------------------------------------------------------------------
/PermissionManager/build_apk/PermissionManager.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/build_apk/PermissionManager.apk
--------------------------------------------------------------------------------
/PermissionManager/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/PermissionManager/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/PermissionManager/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/PermissionManager/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Feb 19 21:34:04 CST 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/PermissionManager/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/PermissionManager/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | google()
5 | mavenCentral()
6 | }
7 | plugins {
8 | id 'com.android.application' version '7.1.0-alpha11'
9 | id 'com.android.library' version '7.1.0-alpha11'
10 | }
11 | }
12 | dependencyResolutionManagement {
13 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
14 | repositories {
15 | google()
16 | mavenCentral()
17 | }
18 | }
19 | rootProject.name = "PermissionManager"
20 | include ':app'
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SKRoot - SuperKernelRoot - Linux内核级完美隐藏ROOT演示
2 | 新一代SKRoot,挑战全网root检测手段,跟面具完全不同思路,摆脱面具被检测的弱点,完美隐藏root功能,实现真正的SELinux 0%触碰,通用性强,通杀所有内核,不需要内核源码,直接patch内核,兼容安卓APP直接JNI调用,稳定、流畅、不闪退。
3 | ## 功能列表:
4 | #### 1.测试ROOT权限
5 | #### 2.执行ROOT命令
6 | #### 3.以ROOT执行程序
7 | #### 4.安装部署su
8 | #### 5.注入su到指定进程
9 | #### 6.完全卸载清理su
10 | #### 7.寄生目标APP
11 |
12 | ## 效果:
13 | * **实验设备包括:红米K20\K30\K40\K50\K60、小米8\9\10\11\12\13、小米平板5\6、红魔5\6\7、联想、三星、一加、ROG2\3等,支持型号非常多。测试结果显示,SKRoot能够在所支持设备上非常稳定的运行。**
14 | * **过市面上所有主流APP的ROOT检测,如农业XX、交X12XX3等...**
15 | * **无需厂商提供源代码**
16 | * **愿世界迎来一个美好的ROOT时代!**
17 |
18 | 
19 | 
20 | 
21 |
22 | ## 功能备注:
23 | 1. APP应用程序得到ROOT权限的唯一方法就是得到ROOT密匙,此密匙为48位的随机字符串,安全可靠。
24 |
25 | 2. 其中【**注入su到指定进程**】**只支持授权su到64位的APP**,老式32位APP不再进行支持,因市面上几乎所有APP都是64位,例如MT文件管理器、Root Explorer文件管理器等等。
26 |
27 | ## 使用流程:
28 | 1.将内核文件拖拽置`patch_kernel_root.exe`即可一键自动化流程补丁内核,同时会自动生成ROOT密匙。
29 |
30 | 2.编译并启动`PermissionManager`或者`testRoot`,输入ROOT密匙值,开始享受舒爽的ROOT环境。
31 |
32 | ## 更新日志:
33 |
34 | 2025-5:
35 | * **1.修复Linux 6.1、6.6及以上无法解析问题**
36 | * **2.新增内核隐藏su路径(抵御安卓漏洞)**
37 | * **3.修复su进程不能退出有残留的问题**
38 | * **4.新增以ROOT身份直接执行程序功能**
39 | * **5.新增内核防冻结进程功能**
40 |
41 |
42 | 2024-9:
43 | * **1.新增永久授权su功能**
44 |
45 | 2023-8:
46 | * **1.新增seccomp补丁代码**
47 | * **2.新增寄生目标功能**
48 | * **3.新增一键自动化流程补丁内核功能**
49 | * **4.修复Linux 3.X老内核兼容问题**
50 | * **5.修复Linux 5.10、5.15无法开机问题**
51 |
52 | ## 问题排查:
53 | 1、如遇到Linux 6.0以上内核无法开机,请阅读:
54 | * **请不要使用Android.Image.Kitchen进行打包,该工具不支持Linux 6.0以上内核!**
55 | * **可使用magiskboot进行打包。**
56 | * **magiskboot的快速获取方式:使用7z解压Magisk apk,把lib文件夹里的libmagiskboot.so直接改名magiskboot即可使用。因为这是个可执行文件,并不是动态库,不要被名字带so字样所迷惑。**
57 | * **解包命令:./magiskboot unpack boot.img**
58 | * **打包命令:./magiskboot repack boot.img**
59 |
60 | 2、如发现第三方应用程序依然有侦测行为,请按照以下步骤进行排查:
61 | * **内核必须保证是基于官方原版进行修改,而非自行编译或使用第三方源码编译。**
62 | * **如果你曾经使用过Magisk,你应该先将手机完全刷机,因为Magisk可能会残留日志文件等信息。**
63 | * **不要安装需要ROOT权限的工具,或涉及系统环境检测的应用,如冰箱、黑洞、momo和密匙认证等。这些应用的存在可能会被用作证据,推断你的设备已获取ROOT权限。若需使用,请在使用后立即卸载。**
64 | * **Android APP可能会被特征检测。这里的APP只是演示功能写法。在实际使用中,请尽量隐藏APP。例如使用寄生功能,寄生到其他无害的APP内,以免被侦测。**
65 | * **如果在解锁BL后手机会发出警报,你需要自行解决这个问题,因为它与SKRoot无关。**
66 | * **如果对方是检测BL锁,而不是ROOT权限。你应该安装SKRoot的隐藏BL锁模块。**
67 | * **请检查SELinux状态是否被恶意软件禁用。**
68 |
--------------------------------------------------------------------------------
/ScreenCap/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/ScreenCap/1.png
--------------------------------------------------------------------------------
/ScreenCap/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/ScreenCap/3.png
--------------------------------------------------------------------------------
/ScreenCap/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/ScreenCap/4.png
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/CREDITS.TXT:
--------------------------------------------------------------------------------
1 | This file credits all the contributors of the Capstone engine project.
2 |
3 | Key developers
4 | ==============
5 | 1. Nguyen Anh Quynh
6 | - Core engine
7 | - Bindings: Python, Ruby, OCaml, Java, C#
8 |
9 | 2. Tan Sheng Di
10 | - Bindings: Ruby
11 |
12 | 3. Ben Nagy
13 | - Bindings: Ruby, Go
14 |
15 | 4. Dang Hoang Vu
16 | - Bindings: Java
17 |
18 |
19 | Beta testers (in random order)
20 | ==============================
21 | Pancake
22 | Van Hauser
23 | FX of Phenoelit
24 | The Grugq, The Grugq <-- our hero for submitting the first ever patch!
25 | Isaac Dawson, Veracode Inc
26 | Patroklos Argyroudis, Census Inc. (http://census-labs.com)
27 | Attila Suszter
28 | Le Dinh Long
29 | Nicolas Ruff
30 | Gunther
31 | Alex Ionescu, Winsider Seminars & Solutions Inc.
32 | Snare
33 | Daniel Godas-Lopez
34 | Joshua J. Drake
35 | Edgar Barbosa
36 | Ralf-Philipp Weinmann
37 | Hugo Fortier
38 | Joxean Koret
39 | Bruce Dang
40 | Andrew Dunham
41 |
42 |
43 | Contributors (in no particular order)
44 | =====================================
45 | (Please let us know if you want to have your name here)
46 |
47 | Ole André Vadla Ravnås (author of the 100th Pull-Request in our Github repo, thanks!)
48 | Axel "0vercl0k" Souchet (@0vercl0k) & Alex Ionescu: port to MSVC.
49 | Daniel Pistelli: Cmake support.
50 | Peter Hlavaty: integrate Capstone for Windows kernel drivers.
51 | Guillaume Jeanne: Ocaml binding.
52 | Martin Tofall, Obsidium Software: Optimize X86 performance & size + x86 encoding features.
53 | David Martínez Moreno & Hilko Bengen: Debian package.
54 | Félix Cloutier: Xcode project.
55 | Benoit Lecocq: OpenBSD package.
56 | Christophe Avoinne (Hlide): Improve memory management for better performance.
57 | Michael Cohen & Nguyen Tan Cong: Python module installer.
58 | Adel Gadllah, Francisco Alonso & Stefan Cornelius: RPM package.
59 | Felix Gröbert (Google): fuzz testing harness.
60 | Xipiter LLC: Capstone logo redesigned.
61 | Satoshi Tanda: Support Windows kernel driver.
62 | Tang Yuhang: cstool.
63 | Andrew Dutcher: better Python setup.
64 | Ruben Boonen: PowerShell binding.
65 | David Zimmer: VB6 binding.
66 | Philippe Antoine: Integration with oss-fuzz and various fixes.
67 | Bui Dinh Cuong: Explicit registers accessed for Arm64.
68 | Vincent Bénony: Explicit registers accessed for X86.
69 | Adel Gadllah, Francisco Alonso & Stefan Cornelius: RPM package.
70 | Felix Gröbert (Google): fuzz testing harness.
71 | Daniel Collin & Nicolas Planel: M68K architecture.
72 | Pranith Kumar: Explicit registers accessed for Arm64.
73 | Xipiter LLC: Capstone logo redesigned.
74 | Satoshi Tanda: Support Windows kernel driver.
75 | Koutheir Attouchi: Support for Windows CE.
76 | Fotis Loukos: TMS320C64x architecture.
77 | Wolfgang Schwotzer: M680X architecture.
78 | Philippe Antoine: Integration with oss-fuzz and various fixes.
79 | Stephen Eckels (stevemk14ebr): x86 encoding features
80 |
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/LICENSE.TXT:
--------------------------------------------------------------------------------
1 | This is the software license for Capstone disassembly framework.
2 | Capstone has been designed & implemented by Nguyen Anh Quynh
3 |
4 | See http://www.capstone-engine.org for further information.
5 |
6 | Copyright (c) 2013, COSEINC.
7 | All rights reserved.
8 |
9 | Redistribution and use in source and binary forms, with or without
10 | modification, are permitted provided that the following conditions are met:
11 |
12 | * Redistributions of source code must retain the above copyright notice,
13 | this list of conditions and the following disclaimer.
14 | * Redistributions in binary form must reproduce the above copyright notice,
15 | this list of conditions and the following disclaimer in the documentation
16 | and/or other materials provided with the distribution.
17 | * Neither the name of the developer(s) nor the names of its
18 | contributors may be used to endorse or promote products derived from this
19 | software without specific prior written permission.
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 | POSSIBILITY OF SUCH DAMAGE.
32 |
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/LICENSE_LLVM.TXT:
--------------------------------------------------------------------------------
1 | ==============================================================================
2 | LLVM Release License
3 | ==============================================================================
4 | University of Illinois/NCSA
5 | Open Source License
6 |
7 | Copyright (c) 2003-2013 University of Illinois at Urbana-Champaign.
8 | All rights reserved.
9 |
10 | Developed by:
11 |
12 | LLVM Team
13 |
14 | University of Illinois at Urbana-Champaign
15 |
16 | http://llvm.org
17 |
18 | Permission is hereby granted, free of charge, to any person obtaining a copy of
19 | this software and associated documentation files (the "Software"), to deal with
20 | the Software without restriction, including without limitation the rights to
21 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
22 | of the Software, and to permit persons to whom the Software is furnished to do
23 | so, subject to the following conditions:
24 |
25 | * Redistributions of source code must retain the above copyright notice,
26 | this list of conditions and the following disclaimers.
27 |
28 | * Redistributions in binary form must reproduce the above copyright notice,
29 | this list of conditions and the following disclaimers in the
30 | documentation and/or other materials provided with the distribution.
31 |
32 | * Neither the names of the LLVM Team, University of Illinois at
33 | Urbana-Champaign, nor the names of its contributors may be used to
34 | endorse or promote products derived from this Software without specific
35 | prior written permission.
36 |
37 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
39 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40 | CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
43 | SOFTWARE.
44 |
45 | ==============================================================================
46 | Copyrights and Licenses for Third Party Software Distributed with LLVM:
47 | ==============================================================================
48 | The LLVM software contains code written by third parties. Such software will
49 | have its own individual LICENSE.TXT file in the directory in which it appears.
50 | This file will describe the copyrights, license, and restrictions which apply
51 | to that code.
52 |
53 | The disclaimer of warranty in the University of Illinois Open Source License
54 | applies to all code in the LLVM Distribution, and nothing in any of the
55 | other licenses gives permission to use the names of the LLVM Team or the
56 | University of Illinois to endorse or promote products derived from this
57 | Software.
58 |
59 | The following pieces of software have additional or alternate copyrights,
60 | licenses, and/or restrictions:
61 |
62 | Program Directory
63 | ------- ---------
64 | Autoconf llvm/autoconf
65 | llvm/projects/ModuleMaker/autoconf
66 | llvm/projects/sample/autoconf
67 | Google Test llvm/utils/unittest/googletest
68 | OpenBSD regex llvm/lib/Support/{reg*, COPYRIGHT.regex}
69 | pyyaml tests llvm/test/YAMLParser/{*.data, LICENSE.TXT}
70 | ARM contributions llvm/lib/Target/ARM/LICENSE.TXT
71 | md5 contributions llvm/lib/Support/MD5.cpp llvm/include/llvm/Support/MD5.h
72 |
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/README.md:
--------------------------------------------------------------------------------
1 | Capstone Engine
2 | ===============
3 |
4 | [](https://travis-ci.org/aquynh/capstone)
5 | [](https://ci.appveyor.com/project/aquynh/capstone/branch/v4)
6 |
7 | Capstone is a disassembly framework with the target of becoming the ultimate
8 | disasm engine for binary analysis and reversing in the security community.
9 |
10 | Created by Nguyen Anh Quynh, then developed and maintained by a small community,
11 | Capstone offers some unparalleled features:
12 |
13 | - Support multiple hardware architectures: ARM, ARM64 (ARMv8), Ethereum VM, M68K,
14 | Mips, PPC, Sparc, SystemZ, TMS320C64X, M680X, XCore and X86 (including X86_64).
15 |
16 | - Having clean/simple/lightweight/intuitive architecture-neutral API.
17 |
18 | - Provide details on disassembled instruction (called “decomposer” by others).
19 |
20 | - Provide semantics of the disassembled instruction, such as list of implicit
21 | registers read & written.
22 |
23 | - Implemented in pure C language, with lightweight bindings for D, Clojure, F#,
24 | Common Lisp, Visual Basic, PHP, PowerShell, Emacs, Haskell, Perl, Python,
25 | Ruby, C#, NodeJS, Java, GO, C++, OCaml, Lua, Rust, Delphi, Free Pascal & Vala
26 | (ready either in main code, or provided externally by the community).
27 |
28 | - Native support for all popular platforms: Windows, Mac OSX, iOS, Android,
29 | Linux, \*BSD, Solaris, etc.
30 |
31 | - Thread-safe by design.
32 |
33 | - Special support for embedding into firmware or OS kernel.
34 |
35 | - High performance & suitable for malware analysis (capable of handling various
36 | X86 malware tricks).
37 |
38 | - Distributed under the open source BSD license.
39 |
40 | Further information is available at http://www.capstone-engine.org
41 |
42 |
43 | Compile
44 | -------
45 |
46 | See COMPILE.TXT file for how to compile and install Capstone.
47 |
48 |
49 | Documentation
50 | -------------
51 |
52 | See docs/README for how to customize & program your own tools with Capstone.
53 |
54 |
55 | Hack
56 | ----
57 |
58 | See HACK.TXT file for the structure of the source code.
59 |
60 |
61 | License
62 | -------
63 |
64 | This project is released under the BSD license. If you redistribute the binary
65 | or source code of Capstone, please attach file LICENSE.TXT with your products.
66 |
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/RELEASE_NOTES:
--------------------------------------------------------------------------------
1 | This release 4.0.2 is dedicated to my dad!
2 |
3 | Without him, I would not work in computing field, let alone writing any code
4 | or making contribution to the cyber security community.
5 |
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/SPONSORS.TXT:
--------------------------------------------------------------------------------
1 | * Version 4.0.2 - May 08th, 2020
2 |
3 | Release 4.0.2 was sponsored by the following companies (in no particular order).
4 |
5 | - Senrio: https://senr.io
6 | - Catena Cyber: https://catenacyber.fr
7 |
8 | ------------------------------------
9 |
10 | * Version 4.0.1 - January 10th, 2019
11 |
12 | Release 4.0.1 was sponsored by the following companies (in no particular order).
13 |
14 | - NowSecure: https://www.nowsecure.com
15 | - Verichains: https://verichains.io
16 | - Vsec: https://vsec.com.vn
17 |
18 | -----------------------------------
19 | * Version 4.0 - December 18th, 2018
20 |
21 | Capstone 4.0 version marks 5 years of the project!
22 | This release was sponsored by the following companies (in no particular order).
23 |
24 | - Thinkst Canary: https://canary.tools
25 | - NowSecure: https://www.nowsecure.com
26 | - ECQ: https://e-cq.net
27 | - Senrio: https://senr.io
28 | - GracefulBits: https://gracefulbits.com
29 | - Catena Cyber: https://catenacyber.fr
30 |
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/capstone.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/patch_kernel_root/3rdparty/capstone-4.0.2-win64/capstone.dll
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/capstone.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/patch_kernel_root/3rdparty/capstone-4.0.2-win64/capstone.lib
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/capstone_dll.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/patch_kernel_root/3rdparty/capstone-4.0.2-win64/capstone_dll.lib
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/cstool.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/patch_kernel_root/3rdparty/capstone-4.0.2-win64/cstool.exe
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/include/platform.h:
--------------------------------------------------------------------------------
1 | /* Capstone Disassembly Engine */
2 | /* By Axel Souchet & Nguyen Anh Quynh, 2014 */
3 |
4 | #ifndef CAPSTONE_PLATFORM_H
5 | #define CAPSTONE_PLATFORM_H
6 |
7 | // handle C99 issue (for pre-2013 VisualStudio)
8 | #if !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) && (defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64))
9 | // MSVC
10 |
11 | // stdbool.h
12 | #if (_MSC_VER < 1800) || defined(_KERNEL_MODE)
13 | // this system does not have stdbool.h
14 | #ifndef __cplusplus
15 | typedef unsigned char bool;
16 | #define false 0
17 | #define true 1
18 | #endif
19 |
20 | #else
21 | // VisualStudio 2013+ -> C99 is supported
22 | #include
23 | #endif
24 |
25 | #else
26 | // not MSVC -> C99 is supported
27 | #include
28 | #endif
29 |
30 |
31 | // handle C99 issue (for pre-2013 VisualStudio)
32 | #if defined(CAPSTONE_HAS_OSXKERNEL) || (defined(_MSC_VER) && (_MSC_VER <= 1700 || defined(_KERNEL_MODE)))
33 | // this system does not have inttypes.h
34 |
35 | #if defined(_MSC_VER) && (_MSC_VER < 1600 || defined(_KERNEL_MODE))
36 | // this system does not have stdint.h
37 | typedef signed char int8_t;
38 | typedef signed short int16_t;
39 | typedef signed int int32_t;
40 | typedef unsigned char uint8_t;
41 | typedef unsigned short uint16_t;
42 | typedef unsigned int uint32_t;
43 | typedef signed long long int64_t;
44 | typedef unsigned long long uint64_t;
45 |
46 | #define INT8_MIN (-127i8 - 1)
47 | #define INT16_MIN (-32767i16 - 1)
48 | #define INT32_MIN (-2147483647i32 - 1)
49 | #define INT64_MIN (-9223372036854775807i64 - 1)
50 | #define INT8_MAX 127i8
51 | #define INT16_MAX 32767i16
52 | #define INT32_MAX 2147483647i32
53 | #define INT64_MAX 9223372036854775807i64
54 | #define UINT8_MAX 0xffui8
55 | #define UINT16_MAX 0xffffui16
56 | #define UINT32_MAX 0xffffffffui32
57 | #define UINT64_MAX 0xffffffffffffffffui64
58 | #endif
59 |
60 | #define __PRI_8_LENGTH_MODIFIER__ "hh"
61 | #define __PRI_64_LENGTH_MODIFIER__ "ll"
62 |
63 | #define PRId8 __PRI_8_LENGTH_MODIFIER__ "d"
64 | #define PRIi8 __PRI_8_LENGTH_MODIFIER__ "i"
65 | #define PRIo8 __PRI_8_LENGTH_MODIFIER__ "o"
66 | #define PRIu8 __PRI_8_LENGTH_MODIFIER__ "u"
67 | #define PRIx8 __PRI_8_LENGTH_MODIFIER__ "x"
68 | #define PRIX8 __PRI_8_LENGTH_MODIFIER__ "X"
69 |
70 | #define PRId16 "hd"
71 | #define PRIi16 "hi"
72 | #define PRIo16 "ho"
73 | #define PRIu16 "hu"
74 | #define PRIx16 "hx"
75 | #define PRIX16 "hX"
76 |
77 | #if defined(_MSC_VER) && _MSC_VER <= 1700
78 | #define PRId32 "ld"
79 | #define PRIi32 "li"
80 | #define PRIo32 "lo"
81 | #define PRIu32 "lu"
82 | #define PRIx32 "lx"
83 | #define PRIX32 "lX"
84 | #else // OSX
85 | #define PRId32 "d"
86 | #define PRIi32 "i"
87 | #define PRIo32 "o"
88 | #define PRIu32 "u"
89 | #define PRIx32 "x"
90 | #define PRIX32 "X"
91 | #endif
92 |
93 | #if defined(_MSC_VER) && _MSC_VER <= 1700
94 | // redefine functions from inttypes.h used in cstool
95 | #define strtoull _strtoui64
96 | #endif
97 |
98 | #define PRId64 __PRI_64_LENGTH_MODIFIER__ "d"
99 | #define PRIi64 __PRI_64_LENGTH_MODIFIER__ "i"
100 | #define PRIo64 __PRI_64_LENGTH_MODIFIER__ "o"
101 | #define PRIu64 __PRI_64_LENGTH_MODIFIER__ "u"
102 | #define PRIx64 __PRI_64_LENGTH_MODIFIER__ "x"
103 | #define PRIX64 __PRI_64_LENGTH_MODIFIER__ "X"
104 |
105 | #else
106 | // this system has inttypes.h by default
107 | #include
108 | #endif
109 |
110 | #endif
111 |
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/include/windowsce/intrin.h:
--------------------------------------------------------------------------------
1 |
2 | #if defined(_MSC_VER) && defined(_WIN32_WCE) && (_WIN32_WCE < 0x800) && !defined(__INTRIN_H_) && !defined(_INTRIN)
3 | #define _STDINT
4 |
5 | #ifdef _M_ARM
6 | #include
7 | #if (_WIN32_WCE >= 0x700) && defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__)
8 | #include
9 | #endif
10 | #endif // _M_ARM
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/patch_kernel_root/3rdparty/capstone-4.0.2-win64/include/windowsce/stdint.h:
--------------------------------------------------------------------------------
1 |
2 | #if defined(_MSC_VER) && defined(_WIN32_WCE) && (_WIN32_WCE < 0x800) && !defined(_STDINT_H_) && !defined(_STDINT)
3 | #define _STDINT
4 |
5 | typedef __int8
6 | int8_t,
7 | int_least8_t;
8 |
9 | typedef __int16
10 | int16_t,
11 | int_least16_t;
12 |
13 | typedef __int32
14 | int32_t,
15 | int_least32_t,
16 | int_fast8_t,
17 | int_fast16_t,
18 | int_fast32_t;
19 |
20 | typedef __int64
21 | int64_t,
22 | intmax_t,
23 | int_least64_t,
24 | int_fast64_t;
25 |
26 | typedef unsigned __int8
27 | uint8_t,
28 | uint_least8_t;
29 |
30 | typedef unsigned __int16
31 | uint16_t,
32 | uint_least16_t;
33 |
34 | typedef unsigned __int32
35 | uint32_t,
36 | uint_least32_t,
37 | uint_fast8_t,
38 | uint_fast16_t,
39 | uint_fast32_t;
40 |
41 | typedef unsigned __int64
42 | uint64_t,
43 | uintmax_t,
44 | uint_least64_t,
45 | uint_fast64_t;
46 |
47 | #ifndef _INTPTR_T_DEFINED
48 | #define _INTPTR_T_DEFINED
49 | typedef __int32 intptr_t;
50 | #endif
51 |
52 | #ifndef _UINTPTR_T_DEFINED
53 | #define _UINTPTR_T_DEFINED
54 | typedef unsigned __int32 uintptr_t;
55 | #endif
56 |
57 | #define INT8_MIN (-127i8 - 1)
58 | #define INT16_MIN (-32767i16 - 1)
59 | #define INT32_MIN (-2147483647i32 - 1)
60 | #define INT64_MIN (-9223372036854775807i64 - 1)
61 | #define INT8_MAX 127i8
62 | #define INT16_MAX 32767i16
63 | #define INT32_MAX 2147483647i32
64 | #define INT64_MAX 9223372036854775807i64
65 | #define UINT8_MAX 0xffui8
66 | #define UINT16_MAX 0xffffui16
67 | #define UINT32_MAX 0xffffffffui32
68 | #define UINT64_MAX 0xffffffffffffffffui64
69 |
70 | #define INT_LEAST8_MIN INT8_MIN
71 | #define INT_LEAST16_MIN INT16_MIN
72 | #define INT_LEAST32_MIN INT32_MIN
73 | #define INT_LEAST64_MIN INT64_MIN
74 | #define INT_LEAST8_MAX INT8_MAX
75 | #define INT_LEAST16_MAX INT16_MAX
76 | #define INT_LEAST32_MAX INT32_MAX
77 | #define INT_LEAST64_MAX INT64_MAX
78 | #define UINT_LEAST8_MAX UINT8_MAX
79 | #define UINT_LEAST16_MAX UINT16_MAX
80 | #define UINT_LEAST32_MAX UINT32_MAX
81 | #define UINT_LEAST64_MAX UINT64_MAX
82 |
83 | #define INT_FAST8_MIN INT8_MIN
84 | #define INT_FAST16_MIN INT32_MIN
85 | #define INT_FAST32_MIN INT32_MIN
86 | #define INT_FAST64_MIN INT64_MIN
87 | #define INT_FAST8_MAX INT8_MAX
88 | #define INT_FAST16_MAX INT32_MAX
89 | #define INT_FAST32_MAX INT32_MAX
90 | #define INT_FAST64_MAX INT64_MAX
91 | #define UINT_FAST8_MAX UINT8_MAX
92 | #define UINT_FAST16_MAX UINT32_MAX
93 | #define UINT_FAST32_MAX UINT32_MAX
94 | #define UINT_FAST64_MAX UINT64_MAX
95 |
96 | #define INTPTR_MIN INT32_MIN
97 | #define INTPTR_MAX INT32_MAX
98 | #define UINTPTR_MAX UINT32_MAX
99 |
100 | #define INTMAX_MIN INT64_MIN
101 | #define INTMAX_MAX INT64_MAX
102 | #define UINTMAX_MAX UINT64_MAX
103 |
104 | #define PTRDIFF_MIN INTPTR_MIN
105 | #define PTRDIFF_MAX INTPTR_MAX
106 |
107 | #ifndef SIZE_MAX
108 | #define SIZE_MAX UINTPTR_MAX
109 | #endif
110 |
111 | #define SIG_ATOMIC_MIN INT32_MIN
112 | #define SIG_ATOMIC_MAX INT32_MAX
113 |
114 | #define WCHAR_MIN 0x0000
115 | #define WCHAR_MAX 0xffff
116 |
117 | #define WINT_MIN 0x0000
118 | #define WINT_MAX 0xffff
119 |
120 | #define INT8_C(x) (x)
121 | #define INT16_C(x) (x)
122 | #define INT32_C(x) (x)
123 | #define INT64_C(x) (x ## LL)
124 |
125 | #define UINT8_C(x) (x)
126 | #define UINT16_C(x) (x)
127 | #define UINT32_C(x) (x ## U)
128 | #define UINT64_C(x) (x ## ULL)
129 |
130 | #define INTMAX_C(x) INT64_C(x)
131 | #define UINTMAX_C(x) UINT64_C(x)
132 |
133 | #endif
134 |
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/ARM_asm.h:
--------------------------------------------------------------------------------
1 | #ifndef ARM_ASM_HELPER_H_
2 | #define ARM_ASM_HELPER_H_
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "base_func.h"
9 |
10 | static std::string AsmToBytes(const std::string& strArm64Asm) {
11 | //获取汇编文本
12 |
13 | //获取自身运行目录
14 | char szFileName[MAX_PATH] = { 0 };
15 | ::GetModuleFileNameA(NULL, szFileName, MAX_PATH);
16 | std::string strMyPath = szFileName;
17 | strMyPath = strMyPath.substr(0, strMyPath.find_last_of('\\') + 1);
18 |
19 | std::string asmFilePath = strMyPath + "aarch64-linux-android-as.exe";
20 | if (!std::filesystem::exists(asmFilePath)) {
21 | std::cerr << "Error: aarch64-linux-android-as.exe not found. Please extract this file from the Android NDK." << std::endl;
22 | exit(EXIT_FAILURE);
23 | }
24 |
25 | //写出input.txt
26 | std::ofstream inputFile;
27 | inputFile.open(strMyPath + "input.txt", std::ios_base::out | std::ios_base::trunc);
28 | inputFile << strArm64Asm;
29 | inputFile.close();
30 |
31 | //ARM64
32 | DeleteFileA(std::string(strMyPath + "output.txt").c_str());
33 |
34 | std::string cmd = strMyPath + "aarch64-linux-android-as.exe -ahlm " + strMyPath + "input.txt >> " + strMyPath + "output.txt";
35 | system(cmd.c_str());
36 |
37 | //未开发的
38 | //ARM:arm-linux-as.exe -ahlm -k -mthumb-interwork -march=armv7-a %s >> %s
39 | //Thumb:arm-linux-as.exe -ahlm -k -mthumb-interwork -march=armv7 %s >> %s
40 |
41 | //读取output.txt
42 | std::ifstream in(strMyPath + "output.txt");
43 | std::stringstream ssOutput;
44 | std::string line;
45 | bool bIsFirstLine = true;
46 | if (in) // 有该文件
47 | {
48 | while (getline(in, line)) // line中不包括每行的换行符
49 | {
50 | if (bIsFirstLine) {
51 | bIsFirstLine = false;
52 | continue;
53 | }
54 | if (!line.length()) { continue; }
55 | if (line.length() == 1 && line == "\n") { continue; }
56 | if (line.find("Error") != -1) {
57 | in.close();
58 | return {};
59 | }
60 | if (line.find("AARCH64 GAS") != -1) { continue; }
61 |
62 | std::stringstream ssGetMidBuf;
63 | std::string word;
64 | ssGetMidBuf << line;
65 | int n = 0;
66 | while (ssGetMidBuf >> word) {
67 | n++;
68 | if (n == 3) {
69 | ssOutput << word;
70 | }
71 | word.clear();
72 | }
73 |
74 |
75 | }
76 | in.close();
77 | }
78 |
79 | return ssOutput.str();
80 |
81 | }
82 |
83 | static std::string AsmLabelToOffset(const std::string& asm_code, const char* end_label_name, const char* jump_label_name) {
84 | // 得到结尾位置
85 | std::string s = asm_code;
86 | size_t n = s.find(end_label_name);
87 | if (n == -1) {
88 | return s;
89 | }
90 | std::string before = s.substr(0, n);
91 | size_t end_back_idx_line = count_endl(before);
92 | replace_all_distinct(s, end_label_name, "");
93 |
94 | // 逐行切割
95 | std::vector lines;
96 | {
97 | std::istringstream iss(s);
98 | std::string line;
99 | while (std::getline(iss, line)) {
100 | if (!line.empty() && line.back() == '\r')
101 | line.pop_back();
102 | lines.push_back(line);
103 | }
104 | }
105 |
106 | // 替换每一行中的 #JUMP_END
107 | const std::string placeholder = jump_label_name;
108 | for (size_t idx = 0; idx < lines.size(); ++idx) {
109 | auto p = lines[idx].find(placeholder);
110 | if (p != std::string::npos) {
111 | int imm = (end_back_idx_line - idx) * 4;
112 | lines[idx].replace(p, placeholder.size(), std::to_string(imm));
113 | }
114 | }
115 |
116 | // 拼回去
117 | std::string out;
118 | for (size_t i = 0; i < lines.size(); ++i) {
119 | out += lines[i];
120 | out += "\n";
121 | }
122 | return out;
123 | }
124 |
125 | #endif /* ARM_ASM_HELPER_H_ */
126 |
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/base_func.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | static const char HEX[16] = {
11 | '0', '1', '2', '3',
12 | '4', '5', '6', '7',
13 | '8', '9', 'a', 'b',
14 | 'c', 'd', 'e', 'f'
15 | };
16 |
17 | static std::vector read_file_buf(const std::string& file_path) {
18 | std::ifstream file(file_path, std::ios::binary | std::ios::ate);
19 | if (file) {
20 | auto size = file.tellg();
21 | std::vector buffer(size);
22 | file.seekg(0, std::ios::beg);
23 | file.read(buffer.data(), size);
24 | file.close();
25 | return buffer;
26 | }
27 | return {};
28 | }
29 |
30 | static void get_rand_str(char* dest, int n) {
31 | int i, randno;
32 | char stardstring[63] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
33 | srand((unsigned)time(NULL));
34 | for (i = 0; i < n; i++) {
35 | randno = rand() % 62;
36 | *dest = stardstring[randno];
37 | dest++;
38 | }
39 | }
40 |
41 | static std::string generate_random_root_key() {
42 | const int key_len = 48;
43 | char root_key_data[key_len] = { 0 };
44 | get_rand_str(root_key_data, sizeof(root_key_data));
45 | std::string str_root_key(root_key_data, sizeof(root_key_data));
46 | return str_root_key;
47 | }
48 |
49 | static auto hex2bytes(uint8_t* hex, uint8_t* str) -> void {
50 | char high, low;
51 | for (size_t i = 0, length = strlen((char*)hex); i < length; i += 2) {
52 | high = toupper(hex[i]) - '0';
53 | low = toupper(hex[i + 1]) - '0';
54 | str[i / 2] = ((high > 9 ? high - 7 : high) << 4) + (low > 9 ? low - 7 : low);
55 | }
56 | }
57 | static std::string bytes2hex(const unsigned char* input, size_t length) {
58 |
59 | std::string str;
60 | str.reserve(length << 1);
61 | for (size_t i = 0; i < length; ++i) {
62 | int t = input[i];
63 | int a = t / 16;
64 | int b = t % 16;
65 | str.append(1, HEX[a]);
66 | str.append(1, HEX[b]);
67 | }
68 | return str;
69 | }
70 |
71 | static bool write_file_bytes(const char* file_path, size_t offset, const char* bytes, size_t len) {
72 | std::fstream file_stream(file_path, std::ios::in | std::ios::out | std::ios::binary);
73 | if (!file_stream) {
74 | return false;
75 | }
76 | file_stream.seekp(offset);
77 | if (!file_stream.good()) {
78 | file_stream.close();
79 | return false;
80 | }
81 | file_stream.write(bytes, len);
82 | if (!file_stream.good()) {
83 | file_stream.close();
84 | return false;
85 | }
86 | file_stream.close();
87 | return true;
88 | }
89 |
90 | static size_t align8(size_t addr) {
91 | if (addr % 8 != 0) {
92 | addr = (addr + 7) & ~static_cast(7); // Align to next 8-byte boundary
93 | }
94 | return addr;
95 | }
96 |
97 | static size_t count_endl(const std::string& s) {
98 | return std::count(s.begin(), s.end(), '\n');
99 | }
100 |
101 | static void replace_all_distinct(std::string& str, const std::string& old_value, const std::string& new_value) {
102 | for (std::string::size_type pos(0); pos != std::string::npos; pos += new_value.length()) {
103 | if ((pos = str.find(old_value, pos)) != std::string::npos) {
104 | str.replace(pos, old_value.length(), new_value);
105 | }
106 | else {
107 | break;
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/kallsyms_lookup_name.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | class KallsymsLookupName
5 | {
6 | public:
7 | KallsymsLookupName(const std::vector& file_buf);
8 | ~KallsymsLookupName();
9 |
10 | public:
11 | bool init();
12 | bool is_inited();
13 | uint64_t kallsyms_lookup_name(const char* name, bool include_str_mode = false);
14 | int get_kallsyms_num();
15 |
16 | private:
17 | bool find_kallsyms_addresses_list(size_t& start, size_t& end);
18 | int find_kallsyms_num(size_t addresses_list_start, size_t addresses_list_end, size_t& kallsyms_num_offset);
19 | bool find_kallsyms_names_list(int kallsyms_num, size_t kallsyms_num_end_offset, size_t& name_list_start, size_t& name_list_end);
20 | bool find_kallsyms_markers_list(int kallsyms_num, size_t name_list_end_offset, size_t& markers_list_start, size_t& markers_list_end);
21 | bool find_kallsyms_token_table(size_t markers_list_end_offset, size_t& kallsyms_token_table_start, size_t& kallsyms_token_table_end);
22 | bool find_kallsyms_token_index(size_t kallsyms_token_table_end, size_t& kallsyms_token_index_start);
23 | bool find_kallsyms_sym_func_entry_offset(size_t& kallsyms_sym_func_entry_offset);
24 |
25 | unsigned int kallsyms_expand_symbol(unsigned int off, char* result, size_t maxlen);
26 | uint64_t __kallsyms_lookup_name(const char* name, bool include_str_mode = false);
27 |
28 | const std::vector& m_file_buf;
29 | int m_kallsyms_num = 0;
30 | bool m_inited = false;
31 | size_t m_kallsyms_sym_func_entry_offset = 0;
32 | size_t m_text_offset = 0;
33 | struct kallsyms_addresses_info {
34 | size_t offset = 0;
35 | void printf() {
36 | std::cout << std::hex << "kallsyms_addressess offset: 0x" << offset << std::endl;
37 | }
38 | } m_kallsyms_addresses;
39 |
40 | struct kallsyms_names_info {
41 | size_t offset = 0;
42 | void printf() {
43 | std::cout << std::hex << "kallsyms_names offset: 0x" << offset << std::endl;
44 | }
45 | } m_kallsyms_names;
46 |
47 | struct kallsyms_markers_info {
48 | size_t offset = 0;
49 | void printf() {
50 | std::cout << std::hex << "kallsyms_markers offset: 0x" << offset << std::endl;
51 | }
52 | } m_kallsyms_markers;
53 |
54 | struct kallsyms_token_table_info {
55 | size_t offset = 0;
56 | void printf() {
57 | std::cout << std::hex << "kallsyms_token_table offset: 0x" << offset << std::endl;
58 | }
59 | } m_kallsyms_token_table;
60 |
61 | struct kallsyms_token_index_info {
62 | size_t offset = 0;
63 | void printf() {
64 | std::cout << std::hex << "kallsyms_token_index offset: 0x" << offset << std::endl;
65 | }
66 | } m_kallsyms_token_index;
67 | };
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/kallsyms_lookup_name_4_6_0.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | class KallsymsLookupName_4_6_0
5 | {
6 | public:
7 | KallsymsLookupName_4_6_0(const std::vector& file_buf);
8 | ~KallsymsLookupName_4_6_0();
9 |
10 | public:
11 | bool init();
12 | bool is_inited();
13 | uint64_t kallsyms_lookup_name(const char* name, bool include_str_mode = false);
14 | int get_kallsyms_num();
15 |
16 | private:
17 | bool find_kallsyms_offsets_list(size_t& start, size_t& end);
18 | int find_kallsyms_num(size_t offset_list_start, size_t offset_list_end, size_t& kallsyms_num_offset);
19 | bool find_kallsyms_names_list(int kallsyms_num, size_t kallsyms_num_end_offset, size_t& name_list_start, size_t& name_list_end);
20 | bool find_kallsyms_markers_list(int kallsyms_num, size_t name_list_end_offset, size_t& markers_list_start, size_t& markers_list_end);
21 | bool find_kallsyms_token_table(size_t markers_list_end_offset, size_t& kallsyms_token_table_start, size_t& kallsyms_token_table_end);
22 | bool find_kallsyms_token_index(size_t kallsyms_token_table_end, size_t& kallsyms_token_index_start);
23 | bool find_kallsyms_sym_func_entry_offset(size_t& kallsyms_sym_func_entry_offset);
24 |
25 | unsigned int kallsyms_expand_symbol(unsigned int off, char* result, size_t maxlen);
26 | uint64_t __kallsyms_lookup_name(const char* name, bool include_str_mode = false);
27 |
28 | const std::vector& m_file_buf;
29 | int m_kallsyms_num = 0;
30 | bool m_inited = false;
31 | size_t m_kallsyms_sym_func_entry_offset = 0;
32 |
33 | struct kallsyms_offsets_info {
34 | size_t offset = 0;
35 | void printf() {
36 | std::cout << std::hex << "kallsyms_offsets offset: 0x" << offset << std::endl;
37 | }
38 | } m_kallsyms_offsets;
39 |
40 | struct kallsyms_names_info {
41 | size_t offset = 0;
42 | void printf() {
43 | std::cout << std::hex << "kallsyms_names offset: 0x" << offset << std::endl;
44 | }
45 | } m_kallsyms_names;
46 |
47 | struct kallsyms_markers_info {
48 | size_t offset = 0;
49 | void printf() {
50 | std::cout << std::hex << "kallsyms_markers offset: 0x" << offset << std::endl;
51 | }
52 | } m_kallsyms_markers;
53 |
54 | struct kallsyms_token_table_info {
55 | size_t offset = 0;
56 | void printf() {
57 | std::cout << std::hex << "kallsyms_token_table offset: 0x" << offset << std::endl;
58 | }
59 | } m_kallsyms_token_table;
60 |
61 | struct kallsyms_token_index_info {
62 | size_t offset = 0;
63 | void printf() {
64 | std::cout << std::hex << "kallsyms_token_index offset: 0x" << offset << std::endl;
65 | }
66 | } m_kallsyms_token_index;
67 | };
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/kallsyms_lookup_name_6_1_42.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | class KallsymsLookupName_6_1_42
5 | {
6 | public:
7 | KallsymsLookupName_6_1_42(const std::vector& file_buf);
8 | ~KallsymsLookupName_6_1_42();
9 |
10 | public:
11 | bool init();
12 | bool is_inited();
13 | uint64_t kallsyms_lookup_name(const char* name, bool include_str_mode = false);
14 | int get_kallsyms_num();
15 |
16 | private:
17 | bool find_kallsyms_offsets_list(size_t& start, size_t& end);
18 | uint64_t find_kallsyms_relative_base(size_t offset_list_end, size_t& kallsyms_relative_base_offset);
19 | int find_kallsyms_num(size_t offset_list_start, size_t offset_list_end, size_t kallsyms_relative_base_end_offset, size_t& kallsyms_num_offset);
20 | bool find_kallsyms_names_list(int kallsyms_num, size_t kallsyms_num_end_offset, size_t& name_list_start, size_t& name_list_end);
21 | bool find_kallsyms_markers_list(int kallsyms_num, size_t name_list_end_offset, size_t& markers_list_start, size_t& markers_list_end, bool & markers_list_is_align8);
22 | bool find_kallsyms_seqs_of_names_list(int kallsyms_num, size_t markers_list_end_offset, bool markers_list_is_align8, size_t& seqs_of_names_list_start, size_t& seqs_of_names_list_end);
23 | bool find_kallsyms_token_table(size_t seqs_of_names_list_end_offset, size_t& kallsyms_token_table_start, size_t& kallsyms_token_table_end);
24 | bool find_kallsyms_token_index(size_t kallsyms_token_table_end, size_t& kallsyms_token_index_start);
25 | bool find_kallsyms_sym_func_entry_offset(size_t& kallsyms_sym_func_entry_offset);
26 |
27 | unsigned int kallsyms_expand_symbol(unsigned int off, char* result, size_t maxlen);
28 | uint64_t __kallsyms_lookup_name(const char* name, bool include_str_mode = false);
29 | int kallsyms_lookup_names(const char* name, unsigned int* start, unsigned int* end);
30 | unsigned int get_symbol_offset(unsigned long pos);
31 | uint64_t kallsyms_sym_address(int idx);
32 | int compare_symbol_name(const char* name, char* namebuf);
33 | bool cleanup_symbol_name(char* s);
34 |
35 | const std::vector& m_file_buf;
36 | uint64_t m_kallsyms_relative_base = 0;
37 | int m_kallsyms_num = 0;
38 | bool m_inited = false;
39 | size_t m_kallsyms_sym_func_entry_offset = 0;
40 |
41 | struct kallsyms_offsets_info {
42 | size_t offset = 0;
43 | void printf() {
44 | std::cout << std::hex << "kallsyms_offsets offset: 0x" << offset << std::endl;
45 | }
46 | } m_kallsyms_offsets;
47 |
48 | struct kallsyms_names_info {
49 | size_t offset = 0;
50 | void printf() {
51 | std::cout << std::hex << "kallsyms_names offset: 0x" << offset << std::endl;
52 | }
53 | } m_kallsyms_names;
54 |
55 | struct kallsyms_markers_info {
56 | size_t offset = 0;
57 | void printf() {
58 | std::cout << std::hex << "kallsyms_markers offset: 0x" << offset << std::endl;
59 | }
60 | } m_kallsyms_markers;
61 |
62 | struct kallsyms_seqs_of_names_info {
63 | size_t offset = 0;
64 | void printf() {
65 | std::cout << std::hex << "kallsyms_seqs_of_names offset: 0x" << offset << std::endl;
66 | }
67 | } m_kallsyms_seqs_of_names;
68 |
69 | struct kallsyms_token_table_info {
70 | size_t offset = 0;
71 | void printf() {
72 | std::cout << std::hex << "kallsyms_token_table offset: 0x" << offset << std::endl;
73 | }
74 | } m_kallsyms_token_table;
75 |
76 | struct kallsyms_token_index_info {
77 | size_t offset = 0;
78 | void printf() {
79 | std::cout << std::hex << "kallsyms_token_index offset: 0x" << offset << std::endl;
80 | }
81 | } m_kallsyms_token_index;
82 | };
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/kallsyms_lookup_name_6_1_60.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | class KallsymsLookupName_6_1_60
5 | {
6 | public:
7 | KallsymsLookupName_6_1_60(const std::vector& file_buf);
8 | ~KallsymsLookupName_6_1_60();
9 |
10 | public:
11 | bool init();
12 | bool is_inited();
13 | uint64_t kallsyms_lookup_name(const char* name, bool include_str_mode = false);
14 | int get_kallsyms_num();
15 |
16 | private:
17 | bool find_kallsyms_offsets_list(size_t& start, size_t& end);
18 | uint64_t find_kallsyms_relative_base(size_t offset_list_end, size_t& kallsyms_relative_base_offset);
19 | int find_kallsyms_num(size_t offset_list_start, size_t offset_list_end, size_t kallsyms_relative_base_end_offset, size_t& kallsyms_num_offset);
20 | bool find_kallsyms_names_list(int kallsyms_num, size_t kallsyms_num_end_offset, size_t& name_list_start, size_t& name_list_end);
21 | bool find_kallsyms_markers_list(int kallsyms_num, size_t name_list_end_offset, size_t& markers_list_start, size_t& markers_list_end, bool & markers_list_is_align8);
22 | bool find_kallsyms_seqs_of_names_list(int kallsyms_num, size_t markers_list_end_offset, bool markers_list_is_align8, size_t& seqs_of_names_list_start, size_t& seqs_of_names_list_end);
23 | bool find_kallsyms_token_table(size_t seqs_of_names_list_end_offset, size_t& kallsyms_token_table_start, size_t& kallsyms_token_table_end);
24 | bool find_kallsyms_token_index(size_t kallsyms_token_table_end, size_t& kallsyms_token_index_start);
25 | bool find_kallsyms_sym_func_entry_offset(size_t& kallsyms_sym_func_entry_offset);
26 |
27 | unsigned int kallsyms_expand_symbol(unsigned int off, char* result, size_t maxlen);
28 | uint64_t __kallsyms_lookup_name(const char* name, bool include_str_mode = false);
29 | int kallsyms_lookup_names(const char* name, unsigned int* start, unsigned int* end);
30 | unsigned int get_symbol_seq(int index);
31 | unsigned int get_symbol_offset(unsigned long pos);
32 | uint64_t kallsyms_sym_address(int idx);
33 | int compare_symbol_name(const char* name, char* namebuf);
34 | bool cleanup_symbol_name(char* s);
35 |
36 | const std::vector& m_file_buf;
37 | uint64_t m_kallsyms_relative_base = 0;
38 | int m_kallsyms_num = 0;
39 | bool m_inited = false;
40 | size_t m_kallsyms_sym_func_entry_offset = 0;
41 |
42 | struct kallsyms_offsets_info {
43 | size_t offset = 0;
44 | void printf() {
45 | std::cout << std::hex << "kallsyms_offsets offset: 0x" << offset << std::endl;
46 | }
47 | } m_kallsyms_offsets;
48 |
49 | struct kallsyms_names_info {
50 | size_t offset = 0;
51 | void printf() {
52 | std::cout << std::hex << "kallsyms_names offset: 0x" << offset << std::endl;
53 | }
54 | } m_kallsyms_names;
55 |
56 | struct kallsyms_markers_info {
57 | size_t offset = 0;
58 | void printf() {
59 | std::cout << std::hex << "kallsyms_markers offset: 0x" << offset << std::endl;
60 | }
61 | } m_kallsyms_markers;
62 |
63 | struct kallsyms_seqs_of_names_info {
64 | size_t offset = 0;
65 | void printf() {
66 | std::cout << std::hex << "kallsyms_seqs_of_names offset: 0x" << offset << std::endl;
67 | }
68 | } m_kallsyms_seqs_of_names;
69 |
70 | struct kallsyms_token_table_info {
71 | size_t offset = 0;
72 | void printf() {
73 | std::cout << std::hex << "kallsyms_token_table offset: 0x" << offset << std::endl;
74 | }
75 | } m_kallsyms_token_table;
76 |
77 | struct kallsyms_token_index_info {
78 | size_t offset = 0;
79 | void printf() {
80 | std::cout << std::hex << "kallsyms_token_index offset: 0x" << offset << std::endl;
81 | }
82 | } m_kallsyms_token_index;
83 | };
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/kallsyms_lookup_name_6_6_30.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | class KallsymsLookupName_6_6_30
5 | {
6 | public:
7 | KallsymsLookupName_6_6_30(const std::vector& file_buf);
8 | ~KallsymsLookupName_6_6_30();
9 |
10 | public:
11 | bool init();
12 | bool is_inited();
13 | uint64_t kallsyms_lookup_name(const char* name, bool include_str_mode = false);
14 | int get_kallsyms_num();
15 |
16 | private:
17 | bool find_kallsyms_offsets_list(size_t& start, size_t& end);
18 | uint64_t find_kallsyms_relative_base(size_t offset_list_end, size_t& kallsyms_relative_base_offset);
19 | std::vector find_maybe_kallsyms_num(size_t offset_list_start, size_t offset_list_end);
20 | bool find_kallsyms_names_list(int kallsyms_num, size_t kallsyms_num_end_offset, size_t& name_list_start, size_t& name_list_end);
21 | bool find_kallsyms_markers_list(int kallsyms_num, size_t name_list_end_offset, size_t& markers_list_start, size_t& markers_list_end, bool & markers_list_is_align8);
22 | bool find_kallsyms_seqs_of_names_list(int kallsyms_num, size_t kallsyms_relative_base_end_offset, bool markers_list_is_align8, size_t& seqs_of_names_list_start, size_t& seqs_of_names_list_end);
23 | bool find_kallsyms_token_table(size_t kallsyms_markers_list_end_offset, size_t& kallsyms_token_table_start, size_t& kallsyms_token_table_end);
24 | bool find_kallsyms_token_index(size_t kallsyms_token_table_start, size_t& kallsyms_token_index_start);
25 | bool find_kallsyms_sym_func_entry_offset(size_t& kallsyms_sym_func_entry_offset);
26 |
27 | unsigned int kallsyms_expand_symbol(unsigned int off, char* result, size_t maxlen);
28 | uint64_t __kallsyms_lookup_name(const char* name, bool include_str_mode = false);
29 | int kallsyms_lookup_names(const char* name, unsigned int* start, unsigned int* end);
30 | unsigned int get_symbol_seq(int index);
31 | unsigned int get_symbol_offset(unsigned long pos);
32 | uint64_t kallsyms_sym_address(int idx);
33 | int compare_symbol_name(const char* name, char* namebuf);
34 | bool cleanup_symbol_name(char* s);
35 |
36 | const std::vector& m_file_buf;
37 | uint64_t m_kallsyms_relative_base = 0;
38 | int m_kallsyms_num = 0;
39 | bool m_inited = false;
40 | size_t m_kallsyms_sym_func_entry_offset = 0;
41 |
42 | struct kallsyms_offsets_info {
43 | size_t offset = 0;
44 | void printf() {
45 | std::cout << std::hex << "kallsyms_offsets offset: 0x" << offset << std::endl;
46 | }
47 | } m_kallsyms_offsets;
48 |
49 | struct kallsyms_names_info {
50 | size_t offset = 0;
51 | void printf() {
52 | std::cout << std::hex << "kallsyms_names offset: 0x" << offset << std::endl;
53 | }
54 | } m_kallsyms_names;
55 |
56 | struct kallsyms_markers_info {
57 | size_t offset = 0;
58 | void printf() {
59 | std::cout << std::hex << "kallsyms_markers offset: 0x" << offset << std::endl;
60 | }
61 | } m_kallsyms_markers;
62 |
63 | struct kallsyms_seqs_of_names_info {
64 | size_t offset = 0;
65 | void printf() {
66 | std::cout << std::hex << "kallsyms_seqs_of_names offset: 0x" << offset << std::endl;
67 | }
68 | } m_kallsyms_seqs_of_names;
69 |
70 | struct kallsyms_token_table_info {
71 | size_t offset = 0;
72 | void printf() {
73 | std::cout << std::hex << "kallsyms_token_table offset: 0x" << offset << std::endl;
74 | }
75 | } m_kallsyms_token_table;
76 |
77 | struct kallsyms_token_index_info {
78 | size_t offset = 0;
79 | void printf() {
80 | std::cout << std::hex << "kallsyms_token_index offset: 0x" << offset << std::endl;
81 | }
82 | } m_kallsyms_token_index;
83 | };
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/kernel_symbol_parser.cpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "kernel_symbol_parser.h"
3 | #include
4 |
5 | #ifndef MIN
6 | #define MIN(x, y)(x < y) ? (x) : (y)
7 | #endif // !MIN
8 |
9 | KernelSymbolParser::KernelSymbolParser(const std::vector& file_buf) : m_file_buf(file_buf), m_kernel_ver_parser(file_buf)
10 | , m_kallsyms_lookup_name_6_6_30(file_buf)
11 | , m_kallsyms_lookup_name_6_1_60(file_buf)
12 | , m_kallsyms_lookup_name_6_1_42(file_buf)
13 | , m_kallsyms_lookup_name_4_6_0(file_buf)
14 | , m_kallsyms_lookup_name(file_buf)
15 | {
16 | }
17 |
18 | KernelSymbolParser::~KernelSymbolParser()
19 | {
20 | }
21 |
22 | bool KernelSymbolParser::init_kallsyms_lookup_name() {
23 |
24 | std::string current_version = m_kernel_ver_parser.find_kernel_versions();
25 | if (current_version.empty()) {
26 | std::cout << "Failed to read Linux kernel version" << std::endl;
27 | return false;
28 | }
29 | std::cout << "Find the current Linux kernel version: " << current_version << std::endl;
30 | std::cout << std::endl;
31 |
32 | if (m_kernel_ver_parser.is_version_less(current_version, "4.6.0")) {
33 | if (!m_kallsyms_lookup_name.init()) {
34 | std::cout << "Failed to analyze kernel kallsyms lookup name information" << std::endl;
35 | return false;
36 | }
37 | } else if (m_kernel_ver_parser.is_version_less(current_version, "6.1.42")) {
38 | if (!m_kallsyms_lookup_name_4_6_0.init()) {
39 | std::cout << "Failed to analyze kernel kallsyms lookup name information" << std::endl;
40 | return false;
41 | }
42 | } else if (m_kernel_ver_parser.is_version_less(current_version, "6.1.60")) {
43 | if (!m_kallsyms_lookup_name_6_1_42.init()) {
44 | std::cout << "Failed to analyze kernel kallsyms lookup name information" << std::endl;
45 | return false;
46 | }
47 | } else if (m_kernel_ver_parser.is_version_less(current_version, "6.6.30")) {
48 | if (!m_kallsyms_lookup_name_6_1_60.init()) {
49 | std::cout << "Failed to analyze kernel kallsyms lookup name information" << std::endl;
50 | return false;
51 | }
52 | } else {
53 | if (!m_kallsyms_lookup_name_6_6_30.init()) {
54 | std::cout << "Failed to analyze kernel kallsyms lookup name information" << std::endl;
55 | return false;
56 | }
57 | }
58 | return true;
59 | }
60 |
61 | uint64_t KernelSymbolParser::kallsyms_lookup_name(const char* name, bool include_str_mode) {
62 | if (m_kallsyms_lookup_name_6_6_30.is_inited()) {
63 | return m_kallsyms_lookup_name_6_6_30.kallsyms_lookup_name(name, include_str_mode);
64 | } else if (m_kallsyms_lookup_name_6_1_60.is_inited()) {
65 | return m_kallsyms_lookup_name_6_1_60.kallsyms_lookup_name(name, include_str_mode);
66 | } else if (m_kallsyms_lookup_name_6_1_42.is_inited()) {
67 | return m_kallsyms_lookup_name_6_1_42.kallsyms_lookup_name(name, include_str_mode);
68 | } else if (m_kallsyms_lookup_name_4_6_0.is_inited()) {
69 | return m_kallsyms_lookup_name_4_6_0.kallsyms_lookup_name(name, include_str_mode);
70 | } else if (m_kallsyms_lookup_name.is_inited()) {
71 | return m_kallsyms_lookup_name.kallsyms_lookup_name(name, include_str_mode);
72 | } else {
73 | return 0;
74 | }
75 | }
76 |
77 | bool KernelSymbolParser::is_kernel_version_less(const std::string& ver) const {
78 | std::string current_version = m_kernel_ver_parser.find_kernel_versions();
79 | if (!current_version.empty()) {
80 | return m_kernel_ver_parser.is_version_less(current_version, ver);
81 | }
82 | return false;
83 | }
84 |
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/kernel_symbol_parser.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "kernel_version_parser.h"
3 | #include "kallsyms_lookup_name.h"
4 | #include "kallsyms_lookup_name_4_6_0.h"
5 | #include "kallsyms_lookup_name_6_1_42.h"
6 | #include "kallsyms_lookup_name_6_1_60.h"
7 | #include "kallsyms_lookup_name_6_6_30.h"
8 | #include
9 | #include
10 | class KernelSymbolParser
11 | {
12 | public:
13 | KernelSymbolParser(const std::vector& file_buf);
14 | ~KernelSymbolParser();
15 |
16 | public:
17 | bool init_kallsyms_lookup_name();
18 | uint64_t kallsyms_lookup_name(const char* name, bool include_str_mode = false);
19 | bool is_kernel_version_less(const std::string& ver) const;
20 | private:
21 | const std::vector& m_file_buf;
22 | KernelVersionParser m_kernel_ver_parser;
23 | KallsymsLookupName m_kallsyms_lookup_name;
24 | KallsymsLookupName_4_6_0 m_kallsyms_lookup_name_4_6_0;
25 | KallsymsLookupName_6_1_42 m_kallsyms_lookup_name_6_1_42;
26 | KallsymsLookupName_6_1_60 m_kallsyms_lookup_name_6_1_60;
27 | KallsymsLookupName_6_6_30 m_kallsyms_lookup_name_6_6_30;
28 | };
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/kernel_version_parser.cpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "kernel_version_parser.h"
3 | #include
4 |
5 | #ifndef MIN
6 | #define MIN(x, y)(x < y) ? (x) : (y)
7 | #endif // !MIN
8 |
9 | KernelVersionParser::KernelVersionParser(const std::vector& file_buf) : m_file_buf(file_buf)
10 | {
11 | }
12 |
13 | KernelVersionParser::~KernelVersionParser()
14 | {
15 | }
16 |
17 | // Helper function to extract and print the version number starting from the given index
18 | std::string KernelVersionParser::extract_version(const std::vector& buffer, size_t start_index) const {
19 | std::string version;
20 | // Extract until we hit a non-version character or end of buffer
21 | while (start_index < buffer.size() && (isdigit(buffer[start_index]) || buffer[start_index] == '.')) {
22 | version.push_back(buffer[start_index]);
23 | ++start_index;
24 | }
25 | return version;
26 | }
27 |
28 | // Function to search for Linux version patterns using memcmp
29 | std::string KernelVersionParser::find_kernel_versions() const {
30 | const size_t safe_end = MIN(m_file_buf.size(), 256);
31 | const char* prefix = "Linux version ";
32 | const size_t prefix_len = strlen(prefix);
33 |
34 | for (size_t i = 0; i + prefix_len <= m_file_buf.size() - safe_end; ++i) {
35 | if (memcmp(m_file_buf.data() + i, prefix, prefix_len) == 0 && isdigit(m_file_buf[i + prefix_len])) {
36 | return extract_version(m_file_buf, i + prefix_len);
37 | }
38 | }
39 | return {};
40 | }
41 |
42 |
43 | // Helper function to split the version string and convert to integers
44 | std::vector KernelVersionParser::parse_version(const std::string& version) const {
45 | std::vector parts;
46 | std::stringstream ss(version);
47 | std::string part;
48 |
49 | while (getline(ss, part, '.')) {
50 | parts.push_back(std::stoi(part));
51 | }
52 | // Ensure we always have at least three parts (fill missing parts with zero)
53 | while (parts.size() < 3) {
54 | parts.push_back(0);
55 | }
56 |
57 | return parts;
58 | }
59 |
60 | // Function to compare two version numbers
61 | bool KernelVersionParser::is_version_less(const std::string& v1, const std::string& v2) const {
62 | auto parts1 = parse_version(v1);
63 | auto parts2 = parse_version(v2);
64 |
65 | // Compare major, minor, and patch versions
66 | for (int i = 0; i < 3; ++i) {
67 | if (parts1[i] < parts2[i]) return true; // If version 1 is less than version 2, return true
68 | if (parts1[i] > parts2[i]) return false; // If version 1 is greater than version 2, return false
69 | }
70 |
71 | // If all parts are equal, return false (i.e., v1 is not less than v2)
72 | return false; // If versions are equal, return false (strictly less)
73 | }
74 |
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/kernel_version_parser.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | class KernelVersionParser
5 | {
6 | public:
7 | KernelVersionParser(const std::vector & file_buf);
8 | ~KernelVersionParser();
9 |
10 | public:
11 | std::string find_kernel_versions() const;
12 | bool is_version_less(const std::string& v1, const std::string& v2) const;
13 | private:
14 | std::string extract_version(const std::vector& buffer, size_t start_index) const;
15 | std::vector parse_version(const std::string& version) const;
16 | const std::vector& m_file_buf;
17 | };
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/symbol_analyze.cpp:
--------------------------------------------------------------------------------
1 | #include "symbol_analyze.h"
2 |
3 | SymbolAnalyze::SymbolAnalyze(const std::vector& file_buf) : m_file_buf(file_buf), m_kernel_sym_parser(file_buf)
4 | {
5 | }
6 |
7 | SymbolAnalyze::~SymbolAnalyze()
8 | {
9 | }
10 |
11 | bool SymbolAnalyze::analyze_kernel_symbol() {
12 | if (!m_kernel_sym_parser.init_kallsyms_lookup_name()) {
13 | std::cout << "Failed to initialize kallsyms lookup name" << std::endl;
14 | return false;
15 | }
16 | if (!find_symbol_offset()) {
17 | std::cout << "Failed to find symbol offset" << std::endl;
18 | return false;
19 | }
20 | return true;
21 | }
22 |
23 | KernelSymbolOffset SymbolAnalyze::get_symbol_offset() {
24 | return m_kernel_sym_offset;
25 | }
26 |
27 | bool SymbolAnalyze::is_kernel_version_less(const std::string& ver) const {
28 | return m_kernel_sym_parser.is_kernel_version_less(ver);
29 | }
30 |
31 | bool SymbolAnalyze::find_symbol_offset() {
32 | m_kernel_sym_offset._text = m_kernel_sym_parser.kallsyms_lookup_name("_text");
33 | m_kernel_sym_offset._stext = m_kernel_sym_parser.kallsyms_lookup_name("_stext");
34 |
35 | m_kernel_sym_offset.die = m_kernel_sym_parser.kallsyms_lookup_name("die");
36 | m_kernel_sym_offset.arm64_notify_die = m_kernel_sym_parser.kallsyms_lookup_name("arm64_notify_die");
37 | m_kernel_sym_offset.kernel_restart = m_kernel_sym_parser.kallsyms_lookup_name("kernel_restart");
38 |
39 | m_kernel_sym_offset.__do_execve_file = m_kernel_sym_parser.kallsyms_lookup_name("__do_execve_file");
40 |
41 | m_kernel_sym_offset.do_execveat_common = m_kernel_sym_parser.kallsyms_lookup_name("do_execveat_common");
42 | if (m_kernel_sym_offset.do_execveat_common == 0) {
43 | m_kernel_sym_offset.do_execveat_common = m_kernel_sym_parser.kallsyms_lookup_name("do_execveat_common", true);
44 | }
45 |
46 | m_kernel_sym_offset.do_execve_common = m_kernel_sym_parser.kallsyms_lookup_name("do_execve_common");
47 | if (m_kernel_sym_offset.do_execve_common == 0) {
48 | m_kernel_sym_offset.do_execve_common = m_kernel_sym_parser.kallsyms_lookup_name("do_execve_common", true);
49 | }
50 |
51 | m_kernel_sym_offset.do_execveat = m_kernel_sym_parser.kallsyms_lookup_name("do_execveat");
52 | m_kernel_sym_offset.do_execve = m_kernel_sym_parser.kallsyms_lookup_name("do_execve");
53 |
54 |
55 | m_kernel_sym_offset.avc_denied = m_kernel_sym_parser.kallsyms_lookup_name("avc_denied");
56 | if (m_kernel_sym_offset.avc_denied == 0) {
57 | m_kernel_sym_offset.avc_denied = m_kernel_sym_parser.kallsyms_lookup_name("avc_denied", true);
58 | }
59 | m_kernel_sym_offset.filldir64 = m_kernel_sym_parser.kallsyms_lookup_name("filldir64", true);
60 | m_kernel_sym_offset.freeze_task = m_kernel_sym_parser.kallsyms_lookup_name("freeze_task");
61 |
62 | m_kernel_sym_offset.revert_creds = m_kernel_sym_parser.kallsyms_lookup_name("revert_creds");
63 | m_kernel_sym_offset.prctl_get_seccomp = m_kernel_sym_parser.kallsyms_lookup_name("prctl_get_seccomp"); // backup: seccomp_filter_release
64 |
65 |
66 | m_kernel_sym_offset.__cfi_check = m_kernel_sym_parser.kallsyms_lookup_name("__cfi_check");
67 | m_kernel_sym_offset.__cfi_check_fail = m_kernel_sym_parser.kallsyms_lookup_name("__cfi_check_fail");
68 | m_kernel_sym_offset.__cfi_slowpath_diag = m_kernel_sym_parser.kallsyms_lookup_name("__cfi_slowpath_diag");
69 | m_kernel_sym_offset.__cfi_slowpath = m_kernel_sym_parser.kallsyms_lookup_name("__cfi_slowpath");
70 | m_kernel_sym_offset.__ubsan_handle_cfi_check_fail_abort = m_kernel_sym_parser.kallsyms_lookup_name("__ubsan_handle_cfi_check_fail_abort");
71 | m_kernel_sym_offset.__ubsan_handle_cfi_check_fail = m_kernel_sym_parser.kallsyms_lookup_name("__ubsan_handle_cfi_check_fail");
72 | m_kernel_sym_offset.report_cfi_failure = m_kernel_sym_parser.kallsyms_lookup_name("report_cfi_failure");
73 | return (m_kernel_sym_offset.do_execve || m_kernel_sym_offset.do_execveat || m_kernel_sym_offset.do_execveat_common)
74 | && m_kernel_sym_offset.avc_denied
75 | && m_kernel_sym_offset.filldir64
76 | && m_kernel_sym_offset.freeze_task
77 | && m_kernel_sym_offset.revert_creds
78 | && m_kernel_sym_offset.prctl_get_seccomp;
79 | }
--------------------------------------------------------------------------------
/patch_kernel_root/analyze/symbol_analyze.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "kernel_symbol_parser.h"
3 | #include
4 | #include
5 |
6 | struct KernelSymbolOffset {
7 | size_t _text = 0;
8 | size_t _stext = 0;
9 | size_t die = 0;
10 | size_t arm64_notify_die = 0;
11 | size_t kernel_restart = 0;
12 |
13 | size_t __do_execve_file = 0;
14 | size_t do_execveat_common = 0;
15 | size_t do_execve_common = 0;
16 | size_t do_execveat = 0;
17 | size_t do_execve = 0;
18 |
19 | size_t avc_denied = 0;
20 | size_t filldir64 = 0;
21 | size_t freeze_task = 0;
22 |
23 | size_t revert_creds = 0;
24 | size_t prctl_get_seccomp = 0;
25 |
26 |
27 | size_t __cfi_check = 0;
28 | size_t __cfi_check_fail = 0;
29 | size_t __cfi_slowpath_diag = 0;
30 | size_t __cfi_slowpath = 0;
31 | size_t __ubsan_handle_cfi_check_fail_abort = 0;
32 | size_t __ubsan_handle_cfi_check_fail = 0;
33 | size_t report_cfi_failure = 0;
34 | };
35 |
36 | class SymbolAnalyze
37 | {
38 | public:
39 | SymbolAnalyze(const std::vector & file_buf);
40 | ~SymbolAnalyze();
41 |
42 | public:
43 | bool analyze_kernel_symbol();
44 | KernelSymbolOffset get_symbol_offset();
45 | bool is_kernel_version_less(const std::string& ver) const;
46 | private:
47 | bool find_symbol_offset();
48 | const std::vector& m_file_buf;
49 | KernelSymbolParser m_kernel_sym_parser;
50 | KernelSymbolOffset m_kernel_sym_offset;
51 | };
--------------------------------------------------------------------------------
/patch_kernel_root/exe/aarch64-linux-android-as.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/patch_kernel_root/exe/aarch64-linux-android-as.exe
--------------------------------------------------------------------------------
/patch_kernel_root/exe/arm-linux-androideabi-as.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/patch_kernel_root/exe/arm-linux-androideabi-as.exe
--------------------------------------------------------------------------------
/patch_kernel_root/exe/patch_kernel_root.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/patch_kernel_root/exe/patch_kernel_root.exe
--------------------------------------------------------------------------------
/patch_kernel_root/exe/快速扩充文件体积工具/QuicklyExpandFileSize.cpp:
--------------------------------------------------------------------------------
1 | // QuicklyExpandFileSize.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
2 | //
3 |
4 | #include
5 | #include
6 | #include
7 | using namespace std;
8 | #define TARGET_BYTES 192*1024*1024 //目标体积大小
9 | int main(int argc, char *argv[]) {
10 | char *inimage = argv[0];
11 | ++argv;
12 | --argc;
13 |
14 | cout << "本工具用于快速扩大boot.img的文件体积" << endl << endl;
15 |
16 |
17 | const char *lpszFilePath = argv[0];
18 | FILE * pFile = fopen(lpszFilePath, "rb+");
19 | if (!pFile) {
20 | cout << "打开文件失败:" << lpszFilePath << endl;
21 | system("pause");
22 | return 0;
23 | }
24 | fseek(pFile, 0, SEEK_END);
25 | auto nSize = ftell(pFile);
26 | rewind(pFile);
27 | if (nSize >= TARGET_BYTES) {
28 | cout << "目标文件体积已经大于" << TARGET_BYTES / 1024 / 1024 << "MB,无需再扩大" << endl;
29 | system("pause");
30 | return 0;
31 | }
32 |
33 | fseek(pFile, 0, SEEK_END);
34 | auto writeSize = TARGET_BYTES - nSize;
35 | void * pEmptySize = malloc(writeSize);
36 | if (!pEmptySize) {
37 | cout << "申请内存大小" << writeSize << "字节,失败" << endl;
38 | system("pause");
39 | return 0;
40 | }
41 | fwrite((char*)pEmptySize, writeSize, 1, pFile);
42 | free(pEmptySize);
43 | fclose(pFile);
44 | cout << "目标文件体积扩充完毕:" << TARGET_BYTES / 1024 / 1024 << "MB" << endl;
45 | system("pause");
46 | return 0;
47 | }
48 |
--------------------------------------------------------------------------------
/patch_kernel_root/exe/快速扩充文件体积工具/QuicklyExpandFileSize128M.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/patch_kernel_root/exe/快速扩充文件体积工具/QuicklyExpandFileSize128M.exe
--------------------------------------------------------------------------------
/patch_kernel_root/exe/快速扩充文件体积工具/QuicklyExpandFileSize192M.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/patch_kernel_root/exe/快速扩充文件体积工具/QuicklyExpandFileSize192M.exe
--------------------------------------------------------------------------------
/patch_kernel_root/exe/快速扩充文件体积工具/QuicklyExpandFileSize64.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/patch_kernel_root/exe/快速扩充文件体积工具/QuicklyExpandFileSize64.exe
--------------------------------------------------------------------------------
/patch_kernel_root/exe/快速扩充文件体积工具/QuicklyExpandFileSize96.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/patch_kernel_root/exe/快速扩充文件体积工具/QuicklyExpandFileSize96.exe
--------------------------------------------------------------------------------
/patch_kernel_root/exe/快速扩充文件体积工具/用法:将kernel文件拖拽至exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/patch_kernel_root/exe/快速扩充文件体积工具/用法:将kernel文件拖拽至exe
--------------------------------------------------------------------------------
/patch_kernel_root/patch_avc_denied.cpp:
--------------------------------------------------------------------------------
1 | #include "patch_avc_denied.h"
2 | #include "analyze/base_func.h"
3 | #include "analyze/ARM_asm.h"
4 | PatchAvcDenied::PatchAvcDenied(const std::vector& file_buf, const KernelSymbolOffset& sym,
5 | const SymbolAnalyze& symbol_analyze) : PatchBase(file_buf, sym, symbol_analyze) {
6 |
7 | }
8 |
9 | PatchAvcDenied::~PatchAvcDenied()
10 | {
11 | }
12 |
13 | int PatchAvcDenied::get_need_read_cap_cnt() {
14 | int cnt = get_cap_cnt();
15 | if (cnt < 5) {
16 | cnt = 3;
17 | }
18 | return cnt;
19 | }
20 |
21 |
22 | size_t PatchAvcDenied::patch_avc_denied(size_t hook_func_start_addr, const std::vector& task_struct_offset_cred,
23 | std::vector& vec_out_patch_bytes_data) {
24 | size_t avc_denied_addr = m_sym.avc_denied;
25 | int atomic_usage_len = get_cred_atomic_usage_len();
26 | int securebits_padding = get_cred_securebits_padding();
27 | std::string cap_ability_max = get_cap_ability_max();
28 | int cap_cnt = get_need_read_cap_cnt();
29 |
30 | size_t avc_denied_entry_hook_jump_back_addr = avc_denied_addr + 4;
31 | std::stringstream sstrAsm;
32 | sstrAsm
33 | << "STP X7, X8, [sp, #-16]!" << std::endl
34 | << "STP X9, X10, [sp, #-16]!" << std::endl;
35 | sstrAsm << "MRS X7, SP_EL0" << std::endl;
36 | for (auto x = 0; x < task_struct_offset_cred.size(); x++) {
37 | if (x != task_struct_offset_cred.size() - 1) {
38 | sstrAsm << "LDR X7, [X7, #" << task_struct_offset_cred[x] << "]" << std::endl;
39 | }
40 | }
41 | sstrAsm << "LDR X7, [X7, #" << task_struct_offset_cred[task_struct_offset_cred.size() - 1] << "]" << std::endl
42 | << "CBZ X7, #JUMP_END" << std::endl
43 | << "ADD X7, X7, #" << atomic_usage_len << std::endl
44 | << "MOV X8, #8" << std::endl
45 | << "LABEL_CYCLE_UID:"
46 | << "LDR W9, [X7], #4" << std::endl
47 | << "CBNZ W9, #JUMP_END" << std::endl
48 | << "SUBS X8, X8, #1" << std::endl
49 | << "B.NE #JUMP_CYCLE_UID" << std::endl
50 | << "MOV W8, 0xC" << std::endl
51 | << "LDR W9, [X7], #" << 4 + securebits_padding << std::endl
52 | << "CMP W8, W9" << std::endl
53 | << "B.NE #JUMP_END" << std::endl
54 | << "MOV X8, " << cap_ability_max << std::endl
55 | << "MOV X9, #" << cap_cnt << std::endl
56 | << "LABEL_CYCLE_CAP:"
57 | << "LDR X10, [X7], #8" << std::endl
58 | << "CMP X10, X8" << std::endl
59 | << "B.CC #JUMP_END" << std::endl
60 | << "SUBS X9, X9, #1" << std::endl
61 | << "B.NE #JUMP_CYCLE_CAP" << std::endl
62 | << "LDP X9, X10, [sp], #16" << std::endl
63 | << "LDP X7, X8, [sp], #16" << std::endl
64 | << "MOV W0, WZR" << std::endl
65 | << "RET" << std::endl
66 | << "LABEL_END:"
67 | << "LDP X9, X10, [sp], #16" << std::endl
68 | << "LDP X7, X8, [sp], #16" << std::endl
69 | << "MOV X0, X0" << std::endl;
70 | size_t end_order_len = count_endl(sstrAsm.str()) * 4;
71 | sstrAsm<< "B #" << (int64_t)(avc_denied_entry_hook_jump_back_addr - (hook_func_start_addr + end_order_len)) << std::endl;
72 |
73 | std::string strAsmCode = AsmLabelToOffset(sstrAsm.str(), "LABEL_END:", "JUMP_END");
74 | strAsmCode = AsmLabelToOffset(strAsmCode, "LABEL_CYCLE_UID:", "JUMP_CYCLE_UID");
75 | strAsmCode = AsmLabelToOffset(strAsmCode, "LABEL_CYCLE_CAP:", "JUMP_CYCLE_CAP");
76 | std::cout << std::endl << strAsmCode << std::endl;
77 |
78 | std::string strBytes = AsmToBytes(strAsmCode);
79 | if (!strBytes.length()) {
80 | return 0;
81 | }
82 | size_t nHookFuncSize = strBytes.length() / 2;
83 |
84 | char hookOrigCmd[4] = { 0 };
85 | memcpy(&hookOrigCmd, (void*)((size_t)&m_file_buf[0] + avc_denied_addr), sizeof(hookOrigCmd));
86 | std::string strHookOrigCmd = bytes2hex((const unsigned char*)hookOrigCmd, sizeof(hookOrigCmd));
87 |
88 | end_order_len = (count_endl(sstrAsm.str()) - 2) * 4;
89 | strBytes = strBytes.substr(0, (end_order_len) * 2) + strHookOrigCmd + strBytes.substr((end_order_len + 4) * 2);
90 |
91 | vec_out_patch_bytes_data.push_back({ strBytes, hook_func_start_addr });
92 | std::stringstream sstrAsm2;
93 | sstrAsm2
94 | << "B #" << (int64_t)(hook_func_start_addr - avc_denied_addr) << std::endl;
95 | std::string strBytes2 = AsmToBytes(sstrAsm2.str());
96 | if (!strBytes2.length()) {
97 | return 0;
98 | }
99 | vec_out_patch_bytes_data.push_back({ strBytes2, avc_denied_addr });
100 | hook_func_start_addr += nHookFuncSize;
101 | std::cout << "#下一段HOOK函数起始可写位置:" << std::hex << hook_func_start_addr << std::endl << std::endl;
102 | return hook_func_start_addr
103 | }
104 |
--------------------------------------------------------------------------------
/patch_kernel_root/patch_avc_denied.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include "patch_base.h"
5 | class PatchAvcDenied : public PatchBase
6 | {
7 | public:
8 | PatchAvcDenied(const std::vector& file_buf, const KernelSymbolOffset& sym,
9 | const SymbolAnalyze& symbol_analyze);
10 | ~PatchAvcDenied();
11 |
12 | size_t patch_avc_denied(size_t hook_func_start_addr, const std::vector& task_struct_offset_cred,
13 | std::vector& vec_out_patch_bytes_data);
14 |
15 | private:
16 | int get_need_read_cap_cnt();
17 | };
--------------------------------------------------------------------------------
/patch_kernel_root/patch_base.cpp:
--------------------------------------------------------------------------------
1 | #include "patch_base.h"
2 | #include "analyze/ARM_asm.h"
3 | PatchBase::PatchBase(const std::vector& file_buf, const KernelSymbolOffset& sym,
4 | const SymbolAnalyze& symbol_analyze) : m_file_buf(file_buf), m_sym(sym), m_symbol_analyze(symbol_analyze) {
5 |
6 | }
7 |
8 | PatchBase::~PatchBase()
9 | {
10 | }
11 |
12 | int PatchBase::get_cred_atomic_usage_len() {
13 | int len = 8;
14 | if (m_symbol_analyze.is_kernel_version_less("6.6.0")) {
15 | len = 4;
16 | }
17 | return len;
18 | }
19 |
20 | int PatchBase::get_cred_securebits_padding() {
21 | if (get_cred_atomic_usage_len() == 8) {
22 | return 4;
23 | }
24 | return 0;
25 | }
26 |
27 | std::string PatchBase::get_cap_ability_max() {
28 | std::string cap;
29 | if (m_symbol_analyze.is_kernel_version_less("5.8.0")) {
30 | cap = "0x3FFFFFFFFF";
31 | }
32 | else if (m_symbol_analyze.is_kernel_version_less("5.9.0")) {
33 | cap = "0xFFFFFFFFFF";
34 | }
35 | else {
36 | cap = "0x1FFFFFFFFFF";
37 | }
38 | return cap;
39 | }
40 |
41 | int PatchBase::get_cap_cnt() {
42 | int cnt = 0;
43 | if (m_symbol_analyze.is_kernel_version_less("4.3.0")) {
44 | cnt = 4;
45 | } else {
46 | cnt = 5;
47 | }
48 | return cnt;
49 | }
--------------------------------------------------------------------------------
/patch_kernel_root/patch_base.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include "patch_kernel_root.h"
5 | #include "analyze/symbol_analyze.h"
6 | class PatchBase
7 | {
8 | public:
9 | PatchBase(const std::vector& file_buf, const KernelSymbolOffset& sym,
10 | const SymbolAnalyze& symbol_analyze);
11 | ~PatchBase();
12 | protected:
13 | int get_cred_atomic_usage_len();
14 | int get_cred_securebits_padding();
15 | std::string get_cap_ability_max();
16 | int get_cap_cnt();
17 | const std::vector& m_file_buf;
18 | const KernelSymbolOffset& m_sym;
19 | const SymbolAnalyze& m_symbol_analyze;
20 | };
--------------------------------------------------------------------------------
/patch_kernel_root/patch_do_execve.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include "patch_base.h"
5 | class PatchDoExecve : public PatchBase
6 | {
7 | public:
8 | PatchDoExecve(const std::vector& file_buf, const KernelSymbolOffset& sym,
9 | const SymbolAnalyze& symbol_analyze);
10 | ~PatchDoExecve();
11 |
12 | size_t patch_do_execve(const std::string& str_root_key, size_t hook_func_start_addr,
13 | const std::vector& task_struct_offset_cred,
14 | const std::vector& task_struct_offset_seccomp,
15 | std::vector& vec_out_patch_bytes_data);
16 |
17 | private:
18 | std::pair get_do_execve_param();
19 | int get_need_write_cap_cnt();
20 | };
--------------------------------------------------------------------------------
/patch_kernel_root/patch_filldir64.cpp:
--------------------------------------------------------------------------------
1 | #include "patch_filldir64.h"
2 | #include "analyze/base_func.h"
3 | #include "analyze/ARM_asm.h"
4 | PatchFilldir64::PatchFilldir64(const std::vector& file_buf, const KernelSymbolOffset& sym,
5 | const SymbolAnalyze& symbol_analyze) : PatchBase(file_buf, sym, symbol_analyze) {
6 |
7 | }
8 |
9 | PatchFilldir64::~PatchFilldir64()
10 | {
11 | }
12 |
13 | size_t PatchFilldir64::patch_filldir64(size_t root_key_addr_offset, size_t hook_func_start_addr, std::vector& vec_out_patch_bytes_data) {
14 | size_t filldir64_addr = m_sym.filldir64;
15 |
16 | size_t filldir64_entry_hook_jump_back_addr = filldir64_addr + 4;
17 | std::stringstream sstrAsm;
18 | sstrAsm
19 | << "CMP W2, #16" << std::endl
20 | << "BNE #JUMP_DIRECT_END" << std::endl
21 | << "STP X7, X8, [sp, #-16]!" << std::endl
22 | << "STP X9, X10, [sp, #-16]!" << std::endl;
23 | size_t end_order_cnt = count_endl(sstrAsm.str());
24 | int root_key_adr_offset = root_key_addr_offset - (hook_func_start_addr + end_order_cnt * 4);
25 | sstrAsm << "ADR X7, #" << root_key_adr_offset << std::endl
26 | << "MOV X8, #0" << std::endl
27 | << "LABEL_CYCLE_NAME:"
28 | << "LDRB W9, [X1, X8]" << std::endl
29 | << "LDRB W10, [X7, X8]" << std::endl
30 | << "CMP W9, W10" << std::endl
31 | << "B.NE #JUMP_END" << std::endl
32 | << "ADD X8, X8, 1" << std::endl
33 | << "CMP X8, #16" << std::endl
34 | << "BLT #JUMP_CYCLE_NAME" << std::endl
35 | << "LDP X9, X10, [sp], #16" << std::endl
36 | << "LDP X7, X8, [sp], #16" << std::endl
37 | << "MOV X0, XZR" << std::endl
38 | << "RET" << std::endl
39 | << "LABEL_END:"
40 | << "LDP X9, X10, [sp], #16" << std::endl
41 | << "LDP X7, X8, [sp], #16" << std::endl
42 | << "LABEL_DIRECT_END:"
43 | << "MOV X0, X0" << std::endl;
44 | size_t end_order_len = count_endl(sstrAsm.str()) * 4;
45 | sstrAsm << "B #" << (int64_t)(filldir64_entry_hook_jump_back_addr - (hook_func_start_addr + end_order_len)) << std::endl;
46 |
47 | std::string strAsmCode = AsmLabelToOffset(sstrAsm.str(), "LABEL_END:", "JUMP_END");
48 | strAsmCode = AsmLabelToOffset(strAsmCode, "LABEL_DIRECT_END:", "JUMP_DIRECT_END");
49 | strAsmCode = AsmLabelToOffset(strAsmCode, "LABEL_CYCLE_NAME:", "JUMP_CYCLE_NAME");
50 | std::cout << std::endl << strAsmCode << std::endl;
51 |
52 | std::string strBytes = AsmToBytes(strAsmCode);
53 | if (!strBytes.length()) {
54 | return 0;
55 | }
56 | size_t nHookFuncSize = strBytes.length() / 2;
57 | char hookOrigCmd[4] = { 0 };
58 | memcpy(&hookOrigCmd, (void*)((size_t)&m_file_buf[0] + filldir64_addr), sizeof(hookOrigCmd));
59 | std::string strHookOrigCmd = bytes2hex((const unsigned char*)hookOrigCmd, sizeof(hookOrigCmd));
60 | strBytes = strBytes.substr(0, (0x4C) * 2) + strHookOrigCmd + strBytes.substr((0x4C + 4) * 2);
61 |
62 | vec_out_patch_bytes_data.push_back({ strBytes, hook_func_start_addr });
63 | std::stringstream sstrAsm2;
64 | sstrAsm2
65 | << "B #" << (int64_t)(hook_func_start_addr - filldir64_addr) << std::endl;
66 | std::string strBytes2 = AsmToBytes(sstrAsm2.str());
67 | if (!strBytes2.length()) {
68 | return 0;
69 | }
70 | vec_out_patch_bytes_data.push_back({ strBytes2, filldir64_addr });
71 | hook_func_start_addr += nHookFuncSize;
72 | std::cout << "#下一段HOOK函数起始可写位置:" << std::hex << hook_func_start_addr << std::endl << std::endl;
73 | return hook_func_start_addr;
74 | }
75 |
--------------------------------------------------------------------------------
/patch_kernel_root/patch_filldir64.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include "patch_base.h"
5 | class PatchFilldir64 : public PatchBase
6 | {
7 | public:
8 | PatchFilldir64(const std::vector& file_buf, const KernelSymbolOffset& sym,
9 | const SymbolAnalyze& symbol_analyze);
10 | ~PatchFilldir64();
11 |
12 | size_t patch_filldir64(size_t root_key_addr_offset, size_t hook_func_start_addr, std::vector& vec_out_patch_bytes_data);
13 | };
--------------------------------------------------------------------------------
/patch_kernel_root/patch_freeze_task.cpp:
--------------------------------------------------------------------------------
1 | #include "patch_freeze_task.h"
2 | #include "analyze/base_func.h"
3 | #include "analyze/ARM_asm.h"
4 | PatchFreezeTask::PatchFreezeTask(const std::vector& file_buf, const KernelSymbolOffset& sym,
5 | const SymbolAnalyze& symbol_analyze) : PatchBase(file_buf, sym, symbol_analyze) {
6 |
7 | }
8 |
9 | PatchFreezeTask::~PatchFreezeTask()
10 | {
11 | }
12 |
13 | int PatchFreezeTask::get_need_read_cap_cnt() {
14 | int cnt = get_cap_cnt();
15 | if (cnt < 5) {
16 | cnt = 3;
17 | }
18 | return cnt;
19 | }
20 |
21 |
22 | size_t PatchFreezeTask::patch_freeze_task(size_t hook_func_start_addr, const std::vector& task_struct_offset_cred,
23 | std::vector& vec_out_patch_bytes_data) {
24 | size_t freeze_task_addr = m_sym.freeze_task;
25 | int atomic_usage_len = get_cred_atomic_usage_len();
26 |
27 | size_t freeze_task_entry_hook_jump_back_addr = freeze_task_addr + 4;
28 | std::stringstream sstrAsm;
29 | sstrAsm
30 | << "STP X7, X8, [sp, #-16]!" << std::endl
31 | << "STP X9, X10, [sp, #-16]!" << std::endl;
32 | sstrAsm << "MOV X7, X0" << std::endl;
33 | for (auto x = 0; x < task_struct_offset_cred.size(); x++) {
34 | if (x != task_struct_offset_cred.size() - 1) {
35 | sstrAsm << "LDR X7, [X7, #" << task_struct_offset_cred[x] << "]" << std::endl;
36 | }
37 | }
38 | sstrAsm << "LDR X7, [X7, #" << task_struct_offset_cred[task_struct_offset_cred.size() - 1] << "]" << std::endl
39 | << "CBZ X7, #JUMP_END" << std::endl
40 | << "ADD X7, X7, #" << atomic_usage_len << std::endl
41 | << "MOV X8, #8" << std::endl
42 | << "LABEL_CYCLE_UID:"
43 | << "LDR W9, [X7], #4" << std::endl
44 | << "CBNZ W9, #JUMP_END" << std::endl
45 | << "SUBS X8, X8, #1" << std::endl
46 | << "B.NE #JUMP_CYCLE_UID" << std::endl
47 | << "LDP X9, X10, [sp], #16" << std::endl
48 | << "LDP X7, X8, [sp], #16" << std::endl
49 | << "MOV W0, WZR" << std::endl
50 | << "RET" << std::endl
51 | << "LABEL_END:"
52 | << "LDP X9, X10, [sp], #16" << std::endl
53 | << "LDP X7, X8, [sp], #16" << std::endl
54 | << "MOV X0, X0" << std::endl;
55 | size_t end_order_len = count_endl(sstrAsm.str()) * 4;
56 | sstrAsm << "B #" << freeze_task_entry_hook_jump_back_addr - (hook_func_start_addr + end_order_len) << std::endl;
57 |
58 | std::string strAsmCode = AsmLabelToOffset(sstrAsm.str(), "LABEL_END:", "JUMP_END");
59 | strAsmCode = AsmLabelToOffset(strAsmCode, "LABEL_CYCLE_UID:", "JUMP_CYCLE_UID");
60 | std::cout << std::endl << strAsmCode << std::endl;
61 |
62 | std::string strBytes = AsmToBytes(strAsmCode);
63 | if (!strBytes.length()) {
64 | return 0;
65 | }
66 | size_t nHookFuncSize = strBytes.length() / 2;
67 |
68 | char hookOrigCmd[4] = { 0 };
69 | memcpy(&hookOrigCmd, (void*)((size_t)&m_file_buf[0] + freeze_task_addr), sizeof(hookOrigCmd));
70 | std::string strHookOrigCmd = bytes2hex((const unsigned char*)hookOrigCmd, sizeof(hookOrigCmd));
71 |
72 | end_order_len = (count_endl(sstrAsm.str()) - 2) * 4;
73 | strBytes = strBytes.substr(0, (end_order_len) * 2) + strHookOrigCmd + strBytes.substr((end_order_len + 4) * 2);
74 |
75 | vec_out_patch_bytes_data.push_back({ strBytes, hook_func_start_addr });
76 |
77 | std::stringstream sstrAsm2;
78 | sstrAsm2
79 | << "B #" << (int64_t)(hook_func_start_addr - freeze_task_addr) << std::endl;
80 | std::string strBytes2 = AsmToBytes(sstrAsm2.str());
81 | if (!strBytes2.length()) {
82 | return 0;
83 | }
84 | vec_out_patch_bytes_data.push_back({ strBytes2, freeze_task_addr });
85 | hook_func_start_addr += nHookFuncSize;
86 | std::cout << "#下一段HOOK函数起始可写位置:" << std::hex << hook_func_start_addr << std::endl << std::endl;
87 | return hook_func_start_addr;
88 | }
89 |
--------------------------------------------------------------------------------
/patch_kernel_root/patch_freeze_task.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include "patch_base.h"
5 | class PatchFreezeTask : public PatchBase
6 | {
7 | public:
8 | PatchFreezeTask(const std::vector& file_buf, const KernelSymbolOffset& sym,
9 | const SymbolAnalyze& symbol_analyze);
10 | ~PatchFreezeTask();
11 |
12 | size_t patch_freeze_task(size_t hook_func_start_addr, const std::vector& task_struct_offset_cred,
13 | std::vector& vec_out_patch_bytes_data);
14 |
15 | private:
16 | int get_need_read_cap_cnt();
17 | };
--------------------------------------------------------------------------------
/patch_kernel_root/patch_kernel_root.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | struct patch_bytes_data {
4 | std::string str_bytes;
5 | size_t write_addr = 0;
6 | };
7 |
--------------------------------------------------------------------------------
/patch_kernel_root/patch_kernel_root.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 |
6 |
--------------------------------------------------------------------------------
/testRoot/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | include $(CLEAR_VARS)
4 | LOCAL_CPPFLAGS += -std=c++17 -fPIE -fvisibility=hidden -frtti -fexceptions
5 | LOCAL_LDFLAGS += -fPIE -pie
6 | LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true
7 | LOCAL_MODULE := testRoot
8 | LOCAL_SRC_FILES := \
9 | testRoot.cpp \
10 | kernel_root_kit/kernel_root_kit_process64_inject.cpp \
11 | kernel_root_kit/kernel_root_kit_ptrace_arm64_utils.cpp \
12 | kernel_root_kit/kernel_root_kit_su_install_helper.cpp \
13 | kernel_root_kit/kernel_root_kit_parasite_app.cpp \
14 | kernel_root_kit/kernel_root_kit_parasite_patch_elf.cpp \
15 | kernel_root_kit/kernel_root_kit_upx_helper.cpp
16 | include $(BUILD_EXECUTABLE)
17 |
--------------------------------------------------------------------------------
/testRoot/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_ABI := arm64-v8a
2 | APP_STL := c++_static
--------------------------------------------------------------------------------
/testRoot/jni/Build.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | set "ndk_path=c:\Users\abc\android-ndk-r25\ndk-build.cmd"
3 |
4 | cd /d "%~dp0"
5 |
6 | set "root_path=%~dp0"
7 |
8 | cd %root_path%
9 | call Clean.bat
10 |
11 | if not exist %ndk_path% (
12 | echo Error: Android NDK: '%ndk_path%' does not exist!
13 | pause
14 | exit /b
15 | )
16 |
17 | call "%ndk_path%" clean
18 |
19 | cd %root_path%\su\jni
20 | call "%ndk_path%" clean
21 | call "%ndk_path%"
22 |
23 | cd %root_path%\su
24 | call generate_source_su_exec_data.bat
25 |
26 | cd %root_path%\lib_su_env\jni
27 | call "%ndk_path%" clean
28 | call "%ndk_path%"
29 |
30 | cd %root_path%\lib_su_env
31 | call generate_source_lib_su_env_data.bat
32 |
33 | cd %root_path%\upx
34 | call generate_source_upx_data.bat
35 |
36 | cd %root_path%\lib_root_server
37 | call generate_source_lib_root_server_html_data.bat
38 | cd %root_path%\lib_root_server\jni
39 | call "%ndk_path%" clean
40 | call "%ndk_path%"
41 |
42 | cd %root_path%\lib_root_server
43 | call generate_source_lib_root_server_data.bat
44 |
45 | cd %root_path%
46 | call "%ndk_path%"
47 |
48 | echo All builds completed!
49 | pause
50 |
--------------------------------------------------------------------------------
/testRoot/jni/Clean.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | cd /d "%~dp0"
3 |
4 | set "root_path=%~dp0"
5 |
6 | if exist kernel_root_kit\kernel_root_kit_lib_root_server_data.h (
7 | del kernel_root_kit\kernel_root_kit_lib_root_server_data.h
8 | )
9 |
10 | if exist kernel_root_kit\kernel_root_kit_su_exec_data.h (
11 | del kernel_root_kit\kernel_root_kit_su_exec_data.h
12 | )
13 |
14 | if exist kernel_root_kit\kernel_root_kit_lib_su_env_data.h (
15 | del kernel_root_kit\kernel_root_kit_lib_su_env_data.h
16 | )
17 |
18 | if exist kernel_root_kit\kernel_root_kit_upx_data.h (
19 | del kernel_root_kit\kernel_root_kit_upx_data.h
20 | )
21 |
22 | if exist su\res.h (
23 | del su\res.h
24 | )
25 |
26 | if exist lib_su_env\res.h (
27 | del lib_su_env\res.h
28 | )
29 |
30 | if exist lib_root_server\res.h (
31 | del lib_root_server\res.h
32 | )
33 |
34 | if exist lib_root_server\index.gz.bin (
35 | del lib_root_server\index.gz.bin
36 | )
37 |
38 | if exist lib_root_server\index_html_gz_data.h (
39 | del lib_root_server\index_html_gz_data.h
40 | )
41 |
42 | if exist upx\res.h (
43 | del upx\res.h
44 | )
45 |
46 | if exist "%root_path%\su\libs" (
47 | rmdir /S /Q "%root_path%\su\libs"
48 | )
49 |
50 | if exist "%root_path%\su\obj" (
51 | rmdir /S /Q "%root_path%\su\obj"
52 | )
53 |
54 | if exist "%root_path%\lib_su_env\libs" (
55 | rmdir /S /Q "%root_path%\lib_su_env\libs"
56 | )
57 |
58 | if exist "%root_path%\lib_su_env\obj" (
59 | rmdir /S /Q "%root_path%\lib_su_env\obj"
60 | )
61 |
62 | if exist "%root_path%\lib_root_server\libs" (
63 | rmdir /S /Q "%root_path%\lib_root_server\libs"
64 | )
65 |
66 | if exist "%root_path%\lib_root_server\obj" (
67 | rmdir /S /Q "%root_path%\lib_root_server\obj"
68 | )
69 |
70 | if exist "%root_path%\..\libs" (
71 | rmdir /S /Q "%root_path%\..\libs"
72 | )
73 |
74 | if exist "%root_path%\..\obj" (
75 | rmdir /S /Q "%root_path%\..\obj"
76 | )
77 |
--------------------------------------------------------------------------------
/testRoot/jni/kernel_root_kit/file_convert_to_source_tools/file_convert_to_source_tools.cpp:
--------------------------------------------------------------------------------
1 | // file_convert_to_source_tools.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
2 | //
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | void OutputSourceFile(const std::string& sourceCode, int nFileSize, int nBuffValCount) {
10 | std::ofstream file("res.h");
11 | if (!file) {
12 | std::cerr << "无法打开输出文件 res.h\n";
13 | return;
14 | }
15 |
16 | file << "namespace {\n";
17 | file << "static int fileSize = " << nFileSize << ";\n";
18 | file << "static uint64_t data[" << nBuffValCount << "] = {\n";
19 | file << sourceCode << "\n";
20 | file << "};\n";
21 | file << "}\n";
22 | }
23 |
24 | void processFile(const std::string& filePath) {
25 | std::ifstream file(filePath, std::ios::binary | std::ios::ate);
26 | if (!file) {
27 | std::cerr << "打开文件失败: " << filePath << "\n";
28 | return;
29 | }
30 |
31 | std::streamsize nFileSize = file.tellg();
32 | file.seekg(0, std::ios::beg);
33 |
34 | std::vector buffer(nFileSize);
35 | if (!file.read(buffer.data(), nFileSize)) {
36 | std::cerr << "读取文件失败: " << filePath << "\n";
37 | return;
38 | }
39 |
40 | int yu = nFileSize % 8;
41 | if (yu > 0) {
42 | yu = 8 - yu;
43 | }
44 | buffer.resize(nFileSize + yu, 0); // 扩大并填充零
45 |
46 | std::ostringstream code;
47 | for (int i = 0; i < buffer.size() / 8; i++) {
48 | uint64_t val = *(uint64_t*)&buffer[i * 8];
49 | if (i > 0) {
50 | code << ", ";
51 | if (i % 3 == 0) {
52 | code << "\n";
53 | }
54 | }
55 | code << "0x" << std::hex << val;
56 | }
57 |
58 | OutputSourceFile(code.str(), nFileSize, buffer.size() / 8);
59 | std::cout << "完成\n";
60 | }
61 |
62 | int main(int argc, char* argv[]) {
63 | #ifdef _DEBUG
64 | const char* filePath = R"***(D:\123.txt)***";
65 | #else
66 | if (argc < 2) {
67 | std::cerr << "无输入文件\n";
68 | return 1;
69 | }
70 | const char* filePath = argv[1];
71 | #endif
72 |
73 | processFile(filePath);
74 | std::cin.get();
75 | return 0;
76 | }
77 |
--------------------------------------------------------------------------------
/testRoot/jni/kernel_root_kit/file_convert_to_source_tools/file_convert_to_source_tools.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abcz316/SKRoot-linuxKernelRoot/d56fdd17e8089285123adf1b663081cc9de9fffa/testRoot/jni/kernel_root_kit/file_convert_to_source_tools/file_convert_to_source_tools.exe
--------------------------------------------------------------------------------
/testRoot/jni/kernel_root_kit/kernel_root_kit_command.h:
--------------------------------------------------------------------------------
1 | #ifndef _KERNEL_ROOT_KIT_COMMAND_H_
2 | #define _KERNEL_ROOT_KIT_COMMAND_H_
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | #include
20 |
21 | #include "kernel_root_kit_err_def.h"
22 | #include "kernel_root_kit_fork_helper.h"
23 |
24 | namespace kernel_root {
25 | //获取ROOT权限,返回值为0则代表成功
26 | static inline ssize_t get_root(const char* str_root_key) {
27 | if(getuid() == 0) { return ERR_NONE; }
28 | if (str_root_key == NULL) { return ERR_PARAM; }
29 | syscall(__NR_execve, str_root_key, NULL, NULL);
30 | if(getuid() != 0) { return ERR_NO_ROOT; }
31 | return ERR_NONE;
32 | }
33 |
34 | //检查系统SELinux的是否为禁用状态
35 | static bool is_enable_selinux() {
36 | int cnt = 0;
37 | DIR* dir = opendir("/");
38 | if (NULL != dir) {
39 | struct dirent* ptr = NULL;
40 | while ((ptr = readdir(dir)) != NULL) {
41 | if ((strcmp(ptr->d_name, ".") == 0) || (strcmp(ptr->d_name, "..") == 0)) {
42 | continue;
43 | }
44 | cnt++;
45 | }
46 | closedir(dir);
47 | }
48 | return cnt > 5 ? false : true;
49 | }
50 |
51 | //执行root命令,返回值为0则代表成功
52 | static std::string run_root_cmd(const char* str_root_key, const char* cmd, ssize_t & err) {
53 | if (str_root_key == NULL || cmd == NULL || strlen(cmd) == 0) {
54 | err = ERR_PARAM;
55 | return {};
56 | }
57 | //把错误信息也打出来
58 | std::string cmd_add_err_info = cmd;
59 | cmd_add_err_info += " 2>&1";
60 |
61 | std::string result;
62 | fork_pipe_info finfo;
63 | if(fork_pipe_child_process(finfo)) {
64 | err = ERR_NONE;
65 | do {
66 | if (get_root(str_root_key) != ERR_NONE) {
67 | err = ERR_NO_ROOT;
68 | break;
69 | }
70 | FILE * fp = popen(cmd_add_err_info.c_str(), "r");
71 | if(!fp) {
72 | err = ERR_POPEN;
73 | break;
74 | }
75 | int pip = fileno(fp);
76 | while(true) {
77 | char rbuf[1024] = {0};
78 | ssize_t r = read(pip, rbuf, sizeof(rbuf));
79 | if (r == -1 && errno == EAGAIN) {
80 | continue; //意味着现在没有可用的数据,以后再试一次
81 | } else if(r > 0) {
82 | std::string str_convert(rbuf, r);
83 | result += str_convert;
84 | } else {
85 | break;
86 | }
87 | }
88 | pclose(fp);
89 | } while(0);
90 | write_errcode_from_child(finfo, err);
91 | write_string_from_child(finfo, result);
92 | _exit(0);
93 | return {};
94 | }
95 | err = ERR_NONE;
96 | if(!wait_fork_child_process(finfo)) {
97 | err = ERR_WAIT_FORK_CHILD;
98 | } else {
99 | if(!read_errcode_from_child(finfo, err)) {
100 | err = ERR_READ_CHILD_ERRCODE;
101 | } else if(!read_string_from_child(finfo, result)) {
102 | err = ERR_READ_CHILD_STRING;
103 | }
104 | }
105 | return result;
106 | }
107 | }
108 | #endif /* _KERNEL_ROOT_KIT_COMMAND_H_ */
109 |
--------------------------------------------------------------------------------
/testRoot/jni/kernel_root_kit/kernel_root_kit_elf64_symbol_parser.h:
--------------------------------------------------------------------------------
1 | #ifndef _KERNEL_ROOT_KIT_SO_SYMBOL_PARSER_H_
2 | #define _KERNEL_ROOT_KIT_SO_SYMBOL_PARSER_H_
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include