Handle reading file properly

This commit is contained in:
shìwēi nguyen 2023-11-27 00:32:01 +07:00 committed by GitHub
parent b72efd6f71
commit 98bd06eb44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
#include <android/log.h>
#include <sys/system_properties.h>
#include <unistd.h>
#include <stdlib.h>
#include "zygisk.hpp"
#include "shadowhook.h"
@ -214,26 +215,34 @@ private:
static void companion(int fd) {
FILE *dex = fopen(DEX_FILE_PATH, "rb");
long dexSize = 0;
char *dexBuffer = nullptr;
long jsonSize = 0;
char *jsonBuffer = nullptr;
fseek(dex, 0, SEEK_END);
long dexSize = ftell(dex);
fseek(dex, 0, SEEK_SET);
if (dex) {
fseek(dex, 0, SEEK_END);
dexSize = ftell(dex);
fseek(dex, 0, SEEK_SET);
char dexBuffer[dexSize];
fread(dexBuffer, 1, dexSize, dex);
dexBuffer = (char*)calloc(1, dexSize);
fread(dexBuffer, 1, dexSize, dex);
fclose(dex);
fclose(dex);
}
FILE *json = fopen(JSON_FILE_PATH, "r");
fseek(json, 0, SEEK_END);
long jsonSize = ftell(json);
fseek(json, 0, SEEK_SET);
if (json) {
fseek(json, 0, SEEK_END);
jsonSize = ftell(json);
fseek(json, 0, SEEK_SET);
char jsonBuffer[jsonSize];
fread(jsonBuffer, 1, jsonSize, json);
jsonBuffer = (char*)calloc(1, jsonSize);
fread(jsonBuffer, 1, jsonSize, json);
fclose(json);
fclose(json);
}
dexBuffer[dexSize] = 0;
jsonBuffer[jsonSize] = 0;
@ -243,9 +252,12 @@ static void companion(int fd) {
write(fd, &jsonSize, sizeof(long));
write(fd, jsonBuffer, jsonSize);
free(dexBuffer);
free(jsonBuffer);
}
REGISTER_ZYGISK_MODULE(PlayIntegrityFix)
REGISTER_ZYGISK_COMPANION(companion)
REGISTER_ZYGISK_COMPANION(companion)