在反汇编 .NET 函数时,我注意到它们都以类似的模式开始。这个初始代码有什么作用?
此代码出现在函数应该执行的实际代码之前。是某种参数计数验证吗?
功能1
private static void Foo(int i)
{
Console.WriteLine("hello");
}
00000000 push ebp
00000001 mov ebp,esp
00000003 push eax
00000004 mov dword ptr [ebp-4],ecx
00000007 cmp dword ptr ds:[005C14A4h],0
0000000e je 00000015
00000010 call 65E0367F
//the console writleline code follows here and is not part of the question
功能2
static private void Bar()
{
for (int i = 0; i < 1000; i++)
{
Foo(i);
}
}
00000000 push ebp
00000001 mov ebp,esp
00000003 push eax
00000004 cmp dword ptr ds:[006914A4h],0
0000000b je 00000012
0000000d call 65CC36CF
// the for loop code follows here
功能3
private static void Foo()
{
Console.WriteLine("hello");
}
00000000 push ebp
00000001 mov ebp,esp
00000003 cmp dword ptr ds:[005614A4h],0
0000000a je 00000011
0000000c call 65E3367F
[编辑] 那么这是对它的正确描述吗?
//fix stackframe
00000000 push ebp
00000001 mov ebp,esp
//store eax so it can be used locally
00000003 push eax
//ensure static ctor have been called
00000004 cmp dword ptr ds:[006914A4h],0
//it has been called, ignore it
0000000b je 00000012
//it hasn't been called, call it now
0000000d call 65CC36CF
或者?