How would i create a brtrue instruction with this operand.

73 views
Skip to first unread message

Hi_ImKyle

unread,
Sep 7, 2018, 1:33:24 PM9/7/18
to mono-cecil
Ok so I've been using Mono.Cecil for a bit now and all is good till i needed to create the brtrue instruction.

So this is what i have setup so far.

Instruction.Create(OpCodes.Ldsfld, ILUtils.GetField(Assembly.MainModule, "****.****", "****")), 
Instruction.Create(OpCodes.Call, Assembly.MainModule.ImportReference(typeof(MainTest).GetMethod("Chat_Hook"))), 
Instruction.Create(OpCodes.Brtrue, "")

This is what I'm trying to recreate













But whenever i try to create a brtrue instruction I always get an exception with the error message "opcode" which isnt useful at all.

Is there a way to have that operand in IL_01AD in Instruction.Create?

Adriano Verona

unread,
Sep 7, 2018, 4:44:48 PM9/7/18
to mono-...@googlegroups.com
Assuming Instruction  is a ILProcessor, you need to pass the instruction you want to jump to Create(OpCodes.Brtrue)  (instead of a string)
something like this:

var target = Instruction.Create(OpCodes.Nop); // you can use any instruction.. to simplify I am adding a nop as the target
// add other instructions
Instuction.Emit(OpCodes.Brtrue, target);

// some more instructions
Instruction.Append(target);

// More instructions


Best 

Adriano



--
--
--
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.
For more options, visit https://groups.google.com/d/optout.


--
Adriano Carlos Verona
http://programing-fun.blogspot.com

M: +1 (514) 771-0190
500 Françóis Street, #310, H3E 1G4
Montreal, Canada
Contact Me Linkedin

Reply all
Reply to author
Forward
0 new messages