luoyesiqiu / dpt-shell

An android Dex protects shell implementation
MIT License
519 stars 190 forks source link

dpt_hoop.cpp dexNumber函数里有一个函数看不懂,谁能给讲讲啊 #15

Closed soibhanZhangxb closed 1 year ago

soibhanZhangxb commented 1 year ago

//这个函数里的location看不懂???

void LoadMethod(void *thiz, void *self, const void *dex_file,  const void *it, const void *method, void *klass, void *dst) {

    //这行返回 40 ,根据api版本和是否64位来判断(64位,安卓12)
     uint32_t location_offset = getDexFileLocationOffset(); //40

      // location指向 dex 的 file_size位置
      std::string *location = (reinterpret_cast<std::string *>((uint8_t *)dex_file + location_offset));

      // 为什么会从 dex的 file_size位置开始搜索  base.apk呢,这个base.apk又是什么那里来的???
      // 【我用 010editor搜索了dex 都没有 base.apk 】
      if (location->find("base.apk") != std::string::npos) {
      }
}

// 这个函数好像是从Dex里面搜索是第几个 Dex

int dexNumber(std::string *location) {
    char buf[3] = {0};
    // 根据上面的函数,location是 dex file_size 位置,为什么要从这里搜索 .dex ??? 【我用 010editor搜索了dex 都没有 .dex 】
    if (location->find(".dex") != std::string::npos) {
        const char *chs = strchr(location->c_str(), '!'); //返回字符串从'!'开始之后的字符串
        if(nullptr != chs) {
            sscanf(chs, "%*[^0-9]%[^.]", buf);
        } else {
            const char* chs2 = strchr(location->c_str(), ':');
            if(nullptr != chs2) {
                sscanf(chs2, "%*[^0-9]%[^.]", buf);
            } else {
                sprintf(buf, "%s", "1");
            }
        }
    } else {
        sprintf(buf, "%s", "1");
    }
    int dexIndex = 0;
    sscanf(buf, "%d", &dexIndex);
    return dexIndex;
}
luoyesiqiu commented 1 year ago

LoadMethod是运行时就会调用的,你可以在运行时把location打印出来,看看它的格式,它里面就是会包含base.apk的