New created Instructions falls into previous code block

44 views
Skip to first unread message

Molowe

unread,
Jun 4, 2019, 3:12:48 PM6/4/19
to mono-cecil

Hi ,


I have some issues when instrumenting .NET assemblies. They are related with the needed to duplicate params when replacing an existing constructor by a new call to custom static method for custom class.

For instance let´s say that we want to update following code:


StreamWriter sw = new StreamWriter(sourcePath)


By


StreamWriter sw = new MetaStreamWriter.MyStaticMethod(sourcePath, new StreamWriter(sourcePath))


Note:Signature for MyStaticMethod is MetaStreamWriter.MyStaticMethod(string, StreamWriter)



As this point, I have no issues for importing the MetaStreamWriter.MyStaticMethod, and locale target-instruction at which to include the parameter duplication:


processor.InsertBefore(targetReferenceIntruction, targetReferenceIntruction);

processor.InsertAfter(instruction, aspectInstruction);

 

The problem is the insertion of new parameter instruction which does not respect surrounding code-blocks (autogenerated finally block when code is inside using, else blocks, etc…).


In order to be more specific :Let´s suppose that this origin-sentence is immediately after a using statement [endfinally-opCode]


Using (FileInfo fileinfo = new FileInfo(sourcePath))

{

// code for using

}

StreamWriter sw = new StreamWriter(sourcePath)



Or that origin-sentence is immediately after a [ret-OpCode]  something like


If (null== fileInfo)

{

return;

}


StreamWriter sw = new StreamWriter(sourcePath)

 


Then, when I create the new IL-sentences (InserAfter, InserBefore), the new parameter instruction falls into previous existing blocks which makes PEVerify to raise very ugly errors.

Is there any alternative way for avoiding these issues

Thanks in advance !

David

Jb Evain

unread,
Jun 5, 2019, 1:01:35 PM6/5/19
to mono-...@googlegroups.com
Hi David,

There's no magic bullet I'm afraid. If you're modifying the IL, you need to make sure that all exception blocks are updated to match the new IL.

Jb

--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups "mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mono-cecil+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mono-cecil/4be0eed7-f289-4ca7-92e1-4d9c9c1c387a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Molowe

unread,
Jun 7, 2019, 5:30:28 AM6/7/19
to mono-cecil
Thxs Jb !


Having the tools for making this possible is great regardless inner complexities


Regards
David


El miércoles, 5 de junio de 2019, 19:01:35 (UTC+2), Jb Evain escribió:
Hi David,

There's no magic bullet I'm afraid. If you're modifying the IL, you need to make sure that all exception blocks are updated to match the new IL.

Jb

To unsubscribe from this group and stop receiving emails from it, send an email to mono-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages