mkaring / ConfuserEx

An open-source, free protector for .NET applications
https://mkaring.github.io/ConfuserEx/
MIT License
2.26k stars 349 forks source link

Could not resolve type: System.Environment #500

Closed Princekin closed 1 year ago

Princekin commented 1 year ago

While trying to obfuscate a .net 4.0 x86 executable i get this error:

[ERROR] Failed to resolve a type, check if all dependencies are present in the correct version.

However i do not use any external dependency.

Full stacktrace:

 [INFO] Confuser.Core 1.5.0+b5197549e4 Copyright © 2014 Ki, 2018 - 2021 Martin Karing
 [INFO] Running on Microsoft Windows NT 6.2.9200.0, .NET Framework v4.0.30319.42000, 64 bits
[DEBUG] Discovering plugins...
 [INFO] Discovered 13 protections, 1 packers.
[DEBUG] Resolving component dependency...
 [INFO] Loading input modules...
 [INFO] Loading 'File.exe'...
 [INFO] Initializing...
[DEBUG] Building pipeline...
[DEBUG] Executing 'Type scanner' phase...
 [INFO] Resolving dependencies...
[DEBUG] Checking Strong Name...
[DEBUG] Creating global .cctors...
[DEBUG] Executing 'Name analysis' phase...
[DEBUG] Building VTables & identifier list...
[DEBUG] Analyzing...
[DEBUG] WinForms found, enabling compatibility.
 [INFO] Processing module 'mscorlib.exe'...
[DEBUG] Executing 'Invalid metadata addition' phase...
[DEBUG] Executing 'Renaming' phase...
[DEBUG] Renaming...
[DEBUG] Executing 'Anti-tamper module writer preparation' phase...
[DEBUG] Executing 'Anti-debug injection' phase...
[ERROR] Failed to resolve a type, check if all dependencies are present in the correct version.
Exception: dnlib.DotNet.TypeResolveException: Could not resolve type: System.Environment (mscorlib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null)
   in dnlib.DotNet.TypeRef.ResolveThrow(ModuleDef sourceModule)
   in dnlib.DotNet.Extensions.ResolveTypeDefThrow(ITypeDefOrRef tdr)
   in Confuser.Renamer.Analyzers.LdtokenEnumAnalyzer.Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
   in Confuser.Renamer.AnalyzePhase.Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, IDnlibDef def, Boolean runAnalyzer)
   in Confuser.Renamer.NameService.Analyze(IDnlibDef def)
   in Confuser.Protections.AntiDebugProtection.AntiDebugPhase.Execute(ConfuserContext context, ProtectionParameters parameters)
   in Confuser.Core.ProtectionPipeline.ExecuteStage(PipelineStage stage, Action`1 func, Func`1 targets, ConfuserContext context)
   in Confuser.Core.ConfuserEngine.RunPipeline(ProtectionPipeline pipeline, ConfuserContext context)
   in Confuser.Core.ConfuserEngine.RunInternal(ConfuserParameters parameters, CancellationToken token)
[ERROR] ---BEGIN DEBUG INFO---
[ERROR] Installed Framework Versions:
[ERROR]     v2.0.50727  2.0.50727.4927
[ERROR]     v3.0  3.0.30729.4926
[ERROR]     v3.5  3.5.30729.4926
[ERROR]     v4
[ERROR]     Client  4.8.04161
[ERROR]     Full  4.8.04161
[ERROR]     v4.0
[ERROR]     Client  4.0.0.0
[ERROR]     v4.5 528449
[ERROR] 
[ERROR] Cached assemblies:
[ERROR]     mscorlib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (C:\Users\Admin\Desktop\File.exe)
[ERROR]         mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR]     mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 (C:\Windows\Microsoft.NET\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll)
[ERROR]     System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 (C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll)
[ERROR]         mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR]         System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]     System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 (C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll)
[ERROR]         mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR]         System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR]         System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR]         Accessibility, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR]         System.Deployment, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR]         System.Runtime.Serialization.Formatters.Soap, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR]     System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 (C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll)
[ERROR]         mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR]     Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll)
[ERROR]         mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Deployment, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR]         System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR]         System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR]         System.Runtime.Remoting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]     mscorlib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (C:\Users\Admin\Desktop\File.exe)
[ERROR]         mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
[ERROR]         Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[ERROR] ---END DEBUG INFO---
Failed at 03:43, 0:00 elapsed.

Config used:

Only Control Flow - Maximum

(With anything else this error still however)

himanshukodwani commented 1 year ago

Adding probe paths like following may solve depending upon your target .Net version :

<probePath>C:\Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.6</probePath>
  <probePath>C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.6</probePath>
  <probePath>C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.6\ref\net6.0</probePath>
  <probePath>C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.9\ref\net6.0</probePath>
  <probePath>C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.9\ref\net6.0</probePath>
  <probePath>C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\6.0.9</probePath>
Princekin commented 1 year ago

The problem was related to the assembly name. Using name mscorlib.exe gives that error, any other works without problems.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.