Skip to content

Commit

Permalink
v16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chiteroman committed Jun 19, 2024
1 parent b2b60f7 commit ecd3b82
Show file tree
Hide file tree
Showing 12 changed files with 13,288 additions and 84 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId = "es.chiteroman.playintegrityfix"
minSdk = 26
targetSdk = 34
versionCode = 15990
versionName = "v15.9.9"
versionCode = 16000
versionName = "v16.0"
multiDexEnabled = false

packaging {
Expand Down Expand Up @@ -66,6 +66,7 @@ android {

dependencies {
implementation("dev.rikka.ndk.thirdparty:cxx:1.2.0")
implementation("com.madgag.spongycastle:bcpkix-jdk15on:1.58.0.0")
}

tasks.register("updateModuleProp") {
Expand Down Expand Up @@ -93,7 +94,7 @@ tasks.register("copyFiles") {
val dexFile = project.layout.buildDirectory.get().asFile.resolve("intermediates/dex/release/minifyReleaseWithR8/classes.dex")
val soDir = project.layout.buildDirectory.get().asFile.resolve("intermediates/stripped_native_libs/release/stripReleaseDebugSymbols/out/lib")

dexFile.copyTo(moduleFolder.resolve("classes.dex"), overwrite = true)
// dexFile.copyTo(moduleFolder.resolve("classes.dex"), overwrite = true)

soDir.walk().filter { it.isFile && it.extension == "so" }.forEach { soFile ->
val abiFolder = soFile.parentFile.name
Expand Down
12,962 changes: 12,962 additions & 0 deletions app/src/main/cpp/dex.h

Large diffs are not rendered by default.

108 changes: 45 additions & 63 deletions app/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@
#include "dobby.h"
#include "json.hpp"
#include "zygisk.hpp"
#include "dex.h"

#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "PIF", __VA_ARGS__)

#define CLASSES_DEX "/data/adb/modules/playintegrityfix/classes.dex"

#define PIF_JSON "/data/adb/pif.json"

#define PIF_JSON_DEFAULT "/data/adb/modules/playintegrityfix/pif.json"

static std::string DEVICE_INITIAL_SDK_INT, SECURITY_PATCH, ID;

typedef void (*T_Callback)(void *, const char *, const char *, uint32_t);

static T_Callback o_callback = nullptr;

ssize_t xread(int fd, void *buffer, size_t count) {
static inline ssize_t xread(int fd, void *buffer, size_t count) {
ssize_t total = 0;
char *buf = (char *)buffer;
char *buf = (char *) buffer;
while (count > 0) {
ssize_t ret = read(fd, buf, count);
if (ret < 0) return -1;
Expand All @@ -32,9 +27,9 @@ ssize_t xread(int fd, void *buffer, size_t count) {
return total;
}

ssize_t xwrite(int fd, void *buffer, size_t count) {
static inline ssize_t xwrite(int fd, void *buffer, size_t count) {
ssize_t total = 0;
char *buf = (char *)buffer;
char *buf = (char *) buffer;
while (count > 0) {
ssize_t ret = write(fd, buf, count);
if (ret < 0) return -1;
Expand All @@ -45,6 +40,10 @@ ssize_t xwrite(int fd, void *buffer, size_t count) {
return total;
}

typedef void (*T_Callback)(void *, const char *, const char *, uint32_t);

static T_Callback o_callback = nullptr;

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;
Expand Down Expand Up @@ -99,81 +98,71 @@ class PlayIntegrityFix : public zygisk::ModuleBase {

void preAppSpecialize(zygisk::AppSpecializeArgs *args) override {

api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);

if (!args) {
api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);
return;
}

const char *rawDir = env->GetStringUTFChars(args->app_data_dir, nullptr);
const char *dir = env->GetStringUTFChars(args->app_data_dir, nullptr);

if (!rawDir) {
if (!dir) {
api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);
return;
}

const char *rawName = env->GetStringUTFChars(args->nice_name, nullptr);

if (!rawName) {
env->ReleaseStringUTFChars(args->app_data_dir, rawDir);
if (!std::string_view(dir).ends_with("/com.google.android.gms")) {
env->ReleaseStringUTFChars(args->app_data_dir, dir);
api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);
return;
}

std::string dir(rawDir);
std::string name(rawName);
env->ReleaseStringUTFChars(args->app_data_dir, dir);

api->setOption(zygisk::FORCE_DENYLIST_UNMOUNT);

env->ReleaseStringUTFChars(args->app_data_dir, rawDir);
env->ReleaseStringUTFChars(args->nice_name, rawName);
const char *name = env->GetStringUTFChars(args->nice_name, nullptr);

if (!dir.ends_with("/com.google.android.gms")) {
if (!name) {
api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);
return;
}

api->setOption(zygisk::FORCE_DENYLIST_UNMOUNT);

if (name != "com.google.android.gms.unstable") {
if (strncmp(name, "com.google.android.gms.unstable", 31) != 0) {
env->ReleaseStringUTFChars(args->nice_name, name);
api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);
return;
}

long dexSize = 0, jsonSize = 0;
env->ReleaseStringUTFChars(args->nice_name, name);

int fd = api->connectCompanion();
long size = 0;
std::vector<char> vector;

xread(fd, &dexSize, sizeof(long));
xread(fd, &jsonSize, sizeof(long));
int fd = api->connectCompanion();

LOGD("Dex file size: %ld", dexSize);
LOGD("Json file size: %ld", jsonSize);
xread(fd, &size, sizeof(long));

if (dexSize < 1 || jsonSize < 1) {
close(fd);
if (size > 0) {
vector.resize(size);
xread(fd, vector.data(), size);
json = nlohmann::json::parse(vector, nullptr, false, true);
} else {
api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);
return;
}

dexVector.resize(dexSize);
xread(fd, dexVector.data(), dexSize);

std::vector<uint8_t> jsonVector;

jsonVector.resize(jsonSize);
xread(fd, jsonVector.data(), jsonSize);

close(fd);

json = nlohmann::json::parse(jsonVector, nullptr, false, true);
}

void postAppSpecialize(const zygisk::AppSpecializeArgs *args) override {
if (dexVector.empty() || json.empty()) return;
if (json.empty()) return;

parseJson();

injectDex();

doHook();
// doHook();
}

void preServerSpecialize(zygisk::ServerSpecializeArgs *args) override {
Expand All @@ -183,7 +172,6 @@ class PlayIntegrityFix : public zygisk::ModuleBase {
private:
zygisk::Api *api = nullptr;
JNIEnv *env = nullptr;
std::vector<uint8_t> dexVector;
nlohmann::json json;

void parseJson() {
Expand All @@ -210,7 +198,7 @@ class PlayIntegrityFix : public zygisk::ModuleBase {
auto dexClClass = env->FindClass("dalvik/system/InMemoryDexClassLoader");
auto dexClInit = env->GetMethodID(dexClClass, "<init>",
"(Ljava/nio/ByteBuffer;Ljava/lang/ClassLoader;)V");
auto buffer = env->NewDirectByteBuffer(dexVector.data(), dexVector.size());
auto buffer = env->NewDirectByteBuffer(classes_dex, classes_dex_len);
auto dexCl = env->NewObject(dexClClass, dexClInit, buffer, systemClassLoader);

LOGD("load class");
Expand All @@ -228,9 +216,9 @@ class PlayIntegrityFix : public zygisk::ModuleBase {
}
};

static std::vector<uint8_t> readFile(const char *path) {
static std::vector<char> readFile(const char *path) {

std::vector<uint8_t> vector;
std::vector<char> vector;

FILE *file = fopen(path, "rb");

Expand All @@ -250,25 +238,19 @@ static std::vector<uint8_t> readFile(const char *path) {
}

static void companion(int fd) {
long size = 0;
std::vector<char> vector;

std::vector<uint8_t> dexVector, jsonVector;

dexVector = readFile(CLASSES_DEX);

jsonVector = readFile(PIF_JSON);

if (jsonVector.empty()) jsonVector = readFile(PIF_JSON_DEFAULT);
vector = readFile(PIF_JSON);

long dexSize = dexVector.size();
long jsonSize = jsonVector.size();
if (vector.empty()) vector = readFile(PIF_JSON_DEFAULT);

xwrite(fd, &dexSize, sizeof(long));
xwrite(fd, &jsonSize, sizeof(long));
size = vector.size();

xwrite(fd, dexVector.data(), dexSize);
xwrite(fd, jsonVector.data(), jsonSize);
xwrite(fd, &size, sizeof(long));
xwrite(fd, vector.data(), size);
}

REGISTER_ZYGISK_MODULE(PlayIntegrityFix)

REGISTER_ZYGISK_COMPANION(companion)
REGISTER_ZYGISK_COMPANION(companion)
Loading

0 comments on commit ecd3b82

Please sign in to comment.