From 08986d312e8c8fa11f1d9135cbbd8d6662b4684a Mon Sep 17 00:00:00 2001 From: chiteroman <98092901+chiteroman@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:46:30 +0100 Subject: [PATCH] Improve code, remove libcxx, use system STL --- .gitmodules | 3 - .idea/.gitignore | 3 + .idea/.name | 1 + .idea/compiler.xml | 6 ++ .idea/deploymentTargetDropDown.xml | 10 +++ .idea/gradle.xml | 18 +++++ .idea/inspectionProfiles/Project_Default.xml | 6 ++ .idea/migrations.xml | 10 +++ .idea/misc.xml | 9 +++ .idea/vcs.xml | 6 ++ app/build.gradle.kts | 29 ++++++++ app/src/main/cpp/Android.mk | 5 +- app/src/main/cpp/Application.mk | 5 +- app/src/main/cpp/libcxx | 1 - app/src/main/cpp/main.cpp | 72 +++++++++++++++---- .../playintegrityfix/EntryPoint.java | 14 ++-- module/customize.sh | 2 +- module/module.prop | 4 +- module/post-fs-data.sh | 2 +- module/service.sh | 5 +- 20 files changed, 176 insertions(+), 35 deletions(-) delete mode 100644 .gitmodules create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/deploymentTargetDropDown.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/migrations.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml delete mode 160000 app/src/main/cpp/libcxx diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 15d4b83..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "app/src/main/cpp/libcxx"] - path = app/src/main/cpp/libcxx - url = https://github.com/topjohnwu/libcxx.git diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..45199ec --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +PlayIntegrityFix \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..0c0c338 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..32522c1 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..4d299ab --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..55c0ec2 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c6a5fc3..ca05e7c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -42,4 +42,33 @@ android { path = file("src/main/cpp/Android.mk") } } +} + +tasks.register("copyFiles") { + doLast { + val moduleFolder = project.rootDir.resolve("module") + val dexFile = project.buildDir.resolve("intermediates/dex/release/minifyReleaseWithR8/classes.dex") + val soDir = project.buildDir.resolve("intermediates/stripped_native_libs/release/out/lib") + + dexFile.copyTo(moduleFolder.resolve("classes.dex"), overwrite = true) + + soDir.walk().filter { it.isFile && it.extension == "so" }.forEach { soFile -> + val abiFolder = soFile.parentFile.name + val destination = moduleFolder.resolve("zygisk/$abiFolder.so") + soFile.copyTo(destination, overwrite = true) + } + } +} + +tasks.register("zip") { + dependsOn("copyFiles") + + archiveFileName.set("PlayIntegrityFix.zip") + destinationDirectory.set(project.rootDir.resolve("out")) + + from(project.rootDir.resolve("module")) +} + +afterEvaluate { + tasks["assembleRelease"].finalizedBy("copyFiles", "zip") } \ No newline at end of file diff --git a/app/src/main/cpp/Android.mk b/app/src/main/cpp/Android.mk index 9632627..dc29e4c 100644 --- a/app/src/main/cpp/Android.mk +++ b/app/src/main/cpp/Android.mk @@ -26,8 +26,5 @@ ifeq ($(TARGET_ARCH_ABI),arm64-v8a) LOCAL_C_INCLUDES += $(LOCAL_PATH)/shadowhook/arch/arm64 endif -LOCAL_STATIC_LIBRARIES := libcxx LOCAL_LDLIBS := -llog -include $(BUILD_SHARED_LIBRARY) - -include $(LOCAL_PATH)/libcxx/Android.mk \ No newline at end of file +include $(BUILD_SHARED_LIBRARY) \ No newline at end of file diff --git a/app/src/main/cpp/Application.mk b/app/src/main/cpp/Application.mk index da73f7c..86370ee 100644 --- a/app/src/main/cpp/Application.mk +++ b/app/src/main/cpp/Application.mk @@ -1,4 +1,3 @@ -APP_STL := none +APP_STL := system APP_CFLAGS := -Oz -fno-exceptions -fno-rtti -fvisibility=hidden -fvisibility-inlines-hidden -APP_CPPFLAGS := -std=c++20 -APP_LDFLAGS := -Oz \ No newline at end of file +APP_CPPFLAGS := -std=c++20 \ No newline at end of file diff --git a/app/src/main/cpp/libcxx b/app/src/main/cpp/libcxx deleted file mode 160000 index 12c8f4e..0000000 --- a/app/src/main/cpp/libcxx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 12c8f4e93f196a700137e983dcceeac43cf807f2 diff --git a/app/src/main/cpp/main.cpp b/app/src/main/cpp/main.cpp index 03b204f..faf2fc6 100644 --- a/app/src/main/cpp/main.cpp +++ b/app/src/main/cpp/main.cpp @@ -1,17 +1,17 @@ #include #include -#include +#include #include +#include #include "zygisk.hpp" #include "shadowhook.h" -#include "classes_dex.h" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "PIF/Native", __VA_ARGS__) -#define FIRST_API_LEVEL "25" +#define FIRST_API_LEVEL "23" -#define SECURITY_PATCH "2018-07-05" +#define SECURITY_PATCH "2018-01-05" typedef void (*T_Callback)(void *, const char *, const char *, uint32_t); @@ -70,28 +70,53 @@ public: } void preAppSpecialize(zygisk::AppSpecializeArgs *args) override { + bool isGms = false, isGmsUnstable = false; + auto rawProcess = env->GetStringUTFChars(args->nice_name, nullptr); - std::string_view process(rawProcess); + if (rawProcess) { + std::string_view process(rawProcess); - bool isGms = process.starts_with("com.google.android.gms"); - isGmsUnstable = process.compare("com.google.android.gms.unstable") == 0; + isGms = process.starts_with("com.google.android.gms"); + isGmsUnstable = process.compare("com.google.android.gms.unstable") == 0; + } env->ReleaseStringUTFChars(args->nice_name, rawProcess); if (isGms) api->setOption(zygisk::FORCE_DENYLIST_UNMOUNT); - if (isGmsUnstable) return; + if (isGmsUnstable) { + long size = 0; + int fd = api->connectCompanion(); + + read(fd, &size, sizeof(long)); + + if (size > 0) { + vector.resize(size); + read(fd, vector.data(), size); + LOGD("Read %ld bytes from fd!", size); + } else { + LOGD("Couldn't read classes.dex from fd!"); + api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY); + return; + } + + close(fd); + + return; + } api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY); } void postAppSpecialize(const zygisk::AppSpecializeArgs *args) override { - if (!isGmsUnstable) return; + if (vector.empty()) return; doHook(); inject(); + + vector.clear(); } void preServerSpecialize(zygisk::ServerSpecializeArgs *args) override { @@ -101,7 +126,7 @@ public: private: zygisk::Api *api = nullptr; JNIEnv *env = nullptr; - bool isGmsUnstable = false; + std::vector vector; void inject() { LOGD("get system classloader"); @@ -114,7 +139,7 @@ private: auto dexClClass = env->FindClass("dalvik/system/InMemoryDexClassLoader"); auto dexClInit = env->GetMethodID(dexClClass, "", "(Ljava/nio/ByteBuffer;Ljava/lang/ClassLoader;)V"); - auto buffer = env->NewDirectByteBuffer(classes_dex, classes_dex_len); + auto buffer = env->NewDirectByteBuffer(vector.data(), static_cast(vector.size())); auto dexCl = env->NewObject(dexClClass, dexClInit, buffer, systemClassLoader); LOGD("load class"); @@ -131,4 +156,27 @@ private: } }; -REGISTER_ZYGISK_MODULE(PlayIntegrityFix) \ No newline at end of file +static void companion(int fd) { + long size = 0; + std::vector vector; + + FILE *file = fopen("/data/adb/modules/playintegrityfix/classes.dex", "rb"); + + if (file) { + fseek(file, 0, SEEK_END); + size = ftell(file); + fseek(file, 0, SEEK_SET); + + vector.resize(size); + fread(vector.data(), 1, size, file); + + fclose(file); + } + + write(fd, &size, sizeof(long)); + write(fd, vector.data(), size); +} + +REGISTER_ZYGISK_MODULE(PlayIntegrityFix) + +REGISTER_ZYGISK_COMPANION(companion) \ No newline at end of file diff --git a/app/src/main/java/es/chiteroman/playintegrityfix/EntryPoint.java b/app/src/main/java/es/chiteroman/playintegrityfix/EntryPoint.java index d537ac5..bc3baf4 100644 --- a/app/src/main/java/es/chiteroman/playintegrityfix/EntryPoint.java +++ b/app/src/main/java/es/chiteroman/playintegrityfix/EntryPoint.java @@ -11,13 +11,13 @@ import java.security.Provider; import java.security.Security; public final class EntryPoint { - private static final String PRODUCT = "sailfish"; - private static final String DEVICE = "sailfish"; - private static final String MANUFACTURER = "Google"; - private static final String BRAND = "google"; - private static final String MODEL = "Pixel"; - private static final String FINGERPRINT = "google/sailfish/sailfish:8.1.0/OPM4.171019.021.P1/4820305:user/release-keys"; - private static final String SECURITY_PATCH = "2018-07-05"; + private static final String PRODUCT = "foster_e"; + private static final String DEVICE = "foster"; + private static final String MANUFACTURER = "NVIDIA"; + private static final String BRAND = "NVIDIA"; + private static final String MODEL = "SHIELD Android TV"; + private static final String FINGERPRINT = "NVIDIA/foster_e/foster:7.0/NRD90M/2427173_1038.2788:user/release-keys"; + private static final String SECURITY_PATCH = "2018-01-05"; public static void init() { spoofProvider(); diff --git a/module/customize.sh b/module/customize.sh index 00c20a4..091ef0f 100644 --- a/module/customize.sh +++ b/module/customize.sh @@ -11,4 +11,4 @@ fi # Clean up any leftover files from previous deprecated methods rm -f /data/data/com.google.android.gms/cache/pif.prop /data/data/com.google.android.gms/pif.prop -rm -f /data/data/com.google.android.gms/cache/pif.json /data/data/com.google.android.gms/pif.json +rm -f /data/data/com.google.android.gms/cache/pif.json /data/data/com.google.android.gms/pif.json \ No newline at end of file diff --git a/module/module.prop b/module/module.prop index 437c586..97bcee7 100644 --- a/module/module.prop +++ b/module/module.prop @@ -1,7 +1,7 @@ id=playintegrityfix name=Play Integrity Fix -version=v13.8 -versionCode=138 +version=v13.9 +versionCode=139 author=chiteroman description=Fix CTS profile (SafetyNet) and DEVICE verdict (Play Integrity). updateJson=https://raw.githubusercontent.com/chiteroman/PlayIntegrityFix/main/update.json \ No newline at end of file diff --git a/module/post-fs-data.sh b/module/post-fs-data.sh index 6196daf..39911d7 100644 --- a/module/post-fs-data.sh +++ b/module/post-fs-data.sh @@ -6,4 +6,4 @@ fi # Remove safetynet-fix module if installed if [ -d /data/adb/modules/safetynet-fix ]; then touch /data/adb/modules/safetynet-fix/remove -fi +fi \ No newline at end of file diff --git a/module/service.sh b/module/service.sh index 0c2d8d0..745e296 100644 --- a/module/service.sh +++ b/module/service.sh @@ -38,7 +38,10 @@ resetprop_if_match ro.boot.mode recovery unknown resetprop_if_match vendor.boot.mode recovery unknown # SELinux -resetprop --delete ro.build.selinux +if [ -n "$(getprop ro.build.selinux)" ]; then + resetprop --delete ro.build.selinux +fi + # use toybox to protect *stat* access time reading if [ "$(toybox cat /sys/fs/selinux/enforce)" == "0" ]; then chmod 640 /sys/fs/selinux/enforce