Parsing the COR_PRF_FUNCTION_ARGUMENT_INFO Structure

82 views Asked by At

I'm wondering how I should go about parsing the COR_PRF_FUNCTION_ARGUMENT_INFO structure that is supplied to the callback method of the SetEnterLeaveFunctionHooks3WithInfo function.

From my understand the structure contains a group of memory addresses which contain the locations of the function parameter values. The info regarding this structure can be found here: https://learn.microsoft.com/en-us/dotnet/framework/unmanaged-api/profiling/cor-prf-function-argument-info-structure

I've also parsed the function's metadata to determine the number of parameters supplied to the function and each parameter's type. I used the GetMethodProps function of the IMetaDataImport interface.

I'm stuck on what to do next and how would I would proceed to get the actual value of each parameter using the COR_PRF_FUNCTION_ARGUMENT_INFO structure? Do I need to determine the size of each parameter to calculate an offset from a memory address for each parameter? Thanks for any help

1

There are 1 answers

0
Brian Reichle On BEST ANSWER

You should be able to work out the size of each argument and how to interpret it based on the type of the argument:

  • If its a primitive value type, then the size and representation should be fairly self-evident. (int => '4 byte integer', double => '8 byte floating point', bool => '4 byte integer where 0 is false and everything else is true', IntPtr => 'pointer-sized integer')
  • If its a reference type, then it will be a pointer-sized ObjectID. (warning: ObjectIDs are subject to changing between callbacks, so don't try to hang onto them unless you also hook the GC callbacks and update them when the objects move).
  • If its a value type, then you should be able to use GetClassLayout to get the size of the value and the location of the fields within it.
  • If its passed by reference, then it will be a (pointer-sized) pointer to the memory location where the actual value is stored (or will be stored in the case of out arguments).