Exemplo n.º 1
0
        public override TokenList Simplify(IToken first, IToken last)
        {
            TokenList firstList = first?.Simplify();
            TokenList lastList = last?.Simplify();

            if (firstList == null || lastList == null)
                throw new Exception($"Operation {Text} is a binary operation.");

            TokenList result = new TokenList();
            result.AddRange(firstList);
            result.AddRange(lastList);
            return result;
        }
Exemplo n.º 2
0
        public override TokenList Evaluate(IToken first, IToken last, TokenTreeList parameters)
        {
            TokenList firstList = first?.Evaluate(parameters);
            TokenList lastList = last?.Evaluate(parameters);

            if (firstList == null || lastList == null)
                throw new Exception($"Operation {Text} is a binary operation.");

            TokenList result = new TokenList();
            result.AddRange(firstList);
            result.AddRange(lastList);
            return result;
        }
Exemplo n.º 3
0
        public TokenList Tokenize(Stream str)
        {
            StreamReader sr = new StreamReader(str);
            String       line;
            TokenList    tokenList = new TokenList();

            try
            {
                TokenList tokList = null;
                while ((line = sr.ReadLine()) != null)
                {
                    tokList = TokenizeLine(line);
                    if (tokList != null)
                    {
                        tokenList.AddRange(tokList);
                    }
                }
            }
            finally
            {
                str.Close();
            }
            tokenList.Add(new Token(TokenKind.FileEnd, 0));
            return(tokenList);
        }
Exemplo n.º 4
0
 public ViewData(ParseTree tree)
 {
     this.Tree = tree;
     if (tree == null)
     {
         return;
     }
     NotColoredTokens.AddRange(tree.Tokens);
 }
Exemplo n.º 5
0
        protected override ITokenList GetClassList(UIElement dependencyObject)
        {
            var list       = new TokenList();
            var classNames = (dependencyObject.Class ?? "").Split(classSplitter, StringSplitOptions.RemoveEmptyEntries);

            if (classNames?.Length > 0)
            {
                list.AddRange(classNames);
            }
            return(list);
        }
Exemplo n.º 6
0
        protected override ITokenList GetClassList(DependencyObject dependencyObject)
        {
            var list       = new TokenList();
            var classNames = Css.GetClass(dependencyObject)?.Split(' ');

            if (classNames != null)
            {
                list.AddRange(classNames);
            }

            return(list);
        }
Exemplo n.º 7
0
        protected override ITokenList GetClassList(BindableObject dependencyObject)
        {
            var list = new TokenList();

            var classNames = Css.GetClass(dependencyObject)?.Split(classSplitter, StringSplitOptions.RemoveEmptyEntries);

            if (classNames?.Length > 0)
            {
                list.AddRange(classNames);
            }

            return(list);
        }
Exemplo n.º 8
0
        private void StartFunctionScan(byte[] data)
        {
            DecompiledScriptBlocks.ClearEx();
            TokenList.ClearEx();
            ScriptHeaderBlocks.ClearEx();
            ScriptFooterBlocks.ClearEx();
            if (CurrentLoadedExport.FileRef.Game == MEGame.ME3)
            {
                var func = new ME3Explorer.Unreal.Classes.Function(data, CurrentLoadedExport, CurrentLoadedExport.ClassName == "State" ? Convert.ToInt32(StartOffset_Changer.Text) : 32);


                func.ParseFunction();
                DecompiledScriptBlocks.Add(func.GetSignature());
                DecompiledScriptBlocks.AddRange(func.ScriptBlocks);
                TokenList.AddRange(func.SingularTokenList);

                int pos = 12;

                var functionSuperclass = BitConverter.ToInt32(CurrentLoadedExport.Data, pos);
                ScriptHeaderBlocks.Add(new ScriptHeaderItem("Function superclass", functionSuperclass, pos, functionSuperclass != 0 ? CurrentLoadedExport.FileRef.getEntry(functionSuperclass) : null));

                pos += 4;
                var nextItemCompilingChain = BitConverter.ToInt32(CurrentLoadedExport.Data, pos);
                ScriptHeaderBlocks.Add(new ScriptHeaderItem("Next item in loading chain", nextItemCompilingChain, pos, nextItemCompilingChain > 0 ? CurrentLoadedExport : null));

                pos += 4;
                nextItemCompilingChain = BitConverter.ToInt32(CurrentLoadedExport.Data, pos);
                ScriptHeaderBlocks.Add(new ScriptHeaderItem("Children Probe Start", nextItemCompilingChain, pos, nextItemCompilingChain > 0 ? CurrentLoadedExport : null));

                pos += 4;
                ScriptHeaderBlocks.Add(new ScriptHeaderItem("Unknown 2 (Memory size?)", BitConverter.ToInt32(CurrentLoadedExport.Data, pos), pos));

                pos += 4;
                ScriptHeaderBlocks.Add(new ScriptHeaderItem("Size", BitConverter.ToInt32(CurrentLoadedExport.Data, pos), pos));

                pos = CurrentLoadedExport.Data.Length - 6;
                string flagStr = func.GetFlags();
                ScriptFooterBlocks.Add(new ScriptHeaderItem("Native Index", BitConverter.ToInt16(CurrentLoadedExport.Data, pos), pos));
                pos += 2;
                ScriptFooterBlocks.Add(new ScriptHeaderItem("Flags", $"0x{BitConverter.ToInt32(CurrentLoadedExport.Data, pos).ToString("X8")} {func.GetFlags().Substring(6)}", pos));
            }
            else if (CurrentLoadedExport.FileRef.Game == MEGame.ME1)
            {
                //Header
                int pos = 16;

                var nextItemCompilingChain = BitConverter.ToInt32(CurrentLoadedExport.Data, pos);
                ScriptHeaderBlocks.Add(new ScriptHeaderItem("Next item in loading chain", nextItemCompilingChain, pos, nextItemCompilingChain > 0 ? CurrentLoadedExport : null));

                pos += 8;
                nextItemCompilingChain = BitConverter.ToInt32(CurrentLoadedExport.Data, pos);
                ScriptHeaderBlocks.Add(new ScriptHeaderItem("Children Probe Start", nextItemCompilingChain, pos, nextItemCompilingChain > 0 ? CurrentLoadedExport : null));

                pos += 4;
                ScriptHeaderBlocks.Add(new ScriptHeaderItem("Unknown 1 (??)", BitConverter.ToInt32(CurrentLoadedExport.Data, pos), pos));

                pos += 4;
                ScriptHeaderBlocks.Add(new ScriptHeaderItem("Unknown 2 (Line??)", BitConverter.ToInt32(CurrentLoadedExport.Data, pos), pos));

                pos += 4;
                ScriptHeaderBlocks.Add(new ScriptHeaderItem("Unknown 3 (TextPos??)", BitConverter.ToInt32(CurrentLoadedExport.Data, pos), pos));

                pos += 4;
                ScriptHeaderBlocks.Add(new ScriptHeaderItem("Script Size", BitConverter.ToInt32(CurrentLoadedExport.Data, pos), pos));
                pos          += 4;
                BytecodeStart = pos;
                var func = UE3FunctionReader.ReadFunction(CurrentLoadedExport);
                func.Decompile(new TextBuilder(), false); //parse bytecode

                bool defined = func.HasFlag("Defined");
                if (defined)
                {
                    DecompiledScriptBlocks.Add(func.FunctionSignature + " {");
                }
                else
                {
                    DecompiledScriptBlocks.Add(func.FunctionSignature);
                }
                for (int i = 0; i < func.Statements.statements.Count; i++)
                {
                    Statement s = func.Statements.statements[i];
                    DecompiledScriptBlocks.Add(s);
                    if (s.Reader != null && i == 0)
                    {
                        //Add tokens read from statement. All of them point to the same reader, so just do only the first one.
                        TokenList.AddRange(s.Reader.ReadTokens.Select(x => x.ToBytecodeSingularToken(pos)).OrderBy(x => x.StartPos));
                    }
                }

                if (defined)
                {
                    DecompiledScriptBlocks.Add("}");
                }

                //Footer
                pos = CurrentLoadedExport.Data.Length - (func.HasFlag("Net") ? 17 : 15);
                string flagStr = func.GetFlags();
                ScriptFooterBlocks.Add(new ScriptHeaderItem("Native Index", BitConverter.ToInt16(CurrentLoadedExport.Data, pos), pos));
                pos += 2;

                ScriptFooterBlocks.Add(new ScriptHeaderItem("Operator Precedence", CurrentLoadedExport.Data[pos], pos));
                pos++;

                int functionFlags = BitConverter.ToInt32(CurrentLoadedExport.Data, pos);
                ScriptFooterBlocks.Add(new ScriptHeaderItem("Flags", $"0x{functionFlags.ToString("X8")} {flagStr}", pos));
                pos += 4;

                //if ((functionFlags & func._flagSet.GetMask("Net")) != 0)
                //{
                //ScriptFooterBlocks.Add(new ScriptHeaderItem("Unknown 1 (RepOffset?)", BitConverter.ToInt16(CurrentLoadedExport.Data, pos), pos));
                //pos += 2;
                //}

                int friendlyNameIndex = BitConverter.ToInt32(CurrentLoadedExport.Data, pos);
                ScriptFooterBlocks.Add(new ScriptHeaderItem("Friendly Name Table Index", $"0x{friendlyNameIndex.ToString("X8")} {CurrentLoadedExport.FileRef.getNameEntry(friendlyNameIndex)}", pos));
                pos += 4;

                ScriptFooterBlocks.Add(new ScriptHeaderItem("Unknown 2", $"0x{BitConverter.ToInt16(CurrentLoadedExport.Data, pos).ToString("X4")}", pos));
                pos += 4;

                //ME1Explorer.Unreal.Classes.Function func = new ME1Explorer.Unreal.Classes.Function(data, CurrentLoadedExport.FileRef as ME1Package);
                //try
                //{
                //    Function_TextBox.Text = func.ToRawText();
                //}
                //catch (Exception e)
                //{
                //    Function_TextBox.Text = "Error parsing function: " + e.Message;
                //}
            }
            else
            {
                //Function_TextBox.Text = "Parsing UnrealScript Functions for this game is not supported.";
            }
        }
Exemplo n.º 9
0
 public MultiToken(params Token[] tokens) : this(tokens[0].Terminal, tokens[0].Location, new TokenList())
 {
     ChildTokens.AddRange(tokens);
 }
Exemplo n.º 10
0
 public ViewData(ParseTree tree)
 {
     this.Tree = tree;
     NotColoredTokens.AddRange(tree.Tokens);
 }