|
9 | 9 | #include "zip/shadow_zip.h" |
10 | 10 | #include "xhook/xhook.h" |
11 | 11 | #include "io_github_noodle1983_Boostrap.h" |
| 12 | +#include "mymap32.h" |
12 | 13 |
|
13 | 14 | struct GlobalData |
14 | 15 | { |
15 | | - std::map<int, FILE*> g_fd_to_file; |
16 | | - std::map<FILE*, ShadowZip*> g_file_to_shadowzip; |
| 16 | + /*std::map<int, FILE*>*/MyMap32 g_fd_to_file; |
| 17 | + /*std::map<FILE*, ShadowZip*>*/MyMap32 g_file_to_shadowzip; |
17 | 18 | PthreadRwMutex g_file_to_shadowzip_mutex; |
18 | 19 | }; |
19 | 20 | #define g_global_data (LeakSingleton<GlobalData, 0>::instance()) |
@@ -45,7 +46,10 @@ JNIEXPORT void JNICALL Java_io_github_noodle1983_Boostrap_init |
45 | 46 | jenv->ReleaseStringUTFChars(path, data_file_path); |
46 | 47 | MY_INFO("data file path:%s", g_data_file_path); |
47 | 48 |
|
| 49 | + //all leak |
48 | 50 | LeakSingleton<GlobalData, 0>::init(); |
| 51 | + g_global_data->g_fd_to_file.init(4096, 4096, "fd_to_file"); |
| 52 | + g_global_data->g_file_to_shadowzip.init(8192, 8192, "file_to_shadowzip"); |
49 | 53 | bootstrap(); |
50 | 54 | } |
51 | 55 |
|
@@ -539,19 +543,20 @@ static int my_stat(const char *path, struct stat *file_stat) |
539 | 543 | static ShadowZip* get_cached_shadowzip(FILE *stream) |
540 | 544 | { |
541 | 545 | PthreadReadGuard(g_global_data->g_file_to_shadowzip_mutex); |
542 | | - std::map<FILE*, ShadowZip*>::iterator it = g_global_data->g_file_to_shadowzip.find(stream); |
543 | | - ShadowZip* shadow_zip = (it == g_global_data->g_file_to_shadowzip.end()) ? NULL : it->second; |
| 546 | + ShadowZip* shadow_zip = NULL; |
| 547 | + g_global_data->g_file_to_shadowzip.find((intptr_t)stream, (intptr_t&)shadow_zip); |
544 | 548 | return shadow_zip; |
545 | 549 | } |
546 | 550 |
|
547 | 551 | static ShadowZip* get_cached_shadowzip(int fd) |
548 | 552 | { |
549 | 553 | PthreadReadGuard(g_global_data->g_file_to_shadowzip_mutex); |
550 | | - std::map<int, FILE*>::iterator it_fd = g_global_data->g_fd_to_file.find(fd); |
551 | | - FILE* stream = (it_fd == g_global_data->g_fd_to_file.end()) ? NULL : it_fd->second; |
| 554 | + FILE * stream = NULL; |
| 555 | + g_global_data->g_fd_to_file.find((intptr_t)fd, (intptr_t&)stream); |
552 | 556 | if (stream == NULL){return NULL;} |
553 | | - std::map<FILE*, ShadowZip*>::iterator it = g_global_data->g_file_to_shadowzip.find(stream); |
554 | | - ShadowZip* shadow_zip = (it == g_global_data->g_file_to_shadowzip.end()) ? NULL : it->second; |
| 557 | + |
| 558 | + ShadowZip* shadow_zip = NULL; |
| 559 | + g_global_data->g_file_to_shadowzip.find((intptr_t)stream, (intptr_t&)shadow_zip); |
555 | 560 | return shadow_zip; |
556 | 561 | } |
557 | 562 |
|
@@ -586,7 +591,7 @@ static FILE *my_fopen(const char *path, const char *mode) |
586 | 591 |
|
587 | 592 | MY_LOG("shadow apk in fopen: %s, fd:0x%08x, file*: 0x%08llx", path, fileno(fp), (unsigned long long)fp); |
588 | 593 | PthreadWriteGuard(g_global_data->g_file_to_shadowzip_mutex); |
589 | | - g_global_data->g_file_to_shadowzip[fp] = shadow_zip; |
| 594 | + g_global_data->g_file_to_shadowzip.set((intptr_t)fp, (intptr_t)shadow_zip); |
590 | 595 | return fp; |
591 | 596 | } |
592 | 597 |
|
@@ -667,27 +672,25 @@ static int my_fclose(FILE* stream) |
667 | 672 | MY_METHOD("my_fclose: file*: 0x%08llx", (unsigned long long)stream); |
668 | 673 |
|
669 | 674 | ShadowZip* shadow_zip = NULL; |
670 | | - { |
| 675 | + { |
671 | 676 | PthreadWriteGuard(g_global_data->g_file_to_shadowzip_mutex); |
672 | | - std::map<FILE*, ShadowZip*>::iterator it = g_global_data->g_file_to_shadowzip.find(stream); |
673 | | - shadow_zip = (it == g_global_data->g_file_to_shadowzip.end()) ? NULL : it->second; |
674 | | - if (it != g_global_data->g_file_to_shadowzip.end()){ |
675 | | - g_global_data->g_file_to_shadowzip.erase(it); |
676 | | - } |
677 | | - |
678 | | - int fd = fileno(stream); |
679 | | - MY_METHOD("my_fclose: fd: 0x%08x, file*: 0x%08llx", fd, (unsigned long long)stream); |
680 | | - std::map<int, FILE*>::iterator it_fd = g_global_data->g_fd_to_file.find(fd); |
681 | | - if(it_fd != g_global_data->g_fd_to_file.end()) |
| 677 | + if (g_global_data->g_file_to_shadowzip.find((intptr_t)stream, (intptr_t &)shadow_zip)) |
682 | 678 | { |
683 | | - g_global_data->g_fd_to_file.erase(it_fd); |
| 679 | + g_global_data->g_file_to_shadowzip.del((intptr_t)stream); |
| 680 | + |
| 681 | + int fd = fileno(stream); |
| 682 | + MY_METHOD("my_fclose: fd: 0x%08x, file*: 0x%08llx", fd, (unsigned long long)stream); |
| 683 | + g_global_data->g_fd_to_file.del((intptr_t)fd); |
684 | 684 | } |
| 685 | + |
685 | 686 | } |
686 | 687 |
|
687 | 688 | if (shadow_zip == NULL){ |
688 | 689 | return old_fclose(stream); |
689 | 690 | }else{ |
690 | | - return shadow_zip->fclose(stream); |
| 691 | + int ret = shadow_zip->fclose(stream); |
| 692 | + delete shadow_zip; |
| 693 | + return ret; |
691 | 694 | } |
692 | 695 | } |
693 | 696 |
|
@@ -752,8 +755,8 @@ static int my_open(const char *path, int flags, ...) |
752 | 755 |
|
753 | 756 | MY_LOG("shadow apk: %s, fd:0x%08x, file*: 0x%08llx", path, fd, (unsigned long long)fp); |
754 | 757 | PthreadWriteGuard(g_global_data->g_file_to_shadowzip_mutex); |
755 | | - g_global_data->g_fd_to_file[fd] = fp; |
756 | | - g_global_data->g_file_to_shadowzip[fp] = shadow_zip; |
| 758 | + g_global_data->g_fd_to_file.set((intptr_t)fd, (intptr_t)fp); |
| 759 | + g_global_data->g_file_to_shadowzip.set((intptr_t)fp, (intptr_t)shadow_zip); |
757 | 760 | return fd; |
758 | 761 | } |
759 | 762 |
|
@@ -827,23 +830,25 @@ static int my_close(int fd) |
827 | 830 | ShadowZip* shadow_zip = NULL; |
828 | 831 | { |
829 | 832 | PthreadWriteGuard(g_global_data->g_file_to_shadowzip_mutex); |
830 | | - std::map<int, FILE*>::iterator it_fd = g_global_data->g_fd_to_file.find(fd); |
831 | | - FILE* stream = (it_fd == g_global_data->g_fd_to_file.end()) ? NULL : it_fd->second; |
832 | | - if (stream == NULL){return old_close(fd);} |
833 | | - g_global_data->g_fd_to_file.erase(it_fd); |
834 | | - |
835 | | - MY_METHOD("my_close: fd: 0x%08x, file*: 0x%08llx", fd, (unsigned long long)stream); |
836 | | - std::map<FILE*, ShadowZip*>::iterator it = g_global_data->g_file_to_shadowzip.find(stream); |
837 | | - shadow_zip = (it == g_global_data->g_file_to_shadowzip.end()) ? NULL : it->second; |
838 | | - if (it != g_global_data->g_file_to_shadowzip.end()){ |
839 | | - g_global_data->g_file_to_shadowzip.erase(it); |
840 | | - } |
| 833 | + FILE* stream = NULL; |
| 834 | + if(g_global_data->g_fd_to_file.find((intptr_t)fd, (intptr_t &)stream)) |
| 835 | + { |
| 836 | + g_global_data->g_fd_to_file.del((intptr_t)fd); |
| 837 | + |
| 838 | + MY_METHOD("my_close: fd: 0x%08x, file*: 0x%08llx", fd, (unsigned long long)stream); |
| 839 | + if (g_global_data->g_file_to_shadowzip.find((intptr_t)stream, (intptr_t &)shadow_zip)) |
| 840 | + { |
| 841 | + g_global_data->g_file_to_shadowzip.del((intptr_t)stream); |
| 842 | + } |
| 843 | + } |
841 | 844 | } |
842 | 845 |
|
843 | 846 | if (shadow_zip == NULL){ |
844 | 847 | return old_close(fd); |
845 | 848 | }else{ |
846 | | - return shadow_zip->fclose((FILE*)(size_t)fd); |
| 849 | + int ret = shadow_zip->fclose((FILE*)(size_t)fd); |
| 850 | + delete shadow_zip; |
| 851 | + return ret; |
847 | 852 | } |
848 | 853 | } |
849 | 854 |
|
|
0 commit comments