.NET 函数反汇编第 2 部分
在反汇编处理对象和实例调用的 .NET 代码时,我发现有一些事情我不太明白:
这是我的测试代码:
class Foo
{
public void Bar()
{
Console.WriteLine("hello");
}
}
...
var foo = new Foo();
foo.Bar();
这是反汇编的结果(优化)
15: var foo = new Foo();
00000019 mov ecx,403880h //ecx = address of Foo type ?
0000001e call FFF71FB0 //call ctor ?
00000023 mov esi,eax //esi = result ?
16: foo.Bar();
00000025 call 63377060 //this seems to be console.writeline inlined (from bar)
0000002a mov ecx,eax
0000002c mov edx,dword ptr ds:[03612034h]
00000032 mov eax,dword ptr [ecx]
00000034 mov eax,dword ptr [eax+3Ch]
00000037 call dword ptr [eax+10h] // esi.Bar() ?
我猜测第一部分是加载 Foo 类型,然后调用它的构造函数?
但其余的呢?
另一个奇怪的事情是代码生成以下 IL :
L_0017: callvirt instance void CSApp.Foo::Bar()
为什么它对非虚拟方法执行 callvirt? 这是本机代码中发生的情况吗?虚函数表查找?
When disassembling .NET code dealing with objects and instance calls, I've found that there are a few things I don't quite get:
Here is my test code:
class Foo
{
public void Bar()
{
Console.WriteLine("hello");
}
}
...
var foo = new Foo();
foo.Bar();
And here is the disassembled result (optimized)
15: var foo = new Foo();
00000019 mov ecx,403880h //ecx = address of Foo type ?
0000001e call FFF71FB0 //call ctor ?
00000023 mov esi,eax //esi = result ?
16: foo.Bar();
00000025 call 63377060 //this seems to be console.writeline inlined (from bar)
0000002a mov ecx,eax
0000002c mov edx,dword ptr ds:[03612034h]
00000032 mov eax,dword ptr [ecx]
00000034 mov eax,dword ptr [eax+3Ch]
00000037 call dword ptr [eax+10h] // esi.Bar() ?
I'm guessing that the first part is about loading the Foo type and then calling the constructor on it?
But what about the rest?
Another weird thing is that the code generates the following IL :
L_0017: callvirt instance void CSApp.Foo::Bar()
Why does it do a callvirt on a non virtual method?
Is that what is going on in the native code? a vtable lookup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论