How to write a file in MSIL code

I have an aspx webpage that uses a mounting mine (which configures user authentication). I would like to modify the MSIL code (as well as the ILDASM / ILASM tools) of my assembly to write something to a file.

I tried adding this at the end of the authentication method of my assembly:

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

ILASM does not detect errors, and the CLR does not throw any exceptions at runtime, but the file is not created and does not change !: (

Any idea?

+3
source share
2 answers

Mono.Cecil. , . .

+2

:

  • IL , ret ( ), ( IL, , ). peverify , , ?
  • , ? , ?
+1

Source: https://habr.com/ru/post/1747314/


All Articles