MSDN-WhiteKnight / CilTools

A set of tools to work with CIL in .NET applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mark entry point with .entrypoint directive

MSDN-WhiteKnight opened this issue · comments

When outputting signature of entry point method as CIL assembler code, it should be marked with .entrypoint directive.

Example code:

using System;
using System.Reflection;
using CilBytecodeParser;

class Program
{    
    public static void Main(string[] args)
    {
        Console.WriteLine(CilAnalysis.MethodToText(MethodBase.GetCurrentMethod()));
        Console.ReadKey();
    }    
}

Current output:

.method public hidebysig static void Main(
    string[] args
) cil managed {
 .maxstack 8

          nop
          call       class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetCurrentMethod()
          call       string [CilBytecodeParser]CilBytecodeParser.CilAnalysis::MethodToText(class [mscorlib]System.Reflection.MethodBase)
          call       void [mscorlib]System.Console::WriteLine(string)
          nop
          call       valuetype [mscorlib]System.ConsoleKeyInfo [mscorlib]System.Console::ReadKey()
          pop
          ret
}

Expected output:

.method public hidebysig static void Main(
    string[] args
) cil managed {
 .entrypoint
 .maxstack 8

          nop
          call       class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetCurrentMethod()
          call       string [CilBytecodeParser]CilBytecodeParser.CilAnalysis::MethodToText(class [mscorlib]System.Reflection.MethodBase)
          call       void [mscorlib]System.Console::WriteLine(string)
          nop
          call       valuetype [mscorlib]System.ConsoleKeyInfo [mscorlib]System.Console::ReadKey()
          pop
          ret
}

The Assembly.EntryPoint property can be used to determine what method is an entry point in the given assembly.

Relevant ECMA-335 Specification section: II.15.4.1.2 The .entrypoint directive.