mirror of
https://github.com/chiteroman/PlayIntegrityFix.git
synced 2025-01-19 11:32:39 +02:00
Fix JSON parsing and reformat code
This commit is contained in:
parent
8eaa0f2490
commit
599c27e833
@ -1,7 +1,6 @@
|
|||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#include <sys/system_properties.h>
|
#include <sys/system_properties.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "zygisk.hpp"
|
#include "zygisk.hpp"
|
||||||
#include "shadowhook.h"
|
#include "shadowhook.h"
|
||||||
@ -168,13 +167,31 @@ private:
|
|||||||
std::string data(propVector.cbegin(), propVector.cend());
|
std::string data(propVector.cbegin(), propVector.cend());
|
||||||
nlohmann::json json = nlohmann::json::parse(data, nullptr, false, true);
|
nlohmann::json json = nlohmann::json::parse(data, nullptr, false, true);
|
||||||
|
|
||||||
auto getStringFromJson = [&json](const std::string &key) {
|
if (json.contains("SECURITY_PATCH")) {
|
||||||
return json.contains(key) && !json[key].is_null() ? json[key].get<std::string>()
|
if (json["SECURITY_PATCH"].is_null()) {
|
||||||
: "NULL";
|
SECURITY_PATCH = "NULL";
|
||||||
};
|
} else if (json["SECURITY_PATCH"].is_string()) {
|
||||||
|
SECURITY_PATCH = json["SECURITY_PATCH"].get<std::string>();
|
||||||
|
} else {
|
||||||
|
LOGD("Error parsing SECURITY_PATCH!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGD("Key SECURITY_PATCH doesn't exist in JSON file!");
|
||||||
|
}
|
||||||
|
|
||||||
SECURITY_PATCH = getStringFromJson("SECURITY_PATCH");
|
if (json.contains("FIRST_API_LEVEL")) {
|
||||||
FIRST_API_LEVEL = getStringFromJson("FIRST_API_LEVEL");
|
if (json["FIRST_API_LEVEL"].is_null()) {
|
||||||
|
FIRST_API_LEVEL = "NULL";
|
||||||
|
} else if (json["FIRST_API_LEVEL"].is_string()) {
|
||||||
|
FIRST_API_LEVEL = json["FIRST_API_LEVEL"].get<std::string>();
|
||||||
|
} else {
|
||||||
|
LOGD("Error parsing FIRST_API_LEVEL!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGD("Key FIRST_API_LEVEL doesn't exist in JSON file!");
|
||||||
|
}
|
||||||
|
|
||||||
|
json.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void inject() {
|
void inject() {
|
||||||
@ -214,18 +231,20 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void companion(int fd) {
|
static void companion(int fd) {
|
||||||
FILE *dex = fopen(DEX_FILE_PATH, "rb");
|
|
||||||
long dexSize = 0;
|
long dexSize = 0;
|
||||||
char *dexBuffer = nullptr;
|
char *dexBuffer = nullptr;
|
||||||
|
|
||||||
long jsonSize = 0;
|
long jsonSize = 0;
|
||||||
char *jsonBuffer = nullptr;
|
char *jsonBuffer = nullptr;
|
||||||
|
|
||||||
|
FILE *dex = fopen(DEX_FILE_PATH, "rb");
|
||||||
|
|
||||||
if (dex) {
|
if (dex) {
|
||||||
fseek(dex, 0, SEEK_END);
|
fseek(dex, 0, SEEK_END);
|
||||||
dexSize = ftell(dex);
|
dexSize = ftell(dex);
|
||||||
fseek(dex, 0, SEEK_SET);
|
fseek(dex, 0, SEEK_SET);
|
||||||
|
|
||||||
dexBuffer = (char*)calloc(1, dexSize);
|
dexBuffer = static_cast<char *>(calloc(1, dexSize));
|
||||||
fread(dexBuffer, 1, dexSize, dex);
|
fread(dexBuffer, 1, dexSize, dex);
|
||||||
|
|
||||||
fclose(dex);
|
fclose(dex);
|
||||||
@ -238,7 +257,7 @@ static void companion(int fd) {
|
|||||||
jsonSize = ftell(json);
|
jsonSize = ftell(json);
|
||||||
fseek(json, 0, SEEK_SET);
|
fseek(json, 0, SEEK_SET);
|
||||||
|
|
||||||
jsonBuffer = (char*)calloc(1, jsonSize);
|
jsonBuffer = static_cast<char *>(calloc(1, jsonSize));
|
||||||
fread(jsonBuffer, 1, jsonSize, json);
|
fread(jsonBuffer, 1, jsonSize, json);
|
||||||
|
|
||||||
fclose(json);
|
fclose(json);
|
||||||
@ -254,7 +273,6 @@ static void companion(int fd) {
|
|||||||
free(jsonBuffer);
|
free(jsonBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
REGISTER_ZYGISK_MODULE(PlayIntegrityFix)
|
REGISTER_ZYGISK_MODULE(PlayIntegrityFix)
|
||||||
|
|
||||||
REGISTER_ZYGISK_COMPANION(companion)
|
REGISTER_ZYGISK_COMPANION(companion)
|
Loading…
Reference in New Issue
Block a user