/// <summary> /// /// </summary> /// <param name="source"></param> public void Parse(Stream source) { Init = VariableLengthInteger.ReadU30(source); UInt32 traitsCount = VariableLengthInteger.ReadU30(source); Traits = new List<Traits_info>((int)traitsCount); for (uint i = 0; i < traitsCount; i++) { Traits_info ti = new Traits_info(); ti.Parse(source); Traits.Add(ti); } }
/// <summary> /// /// </summary> /// <param name="source"></param> public void Parse( Stream source ) { //Log.Debug(this, "Offset : " + source.Position); _Name = VariableLengthInteger.ReadU30( source ); _Supername = VariableLengthInteger.ReadU30( source ); byte flags = VariableLengthInteger.ReadU8( source ); _FlagClassSealed = ( ( flags & 0x01 ) != 0 ); _FlagClassFinal = ( ( flags & 0x02 ) != 0 ); _FlagClassInterface = ( ( flags & 0x04 ) != 0 ); _FlagClassProtectedNs = ( ( flags & 0x08 ) != 0 ); if ( ( flags & 0xF0 ) != 0 ) { AbcFormatException fe = new AbcFormatException( "Reserved flags used in Instance_Info" ); Log.Error(this, fe ); throw fe; } if ( _FlagClassProtectedNs ) { _ProtectedNs = VariableLengthInteger.ReadU30( source ); } UInt32 interfaceCount = VariableLengthInteger.ReadU30( source ); _Interface = new List<UInt32>( (int)interfaceCount ); for ( uint i = 0; i < interfaceCount; i++ ) { UInt32 interf = VariableLengthInteger.ReadU30( source ); if ( 0 == interf ) { AbcFormatException fe = new AbcFormatException( "Instance_info interface index is 0" ); Log.Error(this, fe ); throw fe; } _Interface.Add( interf ); } _Iinit = VariableLengthInteger.ReadU30( source ); UInt32 traitCount = VariableLengthInteger.ReadU30( source ); _Trait = new List<Traits_info>( ( int )traitCount ); for ( uint i = 0; i < traitCount; i++ ) { Traits_info ti = new Traits_info(); ti.Parse( source ); _Trait.Add( ti ); } }
/// <summary> /// /// </summary> /// <param name="source"></param> public void Parse(Stream source) { long positionBefore = source.Position; Method = VariableLengthInteger.ReadU30(source); MaxStack = VariableLengthInteger.ReadU30(source); LocalCount = VariableLengthInteger.ReadU30(source); InitScopeDepth = VariableLengthInteger.ReadU30(source); MaxScopeDepth = VariableLengthInteger.ReadU30(source); if (InitScopeDepth > MaxScopeDepth) { String s = String.Format("Method_body_info InitScopeDepth ({0:d}) > MaxScopeDepth ({1:d})", InitScopeDepth, MaxScopeDepth); Log.Warn(this, s); } UInt32 byteCodeLength = VariableLengthInteger.ReadU30(source); String s1 = String.Format("{0:d} bytes AVM2 code found, parsing now", byteCodeLength); //Log.Debug(this, s1); AVM2InstructionSequence avm2code = new AVM2InstructionSequence(); byte[] rawBuffer = new byte[(int)byteCodeLength]; source.Read(rawBuffer, 0, (int)byteCodeLength); MemoryStream ms = new MemoryStream(rawBuffer); BinaryReader br = new BinaryReader(ms); while (br.BaseStream.Position < (long)byteCodeLength) { AbstractInstruction ai = AVM2Factory.Create(br, Method); avm2code.Add(ai); } Code = new AVM2Code(avm2code, Method); if (Code.Length != byteCodeLength) { String s2 = String.Format("AVM2Code calculated length {0:d} differs from declared length {1:d}", Code.Length, byteCodeLength); Log.Warn(this, s2); throw new Exception("This is likely to be a bug!"); } UInt32 exceptionCount = VariableLengthInteger.ReadU30(source); Exceptions = new List<Exception_info>((int)exceptionCount); for (uint i = 0; i < exceptionCount; i++) { Exception_info ei = new Exception_info(); ei.Parse(source); Exceptions.Add(ei); } String s3 = String.Format("{0:d} Exceptions", Exceptions.Count); //Log.Debug(this, s3); UInt32 traitsCount = VariableLengthInteger.ReadU30(source); Traits = new List<Traits_info>((int)traitsCount); for (uint i = 0; i < traitsCount; i++) { Traits_info ti = new Traits_info(); ti.Parse(source); Traits.Add(ti); } String s4 = String.Format("{0:d} Traits", Traits.Count); //Log.Debug(this, s4); long positionAfter = source.Position; source.Seek(positionBefore, SeekOrigin.Begin); this.dataOnRead = new byte[positionAfter - positionBefore]; source.Read(dataOnRead, 0, dataOnRead.Length); }