*>Do i have to simply go back a few instructions to see the parameters that 
were pushed*

Yes. I suggest printing the instructions to better understand what's where.

On Wednesday, November 26, 2014 6:27:49 AM UTC+1, Lior Tal wrote:
>
> Thanks for tge detailed answet.
>
> I want to verify the method is invoked with cerrain inputs, e.g: if its 
> paraneter is an int, then check if the int passed to it adheres to cerrain 
> conditions tgat i will check. 
>
> Do i have to simply go back a few instructions to see the parameters that 
> were pushed, or is there an easier way ?
> On 26 Nov 2014 05:58, "Artem Stekhnovskii" <[email protected] 
> <javascript:>> wrote:
>
>> Load the assembly:
>>
>>  AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(@"C:\...
>> \Assembly.dll"); 
>>  ModuleDefinition mainMod = asm.MainModule; 
>>
>> Find the MethodDefinition for the method you're interested in:
>>
>>  TypeDefinition classContainingYourMethod = mainMod.Types.FirstOrDefault 
>> (x => x.Name == "ClassName"); // this is LINQ
>>  MethodDefinition yourMethod = classContainingYourMethod.Methods.
>> FirstOrDefault (x => x.Name == "YourMethodsName"); //if your method is 
>> void ShowTooltip(), just type in "ShowTooltip"
>>
>> Now parse all Classes (types) in your assembly, parse all their Methods, 
>> parse all their Instructions, parse all their Operands and see if it's 
>> referencing yourMethod.
>>
>>          foreach (TypeDefinition td in mainMod.Types)
>>             foreach (MethodDefinition md in td.Methods)
>>                 if (md.HasBody)
>>                     foreach (Instruction inst in md.Body.Instructions)
>>                         if (inst.Operand == yourMethod)
>>                             System.Console.WriteLine ("your method is 
>> being called here"); 
>>
>> *> how do i verify the parameters that are passed?*
>> Parameters are pushed onto the evaluation stack in the instructions that 
>> are preceding the call.
>>
>> *>when finding it, i'd like to verify it was called correctly.*
>> Don't understand the question.
>>
>> On Tuesday, November 25, 2014 11:13:49 PM UTC+1, Lior Tal wrote:
>>>
>>> Hello,
>>>
>>> I'd like to write a rule that given a method definition, looks through a 
>>> given assembly and checks whether this method has been invoked.
>>>
>>> Also, when finding it, i'd like to verify it was called correctly.
>>>
>>> I am pretty sure this is fairly easy to achieve with Mono.Cecil, are 
>>> there any good examples of code that does something similar online that i 
>>> can have a look at ?
>>>
>>> If not, conceptually what is the process here?
>>>
>>> Can i scan all the methods of the input assembly and look for a Call 
>>> instruction with the method definition i am interested in? how do i verify 
>>> the parameters that are passed?
>>>
>>> Any help will be greatly appreciated.
>>>
>>> Thanks
>>> Lior
>>>
>>  -- 
>> -- 
>> --
>> 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.

Reply via email to