diff --git a/PermissionManager/.gitignore b/PermissionManager/.gitignore new file mode 100644 index 00000000..aa724b77 --- /dev/null +++ b/PermissionManager/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/PermissionManager/.idea/.gitignore b/PermissionManager/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/PermissionManager/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/PermissionManager/.idea/compiler.xml b/PermissionManager/.idea/compiler.xml new file mode 100644 index 00000000..fb7f4a8a --- /dev/null +++ b/PermissionManager/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/PermissionManager/.idea/gradle.xml b/PermissionManager/.idea/gradle.xml new file mode 100644 index 00000000..526b4c25 --- /dev/null +++ b/PermissionManager/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/PermissionManager/.idea/misc.xml b/PermissionManager/.idea/misc.xml new file mode 100644 index 00000000..10a0ff7f --- /dev/null +++ b/PermissionManager/.idea/misc.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/PermissionManager/app/.gitignore b/PermissionManager/app/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/PermissionManager/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/PermissionManager/app/appKey.jks b/PermissionManager/app/appKey.jks new file mode 100644 index 00000000..95ea5aef Binary files /dev/null and b/PermissionManager/app/appKey.jks differ diff --git a/PermissionManager/app/build.gradle b/PermissionManager/app/build.gradle new file mode 100644 index 00000000..02da6ec2 --- /dev/null +++ b/PermissionManager/app/build.gradle @@ -0,0 +1,53 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdk 31 + + defaultConfig { + applicationId "com.linux.permissionmanager" + minSdk 26 + targetSdk 31 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + externalNativeBuild { + cmake { + cppFlags '-std=c++17' + abiFilters "arm64-v8a" //需要什么构架的so,就在这边添加即 + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + externalNativeBuild { + cmake { + path file('src/main/cpp/CMakeLists.txt') + version '3.18.1' + } + } + buildFeatures { + viewBinding true + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'com.google.android.material:material:1.5.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} \ No newline at end of file diff --git a/PermissionManager/app/proguard-rules.pro b/PermissionManager/app/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/PermissionManager/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/PermissionManager/app/src/androidTest/java/com/linux/permissionmanager/ExampleInstrumentedTest.java b/PermissionManager/app/src/androidTest/java/com/linux/permissionmanager/ExampleInstrumentedTest.java new file mode 100644 index 00000000..e63884ad --- /dev/null +++ b/PermissionManager/app/src/androidTest/java/com/linux/permissionmanager/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.linux.permissionmanager; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.linux.permissionmanager", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/PermissionManager/app/src/main/AndroidManifest.xml b/PermissionManager/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..ac7de7ed --- /dev/null +++ b/PermissionManager/app/src/main/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PermissionManager/app/src/main/cpp/CMakeLists.txt b/PermissionManager/app/src/main/cpp/CMakeLists.txt new file mode 100644 index 00000000..01fed11f --- /dev/null +++ b/PermissionManager/app/src/main/cpp/CMakeLists.txt @@ -0,0 +1,53 @@ +# For more information about using CMake with Android Studio, read the +# documentation: https://d.android.com/studio/projects/add-native-code.html + +# Sets the minimum version of CMake required to build the native library. + +cmake_minimum_required(VERSION 3.18.1) + +# Declares and names the project. + +project("permissionmanager") + +# Creates and names a library, sets it as either STATIC +# or SHARED, and provides the relative paths to its source code. +# You can define multiple libraries, and CMake builds them for you. +# Gradle automatically packages shared libraries with your APK. + +add_library( # Sets the name of the library. + permissionmanager + + # Sets the library as a shared library. + SHARED + + # Provides a relative path to your source file(s). + ../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_process64_inject.cpp + ../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_ptrace_arm64_utils.cpp + ../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_su_install_helper.cpp + ../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_parasite_app.cpp + ../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_parasite_patch_elf.cpp + root.cpp) + +# Searches for a specified prebuilt library and stores the path as a +# variable. Because CMake includes system libraries in the search path by +# default, you only need to specify the name of the public NDK library +# you want to add. CMake verifies that the library exists before +# completing its build. + +find_library( # Sets the name of the path variable. + log-lib + + # Specifies the name of the NDK library that + # you want CMake to locate. + log) + +# Specifies libraries CMake should link to your target library. You +# can link multiple libraries, such as libraries you define in this +# build script, prebuilt third-party libraries, or system libraries. + +target_link_libraries( # Specifies the target library. + permissionmanager + + # Links the target library to the log library + # included in the NDK. + ${log-lib}) \ No newline at end of file diff --git a/PermissionManager/app/src/main/cpp/root.cpp b/PermissionManager/app/src/main/cpp/root.cpp new file mode 100644 index 00000000..20bbfcc0 --- /dev/null +++ b/PermissionManager/app/src/main/cpp/root.cpp @@ -0,0 +1,344 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../../../../testRoot/jni/kernel_root_kit/kernel_root_kit_umbrella.h" +#include "../../../../../testRoot/jni/testRoot.h" +#include "urlEncodeUtils.h" +using namespace std; + +std::string g_last_su_full_path; + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_testRoot( + JNIEnv* env, + jobject /* this */, + jstring rootKey) { + const char *str1 = env->GetStringUTFChars(rootKey, 0); + string strRootKey= str1; + env->ReleaseStringUTFChars(rootKey, str1); + + std::string result; + kernel_root::fork_pipe_info finfo; + ssize_t err = 0; + if(fork_pipe_child_process(finfo)) { + err = kernel_root::get_root(strRootKey.c_str()); + result = "getRoot:"; + result += std::to_string(err); + result += "\n\n"; + if(err == 0) { + result += get_capability_info(); + result += "\n\n"; + } + write_errcode_from_child(finfo, err); + write_string_from_child(finfo, result); + _exit(0); + return 0; + } + err = 0; + if(!wait_fork_child_process(finfo)) { + err = -1120001; + } else { + if(!read_errcode_from_child(finfo, err)) { + err = -1120002; + } else if(!read_string_from_child(finfo, result)) { + err = -1120003; + } + } + return env->NewStringUTF(result.c_str()); +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_runRootCmd( + JNIEnv* env, + jobject /* this */, + jstring rootKey, + jstring cmd) { + const char *str1 = env->GetStringUTFChars(rootKey, 0); + string strRootKey= str1; + env->ReleaseStringUTFChars(rootKey, str1); + + str1 = env->GetStringUTFChars(cmd, 0); + string strCmd= str1; + env->ReleaseStringUTFChars(cmd, str1); + + + ssize_t err; + string result = kernel_root::run_root_cmd(strRootKey.c_str(), strCmd.c_str(), err); + stringstream sstr; + sstr << "runRootCmd err:" << err << ", result:" << result; + return env->NewStringUTF(sstr.str().c_str()); +} + + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_runInit64ProcessCmd( + JNIEnv* env, + jobject /* this */, + jstring rootKey, + jstring cmd) { + const char *str1 = env->GetStringUTFChars(rootKey, 0); + string strRootKey= str1; + env->ReleaseStringUTFChars(rootKey, str1); + + str1 = env->GetStringUTFChars(cmd, 0); + string strCmd= str1; + env->ReleaseStringUTFChars(cmd, str1); + + + ssize_t err; + string result = kernel_root::safe_run_init64_cmd_wrapper(strRootKey.c_str(), strCmd.c_str(), err); + + stringstream sstr; + sstr << "runInit64Cmd err:" << err << ", result:" << result; + return env->NewStringUTF(sstr.str().c_str()); +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_installSu( + JNIEnv* env, + jobject /* this */, + jstring rootKey, + jstring basePath) { + + const char *str1 = env->GetStringUTFChars(rootKey, 0); + string strRootKey= str1; + env->ReleaseStringUTFChars(rootKey, str1); + + str1 = env->GetStringUTFChars(basePath, 0); + string strBasePath= str1; + env->ReleaseStringUTFChars(basePath, str1); + + stringstream sstr; + //安装su工具套件 + ssize_t err; + std::string su_hide_full_path = kernel_root::safe_install_su(strRootKey.c_str(), strBasePath.c_str(), err); + sstr << "install su err:" << err<<", su_hide_full_path:" << su_hide_full_path << std::endl; + g_last_su_full_path = su_hide_full_path; + if (err == 0) { + sstr << "installSu done."<< std::endl; + } + return env->NewStringUTF(sstr.str().c_str()); +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_getLastInstallSuFullPath( + JNIEnv* env, + jobject /* this */) { + return env->NewStringUTF(g_last_su_full_path.c_str()); +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_uninstallSu( + JNIEnv* env, + jobject /* this */, + jstring rootKey, + jstring basePath) { + + const char *str1 = env->GetStringUTFChars(rootKey, 0); + string strRootKey= str1; + env->ReleaseStringUTFChars(rootKey, str1); + + str1 = env->GetStringUTFChars(basePath, 0); + string strBasePath= str1; + env->ReleaseStringUTFChars(basePath, str1); + + stringstream sstr; + + ssize_t err = kernel_root::safe_uninstall_su(strRootKey.c_str(), strBasePath.c_str()); + sstr << "uninstallSu err:" << err << std::endl; + if (err != 0) { + return env->NewStringUTF(sstr.str().c_str()); + } + g_last_su_full_path.clear(); + sstr << "uninstallSu done."; + return env->NewStringUTF(sstr.str().c_str()); +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_autoSuEnvInject( + JNIEnv* env, + jobject /* this */, + jstring rootKey, + jstring targetProcessCmdline) { + + if(g_last_su_full_path.empty()) { + return env->NewStringUTF("【错误】请先安装部署su"); + } + const char *str1 = env->GetStringUTFChars(rootKey, 0); + string strRootKey= str1; + env->ReleaseStringUTFChars(rootKey, str1); + + str1 = env->GetStringUTFChars(targetProcessCmdline, 0); + string strTargetProcessCmdline = str1; + env->ReleaseStringUTFChars(targetProcessCmdline, str1); + + stringstream sstr; + + //杀光所有历史进程 + std::set out; + ssize_t err = kernel_root::safe_find_all_cmdline_process(strRootKey.c_str(), strTargetProcessCmdline.c_str(), out); + sstr << "find_all_cmdline_process err:"<< err<<", cnt:"<NewStringUTF(sstr.str().c_str()); + } + std::string kill_cmd; + for (pid_t t : out) { + err = kernel_root::safe_kill_process(strRootKey.c_str(), t); + sstr << "kill_ret err:"<< err << std::endl; + if (err != 0) { + return env->NewStringUTF(sstr.str().c_str()); + } + } + pid_t pid; + err = kernel_root::safe_wait_and_find_cmdline_process(strRootKey.c_str(), strTargetProcessCmdline.c_str(), 60*1000, pid); + + std::string folder_path = g_last_su_full_path; + int n = folder_path.find_last_of("/"); + if(n != -1) { + folder_path = folder_path.substr(0,n); + } + sstr << "autoSuEnvInject("<< err<<", " << folder_path <<")" << std::endl; + if (err != 0) { + return env->NewStringUTF(sstr.str().c_str()); + } + err = kernel_root::safe_inject_process_env64_PATH_wrapper(strRootKey.c_str(), pid, folder_path.c_str()); + sstr << "autoSuEnvInject ret val:" << err << std::endl; + if (err != 0) { + return env->NewStringUTF(sstr.str().c_str()); + } + sstr << "autoSuEnvInject done."; + return env->NewStringUTF(sstr.str().c_str()); +} + + + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_getAllCmdlineProcess( + JNIEnv* env, + jobject /* this */, + jstring rootKey) { + std::stringstream ss; + + const char *str1 = env->GetStringUTFChars(rootKey, 0); + std::string strRootKey = str1; + env->ReleaseStringUTFChars(rootKey, str1); + + std::map pid_map; + ssize_t err = kernel_root::safe_get_all_cmdline_process(strRootKey.c_str(), pid_map); + if(err != 0) { + ss << "get_all_cmdline_process err:"<< err<< std::endl; + return env->NewStringUTF(ss.str().c_str()); + } + + ss << "{\"data\":["; + for (auto iter = pid_map.begin(); iter != pid_map.end(); ) { + size_t len = iter->second.length(); + size_t max_encoded_len = 3 * len + 1; + shared_ptr spData(new (std::nothrow) char[max_encoded_len], std::default_delete()); + memset(spData.get(), 0, max_encoded_len); + url_encode(const_cast(iter->second.c_str()), spData.get()); + ss << "{\"" << iter->first << "\":\"" << spData.get() << "\"}"; + if (++iter != pid_map.end()) { + ss << ","; + } + } + ss << "]}"; + return env->NewStringUTF(ss.str().c_str()); +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_parasitePrecheckApp( + JNIEnv* env, + jobject /* this */, + jstring rootKey, + jstring targetProcessCmdline) { + + const char *str1 = env->GetStringUTFChars(rootKey, 0); + string strRootKey= str1; + env->ReleaseStringUTFChars(rootKey, str1); + + str1 = env->GetStringUTFChars(targetProcessCmdline, 0); + string strTargetProcessCmdline = str1; + env->ReleaseStringUTFChars(targetProcessCmdline, str1); + + stringstream sstr; + std::set test_pid; + ssize_t err = kernel_root::safe_find_all_cmdline_process(strRootKey.c_str(), strTargetProcessCmdline.c_str(), test_pid); + if (err != 0) { + sstr << "find_all_cmdline_process err:"<< err<<", cnt:"<< test_pid.size() << std::endl; + return env->NewStringUTF(sstr.str().c_str()); + } + if (test_pid.size() == 0) { + sstr << "目标进程不存在" << std::endl; + return env->NewStringUTF(sstr.str().c_str()); + } + + std::set so_path_list; + err = kernel_root::safe_parasite_precheck_app(strRootKey.c_str(), strTargetProcessCmdline.c_str(), so_path_list); + if (err) { + sstr << "parasite_precheck_app ret val:" << err << std::endl; + if(err == -9903) { + sstr << "此目标APP为32位应用,无法寄生" << err << std::endl; + } + return env->NewStringUTF(sstr.str().c_str()); + } + + if (!so_path_list.size()) { + sstr << "目标APP无法寄生:无法检测到目标APP的JNI环境,您可尝试重启目标APP后再试" << std::endl; + return env->NewStringUTF(sstr.str().c_str()); + } + + sstr << "{\"soPaths\":["; + for (auto iter = so_path_list.begin(); iter != so_path_list.end(); ) { + size_t len = iter->length(); + size_t max_encoded_len = 3 * len + 1; + std::shared_ptr spData(new (std::nothrow) char[max_encoded_len], std::default_delete()); + memset(spData.get(), 0, max_encoded_len); + url_encode(const_cast(iter->c_str()), spData.get()); + sstr << "\"" << spData.get() << "\""; + if (++iter != so_path_list.end()) { + sstr << ","; + } + } + sstr << "]}"; + return env->NewStringUTF(sstr.str().c_str()); + +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_linux_permissionmanager_MainActivity_parasiteImplantApp( + JNIEnv* env, + jobject /* this */, + jstring rootKey, + jstring targetProcessCmdline, + jstring targetSoFullPath) { + + const char *str1 = env->GetStringUTFChars(rootKey, 0); + string strRootKey= str1; + env->ReleaseStringUTFChars(rootKey, str1); + + str1 = env->GetStringUTFChars(targetProcessCmdline, 0); + string strTargetProcessCmdline = str1; + env->ReleaseStringUTFChars(targetProcessCmdline, str1); + + str1 = env->GetStringUTFChars(targetSoFullPath, 0); + string strTargetSoFullPath = str1; + env->ReleaseStringUTFChars(targetSoFullPath, str1); + + stringstream sstr; + ssize_t err = kernel_root::safe_parasite_implant_app(strRootKey.c_str(), strTargetProcessCmdline.c_str(), strTargetSoFullPath.c_str()); + if (err != 0) { + sstr << "parasite_implant_app err:"<< err << std::endl; + return env->NewStringUTF(sstr.str().c_str()); + } + sstr << "parasiteImplantApp done."; + return env->NewStringUTF(sstr.str().c_str()); + +} + diff --git a/PermissionManager/app/src/main/cpp/urlEncodeUtils.h b/PermissionManager/app/src/main/cpp/urlEncodeUtils.h new file mode 100644 index 00000000..0d1482f7 --- /dev/null +++ b/PermissionManager/app/src/main/cpp/urlEncodeUtils.h @@ -0,0 +1,74 @@ +#ifndef URL_ENCODE_UTILS_H_ +#define URL_ENCODE_UTILS_H_ +#include +#include + +static inline char to_hex(char code) { + static char hex[] = "0123456789ABCDEF"; + return hex[code & 15]; +} +static inline char from_hex(char ch) { + return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; +} + +/* +//使用例子 +int main() { + char str[] = "你好,世界"; + char encoded_str[256]; + url_encode(str, encoded_str); + printf("Encoded URL: %s\n", encoded_str); + return 0; +} +*/ +static void url_encode(char *str, char *encoded_str) { + char *pstr = str, *buf = encoded_str; + while (*pstr) { + unsigned char c = *pstr; + if (c <= 0x7F) { // ASCII + if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { + *buf++ = c; + } else if (c == ' ') { + *buf++ = '+'; + } else { + *buf++ = '%', *buf++ = to_hex(c >> 4), *buf++ = to_hex(c & 15); + } + } else { // Non-ASCII + while (c) { + *buf++ = '%', *buf++ = to_hex(c >> 4), *buf++ = to_hex(c & 15); + c = *(++pstr); + } + continue; + } + pstr++; + } + *buf = '\0'; +} +/* +//使用例子 +int main() { + char url[] = "%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C"; // "你好,世界"的URL编码 + char decoded_str[256]; + url_decode(url, decoded_str); + printf("Decoded URL: %s\n", decoded_str); + return 0; +} +*/ +static void url_decode(char *str, char *decoded_str) { + char *pstr = str, *buf = decoded_str; + while (*pstr) { + if (*pstr == '%') { + if (pstr[1] && pstr[2]) { + *buf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]); + pstr += 2; + } + } else if (*pstr == '+') { + *buf++ = ' '; + } else { + *buf++ = *pstr; + } + pstr++; + } + *buf = '\0'; +} +#endif \ No newline at end of file diff --git a/PermissionManager/app/src/main/java/com/linux/permissionmanager/Adapter/SelectAppRecyclerAdapter.java b/PermissionManager/app/src/main/java/com/linux/permissionmanager/Adapter/SelectAppRecyclerAdapter.java new file mode 100644 index 00000000..8713f088 --- /dev/null +++ b/PermissionManager/app/src/main/java/com/linux/permissionmanager/Adapter/SelectAppRecyclerAdapter.java @@ -0,0 +1,119 @@ +package com.linux.permissionmanager.Adapter; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.os.Handler; +import android.os.Message; +import android.text.Html; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.PopupWindow; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.linux.permissionmanager.Model.SelectAppRecyclerItem; +import com.linux.permissionmanager.R; + +import java.util.ArrayList; +import java.util.List; + +public class SelectAppRecyclerAdapter extends RecyclerView.Adapter { + public static class ViewHolder extends RecyclerView.ViewHolder { + public View v; + public ImageView select_app_icon; + public TextView select_app_text; + public TextView select_package_name; + public ViewHolder(View v) { + super(v); + this.v = v; + } + + } + + private int resourceId; + private List objects; + private PopupWindow popupWindow; + private Handler selectAppCallback; + private Context ctx; + public SelectAppRecyclerAdapter(Context ctx, int textViewResourceId, List objects, PopupWindow popupWindow, Handler selectAppCallback) { + this.resourceId = textViewResourceId; + this.objects = new ArrayList<>(objects); + this. popupWindow = popupWindow; + this. selectAppCallback = selectAppCallback; + this. ctx = ctx; + } + + public void updateList(List newList) { + objects.clear(); + objects.addAll(newList); + notifyDataSetChanged(); + } + + + public List getList() { + return objects; + } + + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View v =LayoutInflater.from(parent.getContext()).inflate(resourceId,parent,false); + SelectAppRecyclerAdapter.ViewHolder holder = new SelectAppRecyclerAdapter.ViewHolder(v); + + holder.select_app_icon = v.findViewById(R.id.select_app_icon); + holder.select_app_text=v.findViewById(R.id.select_app_text) ; + holder.select_package_name=v.findViewById(R.id.select_package_name) ; + return holder; + } + + + @Override + public void onBindViewHolder(@NonNull SelectAppRecyclerAdapter.ViewHolder holder, int position) { + SelectAppRecyclerItem appItem=objects.get(position); + String showName = appItem.getShowName(ctx); + String packageName = appItem.getPackageName(); + Drawable icon = appItem.getDrawable(ctx); + + //图标+进程PID+名字+内存 + holder.select_app_icon.setImageDrawable(icon); + String showText=""+showName +" " + +" "+" ("+packageName+")"+""; + + holder.select_app_text.setText(Html.fromHtml(showText)); + holder.select_package_name.setText(packageName); + + //item被点击 + holder.v.setOnClickListener(new ClickRecyclerItemListener(appItem)); + } + + + @Override + public int getItemCount() { + return objects.size(); + } + + @Override + public int getItemViewType(int position) { + return position; + } + + + class ClickRecyclerItemListener implements View.OnClickListener { + SelectAppRecyclerItem appItem; + public ClickRecyclerItemListener( SelectAppRecyclerItem appItem){ + this.appItem =appItem; + } + @Override + public void onClick(View v) { + popupWindow.dismiss(); + Message msg = new Message(); + msg.obj = (SelectAppRecyclerItem)appItem; + selectAppCallback.sendMessage(msg); + } + } +} diff --git a/PermissionManager/app/src/main/java/com/linux/permissionmanager/Adapter/SelectFileRecyclerAdapter.java b/PermissionManager/app/src/main/java/com/linux/permissionmanager/Adapter/SelectFileRecyclerAdapter.java new file mode 100644 index 00000000..07a642be --- /dev/null +++ b/PermissionManager/app/src/main/java/com/linux/permissionmanager/Adapter/SelectFileRecyclerAdapter.java @@ -0,0 +1,101 @@ +package com.linux.permissionmanager.Adapter; + +import android.content.Context; +import android.os.Handler; +import android.os.Message; +import android.text.Html; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.PopupWindow; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.linux.permissionmanager.Model.SelectFileRecyclerItem; +import com.linux.permissionmanager.R; + +import java.util.ArrayList; +import java.util.List; +public class SelectFileRecyclerAdapter extends RecyclerView.Adapter { + public static class ViewHolder extends RecyclerView.ViewHolder { + public View v; + public TextView select_file_name; + public ViewHolder(View v) { + super(v); + this.v = v; + } + } + private int resourceId; + private List objects; + private PopupWindow popupWindow; + private Handler selectFileCallback; + private Context ctx; + public SelectFileRecyclerAdapter(Context ctx, int textViewResourceId, List objects, PopupWindow popupWindow, Handler selectFileCallback) { + this.resourceId = textViewResourceId; + this.objects = new ArrayList<>(objects); + this. popupWindow = popupWindow; + this. selectFileCallback = selectFileCallback; + this. ctx = ctx; + } + + public void updateList(List newList) { + objects.clear(); + objects.addAll(newList); + notifyDataSetChanged(); + } + + + public List getList() { + return objects; + } + + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View v =LayoutInflater.from(parent.getContext()).inflate(resourceId,parent,false); + SelectFileRecyclerAdapter.ViewHolder holder = new SelectFileRecyclerAdapter.ViewHolder(v); + + holder.select_file_name=v.findViewById(R.id.select_file_name) ; + return holder; + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + SelectFileRecyclerItem fileItem=objects.get(position); + String fileName = fileItem.getFileName(); + String showText=""+fileName +" "; + holder.select_file_name.setText(Html.fromHtml(showText)); + + //item被点击 + holder.v.setOnClickListener(new ClickRecyclerItemListener(fileItem)); + } + + @Override + public int getItemCount() { + return objects.size(); + } + + @Override + public int getItemViewType(int position) { + return position; + } + + + class ClickRecyclerItemListener implements View.OnClickListener { + SelectFileRecyclerItem fileItem; + public ClickRecyclerItemListener(SelectFileRecyclerItem fileItem){ + this.fileItem =fileItem; + } + @Override + public void onClick(View v) { + popupWindow.dismiss(); + Message msg = new Message(); + msg.obj = (SelectFileRecyclerItem)fileItem; + selectFileCallback.sendMessage(msg); + } + } +} \ No newline at end of file diff --git a/PermissionManager/app/src/main/java/com/linux/permissionmanager/MainActivity.java b/PermissionManager/app/src/main/java/com/linux/permissionmanager/MainActivity.java new file mode 100644 index 00000000..0762cd9b --- /dev/null +++ b/PermissionManager/app/src/main/java/com/linux/permissionmanager/MainActivity.java @@ -0,0 +1,654 @@ +package com.linux.permissionmanager; + +import android.annotation.SuppressLint; +import android.app.AlertDialog; +import android.app.ProgressDialog; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.PopupWindow; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.linux.permissionmanager.Adapter.SelectAppRecyclerAdapter; +import com.linux.permissionmanager.Adapter.SelectFileRecyclerAdapter; +import com.linux.permissionmanager.Model.PopupWindowOnTouchClose; +import com.linux.permissionmanager.Model.SelectAppRecyclerItem; +import com.linux.permissionmanager.Model.SelectFileRecyclerItem; +import com.linux.permissionmanager.Utils.ScreenInfoUtils; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + +public class MainActivity extends AppCompatActivity implements View.OnClickListener { + private String rootKey = "bz4kKoPVSAG1tnwlcs1PJ1qp6HtVymj60CoTgsjmMd1UALve"; + private String suBasePath = "/data/local/tmp"; + private String lastInputCmd = "id"; + private SharedPreferences m_shareSave; + private ProgressDialog m_loadingDlg = null; + static { + System.loadLibrary("permissionmanager"); + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + m_shareSave = getSharedPreferences("zhcs", Context.MODE_PRIVATE); + try { + rootKey = m_shareSave.getString("rootKey", rootKey); + } catch (Exception e) { + } + try { + lastInputCmd = m_shareSave.getString("lastInputCmd", lastInputCmd); + } catch (Exception e) { + } + + showUserInputRootKeyDlg(); + + Button test_root_btn = findViewById(R.id.test_root_btn); + Button run_root_cmd_btn = findViewById(R.id.run_root_cmd_btn); + Button run_init_process_cmd_btn = findViewById(R.id.run_init_process_cmd_btn); + Button su_env_install_btn = findViewById(R.id.su_env_install_btn); + Button su_env_inject_btn = findViewById(R.id.su_env_inject_btn); + Button clean_su_btn = findViewById(R.id.clean_su_btn); + Button implant_app_btn = findViewById(R.id.implant_app_btn); + Button copy_info_btn = findViewById(R.id.copy_info_btn); + Button clean_info_btn = findViewById(R.id.clean_info_btn); + + test_root_btn.setOnClickListener(this); + run_root_cmd_btn.setOnClickListener(this); + run_init_process_cmd_btn.setOnClickListener(this); + su_env_install_btn.setOnClickListener(this); + su_env_inject_btn.setOnClickListener(this); + clean_su_btn.setOnClickListener(this); + implant_app_btn.setOnClickListener(this); + copy_info_btn.setOnClickListener(this); + clean_info_btn.setOnClickListener(this); + + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.test_root_btn: + appendConsoleMsg(testRoot(rootKey)); + break; + case R.id.run_root_cmd_btn: + showUserInputRootCmdDlg(false); + break; + case R.id.run_init_process_cmd_btn: + showUserInputRootCmdDlg(true); + break; + case R.id.su_env_install_btn: + //1.安装su工具 + String insRet = installSu(rootKey, suBasePath); + appendConsoleMsg(insRet); + if(insRet.indexOf("installSu done.") != -1) { + //2.复制su的路径到剪贴板 + String suFullPath = getLastInstallSuFullPath(); + appendConsoleMsg("lastInstallSuFullPath:" + suFullPath); + showMsgDlg("温馨提示", + "安装部署su成功,su路径已复制到剪贴板。", null); + copyEditText(suFullPath); + appendConsoleMsg("安装部署su成功,su路径已复制到剪贴板"); + } + break; + case R.id.su_env_inject_btn: + Handler selectInjectSuAppCallback = new Handler() { + @Override + public void handleMessage(@NonNull Message msg) { + + SelectAppRecyclerItem appItem = (SelectAppRecyclerItem) msg.obj; + + if (m_loadingDlg == null) { + m_loadingDlg = new ProgressDialog(MainActivity.this); + m_loadingDlg.setCancelable(false); + } + m_loadingDlg.setTitle(""); + m_loadingDlg.setMessage("请现在手动启动APP [" + appItem.getShowName(MainActivity.this) + "]"); + m_loadingDlg.show(); + + new Thread() { + public void run() { + String autoSuEnvInjectRet = autoSuEnvInject(rootKey, appItem.getPackageName()); + runOnUiThread(new Runnable() { + public void run() { + appendConsoleMsg(autoSuEnvInjectRet); + m_loadingDlg.cancel(); + + if(autoSuEnvInjectRet.indexOf("autoSuEnvInject done.")!= -1) { + showMsgDlg("提示", + "已经授予ROOT权限到APP [" + appItem.getShowName(MainActivity.this) + "]", + appItem.getDrawable(MainActivity.this)); + } + + } + }); + } + }.start(); + super.handleMessage(msg); + } + }; + showSelectAppDlg(selectInjectSuAppCallback); + break; + case R.id.clean_su_btn: + appendConsoleMsg(uninstallSu(rootKey,suBasePath)); + break; + case R.id.implant_app_btn: + showMsgDlg("建议", "为实现APP的最佳隐蔽性,推荐将此工具寄生到能常驻后台的APP上", null); + + Handler selectImplantAppCallback = new Handler() { + @Override + public void handleMessage(@NonNull Message msg) { + SelectAppRecyclerItem appItem = (SelectAppRecyclerItem) msg.obj; + if (m_loadingDlg == null) { + m_loadingDlg = new ProgressDialog(MainActivity.this); + m_loadingDlg.setCancelable(false); + } + m_loadingDlg.setTitle(""); + m_loadingDlg.setMessage("请现在手动启动APP [" + appItem.getShowName(MainActivity.this) + "]"); + m_loadingDlg.show(); + new Thread() { + public void run() { + String parasitePrecheckAppRet = parasitePrecheckApp(rootKey, appItem.getPackageName()); + runOnUiThread(new Runnable() { + public void run() { + m_loadingDlg.cancel(); + List fileList = parseSoFullPathInfo(parasitePrecheckAppRet); + if (fileList.size() == 0 && !parasitePrecheckAppRet.isEmpty()) { + appendConsoleMsg(parasitePrecheckAppRet); + return; + } + Handler selectFileCallback = new Handler() { + @Override + public void handleMessage(@NonNull Message msg) { + SelectFileRecyclerItem fileItem = (SelectFileRecyclerItem) msg.obj; + String parasiteImplantAppRet = parasiteImplantApp(rootKey, appItem.getPackageName(), fileItem.getFilePath()); + appendConsoleMsg(parasiteImplantAppRet); + if(parasiteImplantAppRet.indexOf("parasiteImplantApp done.")!= -1) { + showMsgDlg("提示", + "已经寄生到APP [" + appItem.getShowName(MainActivity.this) + "]", + appItem.getDrawable(MainActivity.this)); + } + super.handleMessage(msg); + } + }; + showSelectFileDlg(fileList, selectFileCallback); + } + }); + } + }.start(); + super.handleMessage(msg); + } + }; + View view = showSelectAppDlg(selectImplantAppCallback); + CheckBox show_system_app_ckbox = view.findViewById(R.id.show_system_app_ckbox); + CheckBox show_thirty_app_ckbox = view.findViewById(R.id.show_thirty_app_ckbox); + CheckBox show_running_app_ckbox = view.findViewById(R.id.show_running_app_ckbox); + show_system_app_ckbox.setChecked(false); + show_thirty_app_ckbox.setChecked(true); + show_running_app_ckbox.setChecked(true); + break; + case R.id.copy_info_btn: + EditText edit = findViewById(R.id.console_edit); + copyEditText(edit.getText().toString()); + Toast.makeText(v.getContext(), "复制成功", Toast.LENGTH_SHORT).show(); + break; + case R.id.clean_info_btn: + cleanConsoleMsg(); + break; + default: + break; + } + } + public void showUserInputRootKeyDlg() { + Handler inputCallback = new Handler() { + @Override + public void handleMessage(@NonNull Message msg) { + String inputTxt = (String)msg.obj; + rootKey = inputTxt; + SharedPreferences.Editor mEdit = m_shareSave.edit(); + mEdit.putString("rootKey", rootKey); + mEdit.commit(); + super.handleMessage(msg); + } + }; + showInputDlg(rootKey,"请输入ROOT权限的KEY", inputCallback); + } + + public void showUserInputRootCmdDlg(boolean isKernelCmd) { + Handler inputCallback = new Handler() { + @Override + public void handleMessage(@NonNull Message msg) { + String inputTxt = (String)msg.obj; + lastInputCmd = inputTxt; + SharedPreferences.Editor mEdit = m_shareSave.edit(); + mEdit.putString("lastInputCmd", lastInputCmd); + mEdit.commit(); + appendConsoleMsg(inputTxt + "\n" + + (isKernelCmd ? runInit64ProcessCmd(rootKey, inputTxt) : runRootCmd(rootKey, inputTxt))); + super.handleMessage(msg); + } + }; + + showInputDlg(lastInputCmd, isKernelCmd ? "输入ROOT命令" : "输入普通命令", inputCallback); + } + + public void showInputDlg(String defaultText, String title, Handler confirmCallback) { + final EditText inputTxt = new EditText(MainActivity.this); + inputTxt.setText(defaultText); + inputTxt.setFocusable(true); + inputTxt.setSelection(defaultText.length(), 0); + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); + builder.setTitle(title).setIcon(android.R.drawable.ic_dialog_info).setView(inputTxt) + .setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + String text = inputTxt.getText().toString(); + Message msg = new Message(); + msg.obj = text; + confirmCallback.sendMessage(msg); + } + }); + AlertDialog dialog = builder.create(); + dialog.show(); + } + + private void showMsgDlg(String title, String msg, Drawable icon) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(title); + builder.setMessage(msg); + if(icon != null) { + builder.setIcon(icon); + } + builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + } + }); + AlertDialog dialog = builder.create(); + dialog.show(); + } + + public void appendConsoleMsg(String msg) { + EditText console_edit = findViewById(R.id.console_edit); + StringBuffer txt = new StringBuffer(); + txt.append(console_edit.getText().toString()); + if (txt.length() != 0) { + txt.append("\n"); + } + txt.append(msg); + txt.append("\n"); + console_edit.setText(txt.toString()); + console_edit.setSelection(txt.length()); + } + + public void cleanConsoleMsg() { + EditText console_edit = findViewById(R.id.console_edit); + console_edit.setText(""); + } + + public void copyEditText(String text) { + ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + ClipData mClipData = ClipData.newPlainText("Label", text); + cm.setPrimaryClip(mClipData); + } + + public View showSelectAppDlg(Handler selectAppCallback) { + final PopupWindow popupWindow = new PopupWindow(this); + + View view = View.inflate(this, R.layout.select_app_wnd, null); + popupWindow.setContentView(view); + + popupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT); + popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); + popupWindow.setBackgroundDrawable(new ColorDrawable(0x9B000000)); + popupWindow.setOutsideTouchable(true); + popupWindow.setFocusable(true); + popupWindow.setTouchable(true); + + //全屏 + View parent = View.inflate(MainActivity.this, R.layout.activity_main, null); + popupWindow.showAtLocation(parent, Gravity.NO_GRAVITY, 0, 0); + popupWindow.showAsDropDown(parent, 0, 0); + + popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { + @Override + public void onDismiss() { + } + }); + + final int screenWidth = ScreenInfoUtils.getRealWidth(this); + final int screenHeight = ScreenInfoUtils.getRealHeight(this); + + final double centerWidth = ((double) screenWidth) * 0.80; + final double centerHeight = ((double) screenHeight) * 0.90; + + LinearLayout center_layout = (LinearLayout) view.findViewById(R.id.center_layout); + android.view.ViewGroup.LayoutParams lp = center_layout.getLayoutParams(); + lp.width = (int) centerWidth; + lp.height = (int) centerHeight; + + //点击阴影部分可关闭窗口 + popupWindow.setTouchInterceptor(new PopupWindowOnTouchClose(popupWindow, + screenWidth, screenHeight, (int) centerWidth, (int) centerHeight)); + + List appList = new ArrayList<>(); + List packages = getPackageManager().getInstalledPackages(0); + + for (int i = 0; i < packages.size(); i++) { + PackageInfo packageInfo = packages.get(i); + String packageName = packageInfo.applicationInfo.packageName; + if(packageName.equals(getPackageName())){ + continue; + } + appList.add(new SelectAppRecyclerItem(packageInfo)); + } + + SelectAppRecyclerAdapter adapter = new SelectAppRecyclerAdapter( + MainActivity.this, R.layout.select_app_recycler_item, appList, popupWindow, selectAppCallback); + RecyclerView select_app_recycler_view = (RecyclerView) view.findViewById(R.id.select_app_recycler_view); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); + linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); + select_app_recycler_view.setLayoutManager(linearLayoutManager); + select_app_recycler_view.setAdapter(adapter); + + // 获取正在运行的APP + String runningApp = getAllCmdlineProcess(rootKey); + Map processMap = parseProcessInfo(runningApp); + if(processMap.size() == 0 && !runningApp.isEmpty()) { + appendConsoleMsg(runningApp); + } + + + TextView clear_search_btn = view.findViewById(R.id.clear_search_btn); + EditText search_edit = view.findViewById(R.id.search_edit); + CheckBox show_system_app_ckbox = view.findViewById(R.id.show_system_app_ckbox); + CheckBox show_thirty_app_ckbox = view.findViewById(R.id.show_thirty_app_ckbox); + CheckBox show_running_app_ckbox = view.findViewById(R.id.show_running_app_ckbox); + + Map finalProcessMap = processMap; + @SuppressLint("HandlerLeak") Handler updateAppListFunc = new Handler() { + @Override + public void handleMessage(@NonNull Message msg) { + List newAppList = new ArrayList<>(); + String filterText = search_edit.getText().toString(); + for(SelectAppRecyclerItem item : appList) { + PackageInfo pack = item.getPackageInfo(); + if(!show_system_app_ckbox.isChecked()) { + if ((pack.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { + //系统应用 + continue; + } + } + if(!show_thirty_app_ckbox.isChecked()) { + if ((pack.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { + //第三方应用 + continue; + } + } + if (show_running_app_ckbox.isChecked()) { + boolean isFound = finalProcessMap.values().stream() + .anyMatch(value -> value.contains(item.getPackageName())); + if (!isFound) { + continue; + } + } + + if(item.getPackageName().indexOf(filterText) != -1 || item.getShowName(MainActivity.this).indexOf(filterText) != -1) { + newAppList.add(item); + } + } + adapter.updateList(newAppList); + super.handleMessage(msg); + } + }; + search_edit.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + String text = s.toString(); + if(text.length() > 0) { + clear_search_btn.setVisibility(View.VISIBLE); + } else { + clear_search_btn.setVisibility(View.GONE); + } + updateAppListFunc.sendMessage(new Message()); + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + clear_search_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + search_edit.setText(""); + } + }); + + show_system_app_ckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + updateAppListFunc.sendMessage(new Message()); + } + }); + show_thirty_app_ckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + updateAppListFunc.sendMessage(new Message()); + } + }); + show_running_app_ckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + updateAppListFunc.sendMessage(new Message()); + } + }); + updateAppListFunc.sendMessage(new Message()); + return view; + } + + + public View showSelectFileDlg(List filePath, Handler selectFileCallback) { + final PopupWindow popupWindow = new PopupWindow(this); + + View view = View.inflate(this, R.layout.select_file_wnd, null); + popupWindow.setContentView(view); + + popupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT); + popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); + popupWindow.setBackgroundDrawable(new ColorDrawable(0x9B000000)); + popupWindow.setOutsideTouchable(true); + popupWindow.setFocusable(true); + popupWindow.setTouchable(true); + + //全屏 + View parent = View.inflate(MainActivity.this, R.layout.activity_main, null); + popupWindow.showAtLocation(parent, Gravity.NO_GRAVITY, 0, 0); + popupWindow.showAsDropDown(parent, 0, 0); + + popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { + @Override + public void onDismiss() { + } + }); + + final int screenWidth = ScreenInfoUtils.getRealWidth(this); + final int screenHeight = ScreenInfoUtils.getRealHeight(this); + + final double centerWidth = ((double) screenWidth) * 0.80; + final double centerHeight = ((double) screenHeight) * 0.90; + + LinearLayout center_layout = (LinearLayout) view.findViewById(R.id.center_layout); + android.view.ViewGroup.LayoutParams lp = center_layout.getLayoutParams(); + lp.width = (int) centerWidth; + lp.height = (int) centerHeight; + + //点击阴影部分可关闭窗口 + popupWindow.setTouchInterceptor(new PopupWindowOnTouchClose(popupWindow, + screenWidth, screenHeight, (int) centerWidth, (int) centerHeight)); + + List fileList = new ArrayList<>(); + for (int i = 0; i < filePath.size(); i++) { + fileList.add(new SelectFileRecyclerItem(filePath.get(i))); + } + + SelectFileRecyclerAdapter adapter = new SelectFileRecyclerAdapter( + MainActivity.this, R.layout.select_file_recycler_item, fileList, popupWindow, selectFileCallback); + RecyclerView select_file_recycler_view = (RecyclerView) view.findViewById(R.id.select_file_recycler_view); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); + linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); + select_file_recycler_view.setLayoutManager(linearLayoutManager); + select_file_recycler_view.setAdapter(adapter); + + TextView clear_search_btn = view.findViewById(R.id.clear_search_btn); + EditText search_edit = view.findViewById(R.id.search_edit); + + + @SuppressLint("HandlerLeak") Handler updateFileListFunc = new Handler() { + @Override + public void handleMessage(@NonNull Message msg) { + List newFileList = new ArrayList<>(); + String filterText = search_edit.getText().toString(); + for(SelectFileRecyclerItem item : fileList) { + String fileName = item.getFileName(); + if(fileName.indexOf(filterText) != -1) { + newFileList.add(item); + } + } + adapter.updateList(newFileList); + super.handleMessage(msg); + } + }; + search_edit.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + String text = s.toString(); + if(text.length() > 0) { + clear_search_btn.setVisibility(View.VISIBLE); + } else { + clear_search_btn.setVisibility(View.GONE); + } + updateFileListFunc.sendMessage(new Message()); + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + clear_search_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + search_edit.setText(""); + } + }); + updateFileListFunc.sendMessage(new Message()); + return view; + } + + private Map parseProcessInfo(String jsonStr) { + Map processMap = new HashMap<>(); + try { + JSONObject obj = new JSONObject(jsonStr); + JSONArray dataArray = obj.getJSONArray("data"); + for (int i = 0; i < dataArray.length(); i++) { + JSONObject item = dataArray.getJSONObject(i); + String key = item.keys().next(); + int pid = Integer.parseInt(key); + String encodedValue = item.getString(key); + String value = URLDecoder.decode(encodedValue, "UTF-8"); + processMap.put(pid, value); + } + } catch (Exception e) { + e.printStackTrace(); + } + return processMap; + } + + public List parseSoFullPathInfo(String jsonStr) { + List soPathList = new ArrayList<>(); + try { + JSONObject obj = new JSONObject(jsonStr); + JSONArray soPaths = obj.getJSONArray("soPaths"); + for (int i = 0; i < soPaths.length(); i++) { + String path = soPaths.getString(i); + String value = URLDecoder.decode(path, "UTF-8"); + soPathList.add(value); + } + } catch (Exception e) { + e.printStackTrace(); + } + return soPathList; + } + + public native String testRoot(String rootKey); + + public native String runRootCmd(String rootKey, String cmd); + + public native String runInit64ProcessCmd(String rootKey, String cmd); + + public native String installSu(String rootKey, String basePath); + + public native String getLastInstallSuFullPath(); + + public native String uninstallSu(String rootKey, String basePath); + + public native String autoSuEnvInject(String rootKey, String targetProcessCmdline); + + public native String getAllCmdlineProcess(String rootKey); + + public native String parasitePrecheckApp(String rootKey, String targetProcessCmdlin); + + public native String parasiteImplantApp(String rootKey, String targetProcessCmdline, String targetSoFullPath); + +} \ No newline at end of file diff --git a/PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/PopupWindowOnTouchClose.java b/PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/PopupWindowOnTouchClose.java new file mode 100644 index 00000000..ca4889d7 --- /dev/null +++ b/PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/PopupWindowOnTouchClose.java @@ -0,0 +1,48 @@ +package com.linux.permissionmanager.Model; + +import android.view.MotionEvent; +import android.view.View; +import android.widget.PopupWindow; + +public class PopupWindowOnTouchClose implements View.OnTouchListener { + private boolean lastVailedDown = true; + private int screenWidth, screenHeight, centerWidth, centerHeight; + private PopupWindow popupWindow; + + public PopupWindowOnTouchClose(PopupWindow popupWindow, int screenWidth, int screenHeight, int centerWidth, int centerHeight) { + this.popupWindow = popupWindow; + this.screenWidth = screenWidth; + this.screenHeight = screenHeight; + this.centerWidth = centerWidth; + this.centerHeight = centerHeight; + } + + private boolean isValiedRegion(View v, MotionEvent event) { + int x = (int) event.getX(); + int y = (int) event.getY(); + double wndLeft = (screenWidth - centerWidth) / 2; + double wndTop = (screenHeight - centerHeight) / 2; + if (x < wndLeft || x > wndLeft + centerWidth || y < wndTop || y > wndTop + centerHeight) { + return false; + } + return true; + } + + @Override + public boolean onTouch(View v, MotionEvent event) { + + if (event.getAction() == MotionEvent.ACTION_DOWN) { + lastVailedDown = isValiedRegion(v, event); + } else if (event.getAction() == MotionEvent.ACTION_UP) { + if (!lastVailedDown) { + if (!isValiedRegion(v, event)) { + popupWindow.dismiss(); + } + } + } + return false; + } +} + + + diff --git a/PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/SelectAppRecyclerItem.java b/PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/SelectAppRecyclerItem.java new file mode 100644 index 00000000..3c6b4f82 --- /dev/null +++ b/PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/SelectAppRecyclerItem.java @@ -0,0 +1,31 @@ +package com.linux.permissionmanager.Model; + +import android.content.Context; +import android.content.pm.PackageInfo; +import android.graphics.drawable.Drawable; + +public class SelectAppRecyclerItem { + private PackageInfo packageInfo; + + public SelectAppRecyclerItem(PackageInfo packageInfo){ + this.packageInfo = packageInfo; + } + + public PackageInfo getPackageInfo() { + return packageInfo; + } + + public String getShowName(Context ctx) { + String showName = this.packageInfo.applicationInfo.loadLabel(ctx.getPackageManager()).toString(); + return showName; + } + public String getPackageName() { + String packageName = this.packageInfo.applicationInfo.packageName; + return packageName; + } + public Drawable getDrawable(Context ctx) { + Drawable icon = this.packageInfo.applicationInfo.loadIcon(ctx.getPackageManager()); + return icon; + } + +} diff --git a/PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/SelectFileRecyclerItem.java b/PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/SelectFileRecyclerItem.java new file mode 100644 index 00000000..1c150af9 --- /dev/null +++ b/PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/SelectFileRecyclerItem.java @@ -0,0 +1,26 @@ +package com.linux.permissionmanager.Model; + +import android.os.Build; + +import androidx.annotation.RequiresApi; + +import java.nio.file.Path; +import java.nio.file.Paths; + +public class SelectFileRecyclerItem { + private String filePath; + + public SelectFileRecyclerItem(String filePath){ + this.filePath = filePath; + } + + public String getFilePath() { + return this.filePath; + } + + public String getFileName() { + Path path = Paths.get(filePath); + Path fileName = path.getFileName(); + return fileName.toString(); + } +} diff --git a/PermissionManager/app/src/main/java/com/linux/permissionmanager/Utils/ScreenInfoUtils.java b/PermissionManager/app/src/main/java/com/linux/permissionmanager/Utils/ScreenInfoUtils.java new file mode 100644 index 00000000..5e50159e --- /dev/null +++ b/PermissionManager/app/src/main/java/com/linux/permissionmanager/Utils/ScreenInfoUtils.java @@ -0,0 +1,187 @@ +package com.linux.permissionmanager.Utils; + +import android.app.Activity; +import android.content.Context; +import android.content.res.Resources; +import android.util.DisplayMetrics; +import android.util.Log; +import android.util.TypedValue; +import android.view.Display; +import android.view.WindowManager; + +/** + * Get Screen Information Utils + * + * @author yh + * @date 2018/12/18. + */ +public class ScreenInfoUtils { + + private static final String TAG = "ScreenInfoUtils"; + + /** + * Get Screen Width + */ + public static int getScreenWidth(Context context) { + return getDisplayMetrics(context).widthPixels; + } + + /** + * Get Screen Height + */ + public static int getScreenHeight(Context context) { + return getDisplayMetrics(context).heightPixels; + } + + + /** + * Get Screen Real Height + * + * @param context Context + * @return Real Height + */ + public static int getRealHeight(Context context) { + Display display = getDisplay(context); + if (display == null) { + return 0; + } + DisplayMetrics dm = new DisplayMetrics(); + display.getRealMetrics(dm); + return dm.heightPixels; + } + + /** + * Get Screen Real Width + * + * @param context Context + * @return Real Width + */ + public static int getRealWidth(Context context) { + Display display = getDisplay(context); + if (display == null) { + return 0; + } + DisplayMetrics dm = new DisplayMetrics(); + display.getRealMetrics(dm); + return dm.widthPixels; + } + + /** + * Get StatusBar Height + */ + public static int getStatusBarHeight(Context mContext) { + int resourceId = mContext.getResources().getIdentifier("status_bar_height", "dimen", "android"); + if (resourceId > 0) { + return mContext.getResources().getDimensionPixelSize(resourceId); + } + return 0; + } + + /** + * Get ActionBar Height + */ + public static int getActionBarHeight(Context mContext) { + TypedValue tv = new TypedValue(); + if (mContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { + return TypedValue.complexToDimensionPixelSize(tv.data, mContext.getResources().getDisplayMetrics()); + } + return 0; + } + + /** + * Get NavigationBar Height + */ + public static int getNavigationBarHeight(Context mContext) { + Resources resources = mContext.getResources(); + int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); + if (resourceId > 0) { + return resources.getDimensionPixelSize(resourceId); + } + return 0; + } + + /** + * Get Density + */ + private static float getDensity(Context context) { + return getDisplayMetrics(context).density; + } + + /** + * Get Dpi + */ + private static int getDpi(Context context) { + return getDisplayMetrics(context).densityDpi; + } + + /** + * Get Display + * + * @param context Context for get WindowManager + * @return Display + */ + private static Display getDisplay(Context context) { + WindowManager wm; + if (context instanceof Activity) { + Activity activity = (Activity) context; + wm = activity.getWindowManager(); + } else { + wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + } + if (wm != null) { + return wm.getDefaultDisplay(); + } + return null; + } + + /** + * Get DisplayMetrics + * + * @param context Context for get Resources + * @return DisplayMetrics + */ + private static DisplayMetrics getDisplayMetrics(Context context) { + return context.getResources().getDisplayMetrics(); + } + + + /** + * Get ScreenInfo + */ + private static String getScreenInfo(Context context) { + return " \n" + + "--------ScreenInfo--------" + "\n" + + "Screen Width : " + getScreenWidth(context) + "px\n" + + "Screen RealWidth :" + getRealWidth(context) + "px\n" + + "Screen Height: " + getScreenHeight(context) + "px\n" + + "Screen RealHeight: " + getRealHeight(context) + "px\n" + + "Screen StatusBar Height: " + getStatusBarHeight(context)+ "px\n" + + "Screen ActionBar Height: " + getActionBarHeight(context)+ "px\n" + + "Screen NavigationBar Height: " + getNavigationBarHeight(context)+ "px\n" + + "Screen Dpi: " + getDpi(context) + "\n" + + "Screen Density: " + getDensity(context) + "\n" + + "--------------------------"; + } + + + /** + * 根据手机的分辨率从 dp 的单位 转成为 px(像素) + */ + public static int dip2px(Context context, float dpValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (dpValue * scale); + } + + /** * 根据手机的分辨率从 px(像素) 的单位 转成为 dp */ + public static int px2dip(Context context, float pxValue) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (pxValue / scale); + } + + /** + * Print screenInfo to logcat + */ + public static void printScreenInfo(Context context) { + Log.d(TAG, getScreenInfo(context)); + } +} diff --git a/PermissionManager/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/PermissionManager/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..2b068d11 --- /dev/null +++ b/PermissionManager/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/PermissionManager/app/src/main/res/drawable/ic_launcher_background.xml b/PermissionManager/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..07d5da9c --- /dev/null +++ b/PermissionManager/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PermissionManager/app/src/main/res/drawable/line.xml b/PermissionManager/app/src/main/res/drawable/line.xml new file mode 100644 index 00000000..597142f2 --- /dev/null +++ b/PermissionManager/app/src/main/res/drawable/line.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/PermissionManager/app/src/main/res/drawable/line_drawable.xml b/PermissionManager/app/src/main/res/drawable/line_drawable.xml new file mode 100644 index 00000000..4f79f470 --- /dev/null +++ b/PermissionManager/app/src/main/res/drawable/line_drawable.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/PermissionManager/app/src/main/res/drawable/ripple_grey.xml b/PermissionManager/app/src/main/res/drawable/ripple_grey.xml new file mode 100644 index 00000000..ac736de4 --- /dev/null +++ b/PermissionManager/app/src/main/res/drawable/ripple_grey.xml @@ -0,0 +1,6 @@ + +//点击时波纹的颜色 + //未点击时控件的背景(可以是图片,可以是颜色,也可以是drawable里的xml背景(比如圆角)) + \ No newline at end of file diff --git a/PermissionManager/app/src/main/res/drawable/shape_wnd_grey_corner.xml b/PermissionManager/app/src/main/res/drawable/shape_wnd_grey_corner.xml new file mode 100644 index 00000000..6bc80841 --- /dev/null +++ b/PermissionManager/app/src/main/res/drawable/shape_wnd_grey_corner.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/PermissionManager/app/src/main/res/drawable/thumb.xml b/PermissionManager/app/src/main/res/drawable/thumb.xml new file mode 100644 index 00000000..0646431b --- /dev/null +++ b/PermissionManager/app/src/main/res/drawable/thumb.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/PermissionManager/app/src/main/res/drawable/thumb_drawable.xml b/PermissionManager/app/src/main/res/drawable/thumb_drawable.xml new file mode 100644 index 00000000..a93b8b83 --- /dev/null +++ b/PermissionManager/app/src/main/res/drawable/thumb_drawable.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/PermissionManager/app/src/main/res/layout/activity_main.xml b/PermissionManager/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..a1abe88e --- /dev/null +++ b/PermissionManager/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ 输出信息: +
+ + +
+ +
+ + +
+
+ +
+
+
+ + + + + +)***"; + +} + +void writeToLog(const std::string & message, const char* logFile = "/data/local/tmp/root_server.log") { + // FILE* file = fopen(logFile, "a"); + // if (file == nullptr) { + // perror("Error opening file"); + // return; + // } + // fwrite(message.c_str(), sizeof(char), message.length(), file); + // fwrite("\n", sizeof(char), 1, file); + // fclose(file); +} + +std::string GetHttpHead_200(long lLen) { + std::stringstream sstrHead; + sstrHead << "HTTP/1.1 200 OK\r\n"; + sstrHead << "Access-Control-Allow-Origin: *\r\n"; + sstrHead << "Connection: keep-alive\r\n"; + sstrHead << "Content-Length: " << lLen << "\r\n"; + sstrHead << "Content-Type: text/html; charset=UTF-8\r\n"; + sstrHead << "\r\n"; + return sstrHead.str(); +} + + +#endif /* _ROOT_SERVER_H_ */ diff --git a/testRoot/jni/root_server/root_server_inline_key.h b/testRoot/jni/root_server/root_server_inline_key.h new file mode 100644 index 00000000..58a61ae4 --- /dev/null +++ b/testRoot/jni/root_server/root_server_inline_key.h @@ -0,0 +1,10 @@ +#ifndef _ROOT_SERVER_INLINE_KEY_H_ +#define _ROOT_SERVER_INLINE_KEY_H_ +#include +#include + +static volatile const char static_inline_root_key[4096] = { + "e21cb39dc7ba99c986deb830ff8b8141b29764128c47ef71ae2375a53a13b880e63262b0e5596c981a9c4ded86b39674d77632683c35adc163812368eb13e75b" +}; + +#endif /* _ROOT_SERVER_INLINE_KEY_H_ */ diff --git a/testRoot/jni/root_server/root_server_inline_so_name.h b/testRoot/jni/root_server/root_server_inline_so_name.h new file mode 100644 index 00000000..f5178a3a --- /dev/null +++ b/testRoot/jni/root_server/root_server_inline_so_name.h @@ -0,0 +1,10 @@ +#ifndef _ROOT_SERVER_INLINE_SO_NAME_H_ +#define _ROOT_SERVER_INLINE_SO_NAME_H_ +#include +#include + +static volatile const char static_inline_so_name[4096] = { + "4b354bade02c335b02dee14bc39a471573c100b7e2f4e14d54dc58749babc678d2e4c740c3bc37c96f85a0d9ec091a44419ff0e14efabc3a4fdba9a3e21f1422" +}; + +#endif /* _ROOT_SERVER_INLINE_SO_NAME_H_ */ diff --git a/testRoot/jni/su/encryptor.h b/testRoot/jni/su/encryptor.h new file mode 100644 index 00000000..6bf32ba0 --- /dev/null +++ b/testRoot/jni/su/encryptor.h @@ -0,0 +1,96 @@ +#ifndef _SU_ENCRYPTOR_H_ +#define _SU_ENCRYPTOR_H_ +#include +#include +#include +#include +#include +namespace { +static void rand_str(char* dest, int n) { + int i, randno; + char stardstring[63] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + srand((unsigned)time(NULL)); + for (i = 0; i < n; i++) { + randno = rand() % 62; + *dest = stardstring[randno]; + dest++; + } +} +static std::string encryp_string(const std::string& src, const std::string& key, bool random = true) { + int KeyPos = -1; + int SrcAsc = 0; + time_t t; + + int KeyLen = key.length(); + if (KeyLen == 0) + return ""; + + + int offset; + if(random) { + srand((unsigned)time(&t)); + offset = rand() % 255; + } else { + offset = 128; + } + + std::stringstream ss; + ss << std::hex << std::setw(2) << std::setfill('0') << offset; + + for (int i = 0; i < src.length(); i++) { + SrcAsc = (src[i] + offset) % 255; + + if (KeyPos < KeyLen - 1) + KeyPos++; + else + KeyPos = 0; + + SrcAsc = SrcAsc ^ key[KeyPos]; + + ss << std::hex << std::setw(2) << std::setfill('0') << SrcAsc; + + offset = SrcAsc; + } + return ss.str(); +} + +static std::string uncryp_string(const std::string& src, const std::string& key) { + int KeyLen = key.length(); + if (KeyLen == 0) + return {}; + + int KeyPos = -1; + int offset = 0; + std::string dest; + int SrcAsc = 0; + int TmpSrcAsc = 0; + + std::stringstream ss; + ss << std::hex << src.substr(0, 2); + ss >> offset; + int SrcPos = 2; + while (SrcPos < src.length()) { + ss.clear(); + ss << std::hex << src.substr(SrcPos, 2); + ss >> SrcAsc; + if (KeyPos < KeyLen - 1) + KeyPos++; + else + KeyPos = 0; + + TmpSrcAsc = SrcAsc ^ key[KeyPos]; + + if (TmpSrcAsc <= offset) + TmpSrcAsc = 255 + TmpSrcAsc - offset; + else + TmpSrcAsc = TmpSrcAsc - offset; + + dest += char(TmpSrcAsc); + offset = SrcAsc; + SrcPos += 2; + } + + return dest; +} +} +#endif /* _SU_ENCRYPTOR_H_ */ diff --git a/testRoot/jni/su/su.cpp b/testRoot/jni/su/su.cpp new file mode 100644 index 00000000..be5a1af0 --- /dev/null +++ b/testRoot/jni/su/su.cpp @@ -0,0 +1,191 @@ +#include "su.h" +#include "su_log.h" +#include "su_hide_path_utils.h" +#include "kernel_root_kit/kernel_root_kit_command.h" +#include + +namespace { + std::string get_executable_directory() { + char processdir[4096] = { 0 }; + ssize_t path_len = readlink("/proc/self/exe", processdir, sizeof(processdir)); + if(path_len > 0) { + std::filesystem::path path(processdir); + return path.parent_path().string(); + } + return {}; + } + + /* + * Bionic's atoi runs through strtol(). + * Use our own implementation for faster conversion. + */ + int parse_int(const char* s) { + int val = 0; + char c; + while ((c = *(s++))) { + if (c > '9' || c < '0') + return -1; + val = val * 10 + c - '0'; + } + return val; + } + + // Set effective uid back to root, otherwise setres[ug]id will fail if uid isn't root + void set_identity(unsigned uid) { + if (seteuid(0)) { + SU_PRINTF("seteuid (root)"); + } + if (setresgid(uid, uid, uid)) { + SU_PRINTF("setresgid (%u)", uid); + } + if (setresuid(uid, uid, uid)) { + SU_PRINTF("setresuid (%u)", uid); + } + } +} + +void usage(int status) { + FILE* stream = (status == EXIT_SUCCESS) ? stdout : stderr; + + fprintf(stream, + "linux kernel root\n\n" + "Usage: su [options] [-] [user [argument...]]\n\n" + "Options:\n" + " -c, --command COMMAND pass COMMAND to the invoked shell\n" + " -h, --help display this help message and exit\n" + " -, -l, --login pretend the shell to be a login shell\n" + " -m, -p,\n" + " --preserve-environment preserve the entire environment\n" + " -s, --shell SHELL use SHELL instead of the default " DEFAULT_SHELL "\n" + " -v, --version display version number and exit\n" + " -V display version code and exit\n" + " -mm, -M,\n" + " --mount-master force run in the global mount namespace\n\n"); + exit(status); +} + +static inline std::string get_root_key() { + std::string myself_path = get_executable_directory(); + std::string str_root_key = kernel_root::su::parse_root_key_by_su_path(myself_path.c_str()); + return str_root_key; +} + +int su_client_main(int argc, char* argv[]) { + int c; + struct option long_opts[] = { + { "command", required_argument, nullptr, 'c' }, + { "help", no_argument, nullptr, 'h' }, + { "login", no_argument, nullptr, 'l' }, + { "preserve-environment", no_argument, nullptr, 'p' }, + { "shell", required_argument, nullptr, 's' }, + { "version", no_argument, nullptr, 'v' }, + { "context", required_argument, nullptr, 'z' }, + { "mount-master", no_argument, nullptr, 'M' }, + { nullptr, 0, nullptr, 0 }, + }; + + su_request su_req; + + for (int i = 0; i < argc; i++) { + // Replace -cn with -z, -mm with -M for supporting getopt_long + if (strcmp(argv[i], "-cn") == 0) + strcpy(argv[i], "-z"); + else if (strcmp(argv[i], "-mm") == 0) + strcpy(argv[i], "-M"); + } + + while ((c = getopt_long(argc, argv, "c:hlmps:Vvuz:M", long_opts, nullptr)) != -1) { + switch (c) { + case 'c': + for (int i = optind - 1; i < argc; ++i) { + if (!su_req.command.empty()) + su_req.command += ' '; + su_req.command += argv[i]; + } + optind = argc; + break; + case 'h': + usage(EXIT_SUCCESS); + break; + case 'l': + su_req.login = true; + break; + case 'm': + case 'p': + su_req.keepenv = true; + break; + case 's': + su_req.shell = optarg; + break; + case 'V': + printf("%d\n", ROOT_VER_CODE); + exit(EXIT_SUCCESS); + case 'v': + printf("%s\n", ROOT_VERSION); + exit(EXIT_SUCCESS); + case 'z': + // Do nothing, placed here for legacy support :) + break; + case 'M': + su_req.mount_master = true; + break; + default: + /* Bionic getopt_long doesn't terminate its error output by newline */ + fprintf(stderr, "\n"); + usage(2); + } + } + + if (optind < argc && strcmp(argv[optind], "-") == 0) { + su_req.login = true; + optind++; + } + + std::string root_key = get_root_key(); + SU_PRINTF("root_key:%s\n", root_key.c_str()); + + if (fork() == 0) { + kernel_root::get_root(root_key.c_str()); + SU_PRINTF("current uid:%d\n", getuid()); + + /* username or uid */ + if (optind < argc) { + struct passwd* pw; + pw = getpwnam(argv[optind]); + if (pw) { + su_req.uid = pw->pw_uid; + } else { + su_req.uid = parse_int(argv[optind]); + } + optind++; + } + struct passwd* pw = getpwuid(su_req.uid); + if (pw) { + setenv("HOME", pw->pw_dir, 1); + setenv("USER", pw->pw_name, 1); + setenv("LOGNAME", pw->pw_name, 1); + setenv("SHELL", su_req.shell.data(), 1); + } + + const char* new_argv[4] = { nullptr }; + new_argv[0] = su_req.login ? "-" : su_req.shell.data(); + + if (!su_req.command.empty()) { + new_argv[1] = "-c"; + new_argv[2] = su_req.command.data(); + } + + // If you need it, you can unblock this line of code yourself + //set_identity(su_req.uid); + + execvp(su_req.shell.data(), (char**)new_argv); + } else { + wait(NULL); + } + exit(0); + return 0; +} + +int main(int argc, char* argv[]) { + return su_client_main(argc, argv); +} diff --git a/testRoot/jni/su/su.h b/testRoot/jni/su/su.h new file mode 100644 index 00000000..6626147a --- /dev/null +++ b/testRoot/jni/su/su.h @@ -0,0 +1,62 @@ +#ifndef _SU_H_ +#define _SU_H_ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEFAULT_SHELL "/system/bin/sh" + +// Constants for atty +#define ATTY_IN (1 << 0) +#define ATTY_OUT (1 << 1) +#define ATTY_ERR (1 << 2) + +#define UID_ROOT 0 +#define UID_SHELL 2000 + +#define ROOT_VER_CODE 1 +#define ROOT_VERSION "1.0" + +struct su_req_base { + int uid = UID_ROOT; + bool login = false; + bool keepenv = false; + bool mount_master = false; +} __attribute__((packed)); + +struct su_request : public su_req_base { + std::string shell = DEFAULT_SHELL; + std::string command; +}; + +#endif /* _SU_H_ */ diff --git a/testRoot/jni/su/su_hide_path_utils.h b/testRoot/jni/su/su_hide_path_utils.h new file mode 100644 index 00000000..688fe0d0 --- /dev/null +++ b/testRoot/jni/su/su_hide_path_utils.h @@ -0,0 +1,105 @@ +#ifndef _SU_HIDDEN_FOLDER_PATH_UTILS_H_ +#define _SU_HIDDEN_FOLDER_PATH_UTILS_H_ +#include +#include +#include +#include +#include +#include +#include "../utils/base64.h" +#include "encryptor.h" + +#define RANDOM_GUID_LEN 8 +#define ROOT_KEY_LEN 48 +#define ENCRYKEY "ECC08B04-B9FF-40B5-9596-4408626181D5" + +namespace kernel_root{ +namespace su{ + +static std::string find_su_hide_folder_path( + const char* base_path, + const char* su_hide_folder_head_flag = "su") { + std::string id; + DIR* dir; + struct dirent* entry; + const char* su_head = su_hide_folder_head_flag; + + dir = opendir(base_path); + if (dir == NULL) + return id; + + while ((entry = readdir(dir)) != NULL) { + if ((strcmp(entry->d_name, ".") == 0) || + (strcmp(entry->d_name, "..") == 0)) { + continue; + } else if (entry->d_type != DT_DIR) { + continue; + } else if (strlen(entry->d_name) <= strlen(su_head)) { + continue; + } + if (!strstr(entry->d_name, su_head)) { + continue; + } + id = base_path; + id += "/"; + id += entry->d_name; + break; + } + closedir(dir); + return id; +} + +static std::string create_su_hide_folder(const char* str_root_key, + const char* base_path, + const char* su_hide_folder_head_flag) { + char guid[RANDOM_GUID_LEN] = {0}; + rand_str(guid, sizeof(guid)); + std::string encodeRootKey(guid, sizeof(guid)); + encodeRootKey += str_root_key; + + encodeRootKey = base64_encode((const unsigned char*)encodeRootKey.c_str(), + encodeRootKey.length()); + encodeRootKey = encryp_string(encodeRootKey, ENCRYKEY); + + std::string file_path = base_path; + file_path += "/"; + file_path += su_hide_folder_head_flag; + file_path += encodeRootKey; + file_path += "/"; + if (mkdir(file_path.c_str(), 0755)) { + return {}; + } + if (chmod(file_path.c_str(), 0777)) { + return {}; + } + return file_path; +} + +static inline std::string parse_root_key_by_su_path( + const char* su_path) { + std::string path = su_path; + if (path.empty()) { + return {}; + } + int n = path.find_last_of("_"); + if (n == -1) { + return {}; + } + path = path.substr(++n); + n = path.find("/"); + if (n != -1) { + path.substr(0, n); + } + + std::string decodeRootKey = uncryp_string(path, ENCRYKEY); + + decodeRootKey = base64_decode(decodeRootKey); + + if (decodeRootKey.length() < (RANDOM_GUID_LEN + ROOT_KEY_LEN)) { + return {}; + } + return decodeRootKey.substr(decodeRootKey.length() - ROOT_KEY_LEN); +} +} +} +#endif /* _SU_HIDDEN_FOLDER_PATH_UTILS_H_ */ diff --git a/testRoot/jni/su/su_log.h b/testRoot/jni/su/su_log.h new file mode 100644 index 00000000..16f77a47 --- /dev/null +++ b/testRoot/jni/su/su_log.h @@ -0,0 +1,16 @@ +#ifndef _LOG_H_ +#define _LOG_H_ +#include +#include +#include + +//安静输出模式 +#define QUIET_PRINTF + +#ifdef QUIET_PRINTF +#define SU_PRINTF(fmt, ...) +#else +#define SU_PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__) +#endif + +#endif /* _LOG_H_ */ diff --git a/testRoot/jni/testRoot.cpp b/testRoot/jni/testRoot.cpp new file mode 100644 index 00000000..77027c7d --- /dev/null +++ b/testRoot/jni/testRoot.cpp @@ -0,0 +1,208 @@ +#include "testRoot.h" + +// TODO:请将此处的KEY替换为你的内核ROOT KEY +#define ROOT_KEY "OM4kKoPVGFG2tnVFcs1PJ1qp6HtVymjV0CoTgFDmMdSDALve" + +namespace { +constexpr const char* k_su_base_path = "/data/local/tmp"; +} +void test_root() { + // 获取ROOT权限 + printf("%s\n", get_capability_info().c_str()); + + printf("get_root ret:%zd\n", kernel_root::get_root(ROOT_KEY)); + + printf("%s\n", get_capability_info().c_str()); + return; +} + +void test_run_root_cmd(int argc, char* argv[]) { + // 执行ROOT命令 + std::stringstream sstrCmd; + for (int i = 0; i < argc; i++) { + sstrCmd << argv[i]; + if (i != (argc - 1)) { + sstrCmd << " "; + } + } + printf("test_run_root_cmd(%s)\n", sstrCmd.str().c_str()); + + ssize_t err; + std::string result = kernel_root::run_root_cmd(ROOT_KEY, sstrCmd.str().c_str(), err); + printf("test_run_root_cmd err:%zd\n", err); + printf("test_run_root_cmd result:%s\n", result.c_str()); +} + +void test_run_init64_cmd(int argc, char* argv[]) { + // 执行原生内核命令 + std::stringstream sstrCmd; + for (int i = 0; i < argc; i++) { + sstrCmd << argv[i]; + if (i != (argc - 1)) { + sstrCmd << " "; + } + } + printf("test_run_init64_cmd(%s)\n", sstrCmd.str().c_str()); + + ssize_t err; + std::string result = kernel_root::run_init64_cmd_wrapper(ROOT_KEY, sstrCmd.str().c_str(), err); + printf("run_init64_cmd_wrapper err:%zd\n", err); + printf("run_init64_cmd_wrapper result:%s\n", result.c_str()); +} + +void test_install_su_env() { + // 安装部署su + ssize_t err; + std::string su_hide_name = kernel_root::install_su(ROOT_KEY, k_su_base_path, err); + printf("install su hide full path:%s, err:%zd\n", su_hide_name.c_str(), + err); +} + +void test_su_env_inject(const char* target_pid_cmdline) { + if (kernel_root::get_root(ROOT_KEY) != 0) { + return; + } + + // 1.获取su_xxx隐藏目录 + std::string su_hide_path = kernel_root::su::find_su_hide_folder_path(k_su_base_path, "su"); + printf("su_hide_path ret val:%s\n", su_hide_path.c_str()); + if (su_hide_path.empty()) { return; } + + // 2.杀光所有历史进程 + std::set out; + ssize_t err = kernel_root::find_all_cmdline_process( + ROOT_KEY, target_pid_cmdline, out); + printf("find_all_cmdline_process err:%zd, cnt:%zu\n", err, out.size()); + if (err) { return; } + for (pid_t pid : out) { kernel_root::kill_process(ROOT_KEY, pid); } + + // 3.注入su环境变量到指定进程 + printf("test_auto_su_env_inject Waiting for process creation(%s)\n", target_pid_cmdline); + pid_t pid; + err = kernel_root::wait_and_find_cmdline_process( + ROOT_KEY, target_pid_cmdline, 60 * 1000, pid); + printf("wait_and_find_cmdline_process(%zd)\n", err); + + err = kernel_root::inject_process_env64_PATH_wrapper(ROOT_KEY, pid, + su_hide_path.c_str()); + printf("inject_process_env64_PATH_wrapper ret val:%zd, error:%s\n", err, + strerror(errno)); +} + +void test_clean_su_env() { + // 完全卸载清理su + ssize_t err = kernel_root::uninstall_su(ROOT_KEY, k_su_base_path, "su"); + printf("uninstall_su err:%zd\n", err); +} + +void test_implant_app(const char* target_pid_cmdline) { + // 1.寄生预检目标APP + std::set out; + ssize_t err = kernel_root::find_all_cmdline_process(ROOT_KEY, target_pid_cmdline, out); + if (err) { + printf("find_all_cmdline_process err:%zd\n", err); + return; + } + if (out.size() == 0) { + printf("请先运行目标APP: %s\n", target_pid_cmdline); + return; + } + std::set so_path_list; + err = kernel_root::parasite_precheck_app(ROOT_KEY, target_pid_cmdline, so_path_list); + if (err) { + printf("parasite_precheck_app error:%zd\n", err); + if(err == -9903) { + printf("此目标APP为32位应用,无法寄生\n"); + } + return; + } + if (!so_path_list.size()) { + printf("无法检测到目标APP的JNI环境,目标APP暂不可被寄生;您可重新运行目标APP后重试\n"); + return; + } + printf("请在以下的目标APP文件列表中选择一个即将要被寄生的文件:\n"); + for (const std::string& item : so_path_list) { + std::filesystem::path filePath(item); + printf("\t%s\n", filePath.filename().string().c_str()); + } + printf("\n"); + printf("请输入将要被寄生的文件名称: "); + std::string user_input_so_name; + std::getline(std::cin, user_input_so_name); + printf("\n"); + auto it = std::find_if(so_path_list.begin(), so_path_list.end(), + [&](const std::string& s) { return s.find(user_input_so_name) != std::string::npos; }); + if (it == so_path_list.end()) { + printf("Not found: %s\n", user_input_so_name.c_str()); + return; + } + + // 2.寄生植入目标APP + err = kernel_root::parasite_implant_app(ROOT_KEY, target_pid_cmdline, it->c_str()); + printf("parasite_implant_app err:%zd\n", err); + if(err) { return; } + + // 3.杀光所有历史进程 + for (pid_t pid : out) { kernel_root::kill_process(ROOT_KEY, pid); } +} + +int main(int argc, char* argv[]) { + printf( + "======================================================\n" + "本工具名称: Linux ARM64 完美隐藏ROOT演示\n\n" + "本工具功能列表:\n" + + "1. 显示自身权限信息\n" + "\tUsage: testRoot id\n\n" + + "2. 获取ROOT权限\n" + "\tUsage: testRoot get\n\n" + + "3. 执行ROOT命令\n" + "\tUsage: testRoot cmd \n\n" + + "4. 执行原生内核命令\n" + "\tUsage: testRoot init \n\n" + + "5. 安装部署su\n" + "\tUsage: testRoot su\n\n" + + "6. 注入su到指定进程\n" + "\tUsage: testRoot process \n\n" + + "7. 完全卸载清理su\n" + "\tUsage: testRoot cleansu\n\n" + + "8. 寄生目标APP\n" + "\tUsage: testRoot implantApp [so-name]\n\n" + + "本工具特点:\n" + "新一代SKRoot,跟面具完全不同思路,摆脱面具被检测的弱点,完美隐藏root功能,兼容安卓APP直接JNI稳定调用。\n" + "======================================================\n" + "为了实现最佳的隐蔽性,推荐使用 [寄生目标APP] 功能,即将此工具寄生到能常驻后台的APP上\n\n" + "如需帮助,请使用对应的命令,或者查看上面的菜单。\n\n"); + + ++argv; + --argc; + if (argc == 0 || strcmp(argv[0], "id") == 0) { // 1.显示自身权限信息 + printf("%s\n", get_capability_info().c_str()); + } else if (strcmp(argv[0], "get") == 0) { // 2.获取ROOT权限 + test_root(); + } else if (argc >= 2 && strcmp(argv[0], "cmd") == 0) { // 3.执行ROOT命令 + test_run_root_cmd(argc - 1, argv + 1); + } else if (argc >= 2 && strcmp(argv[0], "init") == 0) { // 4.执行原生内核命令 + test_run_init64_cmd(argc - 1, argv + 1); + } else if (strcmp(argv[0], "su") == 0) { // 5.安装部署su + test_install_su_env(); + } else if (argc > 1 && strcmp(argv[0], "process") == 0) { // 6.注入su到指定进程 + test_su_env_inject(argv[1]); + } else if (strcmp(argv[0], "cleansu") == 0) { // 7.完全卸载清理su + test_clean_su_env(); + } else if (argc > 1 && strcmp(argv[0], "implantApp") == 0) { // 8.寄生目标APP + test_implant_app(argv[1]); + } else { + printf("unknown command.\n"); + return 1; + } + return 0; +} \ No newline at end of file diff --git a/testRoot/jni/testRoot.h b/testRoot/jni/testRoot.h new file mode 100644 index 00000000..bc5e77a7 --- /dev/null +++ b/testRoot/jni/testRoot.h @@ -0,0 +1,59 @@ +#ifndef _TEST_ROOT_H_ +#define _TEST_ROOT_H_ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kernel_root_kit/kernel_root_kit_umbrella.h" +#include "su/su_hide_path_utils.h" + +static std::string get_capability_info() { + __uid_t now_uid, now_euid, now_suid; + __gid_t now_gid, now_egid, now_sgid; + if (getresuid(&now_uid, &now_euid, &now_suid)) { + return "FAILED getresuid()"; + } + if (getresgid(&now_gid, &now_egid, &now_sgid)) { + return "FAILED getresgid()"; + } + + std::stringstream sstrCapInfo; + sstrCapInfo<< "Current process information:\n"; + sstrCapInfo<< "uid:"<pid = getpid(); + cap_header->version = _LINUX_CAPABILITY_VERSION_3; //_1、_2、_3 + + if (capget(cap_header, cap_data) < 0) { + return "FAILED capget()"; + // perror("FAILED capget()"); + //exit(1); + } + sstrCapInfo << "cap effective:" << std::hex <effective << "," << std::endl + <<"cap permitted:"<< std::hex << cap_data->permitted<< "," << std::endl + <<"cap inheritable:"<< std::hex <inheritable<< std::endl; + FILE * fp = popen("getenforce", "r"); + if (fp) { + char cmd[512] = { 0 }; + fread(cmd, 1, sizeof(cmd), fp); + pclose(fp); + sstrCapInfo<< "read system SELinux status:"<< cmd; + } + return sstrCapInfo.str(); +} + + +#endif /* _TEST_ROOT_H_ */ diff --git a/testRoot/jni/utils/base64.h b/testRoot/jni/utils/base64.h new file mode 100644 index 00000000..555f0d75 --- /dev/null +++ b/testRoot/jni/utils/base64.h @@ -0,0 +1,100 @@ +#ifndef BASE_64_H +#define BASE_64_H +#include +#include +#include +static const std::string base64_chars = +"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +"abcdefghijklmnopqrstuvwxyz" +"0123456789+/"; + + +static inline bool is_base64(unsigned char c) { + return (isalnum(c) || (c == '+') || (c == '/')); +} + +static std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) { + std::string ret; + int i = 0; + int j = 0; + unsigned char char_array_3[3]; + unsigned char char_array_4[4]; + + while (in_len--) { + char_array_3[i++] = *(bytes_to_encode++); + if (i == 3) { + char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; + char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); + char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); + char_array_4[3] = char_array_3[2] & 0x3f; + + for (i = 0; (i < 4); i++) + ret += base64_chars[char_array_4[i]]; + i = 0; + } + } + + if (i) + { + for (j = i; j < 3; j++) + char_array_3[j] = '\0'; + + char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; + char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); + char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); + char_array_4[3] = char_array_3[2] & 0x3f; + + for (j = 0; (j < i + 1); j++) + ret += base64_chars[char_array_4[j]]; + + while ((i++ < 3)) + ret += '='; + + } + + return ret; + +} + +static std::string base64_decode(std::string const& encoded_string) { + int in_len = encoded_string.size(); + int i = 0; + int j = 0; + int in_ = 0; + unsigned char char_array_4[4], char_array_3[3]; + std::string ret; + + while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { + char_array_4[i++] = encoded_string[in_]; in_++; + if (i == 4) { + for (i = 0; i < 4; i++) + char_array_4[i] = base64_chars.find(char_array_4[i]); + + char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); + char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); + char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; + + for (i = 0; (i < 3); i++) + ret += char_array_3[i]; + i = 0; + } + } + + if (i) { + for (j = i; j < 4; j++) + char_array_4[j] = 0; + + for (j = 0; j < 4; j++) + char_array_4[j] = base64_chars.find(char_array_4[j]); + + char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); + char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); + char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; + + for (j = 0; (j < i - 1); j++) ret += char_array_3[j]; + } + + return ret; +} + +#endif diff --git a/testRoot/jni/utils/cJSON.cpp b/testRoot/jni/utils/cJSON.cpp new file mode 100644 index 00000000..f6dd11c5 --- /dev/null +++ b/testRoot/jni/utils/cJSON.cpp @@ -0,0 +1,3119 @@ +/* + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +/* cJSON */ +/* JSON parser in C. */ + +/* disable warnings about old C89 functions in MSVC */ +#if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) +#define _CRT_SECURE_NO_DEPRECATE +#endif + +#ifdef __GNUC__ +#pragma GCC visibility push(default) +#endif +#if defined(_MSC_VER) +#pragma warning (push) +/* disable warning about single line comments in system headers */ +#pragma warning (disable : 4001) +#endif + +#include +#include +#include +#include +#include +#include +#include + +#ifdef ENABLE_LOCALES +#include +#endif + +#if defined(_MSC_VER) +#pragma warning (pop) +#endif +#ifdef __GNUC__ +#pragma GCC visibility pop +#endif + +#include "cJSON.h" + +/* define our own boolean type */ +#ifdef true +#undef true +#endif +#define true ((cJSON_bool)1) + +#ifdef false +#undef false +#endif +#define false ((cJSON_bool)0) + +/* define isnan and isinf for ANSI C, if in C99 or above, isnan and isinf has been defined in math.h */ +#ifndef isinf +#define isinf(d) (isnan((d - d)) && !isnan(d)) +#endif +#ifndef isnan +#define isnan(d) (d != d) +#endif + +#ifndef NAN +#ifdef _WIN32 +#define NAN sqrt(-1.0) +#else +#define NAN 0.0/0.0 +#endif +#endif + +typedef struct { + const unsigned char *json; + size_t position; +} error; +static error global_error = { NULL, 0 }; + +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) +{ + return (const char*) (global_error.json + global_error.position); +} + +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item) +{ + if (!cJSON_IsString(item)) + { + return NULL; + } + + return item->valuestring; +} + +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item) +{ + if (!cJSON_IsNumber(item)) + { + return (double) NAN; + } + + return item->valuedouble; +} + +/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ +#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 16) + #error cJSON.h and cJSON.c have different versions. Make sure that both have the same. +#endif + +CJSON_PUBLIC(const char*) cJSON_Version(void) +{ + static char version[15]; + sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); + + return version; +} + +/* Case insensitive string comparison, doesn't consider two NULL pointers equal though */ +static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) +{ + if ((string1 == NULL) || (string2 == NULL)) + { + return 1; + } + + if (string1 == string2) + { + return 0; + } + + for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++) + { + if (*string1 == '\0') + { + return 0; + } + } + + return tolower(*string1) - tolower(*string2); +} + +typedef struct internal_hooks +{ + void *(CJSON_CDECL *allocate)(size_t size); + void (CJSON_CDECL *deallocate)(void *pointer); + void *(CJSON_CDECL *reallocate)(void *pointer, size_t size); +} internal_hooks; + +#if defined(_MSC_VER) +/* work around MSVC error C2322: '...' address of dllimport '...' is not static */ +static void * CJSON_CDECL internal_malloc(size_t size) +{ + return malloc(size); +} +static void CJSON_CDECL internal_free(void *pointer) +{ + free(pointer); +} +static void * CJSON_CDECL internal_realloc(void *pointer, size_t size) +{ + return realloc(pointer, size); +} +#else +#define internal_malloc malloc +#define internal_free free +#define internal_realloc realloc +#endif + +/* strlen of character literals resolved at compile time */ +#define static_strlen(string_literal) (sizeof(string_literal) - sizeof("")) + +static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc }; + +static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) +{ + size_t length = 0; + unsigned char *copy = NULL; + + if (string == NULL) + { + return NULL; + } + + length = strlen((const char*)string) + sizeof(""); + copy = (unsigned char*)hooks->allocate(length); + if (copy == NULL) + { + return NULL; + } + memcpy(copy, string, length); + + return copy; +} + +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) +{ + if (hooks == NULL) + { + /* Reset hooks */ + global_hooks.allocate = malloc; + global_hooks.deallocate = free; + global_hooks.reallocate = realloc; + return; + } + + global_hooks.allocate = malloc; + if (hooks->malloc_fn != NULL) + { + global_hooks.allocate = hooks->malloc_fn; + } + + global_hooks.deallocate = free; + if (hooks->free_fn != NULL) + { + global_hooks.deallocate = hooks->free_fn; + } + + /* use realloc only if both free and malloc are used */ + global_hooks.reallocate = NULL; + if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) + { + global_hooks.reallocate = realloc; + } +} + +/* Internal constructor. */ +static cJSON *cJSON_New_Item(const internal_hooks * const hooks) +{ + cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); + if (node) + { + memset(node, '\0', sizeof(cJSON)); + } + + return node; +} + +/* Delete a cJSON structure. */ +CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) +{ + cJSON *next = NULL; + while (item != NULL) + { + next = item->next; + if (!(item->type & cJSON_IsReference) && (item->child != NULL)) + { + cJSON_Delete(item->child); + } + if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) + { + global_hooks.deallocate(item->valuestring); + } + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + global_hooks.deallocate(item->string); + } + global_hooks.deallocate(item); + item = next; + } +} + +/* get the decimal point character of the current locale */ +static unsigned char get_decimal_point(void) +{ +#ifdef ENABLE_LOCALES + struct lconv *lconv = localeconv(); + return (unsigned char) lconv->decimal_point[0]; +#else + return '.'; +#endif +} + +typedef struct +{ + const unsigned char *content; + size_t length; + size_t offset; + size_t depth; /* How deeply nested (in arrays/objects) is the input at the current offset. */ + internal_hooks hooks; +} parse_buffer; + +/* check if the given size is left to read in a given parse buffer (starting with 1) */ +#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) +/* check if the buffer can be accessed at the given index (starting with 0) */ +#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) +#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index)) +/* get a pointer to the buffer at the position */ +#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) + +/* Parse the input text to generate a number, and populate the result into item. */ +static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) +{ + double number = 0; + unsigned char *after_end = NULL; + unsigned char number_c_string[64]; + unsigned char decimal_point = get_decimal_point(); + size_t i = 0; + + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; + } + + /* copy the number into a temporary buffer and replace '.' with the decimal point + * of the current locale (for strtod) + * This also takes care of '\0' not necessarily being available for marking the end of the input */ + for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) + { + switch (buffer_at_offset(input_buffer)[i]) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '+': + case '-': + case 'e': + case 'E': + number_c_string[i] = buffer_at_offset(input_buffer)[i]; + break; + + case '.': + number_c_string[i] = decimal_point; + break; + + default: + goto loop_end; + } + } +loop_end: + number_c_string[i] = '\0'; + + number = strtod((const char*)number_c_string, (char**)&after_end); + if (number_c_string == after_end) + { + return false; /* parse_error */ + } + + item->valuedouble = number; + + /* use saturation in case of overflow */ + if (number >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (number <= (double)INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)number; + } + + item->type = cJSON_Number; + + input_buffer->offset += (size_t)(after_end - number_c_string); + return true; +} + +/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) +{ + if (number >= INT_MAX) + { + object->valueint = INT_MAX; + } + else if (number <= (double)INT_MIN) + { + object->valueint = INT_MIN; + } + else + { + object->valueint = (int)number; + } + + return object->valuedouble = number; +} + +CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring) +{ + char *copy = NULL; + /* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */ + if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) + { + return NULL; + } + if (strlen(valuestring) <= strlen(object->valuestring)) + { + strcpy(object->valuestring, valuestring); + return object->valuestring; + } + copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks); + if (copy == NULL) + { + return NULL; + } + if (object->valuestring != NULL) + { + cJSON_free(object->valuestring); + } + object->valuestring = copy; + + return copy; +} + +typedef struct +{ + unsigned char *buffer; + size_t length; + size_t offset; + size_t depth; /* current nesting depth (for formatted printing) */ + cJSON_bool noalloc; + cJSON_bool format; /* is this print a formatted print */ + internal_hooks hooks; +} printbuffer; + +/* realloc printbuffer if necessary to have at least "needed" bytes more */ +static unsigned char* ensure(printbuffer * const p, size_t needed) +{ + unsigned char *newbuffer = NULL; + size_t newsize = 0; + + if ((p == NULL) || (p->buffer == NULL)) + { + return NULL; + } + + if ((p->length > 0) && (p->offset >= p->length)) + { + /* make sure that offset is valid */ + return NULL; + } + + if (needed > INT_MAX) + { + /* sizes bigger than INT_MAX are currently not supported */ + return NULL; + } + + needed += p->offset + 1; + if (needed <= p->length) + { + return p->buffer + p->offset; + } + + if (p->noalloc) { + return NULL; + } + + /* calculate new buffer size */ + if (needed > (INT_MAX / 2)) + { + /* overflow of int, use INT_MAX if possible */ + if (needed <= INT_MAX) + { + newsize = INT_MAX; + } + else + { + return NULL; + } + } + else + { + newsize = needed * 2; + } + + if (p->hooks.reallocate != NULL) + { + /* reallocate with realloc if available */ + newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); + if (newbuffer == NULL) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + } + else + { + /* otherwise reallocate manually */ + newbuffer = (unsigned char*)p->hooks.allocate(newsize); + if (!newbuffer) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + + memcpy(newbuffer, p->buffer, p->offset + 1); + p->hooks.deallocate(p->buffer); + } + p->length = newsize; + p->buffer = newbuffer; + + return newbuffer + p->offset; +} + +/* calculate the new length of the string in a printbuffer and update the offset */ +static void update_offset(printbuffer * const buffer) +{ + const unsigned char *buffer_pointer = NULL; + if ((buffer == NULL) || (buffer->buffer == NULL)) + { + return; + } + buffer_pointer = buffer->buffer + buffer->offset; + + buffer->offset += strlen((const char*)buffer_pointer); +} + +/* securely comparison of floating-point variables */ +static cJSON_bool compare_double(double a, double b) +{ + double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b); + return (fabs(a - b) <= maxVal * DBL_EPSILON); +} + +/* Render the number nicely from the given item into a string. */ +static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + double d = item->valuedouble; + int length = 0; + size_t i = 0; + unsigned char number_buffer[26] = {0}; /* temporary buffer to print the number into */ + unsigned char decimal_point = get_decimal_point(); + double test = 0.0; + + if (output_buffer == NULL) + { + return false; + } + + /* This checks for NaN and Infinity */ + if (isnan(d) || isinf(d)) + { + length = sprintf((char*)number_buffer, "null"); + } + else if(d == (double)item->valueint) + { + length = sprintf((char*)number_buffer, "%d", item->valueint); + } + else + { + /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */ + length = sprintf((char*)number_buffer, "%1.15g", d); + + /* Check whether the original double can be recovered */ + if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d)) + { + /* If not, print with 17 decimal places of precision */ + length = sprintf((char*)number_buffer, "%1.17g", d); + } + } + + /* sprintf failed or buffer overrun occurred */ + if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) + { + return false; + } + + /* reserve appropriate space in the output */ + output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); + if (output_pointer == NULL) + { + return false; + } + + /* copy the printed number to the output and replace locale + * dependent decimal point with '.' */ + for (i = 0; i < ((size_t)length); i++) + { + if (number_buffer[i] == decimal_point) + { + output_pointer[i] = '.'; + continue; + } + + output_pointer[i] = number_buffer[i]; + } + output_pointer[i] = '\0'; + + output_buffer->offset += (size_t)length; + + return true; +} + +/* parse 4 digit hexadecimal number */ +static unsigned parse_hex4(const unsigned char * const input) +{ + unsigned int h = 0; + size_t i = 0; + + for (i = 0; i < 4; i++) + { + /* parse digit */ + if ((input[i] >= '0') && (input[i] <= '9')) + { + h += (unsigned int) input[i] - '0'; + } + else if ((input[i] >= 'A') && (input[i] <= 'F')) + { + h += (unsigned int) 10 + input[i] - 'A'; + } + else if ((input[i] >= 'a') && (input[i] <= 'f')) + { + h += (unsigned int) 10 + input[i] - 'a'; + } + else /* invalid */ + { + return 0; + } + + if (i < 3) + { + /* shift left to make place for the next nibble */ + h = h << 4; + } + } + + return h; +} + +/* converts a UTF-16 literal to UTF-8 + * A literal can be one or two sequences of the form \uXXXX */ +static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer) +{ + long unsigned int codepoint = 0; + unsigned int first_code = 0; + const unsigned char *first_sequence = input_pointer; + unsigned char utf8_length = 0; + unsigned char utf8_position = 0; + unsigned char sequence_length = 0; + unsigned char first_byte_mark = 0; + + if ((input_end - first_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; + } + + /* get the first utf16 sequence */ + first_code = parse_hex4(first_sequence + 2); + + /* check that the code is valid */ + if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) + { + goto fail; + } + + /* UTF16 surrogate pair */ + if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) + { + const unsigned char *second_sequence = first_sequence + 6; + unsigned int second_code = 0; + sequence_length = 12; /* \uXXXX\uXXXX */ + + if ((input_end - second_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; + } + + if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) + { + /* missing second half of the surrogate pair */ + goto fail; + } + + /* get the second utf16 sequence */ + second_code = parse_hex4(second_sequence + 2); + /* check that the code is valid */ + if ((second_code < 0xDC00) || (second_code > 0xDFFF)) + { + /* invalid second half of the surrogate pair */ + goto fail; + } + + + /* calculate the unicode codepoint from the surrogate pair */ + codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); + } + else + { + sequence_length = 6; /* \uXXXX */ + codepoint = first_code; + } + + /* encode as UTF-8 + * takes at maximum 4 bytes to encode: + * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + if (codepoint < 0x80) + { + /* normal ascii, encoding 0xxxxxxx */ + utf8_length = 1; + } + else if (codepoint < 0x800) + { + /* two bytes, encoding 110xxxxx 10xxxxxx */ + utf8_length = 2; + first_byte_mark = 0xC0; /* 11000000 */ + } + else if (codepoint < 0x10000) + { + /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ + utf8_length = 3; + first_byte_mark = 0xE0; /* 11100000 */ + } + else if (codepoint <= 0x10FFFF) + { + /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + utf8_length = 4; + first_byte_mark = 0xF0; /* 11110000 */ + } + else + { + /* invalid unicode codepoint */ + goto fail; + } + + /* encode as utf8 */ + for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) + { + /* 10xxxxxx */ + (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF); + codepoint >>= 6; + } + /* encode first byte */ + if (utf8_length > 1) + { + (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF); + } + else + { + (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); + } + + *output_pointer += utf8_length; + + return sequence_length; + +fail: + return 0; +} + +/* Parse the input text into an unescaped cinput, and populate item. */ +static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) +{ + const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; + const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; + unsigned char *output_pointer = NULL; + unsigned char *output = NULL; + + /* not a string */ + if (buffer_at_offset(input_buffer)[0] != '\"') + { + goto fail; + } + + { + /* calculate approximate size of the output (overestimate) */ + size_t allocation_length = 0; + size_t skipped_bytes = 0; + while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) + { + /* is escape sequence */ + if (input_end[0] == '\\') + { + if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) + { + /* prevent buffer overflow when last input character is a backslash */ + goto fail; + } + skipped_bytes++; + input_end++; + } + input_end++; + } + if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) + { + goto fail; /* string ended unexpectedly */ + } + + /* This is at most how much we need for the output */ + allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes; + output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof("")); + if (output == NULL) + { + goto fail; /* allocation failure */ + } + } + + output_pointer = output; + /* loop through the string literal */ + while (input_pointer < input_end) + { + if (*input_pointer != '\\') + { + *output_pointer++ = *input_pointer++; + } + /* escape sequence */ + else + { + unsigned char sequence_length = 2; + if ((input_end - input_pointer) < 1) + { + goto fail; + } + + switch (input_pointer[1]) + { + case 'b': + *output_pointer++ = '\b'; + break; + case 'f': + *output_pointer++ = '\f'; + break; + case 'n': + *output_pointer++ = '\n'; + break; + case 'r': + *output_pointer++ = '\r'; + break; + case 't': + *output_pointer++ = '\t'; + break; + case '\"': + case '\\': + case '/': + *output_pointer++ = input_pointer[1]; + break; + + /* UTF-16 literal */ + case 'u': + sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); + if (sequence_length == 0) + { + /* failed to convert UTF16-literal to UTF-8 */ + goto fail; + } + break; + + default: + goto fail; + } + input_pointer += sequence_length; + } + } + + /* zero terminate the output */ + *output_pointer = '\0'; + + item->type = cJSON_String; + item->valuestring = (char*)output; + + input_buffer->offset = (size_t) (input_end - input_buffer->content); + input_buffer->offset++; + + return true; + +fail: + if (output != NULL) + { + input_buffer->hooks.deallocate(output); + } + + if (input_pointer != NULL) + { + input_buffer->offset = (size_t)(input_pointer - input_buffer->content); + } + + return false; +} + +/* Render the cstring provided to an escaped version that can be printed. */ +static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer) +{ + const unsigned char *input_pointer = NULL; + unsigned char *output = NULL; + unsigned char *output_pointer = NULL; + size_t output_length = 0; + /* numbers of additional characters needed for escaping */ + size_t escape_characters = 0; + + if (output_buffer == NULL) + { + return false; + } + + /* empty string */ + if (input == NULL) + { + output = ensure(output_buffer, sizeof("\"\"")); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "\"\""); + + return true; + } + + /* set "flag" to 1 if something needs to be escaped */ + for (input_pointer = input; *input_pointer; input_pointer++) + { + switch (*input_pointer) + { + case '\"': + case '\\': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + /* one character escape sequence */ + escape_characters++; + break; + default: + if (*input_pointer < 32) + { + /* UTF-16 escape sequence uXXXX */ + escape_characters += 5; + } + break; + } + } + output_length = (size_t)(input_pointer - input) + escape_characters; + + output = ensure(output_buffer, output_length + sizeof("\"\"")); + if (output == NULL) + { + return false; + } + + /* no characters have to be escaped */ + if (escape_characters == 0) + { + output[0] = '\"'; + memcpy(output + 1, input, output_length); + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; + } + + output[0] = '\"'; + output_pointer = output + 1; + /* copy the string */ + for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) + { + if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) + { + /* normal character, copy */ + *output_pointer = *input_pointer; + } + else + { + /* character needs to be escaped */ + *output_pointer++ = '\\'; + switch (*input_pointer) + { + case '\\': + *output_pointer = '\\'; + break; + case '\"': + *output_pointer = '\"'; + break; + case '\b': + *output_pointer = 'b'; + break; + case '\f': + *output_pointer = 'f'; + break; + case '\n': + *output_pointer = 'n'; + break; + case '\r': + *output_pointer = 'r'; + break; + case '\t': + *output_pointer = 't'; + break; + default: + /* escape and print as unicode codepoint */ + sprintf((char*)output_pointer, "u%04x", *input_pointer); + output_pointer += 4; + break; + } + } + } + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; +} + +/* Invoke print_string_ptr (which is useful) on an item. */ +static cJSON_bool print_string(const cJSON * const item, printbuffer * const p) +{ + return print_string_ptr((unsigned char*)item->valuestring, p); +} + +/* Predeclare these prototypes. */ +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer); + +/* Utility to jump whitespace and cr/lf */ +static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL)) + { + return NULL; + } + + if (cannot_access_at_index(buffer, 0)) + { + return buffer; + } + + while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) + { + buffer->offset++; + } + + if (buffer->offset == buffer->length) + { + buffer->offset--; + } + + return buffer; +} + +/* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */ +static parse_buffer *skip_utf8_bom(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) + { + return NULL; + } + + if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) + { + buffer->offset += 3; + } + + return buffer; +} + +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) +{ + size_t buffer_length; + + if (NULL == value) + { + return NULL; + } + + /* Adding null character size due to require_null_terminated. */ + buffer_length = strlen(value) + sizeof(""); + + return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, require_null_terminated); +} + +/* Parse an object - create a new root, and populate. */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated) +{ + parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; + cJSON *item = NULL; + + /* reset error position */ + global_error.json = NULL; + global_error.position = 0; + + if (value == NULL || 0 == buffer_length) + { + goto fail; + } + + buffer.content = (const unsigned char*)value; + buffer.length = buffer_length; + buffer.offset = 0; + buffer.hooks = global_hooks; + + item = cJSON_New_Item(&global_hooks); + if (item == NULL) /* memory fail */ + { + goto fail; + } + + if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) + { + /* parse failure. ep is set. */ + goto fail; + } + + /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ + if (require_null_terminated) + { + buffer_skip_whitespace(&buffer); + if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') + { + goto fail; + } + } + if (return_parse_end) + { + *return_parse_end = (const char*)buffer_at_offset(&buffer); + } + + return item; + +fail: + if (item != NULL) + { + cJSON_Delete(item); + } + + if (value != NULL) + { + error local_error; + local_error.json = (const unsigned char*)value; + local_error.position = 0; + + if (buffer.offset < buffer.length) + { + local_error.position = buffer.offset; + } + else if (buffer.length > 0) + { + local_error.position = buffer.length - 1; + } + + if (return_parse_end != NULL) + { + *return_parse_end = (const char*)local_error.json + local_error.position; + } + + global_error = local_error; + } + + return NULL; +} + +/* Default options for cJSON_Parse */ +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) +{ + return cJSON_ParseWithOpts(value, 0, 0); +} + +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length) +{ + return cJSON_ParseWithLengthOpts(value, buffer_length, 0, 0); +} + +#define cjson_min(a, b) (((a) < (b)) ? (a) : (b)) + +static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) +{ + static const size_t default_buffer_size = 256; + printbuffer buffer[1]; + unsigned char *printed = NULL; + + memset(buffer, 0, sizeof(buffer)); + + /* create buffer */ + buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size); + buffer->length = default_buffer_size; + buffer->format = format; + buffer->hooks = *hooks; + if (buffer->buffer == NULL) + { + goto fail; + } + + /* print the value */ + if (!print_value(item, buffer)) + { + goto fail; + } + update_offset(buffer); + + /* check if reallocate is available */ + if (hooks->reallocate != NULL) + { + printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); + if (printed == NULL) { + goto fail; + } + buffer->buffer = NULL; + } + else /* otherwise copy the JSON over to a new buffer */ + { + printed = (unsigned char*) hooks->allocate(buffer->offset + 1); + if (printed == NULL) + { + goto fail; + } + memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); + printed[buffer->offset] = '\0'; /* just to be sure */ + + /* free the buffer */ + hooks->deallocate(buffer->buffer); + } + + return printed; + +fail: + if (buffer->buffer != NULL) + { + hooks->deallocate(buffer->buffer); + } + + if (printed != NULL) + { + hooks->deallocate(printed); + } + + return NULL; +} + +/* Render a cJSON item/entity/structure to text. */ +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) +{ + return (char*)print(item, true, &global_hooks); +} + +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) +{ + return (char*)print(item, false, &global_hooks); +} + +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; + + if (prebuffer < 0) + { + return NULL; + } + + p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); + if (!p.buffer) + { + return NULL; + } + + p.length = (size_t)prebuffer; + p.offset = 0; + p.noalloc = false; + p.format = fmt; + p.hooks = global_hooks; + + if (!print_value(item, &p)) + { + global_hooks.deallocate(p.buffer); + return NULL; + } + + return (char*)p.buffer; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; + + if ((length < 0) || (buffer == NULL)) + { + return false; + } + + p.buffer = (unsigned char*)buffer; + p.length = (size_t)length; + p.offset = 0; + p.noalloc = true; + p.format = format; + p.hooks = global_hooks; + + return print_value(item, &p); +} + +/* Parser core - when encountering text, process appropriately. */ +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer) +{ + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; /* no input */ + } + + /* parse the different types of values */ + /* null */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0)) + { + item->type = cJSON_NULL; + input_buffer->offset += 4; + return true; + } + /* false */ + if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0)) + { + item->type = cJSON_False; + input_buffer->offset += 5; + return true; + } + /* true */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "true", 4) == 0)) + { + item->type = cJSON_True; + item->valueint = 1; + input_buffer->offset += 4; + return true; + } + /* string */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) + { + return parse_string(item, input_buffer); + } + /* number */ + if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) + { + return parse_number(item, input_buffer); + } + /* array */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) + { + return parse_array(item, input_buffer); + } + /* object */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) + { + return parse_object(item, input_buffer); + } + + return false; +} + +/* Render a value to text. */ +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output = NULL; + + if ((item == NULL) || (output_buffer == NULL)) + { + return false; + } + + switch ((item->type) & 0xFF) + { + case cJSON_NULL: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "null"); + return true; + + case cJSON_False: + output = ensure(output_buffer, 6); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "false"); + return true; + + case cJSON_True: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "true"); + return true; + + case cJSON_Number: + return print_number(item, output_buffer); + + case cJSON_Raw: + { + size_t raw_length = 0; + if (item->valuestring == NULL) + { + return false; + } + + raw_length = strlen(item->valuestring) + sizeof(""); + output = ensure(output_buffer, raw_length); + if (output == NULL) + { + return false; + } + memcpy(output, item->valuestring, raw_length); + return true; + } + + case cJSON_String: + return print_string(item, output_buffer); + + case cJSON_Array: + return print_array(item, output_buffer); + + case cJSON_Object: + return print_object(item, output_buffer); + + default: + return false; + } +} + +/* Build an array from input text. */ +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) +{ + cJSON *head = NULL; /* head of the linked list */ + cJSON *current_item = NULL; + + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; + + if (buffer_at_offset(input_buffer)[0] != '[') + { + /* not an array */ + goto fail; + } + + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) + { + /* empty array */ + goto success; + } + + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ + input_buffer->offset--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse next value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); + } + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + + if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') + { + goto fail; /* expected end of array */ + } + +success: + input_buffer->depth--; + + if (head != NULL) { + head->prev = current_item; + } + + item->type = cJSON_Array; + item->child = head; + + input_buffer->offset++; + + return true; + +fail: + if (head != NULL) + { + cJSON_Delete(head); + } + + return false; +} + +/* Render an array to text */ +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_element = item->child; + + if (output_buffer == NULL) + { + return false; + } + + /* Compose the output array. */ + /* opening square bracket */ + output_pointer = ensure(output_buffer, 1); + if (output_pointer == NULL) + { + return false; + } + + *output_pointer = '['; + output_buffer->offset++; + output_buffer->depth++; + + while (current_element != NULL) + { + if (!print_value(current_element, output_buffer)) + { + return false; + } + update_offset(output_buffer); + if (current_element->next) + { + length = (size_t) (output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ','; + if(output_buffer->format) + { + *output_pointer++ = ' '; + } + *output_pointer = '\0'; + output_buffer->offset += length; + } + current_element = current_element->next; + } + + output_pointer = ensure(output_buffer, 2); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ']'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; +} + +/* Build an object from the text. */ +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) +{ + cJSON *head = NULL; /* linked list head */ + cJSON *current_item = NULL; + + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) + { + goto fail; /* not an object */ + } + + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) + { + goto success; /* empty object */ + } + + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ + input_buffer->offset--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse the name of the child */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_string(current_item, input_buffer)) + { + goto fail; /* failed to parse name */ + } + buffer_skip_whitespace(input_buffer); + + /* swap valuestring and string, because we parsed the name */ + current_item->string = current_item->valuestring; + current_item->valuestring = NULL; + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) + { + goto fail; /* invalid object */ + } + + /* parse the value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); + } + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) + { + goto fail; /* expected end of object */ + } + +success: + input_buffer->depth--; + + if (head != NULL) { + head->prev = current_item; + } + + item->type = cJSON_Object; + item->child = head; + + input_buffer->offset++; + return true; + +fail: + if (head != NULL) + { + cJSON_Delete(head); + } + + return false; +} + +/* Render an object to text. */ +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_item = item->child; + + if (output_buffer == NULL) + { + return false; + } + + /* Compose the output: */ + length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + + *output_pointer++ = '{'; + output_buffer->depth++; + if (output_buffer->format) + { + *output_pointer++ = '\n'; + } + output_buffer->offset += length; + + while (current_item) + { + if (output_buffer->format) + { + size_t i; + output_pointer = ensure(output_buffer, output_buffer->depth); + if (output_pointer == NULL) + { + return false; + } + for (i = 0; i < output_buffer->depth; i++) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += output_buffer->depth; + } + + /* print key */ + if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + length = (size_t) (output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ':'; + if (output_buffer->format) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += length; + + /* print value */ + if (!print_value(current_item, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + /* print comma if not last */ + length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)(current_item->next ? 1 : 0)); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + if (current_item->next) + { + *output_pointer++ = ','; + } + + if (output_buffer->format) + { + *output_pointer++ = '\n'; + } + *output_pointer = '\0'; + output_buffer->offset += length; + + current_item = current_item->next; + } + + output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); + if (output_pointer == NULL) + { + return false; + } + if (output_buffer->format) + { + size_t i; + for (i = 0; i < (output_buffer->depth - 1); i++) + { + *output_pointer++ = '\t'; + } + } + *output_pointer++ = '}'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; +} + +/* Get Array size/item / object item. */ +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) +{ + cJSON *child = NULL; + size_t size = 0; + + if (array == NULL) + { + return 0; + } + + child = array->child; + + while(child != NULL) + { + size++; + child = child->next; + } + + /* FIXME: Can overflow here. Cannot be fixed without breaking the API */ + + return (int)size; +} + +static cJSON* get_array_item(const cJSON *array, size_t index) +{ + cJSON *current_child = NULL; + + if (array == NULL) + { + return NULL; + } + + current_child = array->child; + while ((current_child != NULL) && (index > 0)) + { + index--; + current_child = current_child->next; + } + + return current_child; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) +{ + if (index < 0) + { + return NULL; + } + + return get_array_item(array, (size_t)index); +} + +static cJSON *get_object_item(const cJSON * const object, const char * const name, const cJSON_bool case_sensitive) +{ + cJSON *current_element = NULL; + + if ((object == NULL) || (name == NULL)) + { + return NULL; + } + + current_element = object->child; + if (case_sensitive) + { + while ((current_element != NULL) && (current_element->string != NULL) && (strcmp(name, current_element->string) != 0)) + { + current_element = current_element->next; + } + } + else + { + while ((current_element != NULL) && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) + { + current_element = current_element->next; + } + } + + if ((current_element == NULL) || (current_element->string == NULL)) { + return NULL; + } + + return current_element; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, false); +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, true); +} + +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) +{ + return cJSON_GetObjectItem(object, string) ? 1 : 0; +} + +/* Utility for array list handling. */ +static void suffix_object(cJSON *prev, cJSON *item) +{ + prev->next = item; + item->prev = prev; +} + +/* Utility for handling references. */ +static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) +{ + cJSON *reference = NULL; + if (item == NULL) + { + return NULL; + } + + reference = cJSON_New_Item(hooks); + if (reference == NULL) + { + return NULL; + } + + memcpy(reference, item, sizeof(cJSON)); + reference->string = NULL; + reference->type |= cJSON_IsReference; + reference->next = reference->prev = NULL; + return reference; +} + +static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) +{ + cJSON *child = NULL; + + if ((item == NULL) || (array == NULL) || (array == item)) + { + return false; + } + + child = array->child; + /* + * To find the last item in array quickly, we use prev in array + */ + if (child == NULL) + { + /* list is empty, start new one */ + array->child = item; + item->prev = item; + item->next = NULL; + } + else + { + /* append to the end */ + if (child->prev) + { + suffix_object(child->prev, item); + array->child->prev = item; + } + } + + return true; +} + +/* Add item to array/object. */ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) +{ + return add_item_to_array(array, item); +} + +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) + #pragma GCC diagnostic push +#endif +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wcast-qual" +#endif +/* helper function to cast away const */ +static void* cast_away_const(const void* string) +{ + return (void*)string; +} +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) + #pragma GCC diagnostic pop +#endif + + +static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key) +{ + char *new_key = NULL; + int new_type = cJSON_Invalid; + + if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item)) + { + return false; + } + + if (constant_key) + { + new_key = (char*)cast_away_const(string); + new_type = item->type | cJSON_StringIsConst; + } + else + { + new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); + if (new_key == NULL) + { + return false; + } + + new_type = item->type & ~cJSON_StringIsConst; + } + + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + hooks->deallocate(item->string); + } + + item->string = new_key; + item->type = new_type; + + return add_item_to_array(object, item); +} + +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) +{ + return add_item_to_object(object, string, item, &global_hooks, false); +} + +/* Add an item to an object with constant string as key */ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) +{ + return add_item_to_object(object, string, item, &global_hooks, true); +} + +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) +{ + if (array == NULL) + { + return false; + } + + return add_item_to_array(array, create_reference(item, &global_hooks)); +} + +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) +{ + if ((object == NULL) || (string == NULL)) + { + return false; + } + + return add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); +} + +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name) +{ + cJSON *null = cJSON_CreateNull(); + if (add_item_to_object(object, name, null, &global_hooks, false)) + { + return null; + } + + cJSON_Delete(null); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name) +{ + cJSON *true_item = cJSON_CreateTrue(); + if (add_item_to_object(object, name, true_item, &global_hooks, false)) + { + return true_item; + } + + cJSON_Delete(true_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name) +{ + cJSON *false_item = cJSON_CreateFalse(); + if (add_item_to_object(object, name, false_item, &global_hooks, false)) + { + return false_item; + } + + cJSON_Delete(false_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean) +{ + cJSON *bool_item = cJSON_CreateBool(boolean); + if (add_item_to_object(object, name, bool_item, &global_hooks, false)) + { + return bool_item; + } + + cJSON_Delete(bool_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number) +{ + cJSON *number_item = cJSON_CreateNumber(number); + if (add_item_to_object(object, name, number_item, &global_hooks, false)) + { + return number_item; + } + + cJSON_Delete(number_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string) +{ + cJSON *string_item = cJSON_CreateString(string); + if (add_item_to_object(object, name, string_item, &global_hooks, false)) + { + return string_item; + } + + cJSON_Delete(string_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw) +{ + cJSON *raw_item = cJSON_CreateRaw(raw); + if (add_item_to_object(object, name, raw_item, &global_hooks, false)) + { + return raw_item; + } + + cJSON_Delete(raw_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name) +{ + cJSON *object_item = cJSON_CreateObject(); + if (add_item_to_object(object, name, object_item, &global_hooks, false)) + { + return object_item; + } + + cJSON_Delete(object_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name) +{ + cJSON *array = cJSON_CreateArray(); + if (add_item_to_object(object, name, array, &global_hooks, false)) + { + return array; + } + + cJSON_Delete(array); + return NULL; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item) +{ + if ((parent == NULL) || (item == NULL)) + { + return NULL; + } + + if (item != parent->child) + { + /* not the first element */ + item->prev->next = item->next; + } + if (item->next != NULL) + { + /* not the last element */ + item->next->prev = item->prev; + } + + if (item == parent->child) + { + /* first element */ + parent->child = item->next; + } + else if (item->next == NULL) + { + /* last element */ + parent->child->prev = item->prev; + } + + /* make sure the detached item doesn't point anywhere anymore */ + item->prev = NULL; + item->next = NULL; + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) +{ + if (which < 0) + { + return NULL; + } + + return cJSON_DetachItemViaPointer(array, get_array_item(array, (size_t)which)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) +{ + cJSON_Delete(cJSON_DetachItemFromArray(array, which)); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItem(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObject(object, string)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); +} + +/* Replace array/object items with new ones. */ +CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) +{ + cJSON *after_inserted = NULL; + + if (which < 0) + { + return false; + } + + after_inserted = get_array_item(array, (size_t)which); + if (after_inserted == NULL) + { + return add_item_to_array(array, newitem); + } + + newitem->next = after_inserted; + newitem->prev = after_inserted->prev; + after_inserted->prev = newitem; + if (after_inserted == array->child) + { + array->child = newitem; + } + else + { + newitem->prev->next = newitem; + } + return true; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) +{ + if ((parent == NULL) || (parent->child == NULL) || (replacement == NULL) || (item == NULL)) + { + return false; + } + + if (replacement == item) + { + return true; + } + + replacement->next = item->next; + replacement->prev = item->prev; + + if (replacement->next != NULL) + { + replacement->next->prev = replacement; + } + if (parent->child == item) + { + if (parent->child->prev == parent->child) + { + replacement->prev = replacement; + } + parent->child = replacement; + } + else + { /* + * To find the last item in array quickly, we use prev in array. + * We can't modify the last item's next pointer where this item was the parent's child + */ + if (replacement->prev != NULL) + { + replacement->prev->next = replacement; + } + if (replacement->next == NULL) + { + parent->child->prev = replacement; + } + } + + item->next = NULL; + item->prev = NULL; + cJSON_Delete(item); + + return true; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) +{ + if (which < 0) + { + return false; + } + + return cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem); +} + +static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive) +{ + if ((replacement == NULL) || (string == NULL)) + { + return false; + } + + /* replace the name in the replacement */ + if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != NULL)) + { + cJSON_free(replacement->string); + } + replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + if (replacement->string == NULL) + { + return false; + } + + replacement->type &= ~cJSON_StringIsConst; + + return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); +} + +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) +{ + return replace_item_in_object(object, string, newitem, false); +} + +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) +{ + return replace_item_in_object(object, string, newitem, true); +} + +/* Create basic types: */ +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_NULL; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_True; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_False; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = boolean ? cJSON_True : cJSON_False; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Number; + item->valuedouble = num; + + /* use saturation in case of overflow */ + if (num >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (num <= (double)INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)num; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_String; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) + { + item->type = cJSON_String | cJSON_IsReference; + item->valuestring = (char*)cast_away_const(string); + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { + item->type = cJSON_Object | cJSON_IsReference; + item->child = (cJSON*)cast_away_const(child); + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) { + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { + item->type = cJSON_Array | cJSON_IsReference; + item->child = (cJSON*)cast_away_const(child); + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Raw; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type=cJSON_Array; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_Object; + } + + return item; +} + +/* Create Arrays: */ +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if (!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + if (a && a->child) { + a->child->prev = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber((double)numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + if (a && a->child) { + a->child->prev = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + if (a && a->child) { + a->child->prev = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (strings == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for (i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateString(strings[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p,n); + } + p = n; + } + + if (a && a->child) { + a->child->prev = n; + } + + return a; +} + +/* Duplication */ +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) +{ + cJSON *newitem = NULL; + cJSON *child = NULL; + cJSON *next = NULL; + cJSON *newchild = NULL; + + /* Bail on bad ptr */ + if (!item) + { + goto fail; + } + /* Create new item */ + newitem = cJSON_New_Item(&global_hooks); + if (!newitem) + { + goto fail; + } + /* Copy over all vars */ + newitem->type = item->type & (~cJSON_IsReference); + newitem->valueint = item->valueint; + newitem->valuedouble = item->valuedouble; + if (item->valuestring) + { + newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); + if (!newitem->valuestring) + { + goto fail; + } + } + if (item->string) + { + newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); + if (!newitem->string) + { + goto fail; + } + } + /* If non-recursive, then we're done! */ + if (!recurse) + { + return newitem; + } + /* Walk the ->next chain for the child. */ + child = item->child; + while (child != NULL) + { + newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */ + if (!newchild) + { + goto fail; + } + if (next != NULL) + { + /* If newitem->child already set, then crosswire ->prev and ->next and move on */ + next->next = newchild; + newchild->prev = next; + next = newchild; + } + else + { + /* Set newitem->child and move to it */ + newitem->child = newchild; + next = newchild; + } + child = child->next; + } + if (newitem && newitem->child) + { + newitem->child->prev = newchild; + } + + return newitem; + +fail: + if (newitem != NULL) + { + cJSON_Delete(newitem); + } + + return NULL; +} + +static void skip_oneline_comment(char **input) +{ + *input += static_strlen("//"); + + for (; (*input)[0] != '\0'; ++(*input)) + { + if ((*input)[0] == '\n') { + *input += static_strlen("\n"); + return; + } + } +} + +static void skip_multiline_comment(char **input) +{ + *input += static_strlen("/*"); + + for (; (*input)[0] != '\0'; ++(*input)) + { + if (((*input)[0] == '*') && ((*input)[1] == '/')) + { + *input += static_strlen("*/"); + return; + } + } +} + +static void minify_string(char **input, char **output) { + (*output)[0] = (*input)[0]; + *input += static_strlen("\""); + *output += static_strlen("\""); + + + for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) { + (*output)[0] = (*input)[0]; + + if ((*input)[0] == '\"') { + (*output)[0] = '\"'; + *input += static_strlen("\""); + *output += static_strlen("\""); + return; + } else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) { + (*output)[1] = (*input)[1]; + *input += static_strlen("\""); + *output += static_strlen("\""); + } + } +} + +CJSON_PUBLIC(void) cJSON_Minify(char *json) +{ + char *into = json; + + if (json == NULL) + { + return; + } + + while (json[0] != '\0') + { + switch (json[0]) + { + case ' ': + case '\t': + case '\r': + case '\n': + json++; + break; + + case '/': + if (json[1] == '/') + { + skip_oneline_comment(&json); + } + else if (json[1] == '*') + { + skip_multiline_comment(&json); + } else { + json++; + } + break; + + case '\"': + minify_string(&json, (char**)&into); + break; + + default: + into[0] = json[0]; + json++; + into++; + } + } + + /* and null-terminate. */ + *into = '\0'; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Invalid; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_False; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xff) == cJSON_True; +} + + +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & (cJSON_True | cJSON_False)) != 0; +} +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_NULL; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Number; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_String; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Array; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Object; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Raw; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) +{ + if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF))) + { + return false; + } + + /* check if type is valid */ + switch (a->type & 0xFF) + { + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + case cJSON_Number: + case cJSON_String: + case cJSON_Raw: + case cJSON_Array: + case cJSON_Object: + break; + + default: + return false; + } + + /* identical objects are equal */ + if (a == b) + { + return true; + } + + switch (a->type & 0xFF) + { + /* in these cases and equal type is enough */ + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + return true; + + case cJSON_Number: + if (compare_double(a->valuedouble, b->valuedouble)) + { + return true; + } + return false; + + case cJSON_String: + case cJSON_Raw: + if ((a->valuestring == NULL) || (b->valuestring == NULL)) + { + return false; + } + if (strcmp(a->valuestring, b->valuestring) == 0) + { + return true; + } + + return false; + + case cJSON_Array: + { + cJSON *a_element = a->child; + cJSON *b_element = b->child; + + for (; (a_element != NULL) && (b_element != NULL);) + { + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + + a_element = a_element->next; + b_element = b_element->next; + } + + /* one of the arrays is longer than the other */ + if (a_element != b_element) { + return false; + } + + return true; + } + + case cJSON_Object: + { + cJSON *a_element = NULL; + cJSON *b_element = NULL; + cJSON_ArrayForEach(a_element, a) + { + /* TODO This has O(n^2) runtime, which is horrible! */ + b_element = get_object_item(b, a_element->string, case_sensitive); + if (b_element == NULL) + { + return false; + } + + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + } + + /* doing this twice, once on a and b to prevent true comparison if a subset of b + * TODO: Do this the proper way, this is just a fix for now */ + cJSON_ArrayForEach(b_element, b) + { + a_element = get_object_item(a, b_element->string, case_sensitive); + if (a_element == NULL) + { + return false; + } + + if (!cJSON_Compare(b_element, a_element, case_sensitive)) + { + return false; + } + } + + return true; + } + + default: + return false; + } +} + +CJSON_PUBLIC(void *) cJSON_malloc(size_t size) +{ + return global_hooks.allocate(size); +} + +CJSON_PUBLIC(void) cJSON_free(void *object) +{ + global_hooks.deallocate(object); +} diff --git a/testRoot/jni/utils/cJSON.h b/testRoot/jni/utils/cJSON.h new file mode 100644 index 00000000..2628d763 --- /dev/null +++ b/testRoot/jni/utils/cJSON.h @@ -0,0 +1,300 @@ +/* + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef cJSON__h +#define cJSON__h + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) +#define __WINDOWS__ +#endif + +#ifdef __WINDOWS__ + +/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options: + +CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols +CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default) +CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol + +For *nix builds that support visibility attribute, you can define similar behavior by + +setting default visibility to hidden by adding +-fvisibility=hidden (for gcc) +or +-xldscope=hidden (for sun cc) +to CFLAGS + +then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does + +*/ + +#define CJSON_CDECL __cdecl +#define CJSON_STDCALL __stdcall + +/* export symbols by default, this is necessary for copy pasting the C and header file */ +#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_EXPORT_SYMBOLS +#endif + +#if defined(CJSON_HIDE_SYMBOLS) +#define CJSON_PUBLIC(type) type CJSON_STDCALL +#elif defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL +#elif defined(CJSON_IMPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL +#endif +#else /* !__WINDOWS__ */ +#define CJSON_CDECL +#define CJSON_STDCALL + +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) +#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type +#else +#define CJSON_PUBLIC(type) type +#endif +#endif + +/* project version */ +#define CJSON_VERSION_MAJOR 1 +#define CJSON_VERSION_MINOR 7 +#define CJSON_VERSION_PATCH 16 + +#include + +/* cJSON Types: */ +#define cJSON_Invalid (0) +#define cJSON_False (1 << 0) +#define cJSON_True (1 << 1) +#define cJSON_NULL (1 << 2) +#define cJSON_Number (1 << 3) +#define cJSON_String (1 << 4) +#define cJSON_Array (1 << 5) +#define cJSON_Object (1 << 6) +#define cJSON_Raw (1 << 7) /* raw json */ + +#define cJSON_IsReference 256 +#define cJSON_StringIsConst 512 + +/* The cJSON structure: */ +typedef struct cJSON +{ + /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON *next; + struct cJSON *prev; + /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + struct cJSON *child; + + /* The type of the item, as above. */ + int type; + + /* The item's string, if type==cJSON_String and type == cJSON_Raw */ + char *valuestring; + /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ + int valueint; + /* The item's number, if type==cJSON_Number */ + double valuedouble; + + /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + char *string; +} cJSON; + +typedef struct cJSON_Hooks +{ + /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ + void *(CJSON_CDECL *malloc_fn)(size_t sz); + void (CJSON_CDECL *free_fn)(void *ptr); +} cJSON_Hooks; + +typedef int cJSON_bool; + +/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. + * This is to prevent stack overflows. */ +#ifndef CJSON_NESTING_LIMIT +#define CJSON_NESTING_LIMIT 1000 +#endif + +/* returns the version of cJSON as a string */ +CJSON_PUBLIC(const char*) cJSON_Version(void); + +/* Supply malloc, realloc and free functions to cJSON */ +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); + +/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ +/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length); +/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ +/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated); + +/* Render a cJSON entity to text for transfer/storage. */ +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); +/* Render a cJSON entity to text for transfer/storage without any formatting. */ +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); +/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); +/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ +/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); +/* Delete a cJSON entity and all subentities. */ +CJSON_PUBLIC(void) cJSON_Delete(cJSON *item); + +/* Returns the number of items in an array (or object). */ +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); +/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */ +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); +/* Get item "string" from object. Case insensitive. */ +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); +/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); + +/* Check item type and return its value */ +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item); +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item); + +/* These functions check the type of an item */ +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); + +/* These calls create a cJSON item of the appropriate type. */ +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean); +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num); +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string); +/* raw json */ +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw); +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); + +/* Create a string where valuestring references a string so + * it will not be freed by cJSON_Delete */ +CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string); +/* Create an object/array that only references it's elements so + * they will not be freed by cJSON_Delete */ +CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); +CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); + +/* These utilities create an Array of count items. + * The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/ +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count); + +/* Append item to the specified array/object. */ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); +/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. + * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before + * writing to `item->string` */ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); +/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); + +/* Remove/Detach items from Arrays/Objects. */ +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); + +/* Update array items. */ +CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); + +/* Duplicate a cJSON item */ +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); +/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will + * need to be released. With recurse!=0, it will duplicate any children connected to the item. + * The item->next and ->prev pointers are always zero on return from Duplicate. */ +/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. + * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); + +/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. + * The input pointer json cannot point to a read-only address area, such as a string constant, + * but should point to a readable and writable address area. */ +CJSON_PUBLIC(void) cJSON_Minify(char *json); + +/* Helper functions for creating and adding items to an object at the same time. + * They return the added item or NULL on failure. */ +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean); +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number); +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string); +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw); +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name); +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name); + +/* When assigning an integer value, it needs to be propagated to valuedouble too. */ +#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) +/* helper for the cJSON_SetNumberValue macro */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); +#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) +/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */ +CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring); + +/* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/ +#define cJSON_SetBoolValue(object, boolValue) ( \ + (object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \ + (object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \ + cJSON_Invalid\ +) + +/* Macro for iterating over an array or object */ +#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) + +/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ +CJSON_PUBLIC(void *) cJSON_malloc(size_t size); +CJSON_PUBLIC(void) cJSON_free(void *object); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/testRoot/jni/utils/jsonUtils.h b/testRoot/jni/utils/jsonUtils.h new file mode 100644 index 00000000..96a9bebb --- /dev/null +++ b/testRoot/jni/utils/jsonUtils.h @@ -0,0 +1,34 @@ +#ifndef JSON_ENCODE_UTILS_H_ +#define JSON_ENCODE_UTILS_H_ +#include +#include +#include +#include "cJSON.h" + +static std::string CreateJsonBody(const std::vector>& keyValuePairs) { + cJSON *root = cJSON_CreateObject(); + if(!root) { + return {}; + } + for (const auto& pair : keyValuePairs) { + cJSON_AddItemToObject(root, std::get<0>(pair).c_str(), cJSON_CreateString(std::get<1>(pair).c_str())); + } + + char *json = cJSON_Print(root); + std::string jsonStr(json); + free(json); + cJSON_Delete(root); + return jsonStr; +} + +static std::string GetMiddleJsonString(std::string_view text) { + std::string jsonString; + int jsonStart = text.find("{"); + int jsonEnd = text.find_last_of("}"); + if(jsonStart != std::string::npos && jsonEnd != std::string::npos) { + jsonString = text.substr(jsonStart, jsonEnd - jsonStart + 1); + } + return jsonString; +} + +#endif \ No newline at end of file diff --git a/testRoot/jni/utils/stringUtils.h b/testRoot/jni/utils/stringUtils.h new file mode 100644 index 00000000..37289f8d --- /dev/null +++ b/testRoot/jni/utils/stringUtils.h @@ -0,0 +1,13 @@ +#ifndef STRING_UTILS_H_ +#define STRING_UTILS_H_ +#include +#include + +static void replaceAllOccurrences(std::string& str, const std::string& toSearch, const std::string& replaceWith) { + size_t pos = str.find(toSearch); + while(pos != std::string::npos) { + str.replace(pos, toSearch.length(), replaceWith); + pos = str.find(toSearch, pos + replaceWith.length()); + } +} +#endif \ No newline at end of file diff --git "a/testRoot/jni/\347\274\226\350\257\221\346\265\201\347\250\213.txt" "b/testRoot/jni/\347\274\226\350\257\221\346\265\201\347\250\213.txt" new file mode 100644 index 00000000..187ac337 --- /dev/null +++ "b/testRoot/jni/\347\274\226\350\257\221\346\265\201\347\250\213.txt" @@ -0,0 +1,4 @@ +1.首次编译Android.mk只可得su与lib_root_server.so文件, +2.双击运行generate_source_file_kernel_root_kit_lib_root_server_data.bat +3.双击运行generate_source_file_kernel_root_kit_su_exec_data.bat +4.再次编译Android.mk可得testRoot文件 \ No newline at end of file diff --git a/testRoot/main.cpp b/testRoot/main.cpp deleted file mode 100644 index ca905fee..00000000 --- a/testRoot/main.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include -#include - -#include "super_root.h" -#include "adb_inject.h" -#define ROOT_KEY 0x7F6766F8 - -void show_capability_info() -{ - struct __user_cap_header_struct cap_header_data; - cap_user_header_t cap_header = &cap_header_data; - - struct __user_cap_data_struct cap_data_data; - cap_user_data_t cap_data = &cap_data_data; - - cap_header->pid = getpid(); - cap_header->version = _LINUX_CAPABILITY_VERSION_3; //_1、_2、_3 - - if (capget(cap_header, cap_data) < 0) { - perror("FAILED capget()"); - exit(1); - } - - printf("Cap data 0x%x, 0x%x, 0x%x\n", cap_data->effective, cap_data->permitted, cap_data->inheritable); - printf("now getuid()=%d,geteuid()=%d,getgid()=%d,getegid()=%d\n", getuid(), geteuid(), getgid(), getegid()); - - FILE * fp = popen("getenforce", "r"); - if (fp) - { - char cmd[512] = { 0 }; - fread(cmd, 1, sizeof(cmd), fp); - pclose(fp); - - printf("SELinux status: %s\n", cmd); - } -} -void test_root() -{ - show_capability_info(); - - printf("get_root ret:%d\n", get_root(ROOT_KEY)); - - show_capability_info(); - - //system("id"); - //system("/data/local/tmp/getmyinfo"); - //system("insmod /sdcard/rwProcMem37.ko ; echo $?"); - //system("cat /proc/1/maps"); - //system("ls /proc"); - //system("screencap -p /sdcard/temp.png"); - return; -} - -void test_disable_selinux() -{ - int ret = disable_selinux(ROOT_KEY); - printf("disable_selinux ret:%d\n", ret); - printf("done.\n"); - return; -} - -void test_enable_selinux() -{ - int ret = enable_selinux(ROOT_KEY); - printf("enable_selinux ret:%d\n", ret); - printf("done.\n"); - return; -} - - -void test_run_cmd(char * cmd, bool bKeepAdbRoot = false) { - printf("inject_cmd_remote_process(%s)\n", cmd); - char szResult[0x1000] = { 0 }; - ssize_t ret = safe_inject_adb_process_run_cmd_wrapper(ROOT_KEY, cmd, bKeepAdbRoot, szResult, sizeof(szResult)); - printf("inject_cmd_remote_process ret val:%zd\n", ret); - printf("inject_cmd_remote_process result:%s\n", szResult); -} - -int main(int argc, char *argv[]) -{ - printf( - "======================================================\n" - "本工具名称: Linux ARM64 完美隐藏ROOT演示\n" - "本工具功能列表:\n" - "\t1.显示自身权限信息\n" - "\t2.获取ROOT权限\n" - "\t3.绕过SELinux\n" - "\t4.还原SELinux\n" - "\t5.执行ROOT权限级别的Shell命令\n" - "\t6.赋予ADB最高级别权限\n" - "\t新一代root,跟面具完全不同思路,摆脱面具被检测的弱点,完美隐藏root功能,挑战全网root检测手段,兼容安卓APP直接JNI调用,稳定、流畅、不闪退。\n" - "======================================================\n" - ); - - - ++argv; - --argc; - - - int cmdc; - char *cmdv[6]; - - while (argc) { - // Clean up - cmdc = 0; - memset(cmdv, 0, sizeof(cmdv)); - - // Split the commands - for (char *tok = strtok(argv[0], " "); tok; tok = strtok(nullptr, " ")) - { - cmdv[cmdc++] = tok; - if (cmdc == 0) - { - continue; - } - } - - - if (strcmp(cmdv[0], "show") == 0) { - show_capability_info(); - } - else if (strcmp(cmdv[0], "root") == 0) { - test_root(); - } - else if (strcmp(cmdv[0], "disable") == 0) { - test_disable_selinux(); - } - else if (strcmp(cmdv[0], "enable") == 0) { - test_enable_selinux(); - } - else if (strcmp(cmdv[0], "cmd") == 0) { - test_run_cmd("id"); - //test_run_cmd("id > /sdcard/run.txt"); - //test_run_cmd("insmod rwProcMem37.ko > /sdcard/run.txt"); - } - else if (strcmp(cmdv[0], "adb") == 0) { - test_run_cmd("id", true); - } - else { - return 1; - } - - --argc; - ++argv; - } - return 0; -} \ No newline at end of file diff --git a/testRoot/testRoot.vcxproj b/testRoot/testRoot.vcxproj deleted file mode 100644 index 87beb8d5..00000000 --- a/testRoot/testRoot.vcxproj +++ /dev/null @@ -1,94 +0,0 @@ - - - - - Debug - ARM - - - Release - ARM - - - Debug - ARM64 - - - Release - ARM64 - - - Debug - x86 - - - Release - x86 - - - Debug - x64 - - - Release - x64 - - - - {2a287d40-5742-4389-a623-50f6bcea2a0f} - Linux - testRoot - 15.0 - Linux - 1.0 - Generic - {D51BCBC9-82E9-4017-911E-C93873C4EA2B} - - - - true - - - false - - - true - - - false - - - true - - - false - - - false - - - true - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/testRoot/testRoot.vcxproj.filters b/testRoot/testRoot.vcxproj.filters deleted file mode 100644 index 52b27543..00000000 --- a/testRoot/testRoot.vcxproj.filters +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - {4f0b16e1-e05c-44ce-8377-35b973d209f5} - - - - - jni - - - jni - - - - - - - - \ No newline at end of file diff --git a/testRoot/testRoot.vcxproj.user b/testRoot/testRoot.vcxproj.user deleted file mode 100644 index 6e2aec7a..00000000 --- a/testRoot/testRoot.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file