【问题标题】:MSIL code problemMSIL代码问题
【发布时间】:2010-05-27 15:31:14
【问题描述】:

我试图通过 ildassemble 和修改 MSIL 代码来修改程序集(我的)。 我只想弹出一个MessageBox。

这是我的代码:

.module extern Fusion.dll

.module extern kernel32.dll

.module extern advapi32.dll

.module extern aspnet_state.exe

.module extern webengine.dll

.module extern aspnet_wp.exe

.module extern mscorwks.dll

.module extern ole32.dll

.module extern mscoree.dll

.module extern Netapi32.dll

.assembly extern mscorlib

{

...

...

IL_0052: ldstr "ahahahahahah"

IL_0057: callvirt instance [mscorlib]System.Windows.Forms.MessageBox::Show(string)

IL_005c: ldloc.0

IL_005d: ret

} // end of method

...

我没有错误,但 MessageBox 没有出现:\

感谢您的帮助!

【问题讨论】:

    标签: .net cil


    【解决方案1】:

    应该是

      ldstr "ahahahahahah"
      call valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult[System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string)
      pop
      ret
    

    顺便说一句,MessageBox 不应该在网络应用程序中工作,因为它与桌面用户交互

    你的代码有什么问题:

    callvirt instance [mscorlib]System.Windows.Forms.MessageBox::Show(string)
    
    1. 显示是静态方法。所以它应该被称为 a) 有call b) 没有instance
    2. MessageBox 在System.Windows.Forms,不在mscorlib
    3. 你应该指定结果类型,它实际上是DialogResult
    4. 你应该pop结果,因为你不需要它

    【讨论】:

    • 否 :( 我准确地说它是一个 web .net 应用程序 (file.aspx)
    【解决方案2】:

    MessageBox 是 System.Windows.Forms.dll 中的一个 Windows 窗体函数,因此您需要为此添加一个 extern 并删除 call[mscorlib] 位......但我认为它不会有帮助.

    ASPX 页面如何生成 Winforms 消息框? 你唯一能做的就是发出一个 Javascript 'alert(message)' 来获得一个网页样式的消息框,但是通过修改 MSIL 并不容易做到这一点。

    也许你应该添加类似的东西:

    call void [System]System.Diagnostics.Trace::Write(string)
    

    通过反编译快速控制台应用程序,消息框调用的工作方式如下:

    ldstr "blah"
    stloc.0 
    ldloc.0 
    call valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string)
    pop 
    

    【讨论】:

      【解决方案3】:

      好的,谢谢你的帮助,现在更清楚了。

      好吧,如果无法从 aspx 文件中抛出 MessageBox,我已经尝试在文件中写入一些内容。

      IL_0034:  ldstr      "C:\\...\\WebSite1\\toto.txt"
      IL_0039:  newobj     instance void [mscorlib]System.IO.StreamWriter::.ctor(string)
      IL_003e:  stloc.1
      IL_003f:  ldloc.1
      IL_0040:  ldstr      "hello world"
      IL_0045:  callvirt   instance void [mscorlib]System.IO.TextWriter::WriteLine(string)
      IL_004a:  nop
      IL_004b:  ldloc.1
      IL_004c:  callvirt   instance void [mscorlib]System.IO.TextWriter::Close()
      IL_0051:  nop
      

      我在加载网页时没有错误或异常,但文件没有创建或修改:\

      我不明白为什么,因为如果我将相同的代码直接放在 .aspx 中的 C# 中,那效果很好!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-05
        • 2013-06-29
        • 1970-01-01
        • 1970-01-01
        • 2010-11-26
        • 1970-01-01
        • 2012-04-05
        • 1970-01-01
        相关资源
        最近更新 更多