예제 #1
0
 private static string PrintObjectData(PyObjectData data)
 {
     return("[PyObjectData Name: " + data.Name + "]");
 }
예제 #2
0
 private static string PrintObjectData(PyObjectData data)
 {
     return "[PyObjectData Name: " + data.Name + "]";
 }
예제 #3
0
        public bool Decode(PyObject data)
        {
            PyObject packet = data;

            if (packet.Type == PyObjectType.ChecksumedStream)
            {
                packet = packet.As <PyChecksumedStream>().Data;
            }

            if (packet.Type == PyObjectType.SubStream)
            {
                packet = packet.As <PySubStream>().Data;
            }

            if (packet.Type != PyObjectType.ObjectData)
            {
                return(false);
            }

            PyObjectData packeto = packet.As <PyObjectData>();

            type_string = packeto.Name;

            if (packeto.Arguments.Type != PyObjectType.Tuple)
            {
                return(false);
            }

            PyTuple tuple = packeto.Arguments.As <PyTuple>();

            if (tuple.Items.Count != 6)
            {
                return(false);
            }

            if ((tuple.Items[0].Type != PyObjectType.IntegerVar) && (tuple.Items[0].Type != PyObjectType.Long))
            {
                return(false);
            }

            PyInt typer = tuple.Items[0].As <PyInt>();

            type = (Macho.MachoNetMsg_Type)typer.Value;

            if (!source.Decode(tuple.Items[1]))
            {
                return(false);
            }

            if (!dest.Decode(tuple.Items[2]))
            {
                return(false);
            }

            if ((tuple.Items[3].Type == PyObjectType.IntegerVar) || (tuple.Items[3].Type == PyObjectType.Long))
            {
                userID = (uint)tuple.Items[3].As <PyInt>().Value;
            }
            else if (tuple.Items[3].Type == PyObjectType.None)
            {
                userID = 0;
            }
            else
            {
                return(false);
            }

            // Payload( or call arguments )
            if ((tuple.Items[4].Type != PyObjectType.Buffer) && (tuple.Items[4].Type != PyObjectType.Tuple))
            {
                return(false);
            }

            payload = tuple.Items[4].As <PyTuple>();

            if (tuple.Items[5].Type == PyObjectType.None)
            {
                named_payload = new PyDict();
            }
            else if (tuple.Items[5].Type == PyObjectType.Dict)
            {
                named_payload = tuple.Items[5].As <PyDict>();
            }
            else
            {
                return(false);
            }

            return(true);
        }
예제 #4
0
        public bool Decode(PyObject from)
        {
            if (from.Type != PyObjectType.ObjectData)
            {
                return(false);
            }

            PyObjectData obj = from.As <PyObjectData>();

            if (obj.Name != "macho.MachoAddress")
            {
                return(false);
            }

            if (obj.Arguments.Type != PyObjectType.Tuple)
            {
                return(false);
            }

            PyTuple args = obj.Arguments.As <PyTuple>();

            if (args.Items.Count < 3)
            {
                return(false);
            }

            if (args.Items[0].Type != PyObjectType.String)
            {
                return(false);
            }

            PyString typei = args.Items[0].As <PyString>();

            switch (typei.Value)
            {
            case "A":
                if (args.Items.Count != 3)
                {
                    return(false);
                }

                if (!DecodeService(args.Items[1]) || !DecodeCallID(args.Items[2]))
                {
                    return(false);
                }

                type = AddrType.Any;
                break;

            case "N":
                if (args.Items.Count != 4)
                {
                    return(false);
                }

                if (!DecodeTypeID(args.Items[1]) || !DecodeService(args.Items[2]) || !DecodeCallID(args.Items[3]))
                {
                    return(false);
                }

                type = AddrType.Node;

                break;

            case "C":
                if (args.Items.Count != 4)
                {
                    return(false);
                }

                if (!DecodeTypeID(args.Items[1]) || !DecodeCallID(args.Items[2]) || !DecodeService(args.Items[3]))
                {
                    return(false);
                }

                type = AddrType.Client;

                break;

            case "B":
                if (args.Items.Count != 4)
                {
                    return(false);
                }

                type = AddrType.Broadcast;

                if (args.Items[1].Type != PyObjectType.String)
                {
                    return(false);
                }

                if (args.Items[3].Type != PyObjectType.String)
                {
                    return(false);
                }

                PyString bid = args.Items[1].As <PyString>();
                PyString idt = args.Items[3].As <PyString>();

                service    = bid.Value;
                bcast_type = idt.Value;

                break;

            default:
                return(false);
            }

            return(true);
        }