4

Dotfuscator uses ildasm to get IL code, which is what it then performs its obfuscation on. Dotfuscator has been choking on one particular assembly. This is the only assembly in the solution which uses Fody, an IL weaver, to "weave" additional CIL into the assembly after it is compiled. Interestingly, Dotfuscator says which line it has a hard time with, and that line is always syntax highlighted differently by ReSharper in Visual Studio. There's always more than one line highlighted that way, but Dotfuscator always errors on the first one... Interesting.

If you tell me why ReSharper thinks these lines are different, maybe I can figure out why Dotfuscator can't obfuscate this assembly, and only this assembly out of 100+ others in the solution.

IL code snippets

Dotfuscator Professional Edition Version 4.21.0.3600-release+990d7ec.20160427.26945 Build machine license. This software may be used on binaries for general release.  (TaskId:2742)
   Your subscription expires in 300 days. (TaskId:2742)
  Copyright 2002-2016 PreEmptive Solutions, LLC All Rights Reserved. (TaskId:2742)
   (TaskId:2742)
  Use of this software implies acceptance of accompanying license agreement. (TaskId:2742)
  LICENSED TO: NOPE! (TaskId:2742)
  SERIAL #: NOPE! (TaskId:2742)
  [Build Output] Loading Assemblies... (TaskId:2742)
  [Build Output]  (TaskId:2742)
  [Build Output] Running C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\ildasm.exe /OUT=C:\Users\NOPE!\AppData\Local\Temp\~NOPE!.142\NOPE!.dll.il /TEXT /NOBAR /RAWEH /QUOTEALLNAMES /UTF8 /LINENUM /FORWARD C:\NOPE!\bin\x64\Release\NOPE!.dll (TaskId:2742)
  [Build Output]  (TaskId:2742)
  [Build Output] Encountered : at line 4194, column 12. (TaskId:2742)
  Was expecting one of: (TaskId:2742)
      <HEXBYTE> ... (TaskId:2742)
      <SQSTRING> ... (TaskId:2742)
      <DSQSTRING> ... (TaskId:2742)
      "{" ... (TaskId:2742)
      "}" ... (TaskId:2742)
      ".zeroinit" ... (TaskId:2742)
      ".#line" ... (TaskId:2742)
      ".language" ... (TaskId:2742)
      ".permission" ... (TaskId:2742)
      ".param" ... (TaskId:2742)
      ".custom" ... (TaskId:2742)
      ".vtentry" ... (TaskId:2742)
      ".locals" ... (TaskId:2742)
      ".entrypoint" ... (TaskId:2742)
      ".emitbyte" ... (TaskId:2742)
      ".override" ... (TaskId:2742)
      ".data" ... (TaskId:2742)
      ".maxstack" ... (TaskId:2742)
      ".export" ... (TaskId:2742)
      ".try" ... (TaskId:2742)
      ".permissionset" ... (TaskId:2742)
      ".line" ... (TaskId:2742)
      "sub.ovf.un" ... (TaskId:2742)
      "stobj" ... (TaskId:2742)
      "mul.ovf.un" ... (TaskId:2742)
      "throw" ... (TaskId:2742)
      "stfld" ... (TaskId:2742)
      "conv.ovf.u.un" ... (TaskId:2742)
      "ble" ... (TaskId:2742)
      "stind.i" ... (TaskId:2742)
      "conv.u2" ... (TaskId:2742)
      "newobj" ... (TaskId:2742)
      "br.s" ... (TaskId:2742)
      "cpblk" ... (TaskId:2742)
      "conv.ovf.i4" ... (TaskId:2742)
      "ldind.i4" ... (TaskId:2742)
      "ldelem.r4" ... (TaskId:2742)
      "ldflda" ... (TaskId:2742)
      "mul.ovf" ... (TaskId:2742)
      "ldelem.i1" ... (TaskId:2742)
      "stelem.i8" ... (TaskId:2742)
      "clt" ... (TaskId:2742)
      "ldarg.1" ... (TaskId:2742)
      "rem" ... (TaskId:2742)
      "ckfinite" ... (TaskId:2742)
      "ldc.i4.5" ... (TaskId:2742)
      "unbox" ... (TaskId:2742)
      "add.ovf" ... (TaskId:2742)
      "ldind.ref" ... (TaskId:2742)
      "ldarga.s" ... (TaskId:2742)
      "stind.i8" ... (TaskId:2742)
      "conv.ovf.u4.un" ... (TaskId:2742)
      "ldnull" ... (TaskId:2742)
      "conv.ovf.i4.un" ... (TaskId:2742)
      "ldind.r8" ... (TaskId:2742)
      "conv.i4" ... (TaskId:2742)
      "blt.un.s" ... (TaskId:2742)
      "call" ... (TaskId:2742)
      "ldloca.s" ... (TaskId:2742)
      "nop" ... (TaskId:2742)
      "conv.ovf.u4" ... (TaskId:2742)
      "ldind.u4" ... (TaskId:2742)
      "stelem.r4" ... (TaskId:2742)
      "ldelema" ... (TaskId:2742)
      "leave" ... (TaskId:2742)
      "ldelem.i2" ... (TaskId:2742)
      "stelem.i1" ... (TaskId:2742)
      "ldelem.u1" ... (TaskId:2742)
      "ldarg.2" ... (TaskId:2742)
      "blt.un" ... (TaskId:2742)
      "ldlen" ... (TaskId:2742)
      "ldc.i4.6" ... (TaskId:2742)
      "ldvirtftn" ... (TaskId:2742)
      "rethrow" ... (TaskId:2742)
      "stind.r4" ... (TaskId:2742)
      "bge.un" ... (TaskId:2742)
      "stind.ref" ... (TaskId:2742)
      "ldsfld" ... (TaskId:2742)
      "ldtoken" ... (TaskId:2742)
      "conv.r8" ... (TaskId:2742)
      "conv.ovf.u8.un" ... (TaskId:2742)
      "stind.i1" ... (TaskId:2742)
      "add.ovf.un" ... (TaskId:2742)
      "conv.ovf.i8.un" ... (TaskId:2742)
      "stsfld" ... (TaskId:2742)
      "brtrue.s" ... (TaskId:2742)
      "ldarg.s" ... (TaskId:2742)
      "tail." ... (TaskId:2742)
      "brtrue" ... (TaskId:2742)
      "ldarg" ... (TaskId:2742)
      "xor" ... (TaskId:2742)
      "conv.u4" ... (TaskId:2742)
      "ldc.i8" ... (TaskId:2742)
      "ldloc" ... (TaskId:2742)
      "stloc.0" ... (TaskId:2742)
      "conv.u" ... (TaskId:2742)
      "stelem.i2" ... (TaskId:2742)
      "endfault" ... (TaskId:2742)
      "ldelem.u2" ... (TaskId:2742)
      "ldarg.3" ... (TaskId:2742)
      "ldind.i" ... (TaskId:2742)
      "ldc.i4.7" ... (TaskId:2742)
      "endfilter" ... (TaskId:2742)
      "ble.un.s" ... (TaskId:2742)
      "dup" ... (TaskId:2742)
      "stind.i2" ... (TaskId:2742)
      "isinst" ... (TaskId:2742)
      "initobj" ... (TaskId:2742)
      "ldc.r4" ... (TaskId:2742)
      "unaligned." ... (TaskId:2742)
      "conv.ovf.i" ... (TaskId:2742)
      "and" ... (TaskId:2742)
      "stloc.1" ... (TaskId:2742)
      "sub" ... (TaskId:2742)
      "shr" ... (TaskId:2742)
      "ldelem.i4" ... (TaskId:2742)
      "sub.ovf" ... (TaskId:2742)
      "ldloca" ... (TaskId:2742)
      "ldc.i4.8" ... (TaskId:2742)
      "div.un" ... (TaskId:2742)
      "callvirt" ... (TaskId:2742)
      "ldc.i4.0" ... (TaskId:2742)
      "ble.un" ... (TaskId:2742)
      "arglist" ... (TaskId:2742)
      "rem.un" ... (TaskId:2742)
      "stelem.i" ... (TaskId:2742)
      "conv.ovf.i8" ... (TaskId:2742)
      "ldind.i8" ... (TaskId:2742)
      "starg" ... (TaskId:2742)
      "initblk" ... (TaskId:2742)
      "pop" ... (TaskId:2742)
      "ldelem.r8" ... (TaskId:2742)
      "mul" ... (TaskId:2742)
      "stloc.2" ... (TaskId:2742)
      "conv.ovf.u2.un" ... (TaskId:2742)
      "stloc" ... (TaskId:2742)
      "conv.ovf.i2.un" ... (TaskId:2742)
      "refanytype" ... (TaskId:2742)
      "stelem.i4" ... (TaskId:2742)
      "ldelem.u4" ... (TaskId:2742)
      "bgt.un.s" ... (TaskId:2742)
      "sizeof" ... (TaskId:2742)
      "beq.s" ... (TaskId:2742)
      "ldc.i4.1" ... (TaskId:2742)
      "neg" ... (TaskId:2742)
      "beq" ... (TaskId:2742)
      "ldloc.0" ... (TaskId:2742)
      "stloc.s" ... (TaskId:2742)
      "ldc.i4.m1" ... (TaskId:2742)
      "break" ... (TaskId:2742)
      "stind.i4" ... (TaskId:2742)
      "localloc" ... (TaskId:2742)
      "blt.s" ... (TaskId:2742)
      "conv.i8" ... (TaskId:2742)
      "ldind.r4" ... (TaskId:2742)
      "conv.ovf.i.un" ... (TaskId:2742)
      "brfalse" ... (TaskId:2742)
      "not" ... (TaskId:2742)
      "conv.ovf.i1" ... (TaskId:2742)
      "bgt" ... (TaskId:2742)
      "ldind.i1" ... (TaskId:2742)
      "conv.ovf.u8" ... (TaskId:2742)
      "stloc.3" ... (TaskId:2742)
      "stelem.r8" ... (TaskId:2742)
      "ldsflda" ... (TaskId:2742)
      "ldstr" ... (TaskId:2742)
      "shl" ... (TaskId:2742)
      "cgt.un" ... (TaskId:2742)
      "switch" ... (TaskId:2742)
      "ldelem.ref" ... (TaskId:2742)
      "castclass" ... (TaskId:2742)
      "stind.r8" ... (TaskId:2742)
      "bgt.s" ... (TaskId:2742)
      "volatile." ... (TaskId:2742)
      "ldc.i4.2" ... (TaskId:2742)
      "jmp" ... (TaskId:2742)
      "ldloc.1" ... (TaskId:2742)
      "ldobj" ... (TaskId:2742)
      "conv.r4" ... (TaskId:2742)
      "leave.s" ... (TaskId:2742)
      "ldftn" ... (TaskId:2742)
      "ldfld" ... (TaskId:2742)
      "conv.ovf.u1.un" ... (TaskId:2742)
      "conv.i1" ... (TaskId:2742)
      "conv.u8" ... (TaskId:2742)
      "conv.ovf.i1.un" ... (TaskId:2742)
      "ldc.i4.s" ... (TaskId:2742)
      "conv.ovf.i2" ... (TaskId:2742)
      "ldind.i2" ... (TaskId:2742)
      "ceq" ... (TaskId:2742)
      "ldc.i4" ... (TaskId:2742)
      "bge.un.s" ... (TaskId:2742)
      "conv.ovf.u1" ... (TaskId:2742)
      "ldarga" ... (TaskId:2742)
      "ldind.u1" ... (TaskId:2742)
      "bge" ... (TaskId:2742)
      "conv.i" ... (TaskId:2742)
      "ble.s" ... (TaskId:2742)
      "stelem.ref" ... (TaskId:2742)
      "ldc.i4.3" ... (TaskId:2742)
      "cgt" ... (TaskId:2742)
      "conv.r.un" ... (TaskId:2742)
      "ldloc.2" ... (TaskId:2742)
      "conv.ovf.u" ... (TaskId:2742)
      "shr.un" ... (TaskId:2742)
      "cpobj" ... (TaskId:2742)
      "blt" ... (TaskId:2742)
      "ldc.r8" ... (TaskId:2742)
      "conv.i2" ... (TaskId:2742)
      "or" ... (TaskId:2742)
      "conv.u1" ... (TaskId:2742)
      "br" ... (TaskId:2742)
      "ldloc.s" ... (TaskId:2742)
      "calli" ... (TaskId:2742)
      "box" ... (TaskId:2742)
      "endfinally" ... (TaskId:2742)
      "conv.ovf.u2" ... (TaskId:2742)
      "bge.s" ... (TaskId:2742)
      "ldind.u2" ... (TaskId:2742)
      "ldelem.i" ... (TaskId:2742)
      "newarr" ... (TaskId:2742)
      "clt.un" ... (TaskId:2742)
      "ldelem.i8" ... (TaskId:2742)
      "add" ... (TaskId:2742)
      "ret" ... (TaskId:2742)
      "ldarg.0" ... (TaskId:2742)
      "starg.s" ... (TaskId:2742)
      "brfalse.s" ... (TaskId:2742)
      "bgt.un" ... (TaskId:2742)
      "mkrefany" ... (TaskId:2742)
      "ldc.i4.4" ... (TaskId:2742)
      "bne.un.s" ... (TaskId:2742)
      "div" ... (TaskId:2742)
      "bne.un" ... (TaskId:2742)
      "ldloc.3" ... (TaskId:2742)
      "refanyval" ... (TaskId:2742)
      "stelem" ... (TaskId:2742)
      "stelem.any" ... (TaskId:2742)
      "ldelem" ... (TaskId:2742)
      "ldelem.any" ... (TaskId:2742)
      "unbox.any" ... (TaskId:2742)
      "no." ... (TaskId:2742)
      "constrained." ... (TaskId:2742)
      "readonly." ... (TaskId:2742)
      "ooo" ... (TaskId:2742)
      "lll" ... (TaskId:2742)
      <ID> ... (TaskId:2742)
       (TaskId:2742)
  [Build Output] Build Error. (TaskId:2742)
Void Star
  • 2,401
  • 4
  • 32
  • 57
  • 2
    I am by no means anything resembling an expert on CIL, but my thought is that it's the preceding lines that are causing the issue. the `stloc.s` opcode, from my understanding, should be providing a value in which to place the value popped from the stack. This is the case a little further down, on line 4195, unlike 4193. Again, just a hunch on my end. – Jonathon Chase Sep 02 '16 at 20:44
  • I agree, the IL of the preceding lines looks malformed on closer inspection, but why would ILDASM make bad IL? – Void Star Sep 02 '16 at 22:18
  • You can get IL from other tools, such as ILSpy or dotPeek. Check them out and compare the result. Based on what I know, ILDASM is reliable, so maybe the assembly itself is broken. – Lex Li Sep 02 '16 at 23:31
  • @BigEndian That's really hard to say without having access to the assembly or source that produces it. Can you provide an [mcve]? – svick Sep 04 '16 at 19:42
  • Another option: can your show the IL produced by ildasm with `/bytes` and also show the `.locals` section at the start of the method? – svick Sep 04 '16 at 19:47
  • 1
    @BigEndian, please [contact PreEmptive support](https://www.preemptive.com/contact/supportrequestform) about this. As a Pro user, we can help you solve this problem directly. We looked at what you posted already and don't see an obvious problem, so we'll need to collect more output from you. – Nathan Arthur Sep 06 '16 at 16:33
  • Ok. I will open a support request. Thanks Nathan. – Void Star Sep 06 '16 at 20:28
  • @NathanArthur I found that this is an ILDASM bug for certain, not Dotfuscator, so I think I will direct a bug report to Microsoft not PreEmptive Solutions, unless the Dotfuscator team wants to look into this Microsoft bug as well. I am writing an answer, you'll see details about my debugging efforts and investigation there. – Void Star Sep 06 '16 at 23:08
  • Actually, not an ILDASM bug either... See my answer. – Void Star Sep 06 '16 at 23:19

1 Answers1

3

Fody is evil.

Fody is an IL weaver. It can add code to your assembly after it is compiled. The problem is, the PDB file ended up mismatched with the assembly because of Fody, so ILDASM ran into a problem producing valid IL code. Delete the PDB and Dotfuscator works again.

Void Star
  • 2,401
  • 4
  • 32
  • 57
  • 1
    Good self-fixing, but to make this QA complete you ought to mention your complete toolchain (including Fody) in the Q, otherwise others with the same problem may not find the Q (and your A) in future. – AakashM Sep 07 '16 at 14:06
  • Thank you -- I get the same error from `ildasm` if I run it against an assembly which is output from `ILRepack.exe` ... deleting the `*.pdb` file lets the dotfuscation run to completion. – ChrisW Feb 22 '18 at 14:13
  • I am able to get good PDBs out of ILRepack but I am using a fork of an older version. – Void Star Jul 02 '18 at 20:28