Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

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. }
     
    RPGia, 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.