예제 #1
0
        protected static void HandleScript(LineBuffer Buffer, Object Data)
        {
            if (Buffer.GetKey(true).Equals("START_HEADER"))
            {
                ReadBlock(Buffer, "HEADER", HandleHeader, null);
                HandleScript(Buffer, Data);
            }

            if (Buffer.GetKey(true).Equals("START_METHOD"))
            {
                ReadBlock(Buffer, "METHOD", HandleMethod, HavokScript.MainMethod = new Stub());
                HandleScript(Buffer, Data);
            }
        }
예제 #2
0
        protected static void HandleNumberSizes(LineBuffer Buffer, Object Data)
        {
            String str = Buffer.GetKey(true);

            if (str.Equals("NUMBER"))
            {
                //TODO assert
                HavokScript.Header.NumSize = (int)Buffer.GetValue().NumVal;
                HandleNumberSizes(Buffer, Data);
                return;
            }
            if (str.Equals("SIZE_T"))
            {
                //TODO assert
                HavokScript.Header.SizeSize = (int)Buffer.GetValue().NumVal;
                HandleNumberSizes(Buffer, Data);
                return;
            }
            if (str.Equals("INSTRUCTION"))
            {
                //TODO assert
                HavokScript.Header.AltSize = (int)Buffer.GetValue().NumVal;
                HandleNumberSizes(Buffer, Data);
                return;
            }
            if (str.Equals("INTEGER"))
            {
                //TODO assert
                HavokScript.Header.IntSize = (int)Buffer.GetValue().NumVal;
                HandleNumberSizes(Buffer, Data);
                return;
            }
        }
예제 #3
0
        protected static void HandleHeader(LineBuffer Buffer, Object Data)
        {
            if (Buffer.GetKey(true).Equals("START_NUMBER_SIZES"))
            {
                ReadBlock(Buffer, "NUMBER_SIZES", HandleNumberSizes, null);
                HandleHeader(Buffer, Data);
                return;
            }


            if (Buffer.GetKey(true).Equals("VERSION"))
            {
                //TODO assert
                HavokScript.Header.Version = (int)Buffer.GetValue().NumVal;
                HandleHeader(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("LENDIAN"))
            {
                //TODO assert
                HavokScript.Header.IsLE = Buffer.GetValue().BoolVal;
                HandleHeader(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("UNK"))
            {
                HandleHeader(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("FLAGS"))
            {
                //TODO assert
                HavokScript.Header.Flags = (int)Buffer.GetValue().NumVal;
                HandleHeader(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("TYPES"))
            {
                //TODO assert
                HavokScript.Header.Types = (int)Buffer.GetValue().NumVal;
                HandleHeader(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("SHARE"))
            {
                //TODO assert
                HavokScript.Header.Share = Buffer.GetValue().BoolVal;
                HandleHeader(Buffer, Data);
                return;
            }
        }
예제 #4
0
        protected static void HandleConstants(LineBuffer Buffer, Object Data)
        {
            Stub Current = (Stub)Data;

            if (Buffer.GetKey(true).Equals("END_CONSTANTS"))
            {
                return;
            }


            if (Buffer.GetKey(true).Equals("TSTRING"))
            {
                LineData[] data = Buffer.Next(false);
                Current.Constants.Constants.Add(ConstantIndex++, new Constant(data.Length == 1 ? "" : data[1].Raw));
                HandleConstants(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("TNUMBER"))
            {
                Current.Constants.Constants.Add(ConstantIndex++, new Constant(Buffer.GetValue().NumVal));
                HandleConstants(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("TBOOLEAN"))
            {
                Current.Constants.Constants.Add(ConstantIndex++, new Constant(Buffer.GetValue().BoolVal));
                HandleConstants(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("TNIL"))
            {
                Buffer.GetValue();
                Current.Constants.Constants.Add(ConstantIndex++, new Constant());
                HandleConstants(Buffer, Data);
                return;
            }
        }
예제 #5
0
        protected static bool ReadBlock(LineBuffer buffer, String title, BlockCallback callback, Object data)
        {
            String temp;
            var    start = "START_" + title;
            var    end   = "END_" + title;

            temp = buffer.GetKey();
            if (!temp.Equals(start))
            {
                MessageBox.Show(String.Format("expected: {0}, got {1}", start, temp));
                return(false);
            }

            callback(buffer, data);

            temp = buffer.GetKey();
            if (!temp.Equals(end))
            {
                MessageBox.Show(String.Format("expected: {0}, got {1}", end, temp));
                return(false);
            }
            return(true);
        }
예제 #6
0
        protected static void HandleCodes(LineBuffer Buffer, Object Data)
        {
            Stub Current = (Stub)Data;

            if (Buffer.GetKey(true).Equals("END_CODE"))
            {
                return;
            }

            LineData[]      data = Buffer.Next();
            Type            IType;
            BaseInstruction Ahh;


            if (BaseInstruction.FromName(data[0].Raw) == null)
            {
                data = data.Skip(1).ToArray();
            }

            if ((Ahh = BaseInstruction.FromName(data[0].Raw)) == null)
            {
                MessageBox.Show("Instruction not found error");
                return;
            }

            data  = data.Skip(1).ToArray();
            IType = Ahh.GetType();
            Ahh   = (BaseInstruction)Activator.CreateInstance(IType);

            Ahh.A = (int)data[0].NumVal;
            Ahh.B = (int)data[1].NumVal;

            if (Ahh.HasC())
            {
                Ahh.C = (int)data[2].NumVal;
            }

            Current.Instructions.Add(Ahh);

            HandleCodes(Buffer, Data);
        }
예제 #7
0
        protected static void HandleMethod(LineBuffer Buffer, Object Data)
        {
            Stub Current = (Stub)Data;

            if (Buffer.GetKey(true).Equals("START_DBG"))
            {
                if (!ReadBlock(Buffer, "DBG", HandleDebug, Data))
                {
                    return;
                }
                HandleMethod(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("START_CONSTANTS"))
            {
                ConstantIndex = 0;
                if (!ReadBlock(Buffer, "CONSTANTS", HandleConstants, Data))
                {
                    return;
                }
                HandleMethod(Buffer, Data);
                return;
            }


            if (Buffer.GetKey(true).Equals("START_CODE"))
            {
                if (!ReadBlock(Buffer, "CODE", HandleCodes, Data))
                {
                    return;
                }
                HandleMethod(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("START_CLOSURE"))
            {
                if (!ReadBlock(Buffer, "CLOSURE", HandleClosure, new Stub(Current, (int)Buffer.Next(true)[1].NumVal)))
                {
                    return;
                }

                HandleMethod(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("FLAGS"))
            {
                //TODO assert
                Current.Flags = (int)Buffer.GetValue().NumVal;
                HandleMethod(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("PARAMS"))
            {
                //TODO assert
                Current.Parameters = (int)Buffer.GetValue().NumVal;
                HandleMethod(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("UPVALS"))
            {
                //TODO assert
                Current.UpVals = (int)Buffer.GetValue().NumVal;
                HandleMethod(Buffer, Data);
                return;
            }

            if (Buffer.GetKey(true).Equals("REGCNT"))
            {
                //TODO assert
                Current.Registers = (int)Buffer.GetValue().NumVal;
                HandleMethod(Buffer, Data);
                return;
            }
        }