tags:

views:

71

answers:

4
+1  Q: 

MSIL code problem

Hi all,

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 "ahahahahahah"

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 !

+6  A: 

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
Andrey
No :( I precise that it's a web .net application (file.aspx)
Thomas
A: 

When I try :

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

I have an exception at running ; Impossible to load the type 'System.Windows.Forms.MessageBox" from the assembly mscorlib.

Any idea ?

I precise that the assembly I modify is used by a .aspx file.

Thomas
because MessageBox is not in mscorlib:) it is in System.Windows.Forms
Andrey
+1  A: 

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 
Russ C
A: 

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 !

Thomas
use http://msdn.microsoft.com/en-us/library/ms143356(VS.90).aspx
Andrey