예제 #1
0
파일: HFlash.cs 프로젝트: SirJamal/Sulakore
        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();
            }
        }
예제 #2
0
        private void WriteMethod(BinaryWriter writer, ASMethod method)
        {
            ASMethodBody body = method.Body;
            writer.Write(body.Traits.Count);
            writer.Write(body.Exceptions.Count);
            writer.Write(body.MaxStack);
            writer.Write(body.LocalCount);
            writer.Write(body.MaxScopeDepth);
            writer.Write(body.InitialScopeDepth);
            writer.Write(body.Method.Parameters.Count);

            foreach (ASParameter parameter in body.Method.Parameters)
            {
                switch (parameter.Type.ObjName)
                {
                    case "int":
                    case "Class":
                    case "Array":
                    case "String":
                    case "Boolean":
                    case "Function":
                    {
                        writer.Write(parameter.Type.ObjName);
                        break;
                    }
                }

                writer.Write(parameter.IsOptional);
                if (parameter.IsOptional)
                    writer.Write((byte)parameter.ValueType);
            }

            ASCode code = body.Code;
            writer.Write("OPERATIONS");
            using (var inCode = new FlashReader(code.ToArray()))
            {
                string instructions = string.Empty;
                while (inCode.Position != inCode.Length)
                {
                    OPCode op = inCode.ReadOP();
                    inCode.ReadValues(op);

                    instructions += (op + "\r\n");
                    writer.Write((byte)op);
                }
            }
        }