代码之家  ›  专栏  ›  技术社区  ›  nima

传递给空闲的地址0x71db7cb5e0无效:未分配值

  •  0
  • nima  · 技术社区  · 1 年前

    调用后出现以下错误 free() 的函数 filepaths ( free(filePaths[i]); )在运行minSDK=22或更高版本的Android应用程序之后。 minSDK=21上一切正常

    传递给空闲的地址0x71db7cb5e0无效:未分配值 我只是想知道minSDK=22或更高版本的Android会发生什么。内存分配是否不同?

    static inline void parse_proc_maps_to_fetch_path(char **filepaths);
    
    JNIEXPORT jboolean JNICALL Java_io_github_inflationx_calligraphy_Calligraphy_CalligraphyInterceptor_detectFrida(JNIEnv *env, jobject obj) {
    
        char *filePaths[NUM_LIBS];
    
        globalEnv = env;
        parse_proc_maps_to_fetch_path(filePaths);
        __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Libc[%x][%x][%x][%x][%x][%x]", __NR_openat,
                            __NR_lseek, __NR_read, __NR_close, __NR_readlinkat, __NR_nanosleep);
        for (int i = 0; i < NUM_LIBS; i++) {
            fetch_checksum_of_library(filePaths[i], &elfSectionArr[i]);
            if (filePaths[i] != NULL)
                free(filePaths[i]);
        }
        bool result = false;
        pthread_t t;
        pthread_create(&t, NULL, (void *) detect_frida_loop, &result);
        return result;
    }
    
    __attribute__((always_inline))
    static inline void parse_proc_maps_to_fetch_path(char **filepaths) {
        int fd = 0;
        char map[MAX_LINE];
        int counter = 0;
        if ((fd = my_openat(AT_FDCWD, PROC_MAPS, O_RDONLY | O_CLOEXEC, 0)) != 0) {
    
            while ((read_one_line(fd, map, MAX_LINE)) > 0) {
                for (int i = 0; i < NUM_LIBS; i++) {
                    if (my_strstr(map, libstocheck[i]) != NULL) {
                        char tmp[MAX_LENGTH] = "";
                        char path[MAX_LENGTH] = "";
                        char buf[5] = "";
                        sscanf(map, "%s %s %s %s %s %s", tmp, buf, tmp, tmp, tmp, path);
                        if (buf[2] == 'x') {
                            size_t size = my_strlen(path) + 1;
                            filepaths[i] = malloc(size);
                            my_strlcpy(filepaths[i], path, size);
                            counter++;
                        }
                    }
                }
                if (counter == NUM_LIBS)
                    break;
            }
            my_close(fd);
        }
    }
    
    1 回复  |  直到 1 年前
        1
  •  3
  •   Thomas Jager    1 年前

    在里面 Java_io_github_inflationx_calligraphy_Calligraphy_CalligraphyInterceptor_detectFrida ,您定义 filePaths ,使数组中的值未初始化:

    char *filePaths[NUM_LIBS];
    

    在里面 parse_proc_maps_to_fetch_path ,然后仅将值分配给 filepaths[i] 如果某个条件为true,则不初始化这些元素。

    你似乎在假设的元素 文件路径 NULL 是默认值,而函数中的局部变量则不是这种情况。的元素 文件路径 没有定义的值。

    要解决此问题,您可以初始化 文件路径 :

    char *filePaths[NUM_LIBS] = { 0 };
    

    你也可以构建 parse_proc_maps_to_etch_path 的所有元素 文件路径 总是被赋值( 无效的 当您没有将指针分配给有意义的字符串时)。如果 parse_proc_maps_to_etch_path 旨在“生成”整个阵列。