Beispiel #1
0
        public string Decompile()
        {
            if (Script == null)
            {
                return("");
            }

            Script.Resolve();

            Dictionary <Method, BlockStatement> methods = new Dictionary <Method, BlockStatement>();

            methods.Add(Script.Methods[Script.TopLevel], DecompileObject(Script.TopLevel));
            foreach (var method in Script.Methods)
            {
                if (method.Key == Script.TopLevel)
                {
                    continue;
                }

                switch (method.Key.ContextType)
                {
                case TjsContextType.PropertyGetter:
                case TjsContextType.PropertySetter:
                    break;

                case TjsContextType.Function:
                case TjsContextType.ExprFunction:
                case TjsContextType.TopLevel:
                    var block = DecompileObject(method.Key);
                    methods.Add(method.Value, block);
                    break;
                }
            }

            var writer = new StringWriter();
            var tjs    = new TjsWriter(writer)
            {
                MethodRefs = methods
            };

            tjs.WriteLicense();

            foreach (var m in methods)
            {
                if (m.Key.IsLambda)
                {
                    continue;
                }

                tjs.WriteLine();
                tjs.WriteFunction(m.Key, m.Value);
                tjs.WriteLine();
            }

            writer.Flush();
            var result = writer.ToString();

            return(result);
        }
Beispiel #2
0
        internal string Decompile(string objName)
        {
            if (Script == null)
            {
                return("");
            }

            Script.Resolve();

            Dictionary <Method, BlockStatement> methods = new Dictionary <Method, BlockStatement>();

            //methods.Add(Script.Methods[Script.TopLevel], DecompileObject(Script.TopLevel));

            var method = Script.Methods.FirstOrDefault(m => m.Key.Name == objName);
            var block  = DecompileObject(method.Key);

            methods.Add(method.Value, block);

            var writer = new StringWriter();
            var tjs    = new TjsWriter(writer)
            {
                MethodRefs = methods
            };

            tjs.WriteLicense();

            foreach (var m in methods)
            {
                if (m.Key.IsLambda)
                {
                    continue;
                }

                tjs.WriteLine();
                tjs.WriteFunction(m.Key, m.Value);
                tjs.WriteLine();
            }

            writer.Flush();
            var result = writer.ToString();

            return(result);
        }