From 98bd06eb44554ea9f898b5a2ba02b89b30103355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?sh=C3=ACw=C4=93i=20nguyen?= <84650617+HuskyDG@users.noreply.github.com> Date: Mon, 27 Nov 2023 00:32:01 +0700 Subject: [PATCH] Handle reading file properly --- app/src/main/cpp/main.cpp | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/app/src/main/cpp/main.cpp b/app/src/main/cpp/main.cpp index 6e9b763..9627dbc 100644 --- a/app/src/main/cpp/main.cpp +++ b/app/src/main/cpp/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #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) \ No newline at end of file +REGISTER_ZYGISK_COMPANION(companion)