This project is read-only.

Is it possible to instrument the class Object?

Jul 31, 2012 at 10:08 AM


I want to instrument the class Object because I need a unique identifier for every heap object. The thing I worry about is that the microsoft assemblies are signed. I know that it is possible to disable the verification for user assemblies. Is it possible to disable the verification for microsoft assemblies too?

Thanks in advance.



Aug 1, 2012 at 4:54 PM

In principle you should be able to do this. However, I do not know if CCI, at this point in time, can rewrite mscorlib sufficiently well that the result could be executed. Even if it were possible, you would have to rewrite all assemblies that you want to execute so that they have a reference to the rewritten mscorlib and not the "real" one.

Why doesn't GetHashCode work as a unique identifier?

Aug 1, 2012 at 5:24 PM

Just to clarify a bit: Rewriting the Metada Model is expected to work. Decompiling a Metadata model to a Code Model, rewriting the Code Model and than recompiling it is still a work in progress.

And yes, do consider using GetHashCode, but you can't just use ob.GetHashCode() since the method is virtual and not all overrides provide a hash code that is a unique identity. There is a way to call GetHashCode non virtually, but I can't remember off the top of my head how to do it.

Aug 1, 2012 at 5:54 PM

Thanks for your suggestions!

I managed to rewrite mscorlib.dll via disassembling (ildasm.exe), manual instrumentation und reassembling (ilasm.exe). I also managed to convince Visual Studio 2010 to use the instrumented mscorlib.dll via a custom target framework profile.

What do you mean with: "Even if it were possible, you would have to rewrite all assemblies that you want to execute so that they have a reference to the rewritten mscorlib and not the "real" one." ?

I only want to use the instrumented mscorlib.dll for special C# projects I compile myself. I don't have to rewrite all assemblies in this case - right?

Aug 1, 2012 at 5:59 PM

Oh, I hadn't know you could do that in VS2010. How do you set that custom target framework profile? Can you post the details? That is very nice!

I was just worried that if your C# project called a method in System.dll (for instance) and that method in turn called one in mscorlib, then it would execute the mscorlib method from the real mscorlib and not your rewritten mscorlib. But maybe your custom profile somehow takes care of that?

Aug 1, 2012 at 6:27 PM

You may be right with your suggestion - I didn't check yet. But I think the custom profile may take care of that since the profile chooses the framework version and therefore the mscorlib.dll version.

To create the custom profile I followed these instructions:

Since I wanted my custom target profile to be an offspring of  ".NET Framework 4.0 Client Profile" I did following:

  • Create a copy named ("Client(customized)") of the folder "Client" in "C:\Progam Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile" and paste in  "C:\Progam Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile"
  • Replace "C:\Progam Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client(customized)\mscorlib.dll" with the customized one. (Use "C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll" as basis for instrumentation and not a mscorlib.dll from the Referenced Assemblies folder since the method bodies of the latter are empty)
  • Edit ..\CustomProfile\Redist\FrameworkList.xml (<FileList  … Name=".NET Framework 4 Client Profile" … > to <FileList  … Name=".NET Framework 4 Client Profile (customized)" … >
  • Add the registy key ".NETFramework,Version=v4.0,Profile=Client(customized)" to "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\"
  • Disable signature checking for the custom mscorlib.dll: Sn.exe -Vr "C:\Progam Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client(customized)\mscorlib.dll"

I hope it also works for you.