Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        protected string WriteVBFromAST(IExpression expression)
        {
            Contract.Requires(expression != null);

            var sourceEmitterOutput = new VBSourceEmitter.SourceEmitterOutputString();
            var VBSourceEmitter     = new VBSourceEmitter.SourceEmitter(this.host, sourceEmitterOutput);
            var es = new ExpressionSimplifier();

            expression = es.Rewrite(expression);
            VBSourceEmitter.Traverse(expression);
            return(sourceEmitterOutput.Data);
        }
Пример #2
0
        static void Main(string[] args)
        {
            string strFileName;

            if (args.Length > 0)
            {
                strFileName = args[0];
            }
            else
            {
                return;
            }

            using (var host = new HostEnvironment()) {
                IModule /*?*/ module = host.LoadUnitFrom(args[0]) as IModule;
                if (module == null || module is Dummy)
                {
                    Console.WriteLine(args[0] + " is not a PE file containing a CLR module or assembly.");
                    return;
                }

                PdbReader /*?*/ pdbReader = null;
                string          pdbFile   = Path.ChangeExtension(module.Location, "pdb");
                if (File.Exists(pdbFile))
                {
                    using (var pdbStream = File.OpenRead(pdbFile)) {
                        pdbReader = new PdbReader(pdbStream, host);
                    }
                }
                using (pdbReader) {
                    module = Decompiler.GetCodeModelFromMetadataModel(host, module, pdbReader, DecompilerOptions.AnonymousDelegates | DecompilerOptions.Iterators | DecompilerOptions.Loops);
                    VBSourceEmitter.SourceEmitterOutputString sourceEmitterOutput = new VBSourceEmitter.SourceEmitterOutputString();
                    VBSourceEmitter.SourceEmitter             CSSourceEmitter     = new VBSourceEmitter.SourceEmitter(host, sourceEmitterOutput);

                    CSSourceEmitter.Traverse(module.UnitNamespaceRoot);

                    Console.WriteLine(sourceEmitterOutput.Data);
                }
            }
            Console.ReadLine();
        }
Пример #3
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="expression"></param>
    /// <returns></returns>
    protected string WriteVBFromAST(IExpression expression) {
      Contract.Requires(expression != null);

      var sourceEmitterOutput = new VBSourceEmitter.SourceEmitterOutputString();
      var VBSourceEmitter = new VBSourceEmitter.SourceEmitter(this.host, sourceEmitterOutput);
      var es = new ExpressionSimplifier();
      expression = es.Rewrite(expression);
      VBSourceEmitter.Traverse(expression);
      return sourceEmitterOutput.Data;
    }