SamboyCoding / Cpp2IL

Work-in-progress tool to reverse unity's IL2CPP toolchain.
MIT License
1.7k stars 200 forks source link

Cpp2IL.Core.Exceptions.DllSaveException #27

Closed gompocp closed 3 years ago

gompocp commented 3 years ago

Using Cpp2Il 2021.3.1. Running analysis on several different games ended with exceptions such as:


[Info] [Program] Saving 1 assembly to D:\Program Files (x86)\Steam\steamapps\common\BONEWORKS\BONEWORKS\cpp2il_out...
[Fail] [Program] Cpp2IL.Core.Exceptions.DllSaveException: Fatal Exception writing DLL D:\Program Files (x86)\Steam\steamapps\common\BONEWORKS\BONEWORKS\cpp2il_out\Assembly-CSharp.dll
 ---> System.NotSupportedException: Specified method is not supported.
   at Mono.Cecil.SignatureWriter.WriteTypeSignature(TypeReference type)
   at Mono.Cecil.SignatureWriter.WriteGenericInstanceSignature(IGenericInstance instance)
   at Mono.Cecil.MetadataBuilder.GetTypeSpecToken(TypeReference type)
   at Mono.Cecil.MetadataBuilder.CreateMemberRefRow(MemberReference member)
   at Mono.Cecil.MetadataBuilder.GetMemberRefToken(MemberReference member)
   at Mono.Cecil.MetadataBuilder.LookupToken(IMetadataTokenProvider provider)
   at Mono.Cecil.Cil.CodeWriter.WriteOperand(Instruction instruction)
   at Mono.Cecil.Cil.CodeWriter.WriteInstructions()
   at Mono.Cecil.Cil.CodeWriter.WriteResolvedMethodBody(MethodDefinition method)
   at Mono.Cecil.Cil.CodeWriter.WriteMethodBody(MethodDefinition method)
   at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
   at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddTypes()
   at Mono.Cecil.MetadataBuilder.BuildTypes()
   at Mono.Cecil.MetadataBuilder.BuildModule()
   at Mono.Cecil.MetadataBuilder.BuildMetadata()
   at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
   at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
   at Cpp2IL.Core.Cpp2IlApi.SaveAssemblies(String toWhere, List`1 assemblies)
   --- End of inner exception stack trace ---
   at Cpp2IL.Core.Cpp2IlApi.SaveAssemblies(String toWhere, List`1 assemblies)
   at Cpp2IL.Program.DoAssemblyCSharpAnalysis(String assemblyName, AnalysisLevel analysisLevel, String rootDir, KeyFunctionAddresses keyFunctionAddresses, Boolean doIlToAsm, Boolean parallel)
   at Cpp2IL.Program.MainWithArgs(Cpp2IlRuntimeArgs runtimeArgs)
   at Cpp2IL.Program.Main(String[] args)```
SamboyCoding commented 3 years ago

Yep, I've just fixed this in my dev branch - a271ca9 fixes it. Check the CI builds, do they work for you?

gompocp commented 3 years ago

Works 😃

gompocp commented 3 years ago

Reopening as as I've gotten another similar case now in another game

[Fail] [Program] Cpp2IL.Core.Exceptions.DllSaveException: Fatal Exception writing DLL D:\Program Files (x86)\Steam\steamapps\common\BloonsTD6\cpp2il_out\Assembly-CSharp.dll
 ---> System.ArgumentException: Member 'System.Action`1' is declared in another module and needs to be imported
   at Mono.Cecil.MetadataBuilder.LookupToken(IMetadataTokenProvider provider)
   at Mono.Cecil.SignatureWriter.WriteTypeSignature(TypeReference type)
   at Mono.Cecil.SignatureWriter.WriteGenericInstanceSignature(IGenericInstance instance)
SamboyCoding commented 3 years ago

Okay I've applied further fixes in e547eb5, can you let me know if that resolves it?

gompocp commented 3 years ago

Fixes it on BTD6 but I'm now getting the original error I had above again using a unobfuscated old copy of VRChat


[Info] [Program] Saving 1 assembly to E:\Windows\Programs\Software\SteamLibrary\steamapps\common\VRChatCopy\cpp2il_out...
[Fail] [Program] Cpp2IL.Core.Exceptions.DllSaveException: Fatal Exception writing DLL E:\Windows\Programs\Software\SteamLibrary\steamapps\common\VRChatCopy\cpp2il_out\Assembly-CSharp.dll
 ---> System.NotSupportedException: Specified method is not supported.
   at Mono.Cecil.SignatureWriter.WriteTypeSignature(TypeReference type)
   at Mono.Cecil.SignatureWriter.WriteGenericInstanceSignature(IGenericInstance instance)
   at Mono.Cecil.MetadataBuilder.GetVariablesSignature(Collection`1 variables)
   at Mono.Cecil.Cil.CodeWriter.WriteFatHeader()
   at Mono.Cecil.Cil.CodeWriter.WriteResolvedMethodBody(MethodDefinition method)
   at Mono.Cecil.Cil.CodeWriter.WriteMethodBody(MethodDefinition method)
   at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
   at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddTypes()
   at Mono.Cecil.MetadataBuilder.BuildTypes()
   at Mono.Cecil.MetadataBuilder.BuildModule()
   at Mono.Cecil.MetadataBuilder.BuildMetadata()
   at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
   at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
   at Cpp2IL.Core.Cpp2IlApi.SaveAssemblies(String toWhere, List`1 assemblies)
   --- End of inner exception stack trace ---
   at Cpp2IL.Core.Cpp2IlApi.SaveAssemblies(String toWhere, List`1 assemblies)
   at Cpp2IL.Program.DoAssemblyCSharpAnalysis(String assemblyName, AnalysisLevel analysisLevel, String rootDir, KeyFunctionAddresses keyFunctionAddresses, Boolean doIlToAsm, Boolean parallel)
   at Cpp2IL.Program.MainWithArgs(Cpp2IlRuntimeArgs runtimeArgs)
   at Cpp2IL.Program.Main(String[] args)```
SamboyCoding commented 3 years ago

Right okay, that's actually slightly different. I've now applied the same fix to the local variable definitions (which is what was causing this issue), can you check with commit 70da56

gompocp commented 3 years ago

Seems to be working 😄