开发者

MSIL code problem

I am trying to modificate an assembly (mine) just by ildassembling it and by modifying the MSIL code. I just want to pop a MessageBox.

Here is my code :

.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 "ahah开发者_如何学编程ahahahah"

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

IL_005c: ldloc.0

IL_005d: ret

} // end of method

...

I have no error, but the MessageBox does not appear :\

Thanks for helping !


should be

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

btw, MessageBox should not work in web app, because it interacts with desktop user

what is wrong with your code:

callvirt instance [mscorlib]System.Windows.Forms.MessageBox::Show(string)
  1. Show is static method. So it should be called a) with call b) without instance
  2. MessageBox is in System.Windows.Forms, not in mscorlib
  3. You should specify result type, it is actually DialogResult
  4. You should pop result because you don't need it


Well MessageBox is a windows form function in System.Windows.Forms.dll so you'd need to add an extern for that and removes the call[mscorlib] bit ...but I don't think it's going to help.

How is an ASPX page is going to generate a Winforms Message box ? The only thing you could possibly do is emit a Javascript 'alert(message)' to get a web-page style message box, but that's not going to be easily done by modifying MSIL.

Perhaps you should add something like:

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

By decompiling a quick console app, this is how the message box call would work:

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 


Ok thanks for helping, it's more clear now.

Well, if it's not possible to throw a MessageBox from a aspx file, I have tried to write something in a file.

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

I have no error or exception when I load the web page, but the file is not created or modified :\

I dont see why because If I put the same code in C# directly in the .aspx, that works fine !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜