Perfare / Zygisk-Il2CppDumper

Using Zygisk to dump il2cpp data at runtime
MIT License
2.31k stars 6k forks source link

傳回byte[]的max_length不準確 導致讀取時崩潰 #149

Open benwong01f611 opened 1 year ago

benwong01f611 commented 1 year ago

遊戲內有個解密函數傳回byte[],已經成功調用,但寫出到檔案時就崩潰了。程式如下:


typedef Il2CppArray *(*GetBytes)(Il2CppString *);

// method為解蜜函數
auto ptr = ((GetBytes) method->methodPointer)(
    il2cpp_string_new("/path/to/encrypted/file")
);

auto outPath = "/path/to/write/out";
std::ofstream outStream(outPath, std::ios::binary);

auto rawData = ptr->vector;
for (int j = 0; j < ptr->max_length; ++j) {
    LOGD("Writing chunk...");
    outStream.write(reinterpret_cast<char*>(&rawData[j]), 8);
    LOGD("Chunk complete");
}
LOGD("Write complete");
outStream.close();
LOGD("Stream close");

去到某個位置顯示Writing chunk...後就崩了,我推算是因為寫出的長度為8,但資料長度並不能整除8,所以導致崩潰。會有甚麼方法能得知byte[]正確的長度嗎?

而且部分vector內有很多\x00,導致寫出的檔案末段也有很多\x00,但用AssetStudio解包是沒有問題的。

=====更新===== 長度為879347的bytes到200000左右就崩了,出現SIGSERV,所以應該是ptr->max_length不準確