コード例 #1
0
        public int GetSwitchOffset(int index)
        {
            if (instruction != Instruction.SWITCH)
            {
                throw new Exception("Not A Switch Statement");
            }

            int cases;

            if (Program.RDROpcodes)
            {
                if ((cases = BitConverter.ToUInt16(operands, 0)) <= index)
                {
                    throw new Exception("Out of range script case");
                }
                Int16 length = BitConverter.ToInt16(operands, 6 + index * 6);
                return((offset + 8 + 1) + index * 6 + (Program.SwapEndian ? Utils.SwapEndian(length) : length));
            }
            else
            {
                if ((cases = GetOperand(0)) <= index)
                {
                    throw new Exception("Out Or Range Script Case");
                }
                Int16 length = BitConverter.ToInt16(operands, 5 + index * 6);
                return(offset + 8 + index * 6 + (Program.SwapEndian ? Utils.SwapEndian(length) : length));
            }
        }
コード例 #2
0
        /*public int GetSwitchCase(int index)
         *      {
         *              if (instruction == Instruction.Switch)
         *              {
         *                      int cases = GetOperand(0);
         *                      if (index >= cases)
         *                              throw new Exception("Out Or Range Script Case");
         *                      return Utils.SwapEndian(BitConverter.ToInt32(operands, 1 + index * 6));
         *              }
         *              throw new Exception("Not A Switch Statement");
         *      }*/

        public string GetSwitchStringCase(int index)
        {
            if (instruction != Instruction.SWITCH)
            {
                throw new Exception("Not A Switch Statement");
            }

            int cases;

            if (Program.RDROpcodes)
            {
                if ((cases = BitConverter.ToUInt16(operands, 0)) <= index)
                {
                    throw new Exception("Out Or Range Script Case");
                }
                else if (Program.IntStyle == Program.IntType._uint)
                {
                    UInt32 hash = BitConverter.ToUInt32(operands, 2 + index * 6);
                    return(Program.hashbank.GetHash(Program.SwapEndian ? Utils.SwapEndian(hash) : hash));
                }
                else
                {
                    Int32 hash = BitConverter.ToInt32(operands, 2 + index * 6);
                    return(Program.hashbank.GetHash(Program.SwapEndian ? Utils.SwapEndian(hash) : hash));
                }
            }
            else
            {
                if ((cases = GetOperand(0)) <= index)
                {
                    throw new Exception("Out Or Range Script Case");
                }
                else if (Program.IntStyle == Program.IntType._uint)
                {
                    UInt32 hash = BitConverter.ToUInt32(operands, 1 + index * 6);
                    return(Program.hashbank.GetHash(Program.SwapEndian ? Utils.SwapEndian(hash) : hash));
                }
                else
                {
                    Int32 hash = BitConverter.ToInt32(operands, 1 + index * 6);
                    return(Program.hashbank.GetHash(Program.SwapEndian ? Utils.SwapEndian(hash) : hash));
                }
            }
        }
コード例 #3
0
 public int GetSwitchOffset(int index)
 {
     if (instruction == Instruction.Switch)
     {
         int cases = GetOperand(0);
         if (index >= cases)
         {
             throw new Exception("Out of range script case");
         }
         if (_consoleVer)
         {
             return(offset + 8 + index * 6 + Utils.SwapEndian(BitConverter.ToInt16(operands, 5 + index * 6)));
         }
         else
         {
             return(offset + 8 + index * 6 + BitConverter.ToInt16(operands, 5 + index * 6));
         }
     }
     throw new Exception("Not A Switch Statement");
 }
コード例 #4
0
        /*public int GetSwitchCase(int index)
         * {
         *      if (instruction == Instruction.Switch)
         *      {
         *              int cases = GetOperand(0);
         *              if (index >= cases)
         *                      throw new Exception("Out Or Range Script Case");
         *              return Utils.SwapEndian(BitConverter.ToInt32(operands, 1 + index * 6));
         *      }
         *      throw new Exception("Not A Switch Statement");
         * }*/

        public string GetSwitchStringCase(int index)
        {
            if (instruction == Instruction.Switch)
            {
                int cases = GetOperand(0);
                if (index >= cases)
                {
                    throw new Exception("Out Or Range Script Case");
                }
                if (_consoleVer)
                {
                    return(Program.getIntType == Program.IntType._uint
                                                ? ScriptFile.hashbank.GetHash(Utils.SwapEndian(BitConverter.ToUInt32(operands, 1 + index * 6)))
                                                : ScriptFile.hashbank.GetHash(Utils.SwapEndian(BitConverter.ToInt32(operands, 1 + index * 6))));
                }
                else
                {
                    return(Program.getIntType == Program.IntType._uint
                                                ? ScriptFile.hashbank.GetHash(BitConverter.ToUInt32(operands, 1 + index * 6))
                                                : ScriptFile.hashbank.GetHash(BitConverter.ToInt32(operands, 1 + index * 6)));
                }
            }
            throw new Exception("Not A Switch Statement");
        }
コード例 #5
0
        void GetFunctions()
        {
            int returnpos = -3;

            while (offset < CodeTable.Count)
            {
                switch (CodeSet.Map(CodeTable[offset]))
                {
                case Instruction.PUSH_CONST_U8: advpos(1); break;

                case Instruction.PUSH_CONST_U8_U8: advpos(2); break;

                case Instruction.PUSH_CONST_U8_U8_U8: advpos(3); break;

                case Instruction.PUSH_CONST_U32:
                case Instruction.PUSH_CONST_F: advpos(4); break;

                case Instruction.NATIVE: advpos(3); break;

                case Instruction.ENTER: AddFunction(offset, returnpos + 3);; advpos(CodeTable[offset + 4] + 4); break;

                case Instruction.LEAVE: returnpos = offset; advpos(2); break;

                case Instruction.ARRAY_U8:
                case Instruction.ARRAY_U8_LOAD:
                case Instruction.ARRAY_U8_STORE:
                case Instruction.LOCAL_U8:
                case Instruction.LOCAL_U8_LOAD:
                case Instruction.LOCAL_U8_STORE:
                case Instruction.STATIC_U8:
                case Instruction.STATIC_U8_LOAD:
                case Instruction.STATIC_U8_STORE:
                case Instruction.IADD_U8:
                case Instruction.IMUL_U8:
                case Instruction.IOFFSET_U8:
                case Instruction.IOFFSET_U8_LOAD:
                case Instruction.IOFFSET_U8_STORE: advpos(1); break;

                case Instruction.PUSH_CONST_S16:
                case Instruction.IADD_S16:
                case Instruction.IMUL_S16:
                case Instruction.IOFFSET_S16:
                case Instruction.IOFFSET_S16_LOAD:
                case Instruction.IOFFSET_S16_STORE:
                case Instruction.ARRAY_U16:
                case Instruction.ARRAY_U16_LOAD:
                case Instruction.ARRAY_U16_STORE:
                case Instruction.LOCAL_U16:
                case Instruction.LOCAL_U16_LOAD:
                case Instruction.LOCAL_U16_STORE:
                case Instruction.STATIC_U16:
                case Instruction.STATIC_U16_LOAD:
                case Instruction.STATIC_U16_STORE:
                case Instruction.GLOBAL_U16:
                case Instruction.GLOBAL_U16_LOAD:
                case Instruction.GLOBAL_U16_STORE:
                case Instruction.J:
                case Instruction.JZ:
                case Instruction.IEQ_JZ:
                case Instruction.INE_JZ:
                case Instruction.IGT_JZ:
                case Instruction.IGE_JZ:
                case Instruction.ILT_JZ:
                case Instruction.ILE_JZ: advpos(2); break;

                case Instruction.CALL:
                case Instruction.STATIC_U24:
                case Instruction.STATIC_U24_LOAD:
                case Instruction.STATIC_U24_STORE:
                case Instruction.GLOBAL_U24:
                case Instruction.GLOBAL_U24_LOAD:
                case Instruction.GLOBAL_U24_STORE:
                case Instruction.PUSH_CONST_U24: advpos(3); break;

                case Instruction.SWITCH:
                {
                    if (Program.RDROpcodes)
                    {
                        int length = (CodeTable[offset + 2] << 8) | CodeTable[offset + 1];
                        advpos(2 + 6 * (Program.SwapEndian ? Utils.SwapEndian(length) : length));
                    }
                    else
                    {
                        advpos(1 + 6 * CodeTable[offset + 1]);
                    }
                    break;
                }

                case Instruction.TEXT_LABEL_ASSIGN_STRING:
                case Instruction.TEXT_LABEL_ASSIGN_INT:
                case Instruction.TEXT_LABEL_APPEND_STRING:
                case Instruction.TEXT_LABEL_APPEND_INT: advpos(1); break;
                }
                advpos(1);
            }
            offset = 0;
            GetFunctionCode();
        }
コード例 #6
0
        void AddFunction(int start1, int start2)
        {
            byte   namelen = CodeTable[start1 + 4];
            string name    = "";

            if (namelen > 0)
            {
                for (int i = 0; i < namelen; i++)
                {
                    name += (char)CodeTable[start1 + 5 + i];
                }
            }
            else if (start1 == 0)
            {
                name = ScriptFile.EntryName;
            }
            else
            {
                name = Function.FunctionName + Functions.Count.ToString();
            }

            int pcount = CodeTable[offset + 1];
            int tmp1 = CodeTable[offset + 2], tmp2 = CodeTable[offset + 3];
            int vcount = ((Program.SwapEndian) ? (tmp1 << 0x8) | tmp2 : (tmp2 << 0x8) | tmp1);

            if (vcount < 0)
            {
                throw new Exception("Well this shouldnt have happened");
            }
            int temp = start1 + 5 + namelen;

            while (CodeSet.Map(CodeTable[temp]) != Instruction.LEAVE)
            {
                switch (CodeSet.Map(CodeTable[temp]))
                {
                case Instruction.PUSH_CONST_U8: temp += 1; break;

                case Instruction.PUSH_CONST_U8_U8: temp += 2; break;

                case Instruction.PUSH_CONST_U8_U8_U8: temp += 3; break;

                case Instruction.PUSH_CONST_U32:
                case Instruction.PUSH_CONST_F: temp += 4; break;

                case Instruction.NATIVE: temp += 3; break;

                case Instruction.ENTER: throw new Exception("Return Expected");

                case Instruction.LEAVE: throw new Exception("Return Expected");

                case Instruction.ARRAY_U8:
                case Instruction.ARRAY_U8_LOAD:
                case Instruction.ARRAY_U8_STORE:
                case Instruction.LOCAL_U8:
                case Instruction.LOCAL_U8_LOAD:
                case Instruction.LOCAL_U8_STORE:
                case Instruction.STATIC_U8:
                case Instruction.STATIC_U8_LOAD:
                case Instruction.STATIC_U8_STORE:
                case Instruction.IADD_U8:
                case Instruction.IMUL_U8:
                case Instruction.IOFFSET_U8:
                case Instruction.IOFFSET_U8_LOAD:
                case Instruction.IOFFSET_U8_STORE: temp += 1; break;

                case Instruction.PUSH_CONST_S16:
                case Instruction.IADD_S16:
                case Instruction.IMUL_S16:
                case Instruction.IOFFSET_S16:
                case Instruction.IOFFSET_S16_LOAD:
                case Instruction.IOFFSET_S16_STORE:
                case Instruction.ARRAY_U16:
                case Instruction.ARRAY_U16_LOAD:
                case Instruction.ARRAY_U16_STORE:
                case Instruction.LOCAL_U16:
                case Instruction.LOCAL_U16_LOAD:
                case Instruction.LOCAL_U16_STORE:
                case Instruction.STATIC_U16:
                case Instruction.STATIC_U16_LOAD:
                case Instruction.STATIC_U16_STORE:
                case Instruction.GLOBAL_U16:
                case Instruction.GLOBAL_U16_LOAD:
                case Instruction.GLOBAL_U16_STORE:
                case Instruction.J:
                case Instruction.JZ:
                case Instruction.IEQ_JZ:
                case Instruction.INE_JZ:
                case Instruction.IGT_JZ:
                case Instruction.IGE_JZ:
                case Instruction.ILT_JZ:
                case Instruction.ILE_JZ: temp += 2; break;

                case Instruction.CALL:
                case Instruction.STATIC_U24:
                case Instruction.STATIC_U24_LOAD:
                case Instruction.STATIC_U24_STORE:
                case Instruction.GLOBAL_U24:
                case Instruction.GLOBAL_U24_LOAD:
                case Instruction.GLOBAL_U24_STORE:
                case Instruction.PUSH_CONST_U24: temp += 3; break;

                case Instruction.SWITCH:
                {
                    if (Program.RDROpcodes)
                    {
                        int length = (CodeTable[temp + 2] << 8) | CodeTable[temp + 1];
                        temp += 2 + 6 * (Program.SwapEndian ? Utils.SwapEndian(length) : length);
                    }
                    else
                    {
                        temp += 1 + 6 * CodeTable[temp + 1];
                    }
                    break;
                }

                case Instruction.TEXT_LABEL_ASSIGN_STRING:
                case Instruction.TEXT_LABEL_ASSIGN_INT:
                case Instruction.TEXT_LABEL_APPEND_STRING:
                case Instruction.TEXT_LABEL_APPEND_INT: temp += 1; break;
                }
                temp += 1;
            }
            int rcount   = CodeTable[temp + 2];
            int Location = start2;

            if (start1 == start2)
            {
                Functions.Add(new Function(this, name, pcount, vcount, rcount, Location, -1));
            }
            else
            {
                Functions.Add(new Function(this, name, pcount, vcount, rcount, Location, start1));
            }
        }