Hey guys,

I'm currently trying to inject a new class into an assembly. I've been
creating the same instructions that I see when using a disassembler
and I'm stuck on this opCode:

Ldloca_S  V_0

I'm not quite sure how to use the CilWorker to insert that instruction
into my method body. The MS doc seems to indicate that it takes a byte
as a parameter, which makes sense, but I get an argument exception
when doing this:

init.Body.CilWorker.Append(init.Body.CilWorker.Create(OpCodes.Ldloca_S,
0));

Here's the code I'm trying to put in:

someVar = string.Format("start time:{0}\n",
DateTime.Now.Ticks.ToString());

which is decompiled into the following IL:

IL_0011: ldstr "start time:{0}"
IL_0016: call System.DateTime.get_Now()
IL_001B: stloc.0
IL_001C: ldloca.s V_0
IL_001E: call System.DateTime.get_Ticks()
IL_0023: stloc.1
IL_0024: ldloca.s V_1
IL_0026: call System.Int64.ToString()
IL_002B: call System.String.Format(System.String,System.Object)

How can I append the Ldloca_S instruction?

Thanks!

Louis

-- 
--
mono-cecil

Reply via email to