Beispiel #1
0
		public bool Open()
		{
			if (File.Exists(FClassFileName))
			{
				try
				{
					// read the .class file systematically
					FileStream fs = new FileStream(FClassFileName, FileMode.Open, FileAccess.Read);
					FReader = new BinaryReader(fs);
					// read header
					FMagic = Common.ReadDWord(FReader);

					if (FMagic != 0x0CAFEBABE)
						return false;

					FMinorVersion = Common.ReadWord(FReader);
					FMajorVersion = Common.ReadWord(FReader);
					// read constant pool
					// this also reads the "FConstantPoolCount"
					// so instead use FConstantPool.MaxItems or somesuch
					FConstantPool = new TConstantPool(FReader);
					// more constants
					FAccessFlags = (AccessFlags)Common.ReadWord(FReader);
					FThisClass = Common.ReadWord(FReader);
					FThisClass--;
					FSuperClass = Common.ReadWord(FReader);
					FSuperClass--;

					FThisClassName = ((ConstantClassInfo)FConstantPool.Item(FThisClass)).Name;
					(FConstantPool.Item(FThisClass)).References++;
					FSuperClassName = ((ConstantClassInfo)FConstantPool.Item(FSuperClass)).Name;
					(FConstantPool.Item(FSuperClass)).References++;

					FInterfaces = new TInterfaces(FReader, FConstantPool);
					FFields = new TFields(FReader, FConstantPool);
					FMethods = new TMethods(FReader, FConstantPool);
					FAttributes = new TAttributes(FReader, FConstantPool);

					//FHasBeenOpened = true;

					fs.Close();
					return true;
				}
				catch (Exception e)
				{
					// catch any unhandled exceptions here
					// and exit gracefully.
					// garbage collection does the rest ;D
					return false;
				}
			}

			return false;
		}
Beispiel #2
0
		public TMethods(BinaryReader Reader, TConstantPool ConstantPool)
		{
			FReader = Reader;

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

			// goes from 1 -> fieldcount - 1
			while (count < FMaxItems)
			{
				MethodInfo mi = new MethodInfo(FReader, ConstantPool);
				FItems.Add(mi);

				count++;
			}
		}
Beispiel #3
0
		public TInterfaces(BinaryReader Reader, TConstantPool ConstantPool)
		{
			FReader = Reader;

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

			// goes from 1 -> interfacecount - 1
			while (count <= FMaxItems)
			{
				InterfaceInfo ii = new InterfaceInfo(FReader, ConstantPool);
				FItems.Add(ii);

				count++;
			}
		}
Beispiel #4
0
        public bool Open()
        {
            if (File.Exists(FClassFileName))
            {
                try
                {
                    // read the .class file systematically
                    FileStream fs = new FileStream(FClassFileName, FileMode.Open, FileAccess.Read);
                    FReader = new BinaryReader(fs);
                    // read header
                    FMagic = Common.ReadDWord(FReader);

                    if (FMagic != 0x0CAFEBABE)
                        return false;

                    FMinorVersion = Common.ReadWord(FReader);
                    FMajorVersion = Common.ReadWord(FReader);
                    // read constant pool
                    // this also reads the "FConstantPoolCount"
                    // so instead use FConstantPool.MaxItems or somesuch
                    FConstantPool = new TConstantPool(FReader);
                    // more constants
                    FAccessFlags = (AccessFlags)Common.ReadWord(FReader);
                    FThisClass = Common.ReadWord(FReader);
                    FThisClass--;
                    FSuperClass = Common.ReadWord(FReader);
                    FSuperClass--;

                    FThisClassName = ((ConstantClassInfo)FConstantPool.Item(FThisClass)).Name;
                    (FConstantPool.Item(FThisClass)).References++;
                    FSuperClassName = ((ConstantClassInfo)FConstantPool.Item(FSuperClass)).Name;
                    (FConstantPool.Item(FSuperClass)).References++;

                    FInterfaces = new TInterfaces(FReader, FConstantPool);
                    FFields = new TFields(FReader, FConstantPool);
                    FMethods = new TMethods(FReader, FConstantPool);
                    FAttributes = new TAttributes(FReader, FConstantPool);

                    //FHasBeenOpened = true;

                    fs.Close();
                    return true;
                }
                catch (Exception e)
                {
                    // catch any unhandled exceptions here
                    // and exit gracefully.
                    // garbage collection does the rest ;D
                    return false;
                }
            }

            return false;
        }
Beispiel #5
0
        public TMethods(BinaryReader Reader, TConstantPool ConstantPool)
        {
            FReader = Reader;

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

            // goes from 1 -> fieldcount - 1
            while (count < FMaxItems)
            {
                MethodInfo mi = new MethodInfo(FReader, ConstantPool);
                FItems.Add(mi);

                count++;
            }
        }
Beispiel #6
0
        public TInterfaces(BinaryReader Reader, TConstantPool ConstantPool)
        {
            FReader = Reader;

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

            // goes from 1 -> interfacecount - 1
            while (count <= FMaxItems)
            {
                InterfaceInfo ii = new InterfaceInfo(FReader, ConstantPool);
                FItems.Add(ii);

                count++;
            }
        }
Beispiel #7
0
        public TAttributes(BinaryReader Reader, TConstantPool ConstantPool)
        {
            FReader = Reader;

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

            // goes from 1 -> attributescount - 1
            while (count <= FMaxItems)
            {
                ushort NameIndex = Common.ReadWord(FReader);
                NameIndex--;
                ConstantUtf8Info Name = (ConstantUtf8Info)ConstantPool.Item(NameIndex);

                switch (Name.Value)
                {
                    case AttributeType.Code:
                        {
                            CodeAttributeInfo ai = new CodeAttributeInfo(NameIndex, FReader, ConstantPool);

                            FItems.Add(ai);
                            break;
                        }
                    case AttributeType.ConstantValue:
                        {
                            ConstantValueAttributeInfo ai = new ConstantValueAttributeInfo(NameIndex, FReader, ConstantPool);

                            FItems.Add(ai);
                            break;
                        }
                    case AttributeType.Deprecated:
                        {
                            DeprecatedAttributeInfo ai = new DeprecatedAttributeInfo(NameIndex, FReader, ConstantPool);

                            FItems.Add(ai);
                            break;
                        }
                    case AttributeType.Exceptions:
                        {
                            ExceptionsAttributeInfo ai = new ExceptionsAttributeInfo(NameIndex, FReader, ConstantPool);

                            FItems.Add(ai);
                            break;
                        }
                    case AttributeType.InnerClasses:
                        {
                            InnerClassesAttributeInfo ai = new InnerClassesAttributeInfo(NameIndex, FReader, ConstantPool);

                            FItems.Add(ai);
                            break;
                        }
                    case AttributeType.LineNumberTable:
                        {
                            LineNumberAttributeInfo ai = new LineNumberAttributeInfo(NameIndex, FReader, ConstantPool);

                            FItems.Add(ai);
                            break;
                        }
                    case AttributeType.LocalVariableTable:
                        {
                            LocalVariablesAttributeInfo ai = new LocalVariablesAttributeInfo(NameIndex, FReader, ConstantPool);

                            FItems.Add(ai);
                            break;
                        }
                    case AttributeType.SourceFile:
                        {
                            SourceFileAttributeInfo ai = new SourceFileAttributeInfo(NameIndex, FReader, ConstantPool);

                            FItems.Add(ai);
                            break;
                        }
                    case AttributeType.Synthetic:
                        {
                            SyntheticAttributeInfo ai = new SyntheticAttributeInfo(NameIndex, FReader, ConstantPool);

                            FItems.Add(ai);
                            break;
                        }

                    default:
                        {
                            AttributeInfo ai = new UnknownAttributeInfo(NameIndex, FReader, ConstantPool);

                            FItems.Add(ai);
                            break;
                        }
                }

                count++;
            }
        }
Beispiel #8
0
		public TAttributes(BinaryReader Reader, TConstantPool ConstantPool)
		{
			FReader = Reader;

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

			// goes from 1 -> attributescount - 1
			while (count <= FMaxItems)
			{
				ushort NameIndex = Common.ReadWord(FReader);
				NameIndex--;
				ConstantUtf8Info Name = (ConstantUtf8Info)ConstantPool.Item(NameIndex);

				switch (Name.Value)
				{
					case AttributeType.Code:
						{
							CodeAttributeInfo ai = new CodeAttributeInfo(NameIndex, FReader, ConstantPool);

							FItems.Add(ai);
							break;
						}
					case AttributeType.ConstantValue:
						{
							ConstantValueAttributeInfo ai = new ConstantValueAttributeInfo(NameIndex, FReader, ConstantPool);

							FItems.Add(ai);
							break;
						}
					case AttributeType.Deprecated:
						{
							DeprecatedAttributeInfo ai = new DeprecatedAttributeInfo(NameIndex, FReader, ConstantPool);

							FItems.Add(ai);
							break;
						}
					case AttributeType.Exceptions:
						{
							ExceptionsAttributeInfo ai = new ExceptionsAttributeInfo(NameIndex, FReader, ConstantPool);

							FItems.Add(ai);
							break;
						}
					case AttributeType.InnerClasses:
						{
							InnerClassesAttributeInfo ai = new InnerClassesAttributeInfo(NameIndex, FReader, ConstantPool);

							FItems.Add(ai);
							break;
						}
					case AttributeType.LineNumberTable:
						{
							LineNumberAttributeInfo ai = new LineNumberAttributeInfo(NameIndex, FReader, ConstantPool);

							FItems.Add(ai);
							break;
						}
					case AttributeType.LocalVariableTable:
						{
							LocalVariablesAttributeInfo ai = new LocalVariablesAttributeInfo(NameIndex, FReader, ConstantPool);

							FItems.Add(ai);
							break;
						}
					case AttributeType.SourceFile:
						{
							SourceFileAttributeInfo ai = new SourceFileAttributeInfo(NameIndex, FReader, ConstantPool);

							FItems.Add(ai);
							break;
						}
					case AttributeType.Synthetic:
						{
							SyntheticAttributeInfo ai = new SyntheticAttributeInfo(NameIndex, FReader, ConstantPool);

							FItems.Add(ai);
							break;
						}

					default:
						{
							AttributeInfo ai = new UnknownAttributeInfo(NameIndex, FReader, ConstantPool);

							FItems.Add(ai);
							break;
						}
				}

				count++;
			}
		}