66#include < fcntl.h>
77#include < vector>
88#include < cerrno>
9- #include < filesystem>
109#include < sys/stat.h>
11- #include < fcntl.h>
12- #include < vector>
1310#include " checksum.h"
1411
1512#define LOGD (...) __android_log_print(ANDROID_LOG_DEBUG, " PIF" , __VA_ARGS__)
@@ -75,16 +72,35 @@ static ssize_t xwrite(int fd, const void *buffer, size_t count_to_write) {
7572}
7673
7774static bool copyFile (const std::string &from, const std::string &to, mode_t perms = 0777 ) {
78- return std::filesystem::exists (from) &&
79- std::filesystem::copy_file (
80- from,
81- to,
82- std::filesystem::copy_options::overwrite_existing
83- ) &&
84- !chmod (
85- to.c_str (),
86- perms
87- );
75+ int src = open (from.c_str (), O_RDONLY);
76+ if (src < 0 ) return false ;
77+
78+ int dst = open (to.c_str (), O_WRONLY | O_CREAT | O_TRUNC, perms);
79+ if (dst < 0 ) {
80+ close (src);
81+ return false ;
82+ }
83+
84+ char buffer[4096 ];
85+ ssize_t n;
86+ bool ok = true ;
87+ while ((n = xread (src, buffer, sizeof (buffer))) > 0 ) {
88+ if (xwrite (dst, buffer, n) != n) {
89+ ok = false ;
90+ break ;
91+ }
92+ }
93+
94+ if (n < 0 ) ok = false ;
95+
96+ close (src);
97+ close (dst);
98+
99+ if (ok) {
100+ chmod (to.c_str (), perms);
101+ }
102+
103+ return ok;
88104}
89105
90106static uint32_t crc32 (const uint8_t *data, size_t len) {
@@ -132,13 +148,11 @@ static bool verifyModule(const char *path, const char *expected_hex) {
132148 std::vector<std::string> lines;
133149 std::string file_str (buf.begin (), buf.end ());
134150 size_t pos = 0 ;
135- bool found = false ;
136151 while (pos < file_str.size ()) {
137152 size_t next = file_str.find (' \n ' , pos);
138153 std::string line = file_str.substr (pos, next - pos + 1 );
139154 if (line.rfind (" description=" , 0 ) == 0 ) {
140155 line = " description=❌ This module has been tampered, please install from official source.\n " ;
141- found = true ;
142156 }
143157 lines.push_back (line);
144158 if (next == std::string::npos) break ;
@@ -310,4 +324,4 @@ class PlayIntegrityFix : public ModuleBase {
310324
311325REGISTER_ZYGISK_MODULE (PlayIntegrityFix)
312326
313- REGISTER_ZYGISK_COMPANION(companion)
327+ REGISTER_ZYGISK_COMPANION(companion)
0 commit comments