From 308654948461c0b8f9e12e2bb3ad3f3ec794203a Mon Sep 17 00:00:00 2001 From: chiteroman <98092901+chiteroman@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:53:00 +0100 Subject: [PATCH] Fix code --- .idea/vcs.xml | 1 + app/src/main/cpp/Application.mk | 5 ++-- app/src/main/cpp/main.cpp | 48 ++++++++++++++++----------------- module/boot-completed.sh | 29 ++++++++++++++++++++ module/post-fs-data.sh | 5 ---- module/service.sh | 36 +++++++++++++------------ 6 files changed, 74 insertions(+), 50 deletions(-) create mode 100644 module/boot-completed.sh diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..9d7f727 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/app/src/main/cpp/Application.mk b/app/src/main/cpp/Application.mk index 1d256e2..8a0542a 100644 --- a/app/src/main/cpp/Application.mk +++ b/app/src/main/cpp/Application.mk @@ -1,4 +1,3 @@ APP_STL := system -APP_CFLAGS := -Oz -flto -fvisibility=hidden -fvisibility-inlines-hidden -faddrsig -ffunction-sections -fdata-sections -APP_CPPFLAGS := -std=c++20 -fno-exceptions -fno-rtti -APP_LDFLAGS := -Oz -flto -Wl,--icf=all -Wl,--exclude-libs,ALL -Wl,--gc-sections \ No newline at end of file +APP_CFLAGS := -Oz -fvisibility=hidden -fvisibility-inlines-hidden +APP_CPPFLAGS := -std=c++20 -fno-exceptions -fno-rtti \ No newline at end of file diff --git a/app/src/main/cpp/main.cpp b/app/src/main/cpp/main.cpp index 543746b..35e1cea 100644 --- a/app/src/main/cpp/main.cpp +++ b/app/src/main/cpp/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "zygisk.hpp" #include "shadowhook.h" @@ -10,9 +11,9 @@ typedef void (*T_Callback)(void *, const char *, const char *, uint32_t); -T_Callback o_callback = nullptr; +static T_Callback o_callback = nullptr; -void modify_callback(void *cookie, const char *name, const char *value, uint32_t serial) { +static void modify_callback(void *cookie, const char *name, const char *value, uint32_t serial) { if (cookie == nullptr || name == nullptr || value == nullptr || o_callback == nullptr) return; @@ -31,9 +32,10 @@ void modify_callback(void *cookie, const char *name, const char *value, uint32_t return o_callback(cookie, name, value, serial); } -void (*o_system_property_read_callback)(const prop_info *, T_Callback, void *); +static void (*o_system_property_read_callback)(const prop_info *, T_Callback, void *); -void my_system_property_read_callback(const prop_info *pi, T_Callback callback, void *cookie) { +static void +my_system_property_read_callback(const prop_info *pi, T_Callback callback, void *cookie) { if (pi == nullptr || callback == nullptr || cookie == nullptr) { return o_system_property_read_callback(pi, callback, cookie); } @@ -41,7 +43,7 @@ void my_system_property_read_callback(const prop_info *pi, T_Callback callback, return o_system_property_read_callback(pi, modify_callback, cookie); } -void doHook() { +static void doHook() { shadowhook_init(SHADOWHOOK_MODE_UNIQUE, false); void *handle = shadowhook_hook_sym_name("libc.so", "__system_property_read_callback", reinterpret_cast(my_system_property_read_callback), @@ -71,13 +73,14 @@ public: if (process == "com.google.android.gms.unstable") { + long size = 0; int fd = api->connectCompanion(); - read(fd, &bufferSize, sizeof(int)); + read(fd, &size, sizeof(long)); - if (bufferSize > 0) { - buffer = static_cast(calloc(1, bufferSize)); - read(fd, buffer, bufferSize); + if (size > 0) { + vector.resize(size); + read(fd, vector.data(), size); } else { api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY); LOGD("Couldn't read classes.dex"); @@ -93,15 +96,13 @@ public: } void postAppSpecialize(const zygisk::AppSpecializeArgs *args) override { - if (bufferSize < 1 || buffer == nullptr) return; + if (vector.empty()) return; - LOGD("Read from fd: %d bytes!", bufferSize); + LOGD("Read from fd: %ld bytes!", static_cast(vector.size())); doHook(); inject(); - - free(buffer); } void preServerSpecialize(zygisk::ServerSpecializeArgs *args) override { @@ -111,8 +112,7 @@ public: private: zygisk::Api *api = nullptr; JNIEnv *env = nullptr; - char *buffer = nullptr; - int bufferSize = 0; + std::vector vector; void inject() { LOGD("get system classloader"); @@ -125,7 +125,7 @@ private: auto dexClClass = env->FindClass("dalvik/system/InMemoryDexClassLoader"); auto dexClInit = env->GetMethodID(dexClClass, "", "(Ljava/nio/ByteBuffer;Ljava/lang/ClassLoader;)V"); - auto buff = env->NewDirectByteBuffer(buffer, bufferSize); + auto buff = env->NewDirectByteBuffer(vector.data(), vector.size()); auto dexCl = env->NewObject(dexClClass, dexClInit, buff, systemClassLoader); LOGD("load class"); @@ -143,26 +143,24 @@ private: }; static void companion(int fd) { - int dexSize = 0; - char *buffer = nullptr; + std::vector vector; + long size = 0; FILE *dex = fopen("/data/adb/modules/playintegrityfix/classes.dex", "rb"); if (dex) { fseek(dex, 0, SEEK_END); - dexSize = static_cast(ftell(dex)); + size = ftell(dex); fseek(dex, 0, SEEK_SET); - buffer = static_cast(calloc(1, dexSize)); - fread(buffer, 1, dexSize, dex); + vector.resize(size); + fread(vector.data(), 1, size, dex); fclose(dex); } - write(fd, &dexSize, sizeof(int)); - write(fd, buffer, dexSize); - - free(buffer); + write(fd, &size, sizeof(long)); + write(fd, vector.data(), size); } REGISTER_ZYGISK_MODULE(PlayIntegrityFix) diff --git a/module/boot-completed.sh b/module/boot-completed.sh new file mode 100644 index 0000000..e03ab5c --- /dev/null +++ b/module/boot-completed.sh @@ -0,0 +1,29 @@ +resetprop_if_diff() { + local NAME=$1 + local EXPECTED=$2 + local CURRENT=$(resetprop $NAME) + + [ -z "$CURRENT" ] || [ "$CURRENT" == "$EXPECTED" ] || resetprop $NAME $EXPECTED +} + +resetprop_if_match() { + local NAME=$1 + local CONTAINS=$2 + local VALUE=$3 + + [[ "$(resetprop $NAME)" == *"$CONTAINS"* ]] && resetprop $NAME $VALUE +} + +# Avoid breaking Realme fingerprint scanners +resetprop_if_diff ro.boot.flash.locked 1 + +# Avoid breaking Oppo fingerprint scanners +resetprop_if_diff ro.boot.vbmeta.device_state locked + +# Avoid breaking OnePlus display modes/fingerprint scanners +resetprop_if_diff vendor.boot.verifiedbootstate green + +# Avoid breaking OnePlus/Oppo display fingerprint scanners on OOS/ColorOS 12+ +resetprop_if_diff ro.boot.verifiedbootstate green +resetprop_if_diff ro.boot.veritymode enforcing +resetprop_if_diff vendor.boot.vbmeta.device_state locked \ No newline at end of file diff --git a/module/post-fs-data.sh b/module/post-fs-data.sh index c11b950..1ca4671 100644 --- a/module/post-fs-data.sh +++ b/module/post-fs-data.sh @@ -3,11 +3,6 @@ if magisk --denylist status; then magisk --denylist rm com.google.android.gms fi -# Remove conflicting modules if installed -if [ -d /data/adb/modules/safetynet-fix ]; then - touch /data/adb/modules/safetynet-fix/remove -fi - # Conditional early sensitive properties resetprop_if_diff() { diff --git a/module/service.sh b/module/service.sh index ec1d1f8..0446160 100644 --- a/module/service.sh +++ b/module/service.sh @@ -32,24 +32,26 @@ if [ "$(toybox cat /sys/fs/selinux/enforce)" == "0" ]; then chmod 440 /sys/fs/selinux/policy fi -# SafetyNet/Play Integrity -{ - # late props which must be set after boot_completed for various OEMs - until [ "$(getprop sys.boot_completed)" == "1" ]; do - sleep 1 - done +if [ -z "$KSU" ] || [ "$KSU" = false ]; then + # SafetyNet/Play Integrity + { + # late props which must be set after boot_completed for various OEMs + until [ "$(getprop sys.boot_completed)" == "1" ]; do + sleep 1 + done - # Avoid breaking Realme fingerprint scanners - resetprop_if_diff ro.boot.flash.locked 1 + # Avoid breaking Realme fingerprint scanners + resetprop_if_diff ro.boot.flash.locked 1 - # Avoid breaking Oppo fingerprint scanners - resetprop_if_diff ro.boot.vbmeta.device_state locked + # Avoid breaking Oppo fingerprint scanners + resetprop_if_diff ro.boot.vbmeta.device_state locked - # Avoid breaking OnePlus display modes/fingerprint scanners - resetprop_if_diff vendor.boot.verifiedbootstate green + # Avoid breaking OnePlus display modes/fingerprint scanners + resetprop_if_diff vendor.boot.verifiedbootstate green - # Avoid breaking OnePlus/Oppo display fingerprint scanners on OOS/ColorOS 12+ - resetprop_if_diff ro.boot.verifiedbootstate green - resetprop_if_diff ro.boot.veritymode enforcing - resetprop_if_diff vendor.boot.vbmeta.device_state locked -}& + # Avoid breaking OnePlus/Oppo display fingerprint scanners on OOS/ColorOS 12+ + resetprop_if_diff ro.boot.verifiedbootstate green + resetprop_if_diff ro.boot.veritymode enforcing + resetprop_if_diff vendor.boot.vbmeta.device_state locked + }& +fi