CLR profiling: Trying to understand how to fetch variables.
I have been experimenting with a .NET CLR profiler for the purposes of building a powershell monitoring AV tool. I wanted to intercept powershell code (IL) using the profiler right before it is JIT compiled using API functions like JITCompilationStarted, GetFunctionInfo, GetMethodName, GetILFunctionBody.
For testing purpose i have used the following simple commands from my cmd (where i have set the environment variables for profiling) for testing.
- powershell.exe -c "Write-Host 'HelloWorld'"
- powershell.exe -c "(New-Object Net.WebClient).DownloadString('http://example.com')"
My intent is to intercept the strings "HelloWorld" and "example.com" before they are actually executed by powershell.
I am using the IMetaDataImport::GetUserString and IMetaDataImport::GetMethodsProps to resolve the string literals (like ldstr "HelloWorld") and function names (for example callvirt Runspace.InvokeCommand)
But I am still unable to locate the strings.
Kindly tell me how to profile powershell in such a way as too retrive IL code corresponding to the entered command?