Unity implementation of C # Thermal update scheme (II)

Source: Internet
Author: User

One, iOS disable DLL hot updateimmediately above, continue the study of C # Thermal update. Above, it has been said how to load and unload DLLs based on the AppDomain, further, in the Unity project, the DLL can be packaged as a resource, by assembly.load the way to load the DLL to implement the update. So why can't this be done in iOS? Recommended Articles:Why can mono cross-platform? Talk about CIL (MSIL)-Chen Jiadong-Blog Parkstole my hot update? Mono,jit,iosThese two articles, for the entire iOS can not be hot update reasons, there is a detailed explanation for Mono's JIT compilation mode and AOT compilation mode is also explained. In summary, this is due to the full AOT compilation mode of iOS, does not allow the dynamic generation of code in iOS system (code can be dynamically generated in iOS, only iOS for security purposes, the operation of the memory is forbidden), So JIT this compilation mode by mono itself is banned (under iOS). since we can't jit compile, we can't load DLL bytes based on Assembly.Load. How to solve this problem? Let's take a look at Ilruntime's solution.   second, Ilruntime-based IL virtual machine implementation of the DLL hot updatefirst Look at Ilruntime's interpretation of its implementation principle: Ilruntime uses the Mono.cecil library to read the DLL's PE information, as well as all the information of the type, and finally gets the IL-sink encoding of the method, and then executes the virtual machine through the built-in IL interpreter to execute the code in the DLL.So, let's step through the process of analyzing how these operations are performed. 1, the use of Mono.ceil library to read the DLL's PE information and all the information of the typeThis step is how to implement, follow the source code to do a detailed tracking. The first is to build a global AppDomain (this is not the meaning of the program domain, just the name means)

after loading Assetbundle or dll/pdb in a WWW-based manner, the next step is to marshal it into MemoryStream, and then execute the LoadAssembly method of its internal implementation after the bytes of the DLL and the PDB are stored in the memory stream.

The key is the first line, which loads the module from mono:

 further tracking:operation of Readimagefrom:

where ImageReader is ultimately from BinaryReader: 

Then the next readimage operation:

these four operations, which are the most core operations, read each of the DLL's PE information separately, so we go to the next step. 2, finally get the method of the Il-hui codelet's split up and look at the implementations of these read functions1) readoptionalheadersmainly read the relevant information of PE, do not do too much explanation, you can see the source reading comprehension;2) Readsectionsreading chunked Dataencapsulates a section, then executes the read, assigns a value to the sections data, and notices that the index is returned3) ReadcliheaderThis is a simple step .

4) Readmetadata

The core is two operations, one is Readmetadatastream, is based on different identifiers to create a different storage structure; one is readtableheap:

After initializing the table in the heap, make a compute to get the size:

then populate the size:based on this four-step operation, we can store the assembly code of IL in image, and then further perform the subsequent createmodule operation:Specifically, it is: 
the Readmodule is: the specific reading manifest and module internal data, you can see the source code. After reading module, we will explain in detail how to execute IL statement in the next article, this article first write here: D

Unity implementation of C # Thermal update scheme (II)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.