C# EXE文件中的方法调用在哪里?

C# EXE文件中的方法调用在哪里?,c#,clr,windbg,opcode,cracking,C#,Clr,Windbg,Opcode,Cracking,导言 在LIDNUG上观看了这段关于.NET代码保护(特别是从46:30到57:30)的视频后,我想在我创建的EXE中找到对MessageBox.Show的调用 我的“TrialApp.exe”中唯一的逻辑是: 在发布配置上编译: 如何定位呼叫 在WinDBG中运行应用程序,并在消息框出现后中断 使用获取CLR堆栈!clrstack: 0040e840 5e21350b [InlinedCallFrame: 0040e840] System.Windows.Forms.SafeNativeMet

导言

在LIDNUG上观看了这段关于.NET代码保护(特别是从46:30到57:30)的视频后,我想在我创建的EXE中找到对MessageBox.Show的调用

我的“TrialApp.exe”中唯一的逻辑是:

在发布配置上编译:

如何定位呼叫

在WinDBG中运行应用程序,并在消息框出现后中断

使用
获取CLR堆栈!clrstack

0040e840 5e21350b [InlinedCallFrame: 0040e840] System.Windows.Forms.SafeNativeMethods.MessageBox(System.Runtime.InteropServices.HandleRef, System.String, System.String, Int32)
0040e894 5e21350b System.Windows.Forms.MessageBox.ShowCore(System.Windows.Forms.IWin32Window, System.String, System.String, System.Windows.Forms.MessageBoxButtons, System.Windows.Forms.MessageBoxIcon, System.Windows.Forms.MessageBoxDefaultButton, System.Windows.Forms.MessageBoxOptions, Boolean)
0040e898 002701f0 [InlinedCallFrame: 0040e898] 
0040e934 002701f0 TrialApp.Form1.Form1_Load(System.Object, System.EventArgs)
获取MethodDesc结构(使用Form1\u Load的地址)
!ip2md 002701f0

MethodDesc:   001762f8
Method Name:  TrialApp.Form1.Form1_Load(System.Object, System.EventArgs)
Class:        00171678
MethodTable:  00176354
mdToken:      06000005
Module:       00172e9c
IsJitted:     yes
CodeAddr:     002701d0
Transparency: Critical
Source file:  D:\temp\TrialApp\TrialApp\Form1.cs @ 22
转储此方法的IL(按MethodDesc)
!dumpil 001762f8

IL_0000: ldstr "This is trial app"
IL_0005: call System.Windows.Forms.MessageBox::Show 
IL_000a: pop 
IL_000b: ret 
因此,正如视频中提到的,对
Show
的调用距离方法实现的开始有5个字节

现在我打开CFFExplorer(就像在视频中一样),获得Form1_Load方法的RVA:
00002083

之后,我转到地址转换器(再次在CFF Explorer中),并导航到偏移量
00002083
。我们有:

32 72 01 00 00 70 28 16 00 00 0A 26 2A 7A 03 2C
13 02 7B 02 00 00 04 2C 0B 02 7B 02 00 00 04 6F
17 00 00 0A 02 03 28 18 00 00 0A 2A 00 03 30 04 
00 67 00 00 00 00 00 00 00 02 28 19 00 00 0A 02
在视频中提到,前12个字节用于方法头,所以我跳过它们

                                    2A 7A 03 2C
13 02 7B 02 00 00 04 2C 0B 02 7B 02 00 00 04 6F
17 00 00 0A 02 03 28 18 00 00 0A 2A 00 03 30 04 
00 67 00 00 00 00 00 00 00 02 28 19 00 00 0A 02
从实现开始的5个字节应该是方法调用的操作码(28)。不幸的是,没有

   02 7B 02 00 00 04 2C 0B 02 7B 02 00 00 04 6F
17 00 00 0A 02 03 28 18 00 00 0A 2A 00 03 30 04 
00 67 00 00 00 00 00 00 00 02 28 19 00 00 0A 02
问题:

  • 我做错了什么
  • 为什么文件中该位置没有方法调用?或者视频中缺少了一些信息
  • 为什么视频中的那个家伙用9个零来代替电话

  • 当我使用Ildasm.exe并查看启用了“显示字节”的IL时,我看到以下内容:

    .method private hidebysig instance void  Form1_Load(object sender,
                                                        class [mscorlib]System.EventArgs e) cil managed
    // SIG: 20 02 01 1C 12 15
    {
      // Method begins at RVA 0x20f1
      // Code size       12 (0xc)
      .maxstack  8
      IL_0000:  /* 72   | (70)00000D       */ ldstr      "This is trial app"
      IL_0005:  /* 28   | (0A)00001E       */ call       valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string)
      IL_000a:  /* 26   |                  */ pop
      IL_000b:  /* 2A   |                  */ ret
    } // end of method Form1::Form1_Load
    

    转储中的令牌值不同,您似乎有一个更大的程序。但转储中的IL从偏移量1开始,而不是12。不知道为什么会关机。

    嘿!谢谢你的回答。你用你的编译器编译了代码,对吗?因为我看到你有一个不同的RVA。这个问题可能是因为我使用了VS2010的编译器(目标平台是.NET 4.0)造成的吗?当然,CLR版本4的内部结构可能已经完全改变了。你正在攻击未记录的CLR数据结构,一切皆有可能。关于它们的唯一已知原因是SSCLI 2.0源代码。它已经超过5年了。找到它(电话)!在我删除的12个字节中。(从开头开始的6个字节:28 16 00 0A)。汉斯·帕桑,非常感谢你有用的回答!
    .method private hidebysig instance void  Form1_Load(object sender,
                                                        class [mscorlib]System.EventArgs e) cil managed
    // SIG: 20 02 01 1C 12 15
    {
      // Method begins at RVA 0x20f1
      // Code size       12 (0xc)
      .maxstack  8
      IL_0000:  /* 72   | (70)00000D       */ ldstr      "This is trial app"
      IL_0005:  /* 28   | (0A)00001E       */ call       valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string)
      IL_000a:  /* 26   |                  */ pop
      IL_000b:  /* 2A   |                  */ ret
    } // end of method Form1::Form1_Load