/// <summary> /// /// </summary> /// <param name="abc"></param> /// <param name="code"></param> public void Verify(AbcFile abc, AVM2Code code) { if (!abc.VerifyMultinameIndex(_ExceptionType)) { AbcVerifierException ave = new AbcVerifierException("Invalid Exception type: " + _ExceptionType.ToString("d")); Log.Error(this, ave); throw ave; } if (!abc.VerifyMultinameIndex(_VariableName)) { AbcVerifierException ave = new AbcVerifierException("Invalid exception variable name: " + _VariableName.ToString("d")); ; Log.Error(this, ave); throw ave; } try { uint dummy = code.Address2Index(_From) + code.Address2Index(_To) + code.Address2Index(_Target); dummy++; } catch (ArgumentOutOfRangeException aoor) { AbcVerifierException ave = new AbcVerifierException("Exception to/from/target not on a instruction", aoor); Log.Error(this, ave); throw ave; } }
/// <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); }