当前位置: 首页>>代码示例>>C#>>正文


C# AssemblyNode.WriteModule方法代码示例

本文整理汇总了C#中System.Compiler.AssemblyNode.WriteModule方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyNode.WriteModule方法的具体用法?C# AssemblyNode.WriteModule怎么用?C# AssemblyNode.WriteModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Compiler.AssemblyNode的用法示例。


在下文中一共展示了AssemblyNode.WriteModule方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MikesArchitecture


//.........这里部分代码省略.........

                Rewriter rewriter = new Rewriter(assemblyNode, runtimeContracts, options.EmitError,
                    options.inheritInvariants, options.skipQuantifiers);

                rewriter.Verbose = 0 < options.verbose;
                rewriter.Visit(assemblyNode);

                // Perform this check only when there are no out-of-band contracts in use due to rewriter bug #336
                if (contractAssembly == null)
                {
                    PostRewriteChecker checker = new PostRewriteChecker(options.EmitError);
                    checker.Visit(assemblyNode);
                }
            }

            //Console.WriteLine(">>>Finished Rewriting<<<");

            // Set metadata version for target the same as for the source

            TargetPlatform.TargetRuntimeVersion = assemblyNode.TargetRuntimeVersion;

            // Write out the assembly (optional)

            if (options.rewrite || options.passthrough)
            {
                bool updateInPlace = options.output == "same";

                string pdbFile = Path.ChangeExtension(options.assembly, ".pdb");
                bool pdbExists = File.Exists(pdbFile);

                string backupAssembly = options.assembly + ".original";
                string backupPDB = pdbFile + ".original";


                if (updateInPlace)
                {
                    // Write the rewritten assembly in a temporary location.
                    options.output = options.assembly;

                    MoveAssemblyFileAndPDB(options.output, pdbFile, pdbExists, backupAssembly, backupPDB);
                }

                // Write the assembly.
                // Don't pass the debugInfo flag to WriteModule unless the PDB file exists.
                assemblyNode.WriteModule(options.output, options.debug && pdbExists && options.writePDBFile);

                string outputDir = updateInPlace
                    ? Path.GetDirectoryName(options.assembly)
                    : Path.GetDirectoryName(options.output);

                // Re-attach external file resources to the new output assembly.
                MoveModuleResources(assemblyNode, outputDir);

#if false
        if (oldPeVerifyCode == 0)
        {
          var newPeVerifyCode = PEVerify(assemblyNode.Location, originalsourceDir);
          if (newPeVerifyCode > 0)
          {
            if (updateInPlace)
            {
              // move original back in place
              MoveAssemblyFileAndPDB(backupAssembly, backupPDB, pdbExists, options.output, pdbFile);
            }
            throw new Exception("Rewrite failed to produce verifiable assembly");
          }
          else if (newPeVerifyCode == 0)
          {
            Console.WriteLine("rewriter output verified");
          }
        }
#endif
                if (updateInPlace)
                {
                    if (!options.keepOriginalFiles)
                    {
                        try
                        {
                            File.Delete(backupAssembly);
                        }
                        catch
                        {
                            // there are situations where the exe is still in use
                        }
                        if (options.debug && pdbExists && options.writePDBFile)
                        {
                            try
                            {
                                File.Delete(backupPDB);
                            }
                            catch
                            {
                                // I know this is stupid, but somehow on some machines we get an AccessError trying to delete the pdb.
                                // so we leave it in place.
                            }
                        }
                    }
                }
            }
        }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:101,代码来源:Program.cs

示例2: KaelsArchitecture

      private static void KaelsArchitecture(AssemblyNode assemblyNode) {

    // Finish decompiling expressions where CCI left off.
        new Abnormalizer().Visit(assemblyNode);
        

    // Check and extract all inline foxtrot contracts and place them in the object model.
        Checker checker = new Checker(new ContractNodes(assemblyNode));
        bool errorFound = false;
        checker.ErrorFound += delegate(System.CodeDom.Compiler.CompilerError error) {
          if (!error.IsWarning || warningLevel > 0) {
            Console.WriteLine(error.ToString());
          }
          errorFound |= !error.IsWarning;
        };
        checker.Visit(assemblyNode);
        if (errorFound)
          return;
        

        if (verify) {
          throw new NotImplementedException("Static verification is not yet implemented.");
        }

    // Write out the assembly, possibly injecting the runtime checks
        if (rewrite || passthrough) {
          // Reload the assembly to flush out the abnormalized contracts since the rewriter can't handle them yet.
          assemblyNode = LoadAssembly();

          if (!passthrough) {
            // Rewrite the assembly in memory.
            Rewriter rewriter = new Rewriter(new ContractNodes(assemblyNode));
            rewriter.InlinePreconditions = false;
            rewriter.InlinePostconditions = false;
            rewriter.InlineInvariant = false;
            rewriter.Verbose = verbose;
            rewriter.Decompile = decompile;
            rewriter.Visit(assemblyNode);
          }

          if (output == "same") {
            // Save the rewritten assembly to a temporary location.
            output = Path.Combine(Path.GetTempPath(), Path.GetFileName(assembly));

            // Re-attach external file resources to the new output assembly.
            MoveModuleResources(assemblyNode, output);

            // Save the rewritten assembly.
            assemblyNode.WriteModule(output, debug);

            // Make a copy of the original assembly and PDB.
            File.Delete(assembly + ".original");
            File.Delete(Path.ChangeExtension(assembly, ".pdb") + ".original");
            File.Move(assembly, assembly + ".original");
            File.Move(Path.ChangeExtension(assembly, ".pdb"), Path.ChangeExtension(assembly, ".pdb") + ".original");

            // Move the rewritten assembly and PDB to the original location.
            File.Move(output, assembly);
            File.Move(Path.ChangeExtension(output, ".pdb"), Path.ChangeExtension(assembly, ".pdb"));
          } else {
            // Re-attach external file resources to the new output assembly.
            MoveModuleResources(assemblyNode, output);

            // Save the rewritten assembly.
            assemblyNode.WriteModule(output, debug);
          }
        }
      }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:68,代码来源:Program.cs


注:本文中的System.Compiler.AssemblyNode.WriteModule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。