Ejemplo n.º 1
0
        public TConstantPool(BinaryReader Reader)
        {
            FReader = Reader;

            FMaxItems = Common.ReadWord(FReader) - 1;
            FItems = new ArrayList();
            int count = 0;

            // goes from 1 -> constantpoolcount - 1
            while (count < FMaxItems)
            {
                byte tag = Common.ReadByte(FReader);

                switch (tag)
                {
                    case (byte)ConstantPoolInfoTag.ConstantClass:
                        {
                            ConstantClassInfo cc = new ConstantClassInfo();
                            cc.Read(tag, FReader);
                            FItems.Add(cc);
                            break;
                        }
                    case (byte)ConstantPoolInfoTag.ConstantString:
                        {
                            ConstantStringInfo cc = new ConstantStringInfo();
                            cc.Read(tag, FReader);
                            FItems.Add(cc);
                            break;
                        }
                    case (byte)ConstantPoolInfoTag.ConstantFieldref:
                        {
                            ConstantFieldrefInfo cc = new ConstantFieldrefInfo();
                            cc.Read(tag, FReader);
                            FItems.Add(cc);
                            break;
                        }
                    case (byte)ConstantPoolInfoTag.ConstantMethodref:
                        {
                            ConstantMethodrefInfo cc = new ConstantMethodrefInfo();
                            cc.Read(tag, FReader);
                            FItems.Add(cc);
                            break;
                        }
                    case (byte)ConstantPoolInfoTag.ConstantInterfaceMethodref:
                        {
                            ConstantInterfaceMethodrefInfo cc = new ConstantInterfaceMethodrefInfo();
                            cc.Read(tag, FReader);
                            FItems.Add(cc);
                            break;
                        }
                    case (byte)ConstantPoolInfoTag.ConstantInteger:
                        {
                            ConstantIntegerInfo cc = new ConstantIntegerInfo();
                            cc.Read(tag, FReader);
                            FItems.Add(cc);
                            break;
                        }
                    case (byte)ConstantPoolInfoTag.ConstantFloat:
                        {
                            ConstantFloatInfo cc = new ConstantFloatInfo();
                            cc.Read(tag, FReader);
                            FItems.Add(cc);
                            break;
                        }
                    case (byte)ConstantPoolInfoTag.ConstantLong:
                        {
                            ConstantLongInfo cc = new ConstantLongInfo();
                            cc.Read(tag, FReader);
                            FItems.Add(cc);
                            // longs take up two entries in the pool table
                            count++;
                            FItems.Add(cc);
                            break;
                        }
                    case (byte)ConstantPoolInfoTag.ConstantDouble:
                        {
                            ConstantDoubleInfo cc = new ConstantDoubleInfo();
                            cc.Read(tag, FReader);
                            FItems.Add(cc);
                            // so do doubles
                            count++;
                            FItems.Add(cc);
                            break;
                        }
                    case (byte)ConstantPoolInfoTag.ConstantNameAndType:
                        {
                            ConstantNameAndTypeInfo cc = new ConstantNameAndTypeInfo();
                            cc.Read(tag, FReader);
                            FItems.Add(cc);
                            break;
                        }
                    case (byte)ConstantPoolInfoTag.ConstantUtf8:
                        {
                            ConstantUtf8Info cc = new ConstantUtf8Info();
                            cc.Read(tag, FReader);
                            FItems.Add(cc);
                            break;
                        }

                    default:
                        // fail safe ?
                        count++;
                        break;
                }

                count++;
            }

            foreach (ConstantPoolInfo cc in FItems)
            {
                cc.Resolve(FItems);
            }
        }
Ejemplo n.º 2
0
		public void Write(BinaryWriter Writer)
		{
			// i am assuming we have a valid constant pool list...
			// i dont do any error checking here except bare minimum!

			// write the number of constant pool entries
			Common.WriteWord(Writer, FMaxItems + 1);
			int count = 0;

			// goes from 1 -> constantpoolcount - 1
			while (count < FMaxItems)
			{
				ConstantPoolInfo Item = (ConstantPoolInfo)FItems[count];

				switch (Item.Tag)
				{
					case (byte)ConstantPoolInfoTag.ConstantClass:
						{
							ConstantClassInfo cc = (ConstantClassInfo)Item;
							cc.Write(Writer);

							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantString:
						{
							ConstantStringInfo cc = (ConstantStringInfo)Item;
							cc.Write(Writer);

							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantFieldref:
						{
							ConstantFieldrefInfo cc = (ConstantFieldrefInfo)Item;
							cc.Write(Writer);

							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantMethodref:
						{
							ConstantMethodrefInfo cc = (ConstantMethodrefInfo)Item;
							cc.Write(Writer);

							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantInterfaceMethodref:
						{
							ConstantInterfaceMethodrefInfo cc = (ConstantInterfaceMethodrefInfo)Item;
							cc.Write(Writer);

							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantInteger:
						{
							ConstantIntegerInfo cc = (ConstantIntegerInfo)Item;
							cc.Write(Writer);

							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantFloat:
						{
							ConstantFloatInfo cc = (ConstantFloatInfo)Item;
							cc.Write(Writer);

							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantLong:
						{
							ConstantLongInfo cc = (ConstantLongInfo)Item;
							cc.Write(Writer);

							// longs take up two entries in the pool table
							count++;
							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantDouble:
						{
							ConstantDoubleInfo cc = (ConstantDoubleInfo)Item;
							cc.Write(Writer);

							// so do doubles
							count++;
							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantNameAndType:
						{
							ConstantNameAndTypeInfo cc = (ConstantNameAndTypeInfo)Item;
							cc.Write(Writer);

							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantUtf8:
						{
							ConstantUtf8Info cc = (ConstantUtf8Info)Item;
							cc.Write(Writer);

							break;
						}

					default:
						// fail safe ?
						// BADDDDDDDDDDDDDDDDDDDDD, prolly should check/fix this
						count++;
						break;
				}

				count++;
			}
		}
Ejemplo n.º 3
0
		public TChangeRecord ChangeMethodName(int MethodNumber, string NewName)
		{
			MethodInfo Method = (MethodInfo)FMethods.Items[MethodNumber];
			//MethodInfo OriginalMethod = Method.Clone();
			//MethodInfo NewMethod = null;
			TChangeRecord Result = null;
			ConstantMethodrefInfo MethodRef = null;
			ushort NewNameIndex;

			// first we need to loop through the constant pool for method 
			// references that match our new method name
			for (int i = 0; i < FConstantPool.MaxItems(); i++)
			{
				if (FConstantPool.Item(i).Tag == (byte)ConstantPoolInfoTag.ConstantMethodref)
				{
					MethodRef = (ConstantMethodrefInfo)FConstantPool.Item(i);
					if (MethodRef.ParentClass.Name == FThisClassName &&
						MethodRef.NameAndType.Name == Method.Name.Value &&
						MethodRef.NameAndType.Descriptor == Method.Descriptor)
					{
						// jackpot, we found the reference!
						// there should be only one, so we will break and fix it up after we generate the new name
						break;
					}
				}

				MethodRef = null;
			}

			Method.Name.References--;
			// add a new string constant to the pool
			ConstantUtf8Info NewUtf = new ConstantUtf8Info(NewName);

			NewNameIndex = ConstantPool.Add(NewUtf);

			// set the method its new name
			Method.SetName(NewNameIndex, ConstantPool);
			Method.Name.References = 1;

			//NewMethod = Method.Clone();

			if (MethodRef == null)
				return Result;

			if (MethodRef.NameAndType.References <= 1)
			{
				// if this is the only reference to the name/type descriptor
				// we can overwrite the value
				MethodRef.NameAndType.SetName(NewNameIndex, FConstantPool);
			}
			else
			{
				// we have to make a new one !
				MethodRef.NameAndType.References--;
				// add a new string constant to the pool
				ConstantNameAndTypeInfo NewNaT = new ConstantNameAndTypeInfo(NewNameIndex, MethodRef.NameAndType.TypeIndex, FConstantPool);

				ushort NewIndex = ConstantPool.Add(NewNaT);

				// set the method its new name
				MethodRef.SetNameAndType(NewIndex, ConstantPool);
				MethodRef.NameAndType.References = 1;
			}

			return Result;
		}
Ejemplo n.º 4
0
		public TConstantPool(BinaryReader Reader)
		{
			FReader = Reader;

			FMaxItems = Common.ReadWord(FReader) - 1;
			FItems = new ArrayList();
			int count = 0;

			// goes from 1 -> constantpoolcount - 1
			while (count < FMaxItems)
			{
				byte tag = Common.ReadByte(FReader);

				switch (tag)
				{
					case (byte)ConstantPoolInfoTag.ConstantClass:
						{
							ConstantClassInfo cc = new ConstantClassInfo();
							cc.Read(tag, FReader);
							FItems.Add(cc);
							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantString:
						{
							ConstantStringInfo cc = new ConstantStringInfo();
							cc.Read(tag, FReader);
							FItems.Add(cc);
							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantFieldref:
						{
							ConstantFieldrefInfo cc = new ConstantFieldrefInfo();
							cc.Read(tag, FReader);
							FItems.Add(cc);
							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantMethodref:
						{
							ConstantMethodrefInfo cc = new ConstantMethodrefInfo();
							cc.Read(tag, FReader);
							FItems.Add(cc);
							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantInterfaceMethodref:
						{
							ConstantInterfaceMethodrefInfo cc = new ConstantInterfaceMethodrefInfo();
							cc.Read(tag, FReader);
							FItems.Add(cc);
							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantInteger:
						{
							ConstantIntegerInfo cc = new ConstantIntegerInfo();
							cc.Read(tag, FReader);
							FItems.Add(cc);
							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantFloat:
						{
							ConstantFloatInfo cc = new ConstantFloatInfo();
							cc.Read(tag, FReader);
							FItems.Add(cc);
							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantLong:
						{
							ConstantLongInfo cc = new ConstantLongInfo();
							cc.Read(tag, FReader);
							FItems.Add(cc);
							// longs take up two entries in the pool table
							count++;
							FItems.Add(cc);
							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantDouble:
						{
							ConstantDoubleInfo cc = new ConstantDoubleInfo();
							cc.Read(tag, FReader);
							FItems.Add(cc);
							// so do doubles
							count++;
							FItems.Add(cc);
							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantNameAndType:
						{
							ConstantNameAndTypeInfo cc = new ConstantNameAndTypeInfo();
							cc.Read(tag, FReader);
							FItems.Add(cc);
							break;
						}
					case (byte)ConstantPoolInfoTag.ConstantUtf8:
						{
							ConstantUtf8Info cc = new ConstantUtf8Info();
							cc.Read(tag, FReader);
							FItems.Add(cc);
							break;
						}

					default:
						// fail safe ?
						count++;
						break;
				}

				count++;
			}

			foreach (ConstantPoolInfo cc in FItems)
			{
				cc.Resolve(FItems);
			}
		}