Reflector: Get The Secret Inside .NET Assembly.

zhaozj2021-02-16  61

Reflector: Get The Secret Inside .NET Assembly.

Updated on Friday, October 29, 2004

Writen by Allen Lee

Friends programming with .NET should know the big name of Ildasm, here is a good Dongdong called Reflector. In order to understand the Reflector, I deliberately wrote a code snippet (here only given the code written by the MAIN method written here):

Static

Void

Main

String

[] ARGS)

{List strlist = new list (); if (args.length! = 0) {FOREACH (String argin args) {switch (arg) {case "il": console.writeline ("IL" Strlist.add ("IL"); Break; Case "C #": console.writeline ("C #"); strlist.add ("c #"); break; case "vb.net": console.writeline VB.NET "); strlist.add (" vb.net "); Break; Case" Delphi ": console.writeline (" delphi "); strlist.add (" delphi "); break; default: console.writeline "Invalid option"; break;}}} else {console.writeline ("No Command Line Args!"); Console.writeline ("Press any key to end."); Console.readline ();} FOREACH (STRING STR in strlist) Console.Writeline (STR);

Compile the above code and name it REFLEctorLab.exe. Then we run the Reflector, starting its interface at:

Next, we open the menu: file | open, find and select an assembly just compiled, this assembly will be added to the program set list, open the tree of ReflectorLab, find main (string []): void this method, right click And select DisasseMbler, will get the anti-compilation code of the figure below: Now intercepting the anti-compiled MAIN method complete code as follows: Static

Void

Main

String

[] ARGS)

{List strlist = new list (); if (args.length! = 0) {FOREACH (String argin args) {switch (arg) {case "il": console.writeline ("IL" Strlist.add ("IL"); Break; Case "C #": console.writeline ("C #"); strlist.add ("c #"); break; case "vb.net": console.writeline VB.NET "); strlist.add (" vb.net "); Break; Case" Delphi ": console.writeline (" delphi "); strlist.add (" delphi "); break; default: console.writeline "Invalid option"; break;}}} else {console.writeline ("No Command Line Args!"); Console.writeline ("Press any key to end."); Console.readline ();} FOREACH (STRING STR in strlist) Console.Writeline (STR);

The anti-compiled code is the same as the original code, but the style of the individual thinks that the anti-compiled code is not very good, especially the goto statement, at first glance, I really fainted. The code converts the original Switch condition block to the IF condition block, replace the Foreach cycle block to the While cycle block. I guess this is because it is translated from IL, and IL is a stack-based language. There is no process control statement in IL, all of which use GOTO Label simulation, so this result.

In addition, I also found some very special things, please pay attention to this sentence: Text3 = string.isInterned (Text3); it actually reflects that the character string processing of .NET is to use a string residence ( String interface, this technology is to reduce the performance loss of the string (see "Microsoft .NET Framework Design (Revision)" on the system (detailed) "262 page 262. In addition, we see the last foreach of the original code to be translated into a try ... finally block, realize the Foreach function in Try, then automatically try to call the IDisposable interface for each Enumerator interface to release the resources, really think about it. I believe that the corresponding IL will also have the same "facility", if you know the IL, and you must not need this kind of finally here, then you can optimize it manually, huh, huh. The translated code is a bit complicated and confusing, but you can run the .NET (part) "(and this kind of peer-like original should use IL), and learn from the simple C # code, the compiler is silently I have made a lot of work for us! Finally, we will also surprise, reflector not only supports the reverse contention C #, but also supports IL, VB.NET, Delphi, this is cool, we can compare and learn these languages, before we used ILDASM to negotiate C # written Program to learn IL, now we can use the REFLEctor to negative C # written programs to learn VB.Net and Delphi! Of course, due to the problem of the space, I can't get water inside (add IL, VB.NET, Delphi anti-compilation code). In addition, you will find some places of these source code, usually the type name or method name or attribute will be a connection, press and see what is happening! Is it connected to the anti-compile code of the .NET base class library connected to this thing (type or method or attribute)?

Finally, in the end of the article, I still have a surprise to you, that is, the Reflector itself is a .NET program, which means it can also neglect itself, don't believe it, you can try it!

Oh, add a little, after you run the Reflector, it will generate a file called Reflector.cfg in its folder. This is not an XML file. It is a configuration file in INI format. Please pay attention to the file [AssemblyLoader ] Section, what is found? Ok, this time, I hope you find more things to share with me!

转载请注明原文地址:https://www.9cbs.com/read-19220.html

New Post(0)