Thanx Jb.
I was able to get and print one argument value of a method.
but error occured while executing console.exe which print two
arguments values. It looks fine when I see injected code with a
Reflector.
Can you give me a tips about code below, please?
private static void InjectCode(MethodDefinition p_method,
ModuleDefinition p_mainModule, string p_output)
{
ILProcessor il = p_method.Body.GetILProcessor();
MethodReference writeLineRef =
p_mainModule.Import(typeof(Console).GetMethod("WriteLine", new Type[]
{ typeof(string) }));
Instruction value1 = il.Create(OpCodes.Ldarg_1);
Instruction value2 = il.Create(OpCodes.Ldarg_2);
Instruction writeMessage = il.Create(OpCodes.Call,
writeLineRef);
Instruction writeMessage2 = il.Create(OpCodes.Call,
writeLineRef);
//var iList = new[] { value1, value2 };
il.InsertBefore(p_method.Body.Instructions[0], value1);
il.InsertAfter(value1, writeMessage);
il.InsertAfter(writeMessage, value2);
il.InsertAfter(value2, writeMessage2);
}
On 6월21일, 오후8시54분, Jb Evain <[email protected]> wrote:
> Hey,
>
> On Mon, Jun 21, 2010 at 6:07 AM, DongYong Lee <[email protected]> wrote:
> > But I'm stuck with inject a statement to catch argument values and
> > shows the values.
>
> You can read the following example:
>
> http://evain.net/blog/articles/2010/05/05/parameterof-propertyof-meth...
>
> with the associated code:
>
> http://gist.github.com/390902
>
> What you want is even simplier, you just want to inject:
>
> ldarg1
> ldarg2
> call WriteLine(string,string)
>
> --
> Jb Evain <[email protected]>
--
--
mono-cecil