[CLR Vir C #] _ CLR execution model of Dongfeng brother Series)

Source: Internet
Author: User
Tags reflector hosting
Lessons learned

The CLR execution model is almost ruined by bloggers. I will not talk much about it anymore. The following links are provided:

    • Debuglzq [CLR execution model] How is A. NET application executed?

Comment: This guy basically copied it from the book and did not have any opinions of his own. See this article.ArticleSee zhenshu for example.

    • Liudong cainiao CLR via C # Journey (1): taste details, CLR execution model

Comment: This Article is good, especially for the. NET specifications and implementation. After reading the two pictures and the instructions below, you will understand what is. net. Finally, this "cainiao" guy is a realProgramMembers, the majority of programmers and friends should learn more from him! But unfortunately, after writing this article, he will not be updated later.

    • With Xiaojing reading CLR via C # (01)-How does the code run on the. NET platform?

Comments: The Standard Notes for Chinese education written by lesbians.

A. What is. Net?

Speaking of. net, it is no stranger to anyone. In general,. Net in our mouth refers to Microsoft's. NET strategy, which includes two parts: specification and implementation. The figure below is rewritten based on the figure of liudong. It may make us better understand the true meaning of. net.

In fact, it can be seen that a specification is like a set of interfaces. You just need to use. Net on that platform to implement this framework. What are the benefits of doing so? That's right, it's cross-platform. This is a big highlight that Microsoft once advocated, but later I saw it on Windows.. net, later on other platforms. net was used by Novell (monotouch on the current popular iPhone, mono on Linux and Android ). Make your C #CodeIt can run on different platforms with a few modifications. In fact, mixed programming is another advantage of this specification. Compilers in different languages developed using the defined common type systems (CTS) and common language standards (CLS, the generated il intermediate language code can be seamlessly connected with the Il intermediate code generated by other languages. This is two major benefits of standardization.

Here we will talk about mixed programming. Why hybrid programming? Hybrid programming means that a project is written in a mix of multiple languages. Assume that there is a cost project, and a complicated calculation using C # may lead to low efficiency. Using C ++ at this time is undoubtedly a clear choice, or the use of Perl in the string processing module may be more efficient in development, or the use of APL in financial computing is easier to implement. NET provides this function to allow your project to support mixed development in multiple languages. Finally, each module generates a standard IL intermediate language. But the premise is that you are using a. Net-based compiler. Currently supported. net Language: In addition to common C #, C ++, iron python, iron Ruby, Ada, APL, caml, COBOL, Eiffel, forth, Fortran, Haskell, lexico, LISP, logo, Lua, mercury, ML, Mondrian, Oberon, Pascal, Perl, PHP, Prolog, RPG, scheme, smalltalk, Tcl/tk ...... Unfortunately, this feature is almost ignored.

This should also be the right sentence: first-class enterprises sell standards, second-class enterprises sell brands, and third-class enterprises sell products. I wonder how many streams your company is?

For the concepts related to the CLI, CTS, CLS, CER, CLR, and FCL mentioned above, you can refer to this article:

Liudong cainiao CLR via C # Journey (1): taste details, CLR execution model

Finally, I used a picture of cainiao's brother:

The following figure shows the relationships between concepts.

How does B. Net program run?

First look at a figure:

Taking a financial project as an example, I wrote the entire framework in C #, wrote N categories, created n files, and VB wrote some interfaces and generated n files, python writes the script and generates n files. As for the advantages of multi-language mixed programming, we have already discussed it. If you click 'generation ', what will happen to the system? First, generate a hosting module for each file (as described below ).

The connector will be connected to the connector (al.exe. For more in-depth Compiler Principles, please refer to the university computer course "compilation principles", which is a very painful course for you) package the package together into the final target file DLL or EXE (you can configure the generated type on the project properties page ). This is a rough compilation process.

C. What is a hosting module?

The concept of a managed module is often mixed with an assembly at the beginning. Jeff lazy often says, "the CLR does not work with the hosting module, but with the Assembly ".

The monks think: the hosting module is just one of youSource codeAnother high-level encapsulated file generated by the corresponding language compiler contains more information (PS: if you have read the original book, then the author will teach you how to generate a suffix. netmodular hosting module ). An assembly is a Windows Executable body composed of multiple hosted modules and resource files.

Well, let's not mention the figure of a rookie brother first:

The figure above shows that a managed module contains the pe32/pe32 + header, CLR header, metadata, and IL code.

The following describes the four concepts:

One more thing about metadata is that when we press code and Press X, we can generate a smart induction like xxxxxo, which is identified by the compiled metadata, metadata is equivalent to an upgraded version of the previous C ++ header file. It extracts all the public attributes, public methods, and interfaces in your source code file. The convenience of this approach is not explained much. Intelligent Sensing is just one of them.

D. Hide chapter: il and Decompilation

Speaking of Il, it reminds me not only of Zhao's:

Old Zhao tan il (1): What is Il, and what is it? So what about assembly?

Old Zhao tan il (2): there are too many things that IL cannot see inside the CLR, including the things you must know at ordinary times.

Lao Zhao talked about il (3): Most of the things that Il can see can also be found in C #.

I will not talk about it much, but I will be sprayed by Zhao once I talk about it.

In fact, CLR is similar to an operating system, but it runs on Windows, so CLR also has a unified assembly language, that is, IL. In addition, the compiler in our mouth is to convert the source code you write into the Il language recognized by CLR in a unified manner, which also reflects a highly encapsulated process. For this compilation process: there are also many unknown conversions (I don't know since I am not familiar with it), such as removing comments and optimizing code.

In international practice, come to helloworld:

In order to obtain the compiled Il, we must use a decompilation artifact reflector, which is probably known to everyone on earth (if you do not know or cannot find the cracked version, please slam here to reflector7.3 with plug-in cracked version ).

This is its interface. You only need to drag the EXE or DLL into it, that is, drag and drop.

 

As for the Il code, I will not explain it more. If you are interested in children's shoes, you can refer to relevant materials or read the original book's explanations.

Let's take a look at the decompiled C # code: Select C # from the drop-down list.

 
Private Static voidMain(String [] ARGs) {console. writeline ("helloworld! ");}
 
 

We can see that the decompilation result does not have the I definition or assignment. But in fact, this part of the code still exists in the Il code. For example: L-0003: LDC, I4, 3 is the I value assignment statement, so do not misunderstand when generating Il, the compiler is automatically optimized (it is estimated that it was optimized when reflector decompiled the Il code, but what about it ?).

At this time, it is estimated that some children's shoes will say: ah? Fortunately, the code was hardened by the overlord of reflector. If you re-compile an interface based on the source code, but add the DLL of malicious code in the implementation to replace the original DLL for distribution, then everyone will understand it later... ....

Various mysteries and defense techniques are coming to the next chapter: weak naming assembly and strong naming assembly.

Finally, I wrote a novel: this series of courses was originally my 30-minute training course every day before I got off work, so I also attached a PPT: CLR Vir C # [1] _ execution model.

Related Article

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.