Exemplo n.º 1
0
 public virtual void Print(TextBuilder result, LabelTableToken labelTable, bool showStartOffset, bool addEmptyline = true)
 {
     if (Token.ToString() == "")
     {
         return;
     }
     PrintLabel(labelTable, result);
     result.Indent();
     if (showStartOffset)
     {
         result.Append("/* ").Append(StartOffset).Append(" */ ");
     }
     result.Append(Token.ToString(), StartOffset, EndOffset).Append(";");
     if (addEmptyline)
     {
         result.Append("\n");
     }
 }
Exemplo n.º 2
0
        public override void Decompile(TextBuilder result)
        {
            result.Append("class ").Append(_self.ObjectName.Instanced);
            if (_super != null)
            {
                result.Append(" extends ").Append(_super.ObjectName.Instanced);
            }
            if (_outerInstance != null && _outerInstance.ObjectName != "Object")
            {
                result.NewLine().Append("    within ").Append(_outerInstance.ObjectName.Instanced);
            }
            if (_hideCategories.Count > 0)
            {
                result.NewLine().Append("    hidecategories(").Append(string.Join(",", _hideCategories.ToArray())).Append(")");
            }
            if (_interfaces.Count > 0)
            {
                var intfNames = _interfaces.ConvertAll(e => e.ObjectName.Instanced).ToArray();
                result.NewLine().Append("    implements(").Append(string.Join(",", intfNames)).Append(")");
            }
            if (_config != "None")
            {
                result.NewLine().Append("    config(").Append(_config).Append(")");
            }
            _flags.Except("Compiled", "Parsed", "Config", "Localized").Each(f => result.NewLine().Append("    ").Append(f.ToLower()));
            result.Append(";").NewLine().NewLine();
            //DecompileChildren(result, false);

            var statementList = ReadBytecode();

            if (statementList.Count > 0)
            {
                DecompileReplicationBlock(result, statementList);
            }
            //if (_defaults != null)
            //{
            //    DecompileDefaultProperties(result);
            //}
        }
Exemplo n.º 3
0
 private void DecompileReplicationBlock(TextBuilder result, StatementList statementList)
 {
     result.Append("replication\n{\n").PushIndent();
     for (int i = 0; i < statementList.Count; i++)
     {
         List <String> names = FindReplicatedProperties(statementList[i].StartOffset);
         if (names.Count > 0)
         {
             result.Indent().Append("if (").Append(statementList[i].Token.ToString()).Append(")").NewLine();
             result.Indent().Append("    ");
             foreach (string name in names)
             {
                 result.Append(name);
                 if (name != names.Last())
                 {
                     result.Append(", ");
                 }
             }
             result.Append(";").NewLine().NewLine();
         }
     }
     result.Append("}").NewLine().NewLine().PopIndent();
 }
Exemplo n.º 4
0
        public void DecompileBytecode(StatementList statements, TextBuilder result, bool createControlStatements)
        {
            var labelTableStatement = statements.Find(s => s.Token is LabelTableToken);
            var labelTable          = labelTableStatement != null ? (LabelTableToken)labelTableStatement.Token : null;

            result.HasErrors = statements.HasErrors();
            if (createControlStatements)
            {
                try
                {
                    statements.CreateControlStatements();
                }
                catch (Exception)
                {
                    ProblemRegistry.RegisterIncompleteControlFlow(this);
                }
                if (statements.IsIncompleteControlFlow())
                {
                    ProblemRegistry.RegisterIncompleteControlFlow(this);
                }
                statements.RemoveRedundantReturns();
            }
            statements.Print(result, labelTable, !createControlStatements);
        }
Exemplo n.º 5
0
 public abstract void Decompile(TextBuilder result);
Exemplo n.º 6
0
 protected override void PrintHead(TextBuilder result)
 {
     result.Append("switch (").Append(Token.ToString()).Append(")");
 }
Exemplo n.º 7
0
 protected override void PrintHead(TextBuilder result)
 {
     result.Append("else");
 }
Exemplo n.º 8
0
 public void Print(TextBuilder result, LabelTableToken labelTable, bool showStartOffset)
 {
     result.PushIndent();
     statements.ForEach(s => s.Print(result, labelTable, showStartOffset));
     result.PopIndent();
 }
Exemplo n.º 9
0
 protected abstract void PrintHead(TextBuilder result);
Exemplo n.º 10
0
 protected virtual void PrintChildren(TextBuilder result, LabelTableToken labelTable, bool showStartOffsets)
 {
     _children.Print(result, labelTable, showStartOffsets);
 }
Exemplo n.º 11
0
        public void Decompile(TextBuilder result, bool createControlStatements)
        {
            result.Indent();
            if (Native)
            {
                result.Append("native");
                if (_nativeIndex > 0)
                {
                    result.Append("(").Append(_nativeIndex).Append(")");
                }
                result.Append(" ");
            }

            _flags.Except("Native", "Event", "Delegate", "Defined", "Public", "HasDefaults", "HasOutParms").Each(f => result.Append(f.ToLower() + " "));

            if (HasFlag("Event"))
            {
                result.Append("event ");
            }
            else if (HasFlag("Delegate"))
            {
                result.Append("delegate ");
            }
            else
            {
                result.Append("function ");
            }
            string type = GetReturnType();

            if (type != null)
            {
                result.Append(type).Append(" ");
            }
            result.Append(_self.ObjectName.Instanced).Append("(");
            int paramCount = 0;
            var locals     = new List <ExportEntry>();

            Tokens     = new List <BytecodeSingularToken>();
            Statements = ReadBytecode();
            List <ExportEntry> childrenReversed = _self.FileRef.Exports.Where(x => x.idxLink == _self.UIndex).ToList();

            childrenReversed.Reverse();

            //Get local children of this function
            foreach (ExportEntry export in childrenReversed)
            {
                //Reading parameters info...
                if (export.ClassName.EndsWith("Property"))
                {
                    UnrealFlags.EPropertyFlags ObjectFlagsMask = (UnrealFlags.EPropertyFlags)BitConverter.ToUInt64(export.Data, 0x18);
                    if (ObjectFlagsMask.HasFlag(UnrealFlags.EPropertyFlags.Parm) && !ObjectFlagsMask.HasFlag(UnrealFlags.EPropertyFlags.ReturnParm))
                    {
                        if (paramCount > 0)
                        {
                            result.Append(", ");
                        }

                        if (export.ClassName == "ObjectProperty" || export.ClassName == "StructProperty")
                        {
                            var    uindexOfOuter = BitConverter.ToInt32(export.Data, export.Data.Length - 4);
                            IEntry entry         = export.FileRef.GetEntry(uindexOfOuter);
                            if (entry != null)
                            {
                                result.Append($"{entry.ObjectName.Instanced} ");
                            }
                        }
                        else
                        {
                            result.Append($"{GetPropertyType(export)} ");
                        }

                        result.Append(export.ObjectName.Instanced);
                        paramCount++;

                        if (ObjectFlagsMask.HasFlag(UnrealFlags.EPropertyFlags.OptionalParm) && Statements.Count > 0)
                        {
                            if (Statements[0].Token is NothingToken)
                            {
                                Statements.RemoveRange(0, 1);
                            }
                            else if (Statements[0].Token is DefaultParamValueToken)
                            {
                                result.Append(" = ").Append(Statements[0].Token.ToString());
                                Statements.RemoveRange(0, 1);
                            }
                        }
                    }
                    if (ObjectFlagsMask.HasFlag(UnrealFlags.EPropertyFlags.ReturnParm))
                    {
                        break; //return param
                    }
                }

                //object instance = export.ReadInstance();
                //if (instance is UnClassProperty)
                //{
                //    var prop = (UnClassProperty)instance;
                //    if (prop.Parm)
                //    {
                //        if (!prop.ReturnParm)
                //        {
                //            if (paramCount > 0)
                //                result.Append(", ");

                //            prop.Flags.Except("Parm").Each(f => result.Append(f.ToLower() + " "));
                //            result.Append(prop.GetPropertyType()).Append(" ").Append(export.ObjectName);
                //            if (prop.OptionalParm && statements.Count > 0)
                //            {
                //                if (statements[0].Token is NothingToken)
                //                    statements.RemoveRange(0, 1);
                //                else if (statements[0].Token is DefaultParamValueToken)
                //                {
                //                    result.Append(" = ").Append(statements[0].Token.ToString());
                //                    statements.RemoveRange(0, 1);
                //                }
                //            }
                //            paramCount++;
                //        }
                //    }
                //    else
                //    {
                //        locals.Add(prop);
                //    }
                //}
            }
            result.Append(")");

            FunctionSignature = result.ToString();
            if (HasFlag("Defined"))
            {
                result.NewLine().Indent().Append("{").NewLine();
                result.PushIndent();
                foreach (var local in locals)
                {
                    result.Indent().Append("local ").Append(GetPropertyType(local)).Append(" ").Append(local.ObjectName.Instanced).Append(";").NewLine();
                }
                result.PopIndent();   // will be pushed again in DecompileBytecode()
                DecompileBytecode(Statements, result, createControlStatements);
                result.Indent().Append("}").NewLine().NewLine();
            }
            else
            {
                result.Append(";").NewLine().NewLine();
            }
        }
Exemplo n.º 12
0
 public override void Decompile(TextBuilder result)
 {
     Decompile(result, true);
 }