Exemple #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;
		}
Exemple #2
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;
        }