Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question Encrypt il2cpp's global-metadata.dat,but not work on ios

Discussion in 'Editor & General Support' started by BlazeAndIce, Jun 11, 2020.

  1. BlazeAndIce

    BlazeAndIce

    Joined:
    Feb 8, 2014
    Posts:
    1
    I want to encrypt the file global-metadata.dat, So I encrypt it after the xcode and Android project was exported.Then I modify MetadataLoader.cpp in unity installed folder.The path is:
    android:\Editor\Data\il2cpp\libil2cpp\vm\MetadataLoader.cpp
    Mac:Unity.app\Contents\il2cpp\libil2cpp\vm\MetadataLoader.cpp
    I add decryption code in the function LoadMetadataFile
    It works well on Android,but it doesn't work on ios. It's like the decryption code never runs.Why?
    Code (CSharp):
    1. void* MetadataLoader::LoadMetadataFile(const char* fileName)
    2. {
    3.     std::string resourcesDirectory = utils::PathUtils::Combine(utils::Runtime::GetDataDir(), utils::StringView<char>("Metadata"));
    4.  
    5.     std::string resourceFilePath = utils::PathUtils::Combine(resourcesDirectory, utils::StringView<char>(fileName, strlen(fileName)));
    6.  
    7.     int error = 0;
    8.     FileHandle* handle = File::Open(resourceFilePath, kFileModeOpen, kFileAccessRead, kFileShareRead, kFileOptionsNone, &error);
    9.     if (error != 0)
    10.         return NULL;
    11.  
    12.     void* fileBuffer = utils::MemoryMappedFile::Map(handle);
    13.  
    14.     File::Close(handle, &error);
    15.     if (error != 0)
    16.     {
    17.         utils::MemoryMappedFile::Unmap(fileBuffer);
    18.         fileBuffer = NULL;
    19.         return NULL;
    20.     }
    21.     // decryption code
    22.     int64_t length = utils::MemoryMappedFile::GetLength(fileBuffer);
    23.     char* data = (char*)malloc(length);
    24.     memcpy(data, fileBuffer, length);
    25.     char* result = MetadataLoader::DecryptFile(data, length);
    26.     return (void*)result;
    27.     //return fileBuffer;
    28. }
     
    l_racher and mylifeisrush like this.
  2. MelbotStudios

    MelbotStudios

    Joined:
    Jan 29, 2018
    Posts:
    7
    When building for the iOS target, a precompiled version of libil2cpp (that is "Libraries/libil2cpp.a" in your generated XCode project) is used instead of building libil2cpp from source, so I'd say there is no quick or easy way to overcome this.
     
    l_racher and Joe-Censored like this.