Why do people parse .NET binaries (CLRs)?

I'm a little new to .NET, but not new to programming, and I'm somewhat puzzled by the trend and excitement about disassembling compiled .NET code. It seems pointless.

Ease of using .NET at a high level is the reason I use it. I wrote the assembly of C and the real (hardware processor) in resource-limited environments. It is for this reason that so much effort has been expended on such thorough detailing as efficiency. In the .NET environment, this strikes the goal of having a high-level object-oriented language if you spend time immersing yourself in the most mysterious implementation details. In the course of working with .NET, I debugged usual performance problems with odd race conditions, and I did all this by reading my own source code, without ever thinking about which intermediate language the compiler generates. For example, it’s pretty obvious that a for (;;) loop will be faster than foreach () for an array, giventhat foreach () will use an enumeration object with a method call to jump next time instead of just incrementing the variable, and this can easily be proved with a limited work cycle several million times (no disassembly is required).

What really makes IL parsing stupid is that this is not real machine code. This is the virtual machine code. I heard that some people actually like to move instructions to optimize them. Are you kidding me? The compiled virtual machine code just in time cannot even make a simple hard cycle (;;) at the speed of the originally compiled code. If you want to squeeze every last cycle from your processor, use C / C ++ and spend time studying the real assembly. Thus, the time you spend understanding a large number of low-level details will really be worth it.

So, besides the fact that they have too much time, why do people parse .NET binaries (CLR)?

+3
13

, , - , , , , , , SQL-, . , ( ) - ; ., , , " ", .

+7

, .

+2

, .

( , .net, BizTalk WCF, , #, , , )

+2

.NET CLR. , CLR , , , , IL .

, , , - , , .

+1

4- , , - . .

, .. .

, , .net . , dotfuscator.

+1

, .

: , backtrace. .

+1

, , , Reflector CLR # VB, , IL!

+1

.

, . .NET Reflector , , Microsoft FileSystemWatcher. , , FileSystemSearcher.

+1

...:)

, . , - , . , , .

, . , MIL, , , "" .

0

, , , IL, ...

0

:

  • , .
  • , .
  • , .Net. ( lc.exe )
  • .
0

, foreach int [] for. , , Enumerator. , FASTER, temp int. , ...

, , .

, , , . , .. ..

:

    static void Main(string[] args)
    {

        int[] ints = Enumerable.Repeat(1, 50000000).ToArray();

        while (true)
        {
            DateTime now = DateTime.Now;
            for (int i = 0; i < ints.Length; i++)
            {
                //nothing really
            }
            Console.WriteLine("for loop: " + (DateTime.Now - now));

            now = DateTime.Now;
            for (int i = 0; i < ints.Length; i++)
            {
                int nothing = ints[i];
            }
            Console.WriteLine("for loop with assignment: " + (DateTime.Now - now));

            now = DateTime.Now;
            foreach (int i in ints)
            {
                //nothing really
            }
            Console.WriteLine("foreach: " + (DateTime.Now - now));

            now = DateTime.Now;
            foreach (int i in (IEnumerable<int>)ints)
            {
                //nothing really
            }
            Console.WriteLine("foreach casted to IEnumerable<int>: " + (DateTime.Now - now));
        }

    }

:

for loop: 00:00:00.0273438
for loop with assignment: 00:00:00.0712890
foreach: 00:00:00.0693359
foreach casted to IEnumerable<int>: 00:00:00.6103516
for loop: 00:00:00.0273437
for loop with assignment: 00:00:00.0683594
foreach: 00:00:00.0703125
foreach casted to IEnumerable<int>: 00:00:00.6250000
for loop: 00:00:00.0273437
for loop with assignment: 00:00:00.0683594
foreach: 00:00:00.0683593
foreach casted to IEnumerable<int>: 00:00:00.6035157
for loop: 00:00:00.0283203
for loop with assignment: 00:00:00.0771484
foreach: 00:00:00.0771484
foreach casted to IEnumerable<int>: 00:00:00.6005859
for loop: 00:00:00.0273438
for loop with assignment: 00:00:00.0722656
foreach: 00:00:00.0712891
foreach casted to IEnumerable<int>: 00:00:00.6210938

decompiled ( , foreach ... - , ):

private static void Main(string[] args)
{
    int[] ints = Enumerable.Repeat<int>(1, 0x2faf080).ToArray<int>();
    while (true)
    {
        DateTime now = DateTime.Now;
        for (int i = 0; i < ints.Length; i++)
        {
        }
        Console.WriteLine("for loop: " + ((TimeSpan) (DateTime.Now - now)));
        now = DateTime.Now;
        for (int i = 0; i < ints.Length; i++)
        {
            int num1 = ints[i];
        }
        Console.WriteLine("for loop with assignment: " + ((TimeSpan) (DateTime.Now - now)));
        now = DateTime.Now;
        int[] CS$6$0000 = ints;
        for (int CS$7$0001 = 0; CS$7$0001 < CS$6$0000.Length; CS$7$0001++)
        {
            int num2 = CS$6$0000[CS$7$0001];
        }
        Console.WriteLine("foreach: " + ((TimeSpan) (DateTime.Now - now)));
        now = DateTime.Now;
        using (IEnumerator<int> CS$5$0002 = ((IEnumerable<int>) ints).GetEnumerator())
        {
            while (CS$5$0002.MoveNext())
            {
                int current = CS$5$0002.Current;
            }
        }
        Console.WriteLine("foreach casted to IEnumerable<int>: " + ((TimeSpan) (DateTime.Now - now)));
    }
}
0

Something that people haven't mentioned is that the reflector comes in super-useful if you use an AOP compilation structure like PostSharp.

0
source

Source: https://habr.com/ru/post/1709446/


All Articles