This commit is contained in:
chiteroman 2023-12-07 13:53:00 +01:00
parent d162b4ff18
commit 3086549484
No known key found for this signature in database
GPG Key ID: 19171A27D600CC72
6 changed files with 74 additions and 50 deletions

View File

@ -2,5 +2,6 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/app/src/main/cpp/libcxx" vcs="Git" />
</component> </component>
</project> </project>

View File

@ -1,4 +1,3 @@
APP_STL := system APP_STL := system
APP_CFLAGS := -Oz -flto -fvisibility=hidden -fvisibility-inlines-hidden -faddrsig -ffunction-sections -fdata-sections APP_CFLAGS := -Oz -fvisibility=hidden -fvisibility-inlines-hidden
APP_CPPFLAGS := -std=c++20 -fno-exceptions -fno-rtti APP_CPPFLAGS := -std=c++20 -fno-exceptions -fno-rtti
APP_LDFLAGS := -Oz -flto -Wl,--icf=all -Wl,--exclude-libs,ALL -Wl,--gc-sections

View File

@ -2,6 +2,7 @@
#include <sys/system_properties.h> #include <sys/system_properties.h>
#include <unistd.h> #include <unistd.h>
#include <string_view> #include <string_view>
#include <vector>
#include "zygisk.hpp" #include "zygisk.hpp"
#include "shadowhook.h" #include "shadowhook.h"
@ -10,9 +11,9 @@
typedef void (*T_Callback)(void *, const char *, const char *, uint32_t); 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; 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); 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) { if (pi == nullptr || callback == nullptr || cookie == nullptr) {
return o_system_property_read_callback(pi, callback, cookie); 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); return o_system_property_read_callback(pi, modify_callback, cookie);
} }
void doHook() { static void doHook() {
shadowhook_init(SHADOWHOOK_MODE_UNIQUE, false); shadowhook_init(SHADOWHOOK_MODE_UNIQUE, false);
void *handle = shadowhook_hook_sym_name("libc.so", "__system_property_read_callback", void *handle = shadowhook_hook_sym_name("libc.so", "__system_property_read_callback",
reinterpret_cast<void *>(my_system_property_read_callback), reinterpret_cast<void *>(my_system_property_read_callback),
@ -71,13 +73,14 @@ public:
if (process == "com.google.android.gms.unstable") { if (process == "com.google.android.gms.unstable") {
long size = 0;
int fd = api->connectCompanion(); int fd = api->connectCompanion();
read(fd, &bufferSize, sizeof(int)); read(fd, &size, sizeof(long));
if (bufferSize > 0) { if (size > 0) {
buffer = static_cast<char *>(calloc(1, bufferSize)); vector.resize(size);
read(fd, buffer, bufferSize); read(fd, vector.data(), size);
} else { } else {
api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY); api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);
LOGD("Couldn't read classes.dex"); LOGD("Couldn't read classes.dex");
@ -93,15 +96,13 @@ public:
} }
void postAppSpecialize(const zygisk::AppSpecializeArgs *args) override { 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<long>(vector.size()));
doHook(); doHook();
inject(); inject();
free(buffer);
} }
void preServerSpecialize(zygisk::ServerSpecializeArgs *args) override { void preServerSpecialize(zygisk::ServerSpecializeArgs *args) override {
@ -111,8 +112,7 @@ public:
private: private:
zygisk::Api *api = nullptr; zygisk::Api *api = nullptr;
JNIEnv *env = nullptr; JNIEnv *env = nullptr;
char *buffer = nullptr; std::vector<char> vector;
int bufferSize = 0;
void inject() { void inject() {
LOGD("get system classloader"); LOGD("get system classloader");
@ -125,7 +125,7 @@ private:
auto dexClClass = env->FindClass("dalvik/system/InMemoryDexClassLoader"); auto dexClClass = env->FindClass("dalvik/system/InMemoryDexClassLoader");
auto dexClInit = env->GetMethodID(dexClClass, "<init>", auto dexClInit = env->GetMethodID(dexClClass, "<init>",
"(Ljava/nio/ByteBuffer;Ljava/lang/ClassLoader;)V"); "(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); auto dexCl = env->NewObject(dexClClass, dexClInit, buff, systemClassLoader);
LOGD("load class"); LOGD("load class");
@ -143,26 +143,24 @@ private:
}; };
static void companion(int fd) { static void companion(int fd) {
int dexSize = 0; std::vector<char> vector;
char *buffer = nullptr; long size = 0;
FILE *dex = fopen("/data/adb/modules/playintegrityfix/classes.dex", "rb"); FILE *dex = fopen("/data/adb/modules/playintegrityfix/classes.dex", "rb");
if (dex) { if (dex) {
fseek(dex, 0, SEEK_END); fseek(dex, 0, SEEK_END);
dexSize = static_cast<int>(ftell(dex)); size = ftell(dex);
fseek(dex, 0, SEEK_SET); fseek(dex, 0, SEEK_SET);
buffer = static_cast<char *>(calloc(1, dexSize)); vector.resize(size);
fread(buffer, 1, dexSize, dex); fread(vector.data(), 1, size, dex);
fclose(dex); fclose(dex);
} }
write(fd, &dexSize, sizeof(int)); write(fd, &size, sizeof(long));
write(fd, buffer, dexSize); write(fd, vector.data(), size);
free(buffer);
} }
REGISTER_ZYGISK_MODULE(PlayIntegrityFix) REGISTER_ZYGISK_MODULE(PlayIntegrityFix)

29
module/boot-completed.sh Normal file
View File

@ -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

View File

@ -3,11 +3,6 @@ if magisk --denylist status; then
magisk --denylist rm com.google.android.gms magisk --denylist rm com.google.android.gms
fi 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 # Conditional early sensitive properties
resetprop_if_diff() { resetprop_if_diff() {

View File

@ -32,8 +32,9 @@ if [ "$(toybox cat /sys/fs/selinux/enforce)" == "0" ]; then
chmod 440 /sys/fs/selinux/policy chmod 440 /sys/fs/selinux/policy
fi fi
# SafetyNet/Play Integrity if [ -z "$KSU" ] || [ "$KSU" = false ]; then
{ # SafetyNet/Play Integrity
{
# late props which must be set after boot_completed for various OEMs # late props which must be set after boot_completed for various OEMs
until [ "$(getprop sys.boot_completed)" == "1" ]; do until [ "$(getprop sys.boot_completed)" == "1" ]; do
sleep 1 sleep 1
@ -52,4 +53,5 @@ fi
resetprop_if_diff ro.boot.verifiedbootstate green resetprop_if_diff ro.boot.verifiedbootstate green
resetprop_if_diff ro.boot.veritymode enforcing resetprop_if_diff ro.boot.veritymode enforcing
resetprop_if_diff vendor.boot.vbmeta.device_state locked resetprop_if_diff vendor.boot.vbmeta.device_state locked
}& }&
fi