Пример #1
0
        public Expression DecompileContext(bool isClass = false)
        {
            PopByte();

            var left = DecompileExpression();

            if (left == null)
            {
                return(null); // ERROR
            }
            ReadInt16();      // discard MemSize value. (size of expr-right in half-bytes)
            ReadObject();     // discard RetValRef.
            ReadByte();       // discard unknown byte.

            isInClassContext = isClass;
            var right = DecompileExpression();

            if (right == null)
            {
                return(null); // ERROR
            }
            isInClassContext = false;

            if (isClass)
            {
                var builder = new CodeBuilderVisitor(); // what a wonderful hack, TODO.
                left.AcceptVisitor(builder);
                var str = builder.GetCodeString() + ".static";
                left = new SymbolReference(null, null, null, str);
            }

            StartPositions.Pop();
            return(new CompositeSymbolRef(left, right, null, null));
        }
Пример #2
0
        public DynArrayFindStructMember DecompileDynArrayFindStructMember()
        {
            PopByte();
            var arr = DecompileExpression();

            if (arr == null)
            {
                return(null);
            }
            ReadInt16(); // MemSize
            var memberNameArg = DecompileExpression();

            if (memberNameArg == null)
            {
                return(null);
            }
            var valueArg = DecompileExpression();

            if (valueArg == null)
            {
                return(null);
            }
            PopByte(); //EndFuncParms
            StartPositions.Pop();
            return(new DynArrayFindStructMember(arr, memberNameArg, valueArg));
        }
Пример #3
0
        public Expression DecompilePrimitiveCast()
        {
            PopByte();
            var typeToken = ReadByte();

            var expr = DecompileExpression();

            if (expr == null)
            {
                return(null); // ERROR
            }
            // TODO: map this out, possibly most are implicit?
            string type = PrimitiveCastTable[typeToken];

            StartPositions.Pop();
            if (typeToken == (byte)ECast.ByteToInt && expr is IntegerLiteral || typeToken == (byte)ECast.InterfaceToObject)
            {
                return(expr);
            }

            //re-enable this once testing is complete
            //if (typeToken == (byte)ECast.IntToFloat && expr is IntegerLiteral shouldBeFloat)
            //{
            //    return new FloatLiteral(shouldBeFloat.Value);
            //}
            return(new PrimitiveCast((ECast)typeToken, new VariableType(type), expr, null, null));
        }
Пример #4
0
        public Expression DecompileNew()
        {
            PopByte();
            var parms = new List <Expression>();

            for (int n = 0; n < 5; n++)
            {
                if (CurrentIs(OpCodes.Nothing))
                {
                    PopByte();
                    parms.Add(null);
                    continue;
                }

                var param = DecompileExpression();
                if (param == null)
                {
                    return(null); // ERROR
                }
                parms.Add(param);
            }

            StartPositions.Pop();
            return(new NewOperator(parms[0], parms[1], parms[2], parms[3], parms[4]));
        }
Пример #5
0
        public ReturnStatement DecompileReturn()
        {
            PopByte();

            Expression expr = null;

            if (CurrentIs(StandardByteCodes.ReturnNullValue))
            {
                // TODO: research this a bit, seems to be the zero-equivalent value for the return type.
                PopByte();
                var retVal = ReadObject();
                expr = new SymbolReference(null, null, null, "null"); // TODO: faulty obv, kind of illustrates the thing though.
            }
            else if (CurrentIs(StandardByteCodes.Nothing))
            {
                PopByte();
            }
            else
            {
                expr = DecompileExpression();
                if (expr == null && PopByte() != (byte)StandardByteCodes.Nothing)
                {
                    return(null); //ERROR ?
                }
            }

            var statement = new ReturnStatement(null, null, expr);

            StatementLocations.Add(StartPositions.Pop(), statement);
            return(statement);
        }
Пример #6
0
        public Expression DecompileConditionalExpression()
        {
            PopByte();

            var cond = DecompileExpression();

            if (cond == null)
            {
                return(null); // ERROR
            }
            ReadInt16();      // MemSizeA

            var trueExpr = DecompileExpression();

            if (trueExpr == null)
            {
                return(null); // ERROR
            }
            ReadInt16();      // MemSizeB

            var falseExpr = DecompileExpression();

            if (falseExpr == null)
            {
                return(null); // ERROR
            }
            StartPositions.Pop();
            return(new ConditionalExpression(cond, trueExpr, falseExpr, null, null));
        }
Пример #7
0
        public DynArrayInsertItem DecompileDynArrayInsertItem()
        {
            PopByte();
            var arr = DecompileExpression();

            if (arr == null)
            {
                return(null);
            }
            ReadInt16(); // MemSize
            var indexArg = DecompileExpression();

            if (indexArg == null)
            {
                return(null);
            }
            var valueArg = DecompileExpression();

            if (valueArg == null)
            {
                return(null);
            }
            PopByte(); //EndFuncParms
            StartPositions.Pop();
            return(new DynArrayInsertItem(arr, indexArg, valueArg));
        }
Пример #8
0
        public Expression DecompileInOpNaive(String opName, bool useEndOfParms = false, bool isStruct = false)
        {
            // TODO: ugly, wrong.
            PopByte();

            if (isStruct)
            {
                ReadObject(); // struct type?
            }
            var left = DecompileExpression();

            if (left == null)
            {
                return(null); // ERROR
            }
            var right = DecompileExpression();

            if (right == null)
            {
                return(null); // ERROR
            }
            if (useEndOfParms)
            {
                PopByte();
            }

            StartPositions.Pop();
            var op = new InOpDeclaration(opName, 0, true, null, null, null, null, null, null, null);

            return(new InOpReference(op, left, right, null, null));
        }
Пример #9
0
        public DynArrayInsert DecompileDynArrayInsert()
        {
            PopByte();
            var arr = DecompileExpression();

            if (arr == null)
            {
                return(null);
            }
            var indexArg = DecompileExpression();

            if (indexArg == null)
            {
                return(null);
            }
            var countArg = DecompileExpression();

            if (countArg == null)
            {
                return(null);
            }
            PopByte(); //EndFuncParms
            StartPositions.Pop();
            return(new DynArrayInsert(arr, indexArg, countArg));
        }
Пример #10
0
        public Statement DecompileForEach(bool isDynArray = false)
        {
            PopByte();
            var scopeStatements = new List <Statement>();

            var iteratorFunc = DecompileExpression();

            if (iteratorFunc == null)
            {
                return(null);
            }

            if (isDynArray)
            {
                Expression dynArrVar   = DecompileExpression();
                bool       hasIndex    = Convert.ToBoolean(ReadByte());
                Expression dynArrIndex = DecompileExpression();
                iteratorFunc = new DynArrayIterator(iteratorFunc, dynArrVar, dynArrIndex);
            }

            var scopeEnd = ReadUInt16(); // MemOff

            ForEachScopes.Push(scopeEnd);

            Scopes.Add(scopeStatements);
            CurrentScope.Push(Scopes.Count - 1);
            while (Position < Size)
            {
                if (CurrentIs(OpCodes.IteratorNext))
                {
                    PopByte(); // IteratorNext
                    if (PeekByte == (byte)OpCodes.IteratorPop)
                    {
                        StatementLocations[(ushort)(Position - 1)] = new IteratorNext();
                        StatementLocations[(ushort)Position]       = new IteratorPop();
                        PopByte(); // IteratorPop
                        break;
                    }
                    Position--;
                }

                var current = DecompileStatement();
                if (current == null)
                {
                    return(null); // ERROR ?
                }
                scopeStatements.Add(current);
            }
            CurrentScope.Pop();
            ForEachScopes.Pop();

            var statement = new ForEachLoop(iteratorFunc, new CodeBody(scopeStatements))
            {
                iteratorPopPos = Position - 1
            };

            StatementLocations.Add(StartPositions.Pop(), statement);
            return(statement);
        }
Пример #11
0
        public Expression DecompileInstanceDelegate() // TODO: check code, seems ok?
        {
            PopByte();
            var name = PCC.GetName(ReadNameRef());

            StartPositions.Pop();
            return(new SymbolReference(null, null, null, "UNSUPPORTED: InstanceDelegate: " + name));
        }
Пример #12
0
        public Expression DecompileNativeParm() // TODO: see code
        {
            PopByte();
            var obj = ReadObject();

            StartPositions.Pop();
            return(new SymbolReference(null, "UNSUPPORTED: NativeParm: " + obj.ObjectName.Instanced + " : " + obj.ClassName, null, null));
        }
Пример #13
0
        public Expression DecompileInstanceDelegate() // TODO: check code, seems ok?
        {
            PopByte();
            var name = ReadNameReference();

            StartPositions.Pop();
            return(new SymbolReference(null, name));
        }
Пример #14
0
        public StringLiteral DecompileStringConst()
        {
            PopByte();

            var value = ReadNullTerminatedString();

            StartPositions.Pop();
            return(new StringLiteral(value));
        }
Пример #15
0
        public ObjectLiteral DecompileObjectConst()
        {
            PopByte();

            var value = ReadObject();

            StartPositions.Pop();
            return(new ObjectLiteral(new NameLiteral(value.ClassName == "Class" || value.Parent == ContainingClass.Export ? value.ObjectName.Instanced : value.InstancedFullPath), new VariableType(value.ClassName)));
        }
Пример #16
0
        public IntegerLiteral DecompileByteConst()
        {
            PopByte();

            var value = ReadByte();

            StartPositions.Pop();
            return(new IntegerLiteral(value, null, null));
        }
Пример #17
0
        public Expression DecompileDelegateProperty() // TODO: is this proper? Is it even used in ME3?
        {
            PopByte();
            var name = ReadNameReference();
            var obj  = ReadObject();

            StartPositions.Pop();
            return(new SymbolReference(null, name, null, null));
        }
Пример #18
0
        public NameLiteral DecompileNameConst()
        {
            PopByte();

            var value = ReadNameReference();

            StartPositions.Pop();
            return(new NameLiteral(value.Instanced));
        }
Пример #19
0
        public IntegerLiteral DecompileIntConst()
        {
            PopByte();

            var value = ReadInt32();

            StartPositions.Pop();
            return(new IntegerLiteral(value));
        }
Пример #20
0
        public FloatLiteral DecompileFloatConst()
        {
            PopByte();

            var value = ReadFloat();

            StartPositions.Pop();
            return(new FloatLiteral(value));
        }
Пример #21
0
        public StringRefLiteral DecompileStringRefConst()
        {
            PopByte();

            var value = ReadInt32();

            StartPositions.Pop();
            return(new StringRefLiteral(value));
        }
Пример #22
0
        public NameLiteral DecompileNameConst()
        {
            PopByte();

            var value = PCC.GetName(ReadNameRef());

            StartPositions.Pop();
            return(new NameLiteral(value, null, null));
        }
Пример #23
0
        public RotatorLiteral DecompileRotationConst()
        {
            PopByte();
            var pitch = ReadInt32();
            var yaw   = ReadInt32();
            var roll  = ReadInt32();

            StartPositions.Pop();
            return(new RotatorLiteral(pitch, yaw, roll));
        }
Пример #24
0
        public Expression /*ObjectLiteral*/ DecompileObjectConst() // TODO: properly
        {
            PopByte();

            var value = ReadObject();

            StartPositions.Pop();
            //return new ObjectLiteral(value, null, null);
            return(new SymbolReference(null, null, null, value.ClassName + "'" + value.ObjectName + "'"));
        }
Пример #25
0
        public VectorLiteral DecompileVectorConst()
        {
            PopByte();
            var x = ReadFloat();
            var y = ReadFloat();
            var z = ReadFloat();

            StartPositions.Pop();
            return(new VectorLiteral(x, y, z));
        }
Пример #26
0
        public Expression DecompileDelegateProperty() // TODO: is this proper? Is it even used in ME3?
        {
            PopByte();
            var name = PCC.GetName(ReadNameRef());
            var obj  = ReadObject(); // probably the delegate

            StartPositions.Pop();
            var objName = obj != null ? obj.ObjectName : "None";

            return(new SymbolReference(null, null, null, name + "(" + objName + ")"));
        }
Пример #27
0
        public Expression DecompileDefaultReference()
        {
            var obj = ReadObject();

            if (obj == null)
            {
                return(null); // ERROR
            }
            StartPositions.Pop();
            return(new DefaultReference(null, obj.ObjectName.Instanced));
        }
Пример #28
0
        public Expression DecompileObjectLookup()
        {
            var obj = ReadObject();

            if (obj == null)
            {
                return(null); // ERROR
            }
            StartPositions.Pop();
            return(new SymbolReference(null, null, null, obj.ObjectName));
        }
Пример #29
0
        public IntegerLiteral DecompileByteConst(string numType)
        {
            PopByte();

            var value = ReadByte();

            StartPositions.Pop();
            return(new IntegerLiteral(value)
            {
                NumType = numType
            });
        }
Пример #30
0
        public Expression /*RotationLiteral*/ DecompileRotationConst() // TODO: properly
        {
            PopByte();
            var Pitch = ReadInt32();
            var Yaw   = ReadInt32();
            var Roll  = ReadInt32();

            StartPositions.Pop();
            var str = "rot(0x" + Pitch.ToString("X8") + ", 0x" + Yaw.ToString("X8") + ", 0x" + Roll.ToString("X8") + ")";

            return(new SymbolReference(null, null, null, str));
        }