This project is read-only.

Problems running PeToPe for mscorlib.dll

Topics: Metadata Model, Source Model
Dec 5, 2012 at 8:44 PM
Edited Dec 5, 2012 at 9:00 PM


I am evaluating whether I could use CCI for instrumenting mscorlib.dll:
- I use a local copy of mscorlib.dll from C:\Windows\Microsoft.NET\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089 (is it possible to attach my version of mscorlib.dll somewhere in this post?).

I run Metadata\Samples\PeToPe for the local copy of mscorlib.dll:
The newly created is about 65kB smaller than the original one - but peverify is able to verify after renaming it (back to mscorlib.dll). Does this mean that CCI produces a valid copy of mscorlib.dll?

Next I run Ast\Samples\PeToTextViaCodeModel for the local copy of mscorlib.dll:
Program.cs, line 43: File.WriteAllText() throws an exception: 'Unable to translate Unicode character \uD800 at index 787 to specified code page.'

Fix: Specify the third argument, replace Program.cs, line 43 through:

File.WriteAllText(txtFile, sourceEmitterOutput.Data, System.Text.Encoding.UTF8);

Next I run Ast\Samples\PeToPeViaCodeModel for the local copy of mscorlib.dll:
- Decompiling works fine but an exception is thrown in CodeDeepCopier.CopyChildren(Expression expression) because expression.Type is Microsoft.Cci.DummyNamespaceTypeReference

I debugged further and found out that:
- the method of mscolib.dll that leads to the exception is:


- the expression of this method that leads to the exception is the right side of the condition of the following if statement (according to mscorlib.txt, generated via PeToTextViaCodeModel):

if (__temp_9 % 8 == default(Microsoft.Cci.DummyTypeReference)) {

I created a table that matches the il instructions to the decompiled code - can you tell me why and where the decompiler messes up? It must be around 'IL_005d: Brtrue_S IL_0065' (I can provide such a table for the whole method).

Dec 5, 2012 at 8:49 PM
Edited Dec 5, 2012 at 8:57 PM

Whoops, the table is not dispalyed correctly.

Sorry for that,


  IL_0054: Ldloc_S local_8    int __temp_9 = local_8 + 1
  IL_0056: Ldc_I4_1 1
  IL_0057: Add
  IL_0058: Dup    int __temp_10 = __temp_9
  IL_0059: Stloc_S local_8    local_8 = __temp_10
  IL_005b: Ldc_I4_8 8    if (__temp_9 % 8 == default(Microsoft.Cci.DummyTypeReference))
  IL_005c: Rem    {
  IL_005d: Brtrue_S IL_0065
  IL_005f: Ldc_I4_1 1    System.Threading.Thread.Sleep(1)
  IL_0060: Call System.Void System.Threading.Thread.Sleep(System.Int32)    }
Dec 6, 2012 at 1:27 AM
Edited Dec 6, 2012 at 1:28 AM

Hi again,

now I can provide a minimal piece of code that leads to the error:

    brtrue.s IL_0010
    IL_0010: ret

Using Ast\Samples\PeToTestViaCodeModel a method with this body will result in:

if (0 % 8 == default(Microsoft.Cci.DummyTypeReference)) { }

I tried to debug through Ast\IlToCodeModel\SourceMethodBody.cs, line 214, GetBlock() but couldn't figure out why the error comes from.



Dec 7, 2012 at 5:34 PM

Please create a work item for this in A handy repro including a binary to submit to peToTextViaCodeModel would be great.

Dec 8, 2012 at 12:17 AM

Thanks, I hope did it right: