Beispiel #1
0
        public EntangledHostedObjectBase(Guid eid, InterfaceDescriptor i, ICommon host)
        {
            _Eid        = eid;
            _Descriptor = i;

            Attach(host);
        }
Beispiel #2
0
 internal LinuxDeviceInterface(InterfaceDescriptor descriptor, string devname, byte[] otherDescriptors = null)
 {
     this.descriptor       = descriptor;
     this.devname          = devname;
     this.otherDescriptors = otherDescriptors;
     SetValues(descriptor);
 }
Beispiel #3
0
        public void AttachTo(IMACInterface iface, Machine machine)
        {
            lock (innerLock)
            {
                if (ifaces.Any(x => x.Interface == iface))
                {
                    throw new RecoverableException("Cannot attach to the provided MAC interface as it is already registered in this switch.");
                }

                var ifaceDescriptor = new InterfaceDescriptor
                {
                    Interface = iface,
                    Delegate  = f => ForwardToReceiver(f, iface)
                };

                //  this is to handle TAPInterfaces that are not peripherals
                if (iface is IPeripheral peripheralInterface)
                {
                    ifaceDescriptor.Machine = machine ?? peripheralInterface.GetMachine();
                }
                // here we try to cast the iface to `ITapInterface` to avoid doing it multiple times for every packet in the future
                ifaceDescriptor.AsTap = iface as HostInterfaces.Network.ITapInterface;
                iface.FrameReady     += ifaceDescriptor.Delegate;
                ifaces.Add(ifaceDescriptor);
            }
        }
        public void AttachTo(IMACInterface iface, Machine machine)
        {
            lock (innerLock)
            {
                if (ifaces.Any(x => x.Interface == iface))
                {
                    throw new RecoverableException("Cannot attach to the provided MAC interface as it is already registered in this switch.");
                }

                var ifaceDescriptor = new InterfaceDescriptor
                {
                    Interface = iface,
                    Delegate  = f => ForwardToReceiver(f, iface)
                };

                //  this is to handle TAPInterfaces that are not peripherals
                if (iface is IPeripheral peripheralInterface)
                {
                    ifaceDescriptor.Machine = machine ?? peripheralInterface.GetMachine();
                }
                iface.FrameReady += ifaceDescriptor.Delegate;
                ifaces.Add(ifaceDescriptor);
                this.Log(LogLevel.Info, "Interface {0} attached", iface.MAC);
            }
        }
Beispiel #5
0
 public GClass872(Guid guid_0, InterfaceDescriptor interfaceDescriptor_0, ICommon icommon_0)
 {
     Class13.NP5bWyNzLwONS();
     this.BotControllers         = new ConcurrentDictionary <string, GClass871>();
     this.concurrentDictionary_0 = new ConcurrentDictionary <string, BotProfile>();
     base..ctor(guid_0, interfaceDescriptor_0, icommon_0);
     this.Bots = new List <GClass871>();
     this.AccountManagerThread = new Thread(new ThreadStart(this.method_2))
     {
         IsBackground = true
     };
     this.AccountManagerThread.Start();
 }
 public EntangledLocalObjectBase(IConnection host, Guid eid, InterfaceDescriptor desc)
 {
     Host        = host;
     _Eid        = eid;
     _Descriptor = desc;
     foreach (var evkv in _Descriptor.Events)
     {
         var ev = evkv.Value;
         if (ev.InvokerDelegate == null)
         {
             _Descriptor.AddEventInvokerDelegate(ev);
         }
     }
 }
Beispiel #7
0
        public void AttachTo(IMACInterface iface)
        {
            lock (innerLock)
            {
                var ifaceDescriptor = new InterfaceDescriptor
                {
                    Interface = iface,
                    Delegate  = (s, f) => ForwardToReceiver(f, iface)
                };

                iface.Link.TransmitFromParentInterface += ifaceDescriptor.Delegate;
                ifaces.Add(ifaceDescriptor);
            }
        }
        private IInterfaceDescriptor CreateInterfaceModel(
            IModelGeneratorContext context,
            IFragmentNode fragmentNode,
            Path path,
            Stack <ISet <string> > levels)
        {
            ISet <string> implementedFields = levels.Peek();
            IReadOnlyList <IFieldDescriptor> fieldDescriptors =
                Array.Empty <IFieldDescriptor>();

            IReadOnlyList <IInterfaceDescriptor> implements =
                CreateChildInterfaceModels(
                    context,
                    fragmentNode,
                    path,
                    levels,
                    implementedFields);

            if (fragmentNode.Fragment.TypeCondition is IComplexOutputType type)
            {
                fieldDescriptors = CreateFields(
                    type,
                    fragmentNode.Fragment.SelectionSet.Selections,
                    name =>
                {
                    if (implementedFields.Add(name))
                    {
                        return(true);
                    }
                    return(false);
                },
                    path);
            }

            NameString interfaceName = context.GetOrCreateName(
                fragmentNode.Fragment.SelectionSet,
                GetInterfaceName(fragmentNode.Name));

            var descriptor = new InterfaceDescriptor(
                interfaceName,
                context.Namespace,
                fragmentNode.Fragment.TypeCondition,
                fieldDescriptors,
                implements);

            context.Register(descriptor);
            return(descriptor);
        }
Beispiel #9
0
        private void Register(Type baseType, Type type, EntanglementAccess access)
        {
            var            guid = baseType.GetTypeInfo().GUID;
            InterfaceEntry e;

            if (!Interfaces.TryAdd(guid,
                                   e = new InterfaceEntry
            {
                Access = access,
                Type = type,
                InterfaceId = guid,
                InterfaceDescriptor = InterfaceDescriptor.Get(baseType)
            }))
            {
                Interfaces[guid].Access = access;
            }
            else
            {
                if (Host?.TypeResolver != null)
                {
                    RegisterTypes(Host.TypeResolver, e);
                }
            }
        }
Beispiel #10
0
        public static unsafe UsbInterfaceInfo FromUsbInterfaceDescriptor(LibUsb.UsbDevice device, InterfaceDescriptor descriptor)
        {
            Debug.Assert(descriptor.DescriptorType == (int)DescriptorType.Interface, "A config descriptor was expected");

            UsbInterfaceInfo value = new UsbInterfaceInfo();

            value.AlternateSetting = descriptor.AlternateSetting;

            var endpoints = (EndpointDescriptor *)descriptor.Endpoint;

            for (int i = 0; i < descriptor.NumEndpoints; i++)
            {
                if (endpoints[i].DescriptorType != 0)
                {
                    value.endpoints.Add(UsbEndpointInfo.FromUsbEndpointDescriptor(endpoints[i]));
                }
            }

            value.RawDescriptors = new byte[descriptor.ExtraLength];
            if (descriptor.ExtraLength > 0)
            {
                Span <byte> extra = new Span <byte>(descriptor.Extra, descriptor.ExtraLength);
                extra.CopyTo(value.RawDescriptors);
            }

            value.Interface = device.GetStringDescriptor(descriptor.Interface, failSilently: true);
            value.Class     = (ClassCode)descriptor.InterfaceClass;
            value.Number    = descriptor.InterfaceNumber;
            value.Protocol  = descriptor.InterfaceProtocol;
            value.SubClass  = descriptor.InterfaceSubClass;

            return(value);
        }
 public PacketInterfaceData(InterfaceDescriptor interfaceDescriptor)
 {
     InterfaceDescriptor = interfaceDescriptor;
 }
        private ICodeDescriptor GenerateUnionSelectionSet(
            OperationDefinitionNode operation,
            UnionType unionType,
            IType fieldType,
            FieldNode fieldSelection,
            IReadOnlyCollection <FieldCollectionResult> typeCases,
            Path path)
        {
            IFragmentNode                 returnType = null;
            FieldCollectionResult         result     = typeCases.First();
            IReadOnlyList <IFragmentNode> fragments  = result.Fragments;

            while (fragments.Count == 1)
            {
                if (fragments[0].Fragment.TypeCondition == unionType)
                {
                    returnType = fragments[0];
                    fragments  = fragments[0].Children;
                }
                else
                {
                    break;
                }
            }

            InterfaceDescriptor unionInterface;

            if (returnType is null)
            {
                string name = CreateName(
                    fieldSelection,
                    unionType,
                    Utilities.NameUtils.GetInterfaceName);
                unionInterface = new InterfaceDescriptor(
                    name, _namespace, unionType);
            }
            else
            {
                unionInterface = CreateInterface(returnType, path);
                unionInterface = unionInterface.RemoveAllImplements();
            }

            var resultParserTypes = new List <ResultParserTypeDescriptor>();

            foreach (var typeCase in typeCases)
            {
                string className;
                string interfaceName;

                IFragmentNode fragment = typeCase.Fragments.FirstOrDefault(
                    t => t.Fragment.TypeCondition == typeCase.Type);

                if (fragment is null)
                {
                    className     = CreateName(typeCase.Type.Name);
                    interfaceName = CreateName(GetInterfaceName(className));
                }
                else
                {
                    className     = CreateName(fragment.Fragment.Name);
                    interfaceName = CreateName(GetInterfaceName(fragment.Fragment.Name));
                }

                var modelInterfaces = new List <IInterfaceDescriptor>();
                modelInterfaces.Add(
                    new InterfaceDescriptor(
                        interfaceName,
                        _namespace,
                        typeCase.Type,
                        typeCase.Fields.Select(t =>
                {
                    string responseName = (t.Selection.Alias ?? t.Selection.Name).Value;
                    return(new FieldDescriptor(
                               t.Field,
                               t.Selection,
                               t.Field.Type,
                               t.Path.Append(responseName)));
                }).ToList(),
                        new[] { unionInterface }));
                modelInterfaces.AddRange(CreateInterfaces(typeCase.Fragments, path));

                var modelClass = new ClassDescriptor(
                    className, _namespace, typeCase.Type, modelInterfaces);

                RegisterDescriptors(modelInterfaces);
                RegisterDescriptor(modelClass);

                resultParserTypes.Add(new ResultParserTypeDescriptor(modelClass));
            }

            RegisterDescriptor(unionInterface);

            RegisterDescriptor(
                new ResultParserMethodDescriptor(
                    GetPathName(path),
                    operation,
                    fieldType,
                    fieldSelection,
                    path,
                    unionInterface,
                    resultParserTypes));

            return(unionInterface);
        }
        public void ReadFromStream(PacketStream stream)
        {
            List <WindowDescriptor> windowDescriptors = new List <WindowDescriptor>();

            int windowCount = stream.ReadByte();

            for (int i = 0; i < windowCount; i++)
            {
                string windowName = stream.ReadString();
                List <ElementDescriptor> elementDescriptors = new List <ElementDescriptor>();

                int elementCount = stream.ReadByte();
                for (int j = 0; j < elementCount; j++)
                {
                    string            elementName = stream.ReadString();
                    DescriptorType    elementType = (DescriptorType)stream.ReadByte();
                    ElementDescriptor elementDescriptor;

                    switch (elementType)
                    {
                    case DescriptorType.Main: elementDescriptor = new ElementDescriptorMain(elementName); break;

                    case DescriptorType.Input: elementDescriptor = new ElementDescriptorInput(elementName); break;

                    case DescriptorType.Button: elementDescriptor = new ElementDescriptorButton(elementName); break;

                    case DescriptorType.Child: elementDescriptor = new ElementDescriptorChild(elementName); break;

                    case DescriptorType.Output: elementDescriptor = new ElementDescriptorOutput(elementName); break;

                    case DescriptorType.Info: elementDescriptor = new ElementDescriptorInfo(elementName); break;

                    case DescriptorType.Map: elementDescriptor = new ElementDescriptorMap(elementName); break;

                    case DescriptorType.Browser: elementDescriptor = new ElementDescriptorBrowser(elementName); break;

                    default: throw new Exception("Invalid descriptor type '" + elementType + "'");
                    }

                    elementDescriptors.Add(elementDescriptor);

                    AttributeType valueType;
                    do
                    {
                        valueType = (AttributeType)stream.ReadByte();
                        switch (valueType)
                        {
                        case AttributeType.Pos: elementDescriptor.Pos = new Point(stream.ReadUInt16(), stream.ReadUInt16()); break;

                        case AttributeType.Size: elementDescriptor.Size = new Size(stream.ReadUInt16(), stream.ReadUInt16()); break;

                        case AttributeType.Anchor1: elementDescriptor.Anchor1 = new Point(stream.ReadUInt16(), stream.ReadUInt16()); break;

                        case AttributeType.Anchor2: elementDescriptor.Anchor2 = new Point(stream.ReadUInt16(), stream.ReadUInt16()); break;

                        case AttributeType.BackgroundColor: elementDescriptor.BackgroundColor = Color.FromArgb(stream.ReadByte(), stream.ReadByte(), stream.ReadByte()); break;

                        case AttributeType.IsVisible: elementDescriptor.IsVisible = stream.ReadBool(); break;

                        case AttributeType.IsDefault: elementDescriptor.IsDefault = stream.ReadBool(); break;

                        case AttributeType.IsPane: ((ElementDescriptorMain)elementDescriptor).IsPane = stream.ReadBool(); break;

                        case AttributeType.Left: ((ElementDescriptorChild)elementDescriptor).Left = stream.ReadString(); break;

                        case AttributeType.Right: ((ElementDescriptorChild)elementDescriptor).Right = stream.ReadString(); break;

                        case AttributeType.IsVert: ((ElementDescriptorChild)elementDescriptor).IsVert = stream.ReadBool(); break;

                        case AttributeType.Text:
                            if (elementDescriptor is ElementDescriptorButton)
                            {
                                ((ElementDescriptorButton)elementDescriptor).Text = stream.ReadString();
                            }
                            break;


                        case AttributeType.End: break;

                        default: throw new Exception("Invalid attribute type '" + valueType + "'");
                        }
                    } while (valueType != AttributeType.End);
                }

                WindowDescriptor windowDescriptor = new WindowDescriptor(windowName, elementDescriptors);
                windowDescriptors.Add(windowDescriptor);
            }

            InterfaceDescriptor = new InterfaceDescriptor(windowDescriptors);
        }
        public unsafe WinUSBInterface(string devicePath)
        {
            DevicePath = devicePath;
            WithHandle(winUsbHandle =>
            {
                var packet = SetupPacket.MakeGetDescriptor(
                    RequestInternalType.Standard,
                    RequestRecipient.Device,
                    DescriptorType.Device, 0,
                    (ushort)sizeof(DeviceDescriptor)
                    );

                var deviceDescriptor = new DeviceDescriptor();
                void *descriptorPtr  = &deviceDescriptor;

                if (!WinUsb_ControlTransfer(winUsbHandle, packet, descriptorPtr, (uint)sizeof(DeviceDescriptor), out _, null))
                {
                    throw new IOException("Failed to retrieve device descriptor");
                }

                var interfaceDescriptor = new InterfaceDescriptor();
                if (!WinUsb_QueryInterfaceSettings(winUsbHandle, 0, &interfaceDescriptor))
                {
                    throw new IOException("Failed to get interface descriptor");
                }

                InterfaceNum = interfaceDescriptor.bInterfaceNumber;

                for (byte i = 0; i < interfaceDescriptor.bNumEndpoints; i++)
                {
                    var b = i; // Workaround CoreCLR bug
                    if (!WinUsb_QueryPipe(winUsbHandle, 0, i, out var pipeInfo))
                    {
                        throw new IOException("Failed to get pipe information");
                    }
                    i = b;

                    var direction = (PipeDirection)((pipeInfo.PipeID >> 7) & 1);
                    switch (direction)
                    {
                    case PipeDirection.Out:
                        if (OutputPipe.HasValue)
                        {
                            throw new IOException("WinUSB HID device unexpectedly have more than one output endpoint on the same interface");
                        }

                        OutputPipe         = pipeInfo.PipeID;
                        OutputReportLength = pipeInfo.MaximumPacketSize;
                        break;

                    case PipeDirection.In:
                        if (InputPipe.HasValue)
                        {
                            throw new IOException("WinUSB HID device unexpectedly have more than one input endpoint on the same interface");
                        }

                        InputPipe         = pipeInfo.PipeID;
                        InputReportLength = pipeInfo.MaximumPacketSize;
                        break;
                    }
                }

                ProductID = deviceDescriptor.idProduct;
                VendorID  = deviceDescriptor.idVendor;

                Manufacturer = deviceDescriptor.iManufacturer != 0
                    ? GetDeviceString(deviceDescriptor.iManufacturer)
                    : "Unknown Manufacturer";

                ProductName = deviceDescriptor.iProduct != 0
                    ? GetDeviceString(deviceDescriptor.iProduct)
                    : "Unknown Product Name";

                SerialNumber = deviceDescriptor.iSerialNumber != 0
                    ? GetDeviceString(deviceDescriptor.iSerialNumber)
                    : "Unknown Serial Number";
            });
        }
Beispiel #15
0
 public GClass871(Guid guid_0, InterfaceDescriptor interfaceDescriptor_0, ICommon icommon_0)
 {
     Class13.NP5bWyNzLwONS();
     base..ctor(guid_0, interfaceDescriptor_0, icommon_0);
 }
Beispiel #16
0
 protected virtual void SetValues(InterfaceDescriptor descriptor)
 {
     this.InterfaceValue = descriptor.bInterfaceNumber;
     this.EndpointCount  = descriptor.bNumEndpoints;
 }
Beispiel #17
0
 public GClass922(Guid guid_0, InterfaceDescriptor interfaceDescriptor_0, ICommon icommon_0)
 {
     Class13.lOBHd9Nzn7x2T();
     base..ctor(guid_0, interfaceDescriptor_0, icommon_0);
 }