protected virtual byte[] GenerateHashData(ASInstance instance, bool isOutgoing) { using (var binStream = new MemoryStream()) using (var binWriter = new BinaryWriter(binStream)) { binWriter.Write(GenerateHashData(instance)); if (!isOutgoing) { ASMethod constructor = instance.Constructor; ASCode ctorCode = constructor.Body.Code; if (constructor.Parameters.Count < 2) { using (var inCode = new FlashReader(ctorCode.ToArray())) { while (inCode.Position != inCode.Length) { OPCode op = inCode.ReadOP(); object[] values = inCode.ReadValues(op); if (op == OPCode.GetLex) { ASMultiname classParamTypeName = _abcFiles[2] .Constants.Multinames[(int)values[0]]; ASInstance inMsgParser = _abcFiles[2] .FindInstanceByName(classParamTypeName.ObjName); if (inCode.ReadOP() == OPCode.ConstructSuper) binWriter.Write(GenerateHashData(inMsgParser)); break; } } } } } binWriter.Close(); return binStream.ToArray(); } }
protected ASMethod FindVerifyMethod(ASInstance instance, ABCFile abc, out int rsaStart) { List<MethodGetterSetterTrait> methodTraits = instance.FindTraits<MethodGetterSetterTrait>(TraitType.Method); rsaStart = -1; foreach (MethodGetterSetterTrait mgsTrait in methodTraits) { ASMethod method = mgsTrait.Method; if (method.ReturnType.ObjName != "void") continue; if (method.Parameters.Count != 1) continue; ASCode methodCode = method.Body.Code; using (var code = new FlashReader(methodCode.ToArray())) { while (code.Position != code.Length) { OPCode op = code.ReadOP(); if (op != OPCode.GetLex) continue; int typeIndex = code.Read7BitEncodedInt(); ASMultiname type = abc.Constants.Multinames[typeIndex]; if (type?.ObjName == "RSAKey") { rsaStart = code.Position; return method; } } } } return null; }
public string GenerateHash(ASInstance instance, bool isOutgoing) { using (var md5 = MD5.Create()) { return BitConverter.ToString( md5.ComputeHash(GenerateHashData(instance, isOutgoing))) .Replace("-", string.Empty).ToLower(); } }
protected virtual byte[] GenerateHashData(ASInstance instance) { using (var binStream = new MemoryStream()) using (var binWriter = new BinaryWriter(binStream, Encoding.UTF8, true)) { binWriter.Write("INSTANCE"); binWriter.Write(instance.InterfaceIndices.Count); binWriter.Write("TRAITS"); WriteTraits(binWriter, instance.Traits); binWriter.Write("CONSTRUCTOR"); WriteMethod(binWriter, instance.Constructor); binWriter.Close(); return binStream.ToArray(); } }