6
6
#include < dirent.h>
7
7
#include < assert.h>
8
8
#include < string.h>
9
+ #include < fstream>
10
+ #include < set>
11
+ #include < algorithm>
9
12
10
13
using namespace android ;
11
14
@@ -38,6 +41,8 @@ static void get_files(const char* _apk_patch_path, std::vector<std::string>& _fi
38
41
closedir (dir);
39
42
}
40
43
44
+ static bool is_illegal_path_char (char ch){return ch == ' \r ' || ch == ' \n ' || ch == ' "' || ch == ' \' ' ;}
45
+
41
46
static int parse_apk (const char * _path, std::vector<ZipEntry*>& _all_entries)
42
47
{
43
48
off_t fileLength, seekStart;
@@ -322,6 +327,23 @@ int ShadowZip::init(const char* _patch_dir, const char* _sys_apk_file, ShadowZip
322
327
MY_INFO (" no apk patches:[%s/assets_bin_Data]" , _patch_dir);
323
328
return -1 ;
324
329
}
330
+
331
+ // all removed files
332
+ char removed_files_path[512 ] = {0 };
333
+ snprintf (removed_files_path, sizeof (removed_files_path), " %s/removed_files.txt" , _patch_dir );
334
+ std::set<std::string> removed_files;
335
+ std::ifstream rmfiles_stream (removed_files_path);
336
+ if (rmfiles_stream.good ()){
337
+ std::string line;
338
+ while ( std::getline ( rmfiles_stream, line ) ) {
339
+ line.erase (std::remove_if (line.begin (), line.end (), is_illegal_path_char), line.end ());
340
+ if (line.length () == 0 ){continue ;}
341
+ MY_INFO (" remove file: [%s]" , line.c_str ());
342
+ removed_files.insert (line);
343
+ }
344
+ rmfiles_stream.close ();
345
+ }
346
+
325
347
326
348
// find all entries in patches
327
349
std::vector<std::vector<ZipEntry*> > entries_in_zip_file (global_data->all_files_ .size ());
@@ -337,7 +359,7 @@ int ShadowZip::init(const char* _patch_dir, const char* _sys_apk_file, ShadowZip
337
359
return -1 ;
338
360
}
339
361
for (int j = 0 ; j < zip_entries.size (); j++)
340
- {
362
+ {
341
363
ZipEntry* entry = zip_entries[j];
342
364
entry->mUserData1 = i;
343
365
std::string filename = entry->getFileName ();
@@ -347,6 +369,11 @@ int ShadowZip::init(const char* _patch_dir, const char* _sys_apk_file, ShadowZip
347
369
clean_file_entries_map (entries_in_zip_file);
348
370
return -1 ;
349
371
}
372
+
373
+ if (removed_files.find (filename) != removed_files.end ()){
374
+ MY_LOG (" rm file:%s in %s" , filename.c_str (), zip_path.c_str ());
375
+ continue ;
376
+ }
350
377
filename_2_entry[filename] = entry;
351
378
}
352
379
}
@@ -370,7 +397,11 @@ int ShadowZip::init(const char* _patch_dir, const char* _sys_apk_file, ShadowZip
370
397
for (int i = 0 ; i < apk_entries.size (); i++)
371
398
{
372
399
ZipEntry* entry = apk_entries[i];
373
- std::string name (entry->getFileName ());
400
+ std::string name (entry->getFileName ());
401
+ if (removed_files.find (name) != removed_files.end ()){
402
+ MY_LOG (" rm file:%s in apk" , name.c_str ());
403
+ continue ;
404
+ }
374
405
std::map<std::string, ZipEntry*>::iterator it = filename_2_entry.find (name);
375
406
if (it != filename_2_entry.end ()){ entry = it->second ; }
376
407
entry->mUserData2 = 1 ;
@@ -642,6 +673,8 @@ FILE* ShadowZip::prepare_file(int _file_index)
642
673
}
643
674
MY_METHOD (" prepare_file %s -> 0x%08zx" , path.c_str (), (size_t )fp);
644
675
fp_array_[_file_index] = fp;
676
+
677
+ setvbuf ( fp , NULL , _IOFBF , 1024 );
645
678
return fp;
646
679
}
647
680
0 commit comments