update c++ logic

This commit is contained in:
chiteroman 2025-01-20 23:15:05 +01:00
parent 663f8dc035
commit c9fc5b8073

View File

@ -3,6 +3,10 @@
#include <unistd.h> #include <unistd.h>
#include "zygisk.hpp" #include "zygisk.hpp"
#include "dobby.h" #include "dobby.h"
#define JSON_NOEXCEPTION 1
#define JSON_NO_IO 1
#include "json.hpp" #include "json.hpp"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "PIF", __VA_ARGS__) #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "PIF", __VA_ARGS__)
@ -10,12 +14,12 @@
#define DEX_PATH "/data/adb/modules/playintegrityfix/classes.dex" #define DEX_PATH "/data/adb/modules/playintegrityfix/classes.dex"
#define PIF_JSON "/data/adb/pif.json"
#define PIF_JSON_DEFAULT "/data/adb/modules/playintegrityfix/pif.json"
#define TS_PATH "/data/adb/modules/tricky_store" #define TS_PATH "/data/adb/modules/tricky_store"
#define DEFAULT_JSON "/data/adb/modules/playintegrityfix/pif.json"
#define CUSTOM_JSON_FORK "/data/adb/modules/playintegrityfix/custom.pif.json"
#define CUSTOM_JSON "/data/adb/pif.json"
static inline ssize_t xread(int fd, void *buffer, size_t count) { static inline ssize_t xread(int fd, void *buffer, size_t count) {
auto *buf = static_cast<char *>(buffer); auto *buf = static_cast<char *>(buffer);
ssize_t total = 0; ssize_t total = 0;
@ -186,33 +190,33 @@ public:
int fd = api->connectCompanion(); int fd = api->connectCompanion();
int dexSize = 0, jsonSize = 0; size_t dexSize = 0, jsonSize = 0;
std::string jsonStr; std::string jsonStr;
xread(fd, &dexSize, sizeof(dexSize)); xread(fd, &dexSize, sizeof(size_t));
xread(fd, &jsonSize, sizeof(jsonSize)); xread(fd, &jsonSize, sizeof(size_t));
if (dexSize > 0) { if (dexSize > 0) {
dexVector.resize(dexSize); dexVector.resize(dexSize);
xread(fd, dexVector.data(), dexSize * sizeof(uint8_t)); xread(fd, dexVector.data(), dexSize);
} }
if (jsonSize > 0) { if (jsonSize > 0) {
jsonStr.resize(jsonSize); jsonStr.resize(jsonSize);
xread(fd, jsonStr.data(), jsonSize * sizeof(uint8_t)); xread(fd, jsonStr.data(), jsonSize);
json = nlohmann::json::parse(jsonStr, nullptr, false, true); json = nlohmann::json::parse(jsonStr, nullptr, false, true);
} }
bool trickyStore = false; bool trickyStore = false;
xread(fd, &trickyStore, sizeof(trickyStore)); xread(fd, &trickyStore, sizeof(bool));
bool testSignedRom = false; bool testSignedRom = false;
xread(fd, &testSignedRom, sizeof(testSignedRom)); xread(fd, &testSignedRom, sizeof(bool));
close(fd); close(fd);
LOGD("Dex file size: %d", dexSize); LOGD("Dex file size: %ld", dexSize);
LOGD("Json file size: %d", jsonSize); LOGD("Json file size: %ld", jsonSize);
parseJSON(); parseJSON();
@ -259,7 +263,7 @@ public:
private: private:
zygisk::Api *api = nullptr; zygisk::Api *api = nullptr;
JNIEnv *env = nullptr; JNIEnv *env = nullptr;
std::vector<uint8_t> dexVector; std::vector<char> dexVector;
nlohmann::json json; nlohmann::json json;
bool spoofProps = true; bool spoofProps = true;
bool spoofProvider = true; bool spoofProvider = true;
@ -441,15 +445,16 @@ private:
} }
}; };
static std::vector<uint8_t> readFile(const char *path) { static std::vector<char> readFile(const char *path) {
FILE *file = fopen(path, "rb"); FILE *file = fopen(path, "rb");
if (!file) return {}; if (!file) return {};
int size = static_cast<int>(std::filesystem::file_size(path)); fseek(file, 0, SEEK_END);
long size = ftell(file);
std::vector<uint8_t> vector(size); fseek(file, 0, SEEK_SET);
std::vector<char> vector(size);
fread(vector.data(), 1, size, file); fread(vector.data(), 1, size, file);
fclose(file); fclose(file);
@ -479,40 +484,42 @@ static bool checkOtaZip() {
static void companion(int fd) { static void companion(int fd) {
std::vector<uint8_t> dex, json; std::vector<char> dex, json;
if (std::filesystem::exists(DEX_PATH)) { if (std::filesystem::exists(DEX_PATH)) {
dex = readFile(DEX_PATH); dex = readFile(DEX_PATH);
} }
if (std::filesystem::exists(PIF_JSON)) { if (std::filesystem::exists(CUSTOM_JSON)) {
json = readFile(PIF_JSON); json = readFile(CUSTOM_JSON);
} else if (std::filesystem::exists(PIF_JSON_DEFAULT)) { } else if (std::filesystem::exists(CUSTOM_JSON_FORK)) {
json = readFile(PIF_JSON_DEFAULT); json = readFile(CUSTOM_JSON_FORK);
} else if (std::filesystem::exists(DEFAULT_JSON)) {
json = readFile(DEFAULT_JSON);
} }
int dexSize = static_cast<int>(dex.size()); size_t dexSize = dex.size();
int jsonSize = static_cast<int>(json.size()); size_t jsonSize = json.size();
xwrite(fd, &dexSize, sizeof(dexSize)); xwrite(fd, &dexSize, sizeof(size_t));
xwrite(fd, &jsonSize, sizeof(jsonSize)); xwrite(fd, &jsonSize, sizeof(size_t));
if (dexSize > 0) { if (dexSize > 0) {
xwrite(fd, dex.data(), dexSize * sizeof(uint8_t)); xwrite(fd, dex.data(), dexSize);
} }
if (jsonSize > 0) { if (jsonSize > 0) {
xwrite(fd, json.data(), jsonSize * sizeof(uint8_t)); xwrite(fd, json.data(), jsonSize);
} }
std::string ts(TS_PATH); std::string ts(TS_PATH);
bool trickyStore = std::filesystem::exists(ts) && bool trickyStore = std::filesystem::exists(ts) &&
!std::filesystem::exists(ts + "/disable") && !std::filesystem::exists(ts + "/disable") &&
!std::filesystem::exists(ts + "/remove"); !std::filesystem::exists(ts + "/remove");
xwrite(fd, &trickyStore, sizeof(trickyStore)); xwrite(fd, &trickyStore, sizeof(bool));
bool testSignedRom = checkOtaZip(); bool testSignedRom = checkOtaZip();
xwrite(fd, &testSignedRom, sizeof(testSignedRom)); xwrite(fd, &testSignedRom, sizeof(bool));
} }
REGISTER_ZYGISK_MODULE(PlayIntegrityFix) REGISTER_ZYGISK_MODULE(PlayIntegrityFix)