Yes, thats clear for me, but I am so desperate. I found some more help on this page http://stackoverflow.com/questions/12769699/mono-cecil-injecting-try-finally/12798309#12798309
Everything works fine until I do not add some more custom code and only the try finally block. If adding own variables and calls, the il code is not valid anymore. I will talk to my Dev Manager because of 'professional help'. Thanks :-) Am Freitag, 9. Januar 2015 09:37:38 UTC+1 schrieb Jb Evain: > > Hi, > > If this group is all for helping people use Cecil, its purpose is not > to debug other people code. > > If you want professional services around Cecil you can contact me > privately. > > Thanks! > > Jb > > On Thu, Jan 8, 2015 at 5:11 PM, Reh Gina <[email protected] <javascript:>> > wrote: > > I would like to kill my computer, but for now I will go home and restart > > tomorrow. Thanks for your help, would it be possible you'll help me a > little > > bit more? > > > > Am Donnerstag, 8. Januar 2015 17:08:27 UTC+1 schrieb Reh Gina: > >> > >> Now I replace the ret instruction by using following code > >> [....] > >> > >> > >> Instruction popFTraceVariableInstruction = > >> Instruction.Create(OpCodes.Stloc, fTraceVar); > >> //Pop a value from stack and store into local variable at index. > >> ilProcessor.InsertAfter(newConstructorInstruction, > >> popFTraceVariableInstruction); > >> > >> var endFinally = Instruction.Create(OpCodes.Endfinally); > >> var leave = Instruction.Create(OpCodes.Leave, endFinally); > >> var ret = Instruction.Create(OpCodes.Ret); > >> > >> for (int i = 0; i < med.Body.Instructions.Count; i++) > >> { > >> Instruction instr = med.Body.Instructions[i]; > >> //Console.WriteLine(instr.ToString()); > >> if (instr.OpCode == OpCodes.Ret) > >> { > >> Instruction previous = instr.Previous; > >> ilProcessor.Remove(instr); > >> ilProcessor.InsertAfter(previous, > >> Instruction.Create(OpCodes.Leave, ret)); > >> } > >> } > >> > >> > >> //////// Start Finally block > >> Instruction loadFTraceVarInstruction = > >> Instruction.Create(OpCodes.Ldloca, fTraceVar); > >> ilProcessor.InsertAfter(med.Body.Instructions.Last(), > >> loadFTraceVarInstruction); //Loads local variable onto stack > >> //ilProcessor.InsertBefore(lastInstruction, > >> loadFTraceVarInstruction); //Loads local variable onto stack > >> > >> [...] > >> [...] > >> > >> ilProcessor.InsertAfter(callDisposeInstruction, endFinally); > >> //ilProcessor.InsertAfter(leave, endFinally); > >> Instruction nopInstruction = Instruction.Create(OpCodes.Nop); > >> ilProcessor.InsertAfter(endFinally, nopInstruction); > >> ilProcessor.InsertAfter(nopInstruction, ret); > >> > >> ///////// End finally block > >> > >> var handler = new ExceptionHandler(ExceptionHandlerType.Finally) > >> { > >> TryStart = med.Body.Instructions.First(), > >> TryEnd = callDisposeInstruction, > >> HandlerStart = callDisposeInstruction, > >> HandlerEnd = nopInstruction, > >> //CatchType = mod.Import(typeof(Exception)), > >> }; > >> [...] > >> > >> PEVerify says: > >> [IL]: Error: > >> > [O:\bin\x64\Debug\MeVis.BizLogic.Applications.LiverAnalysis.Viewing.ViewingCP.dll > > > >> : > >> > MeVis.BizLogic.Applications.LiverAnalysis.Viewing.ViewingCP.AbstractTaskStepBEHandler::Dispose][offset > > > >> 0x000000A9] Stack underflow. > >> [IL]: Error: > >> > [O:\bin\x64\Debug\MeVis.BizLogic.Applications.LiverAnalysis.Viewing.ViewingCP.dll > > > >> : > >> > MeVis.BizLogic.Applications.LiverAnalysis.Viewing.ViewingCP.AbstractTaskStepBEHandler::set_IsActive][offset > > > >> 0x00000027] jmp / exception into the middle of an instruction. > >> [IL]: Error: > >> > [O:\bin\x64\Debug\MeVis.BizLogic.Applications.LiverAnalysis.Viewing.ViewingCP.dll > > > >> : > >> ..... > >> > >> > >> ARRRRGGGHHHHH > >> > >> Am Donnerstag, 8. Januar 2015 16:35:31 UTC+1 schrieb Jb Evain: > >>> > >>> The error means you can not have a ret instruction inside a protected > >>> block. > >>> > >>> It means that if you're injecting protected blocks, you must make sure > >>> that rets in them are replaced by into leave opcodes, that are jumping > >>> outside of the protected block where you'll be able to return. > >>> > >>> I'm afraid there's nothing built-in for this, you'll have to implement > >>> it. > >>> > >>> Jb > >>> > >>> On Thu, Jan 8, 2015 at 4:27 PM, Reh Gina <[email protected]> wrote: > >>> > Something with a return which ist not correct in try block, but how > to > >>> > I > >>> > remove it. Trying this to get work for almost 2 weeks > >>> > > >>> > Am Donnerstag, 8. Januar 2015 16:25:13 UTC+1 schrieb Reh Gina: > >>> >>> > >>> >>> Now the correct file attached > >>> > > >>> > -- > >>> > -- > >>> > -- > >>> > 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 [email protected]. > >>> > For more options, visit https://groups.google.com/d/optout. > > > > -- > > -- > > -- > > 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 [email protected] <javascript:>. > > For more options, visit https://groups.google.com/d/optout. > -- -- -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
