Пример #1
0
        unsafe private void ExtractResourceDescriptor(RegResourceItem.ResourceList resourceList, ref IntPtr p)
        {
            try
            {
                RegResourceItem.FULL_RESOURCE_DESCRIPTOR frd = new RegResourceItem.FULL_RESOURCE_DESCRIPTOR();
                Marshal.PtrToStructure(p, frd);
                p = (IntPtr)(p.ToInt32() + Marshal.SizeOf(frd));
                if (frd != null)
                {
                    RegResourceItem.FullResourceDescriptor fullResourceDescriptor = new RegResourceItem.FullResourceDescriptor(frd.InterfaceType, (int)frd.BusNumber);

                    for (int j = 0; j < frd.PartialResourceList.Count; j++)
                    {
                        RegResourceItem.PARTIAL_RESOURCE_DESCRIPTOR prd = new RegResourceItem.PARTIAL_RESOURCE_DESCRIPTOR();
                        Marshal.PtrToStructure(p, prd);

                        p = (IntPtr)(p.ToInt32() + (sizeof(byte) + sizeof(byte) + sizeof(ushort) + LargestStructSizeInUnion));

                        RegResourceItem.PartialResourceDescriptor partialResourceDescriptor = new RegResourceItem.PartialResourceDescriptor((RegResourceItem.ResourceType)prd.Type, prd.ShareDisposition, prd.Flags);

                        #region Parse Resource
                        switch ((RegResourceItem.ResourceType)prd.Type)
                        {
                        case RegResourceItem.ResourceType.Interrupt:
                        {
                            // Interrupt resource type
                            partialResourceDescriptor.Resource =
                                new RegResourceItem.HardwareResource.Interrupt(prd.Interrupt.Level, prd.Interrupt.Vector, prd.Interrupt.Affinity);
                            break;
                        }

                        case RegResourceItem.ResourceType.Memory:
                        {
                            // Memory resource type
                            partialResourceDescriptor.Resource =
                                new RegResourceItem.HardwareResource.Memory(prd.Memory.Start, prd.Memory.Length);
                            break;
                        }

                        case RegResourceItem.ResourceType.BusNumber:
                        {
                            // BusNumber resource type
                            partialResourceDescriptor.Resource =
                                new RegResourceItem.HardwareResource.BusNumber(prd.BusNumber.Start, prd.BusNumber.Length, prd.BusNumber.Reserved);
                            break;
                        }

                        case RegResourceItem.ResourceType.Dma:
                        {
                            // Dma resource type
                            partialResourceDescriptor.Resource =
                                new RegResourceItem.HardwareResource.Dma(prd.Dma.Channel, prd.Dma.Port, prd.Dma.Reserved1);
                            break;
                        }

                        case RegResourceItem.ResourceType.Null:
                        {
                            // Generic resource type
                            partialResourceDescriptor.Resource =
                                new RegResourceItem.HardwareResource.Generic(prd.Generic.Start, prd.Generic.Length);
                            break;
                        }

                        case RegResourceItem.ResourceType.Port:
                        {
                            // Port resource type
                            partialResourceDescriptor.Resource =
                                new RegResourceItem.HardwareResource.Port(prd.Port.Start, prd.Port.Length);
                            break;
                        }

                        case RegResourceItem.ResourceType.DevicePrivate:
                        {
                            // DevicePrivate resource type
                            partialResourceDescriptor.Resource =
                                new RegResourceItem.HardwareResource.DevicePrivate(prd.DevicePrivate.Data);
                            break;
                        }

                        case RegResourceItem.ResourceType.DeviceSpecific:
                        {
                            // DeviceSpecific resource type
                            partialResourceDescriptor.Resource =
                                new RegResourceItem.HardwareResource.DeviceSpecificData(prd.DeviceSpecificData.DataSize, prd.DeviceSpecificData.Reserved1, prd.DeviceSpecificData.Reserved2);
                            break;
                        }
                        }
                        #endregion

                        fullResourceDescriptor.PartialResourceDescriptors.Add(partialResourceDescriptor);
                    }

                    resourceList.FullResourceDescriptors.Add(fullResourceDescriptor);

                    string[] listOfItems = new string[3];
                    listOfItems[0] = ((int)frd.BusNumber).ToString();
                    string sInterface = RegResourceItem.GetInterfaceString(frd.InterfaceType);
                    listOfItems[1] = sInterface;
                    listOfItems[2] = frd.BusNumber.ToString() + sInterface;

                    if (ResourceListTable == null)
                    {
                        ResourceListTable = new Hashtable();
                        ResourceListTable.Add(listOfItems[2], fullResourceDescriptor);
                    }
                    else
                    {
                        ResourceListTable.Add(listOfItems[2], fullResourceDescriptor);
                    }

                    ListViewItem lvItem = new ListViewItem(listOfItems);
                    LWlvResourceList.Items.Add(lvItem);
                }
            }
            finally
            {
            }
        }
        unsafe private void ExtractResourceDescriptor(RegResourceItem.ResourceList resourceList, ref IntPtr p)
        {
            try
            {
                RegResourceItem.FULL_RESOURCE_DESCRIPTOR frd = new RegResourceItem.FULL_RESOURCE_DESCRIPTOR();
                Marshal.PtrToStructure(p, frd);
                p = (IntPtr)(p.ToInt32() + Marshal.SizeOf(frd));
                if (frd != null)
                {
                    RegResourceItem.FullResourceDescriptor fullResourceDescriptor = new RegResourceItem.FullResourceDescriptor(frd.InterfaceType, (int)frd.BusNumber);

                    for (int j = 0; j < frd.PartialResourceList.Count; j++)
                    {
                        RegResourceItem.PARTIAL_RESOURCE_DESCRIPTOR prd = new RegResourceItem.PARTIAL_RESOURCE_DESCRIPTOR();
                        Marshal.PtrToStructure(p, prd);

                        p = (IntPtr)(p.ToInt32() + (sizeof(byte) + sizeof(byte) + sizeof(ushort) + LargestStructSizeInUnion));

                        RegResourceItem.PartialResourceDescriptor partialResourceDescriptor = new RegResourceItem.PartialResourceDescriptor((RegResourceItem.ResourceType)prd.Type, prd.ShareDisposition, prd.Flags);

                        #region Parse Resource
                        switch ((RegResourceItem.ResourceType)prd.Type)
                        {
                            case RegResourceItem.ResourceType.Interrupt:
                                {
                                    // Interrupt resource type
                                    partialResourceDescriptor.Resource =
                                        new RegResourceItem.HardwareResource.Interrupt(prd.Interrupt.Level, prd.Interrupt.Vector, prd.Interrupt.Affinity);
                                    break;
                                }

                            case RegResourceItem.ResourceType.Memory:
                                {
                                    // Memory resource type
                                    partialResourceDescriptor.Resource =
                                        new RegResourceItem.HardwareResource.Memory(prd.Memory.Start, prd.Memory.Length);
                                    break;
                                }

                            case RegResourceItem.ResourceType.BusNumber:
                                {
                                    // BusNumber resource type
                                    partialResourceDescriptor.Resource =
                                        new RegResourceItem.HardwareResource.BusNumber(prd.BusNumber.Start, prd.BusNumber.Length, prd.BusNumber.Reserved);
                                    break;
                                }

                            case RegResourceItem.ResourceType.Dma:
                                {
                                    // Dma resource type
                                    partialResourceDescriptor.Resource =
                                        new RegResourceItem.HardwareResource.Dma(prd.Dma.Channel, prd.Dma.Port, prd.Dma.Reserved1);
                                    break;
                                }

                            case RegResourceItem.ResourceType.Null:
                                {
                                    // Generic resource type
                                    partialResourceDescriptor.Resource =
                                        new RegResourceItem.HardwareResource.Generic(prd.Generic.Start, prd.Generic.Length);
                                    break;
                                }

                            case RegResourceItem.ResourceType.Port:
                                {
                                    // Port resource type
                                    partialResourceDescriptor.Resource =
                                        new RegResourceItem.HardwareResource.Port(prd.Port.Start, prd.Port.Length);
                                    break;
                                }

                            case RegResourceItem.ResourceType.DevicePrivate:
                                {
                                    // DevicePrivate resource type
                                    partialResourceDescriptor.Resource =
                                        new RegResourceItem.HardwareResource.DevicePrivate(prd.DevicePrivate.Data);
                                    break;
                                }

                            case RegResourceItem.ResourceType.DeviceSpecific:
                                {
                                    // DeviceSpecific resource type
                                    partialResourceDescriptor.Resource =
                                        new RegResourceItem.HardwareResource.DeviceSpecificData(prd.DeviceSpecificData.DataSize, prd.DeviceSpecificData.Reserved1, prd.DeviceSpecificData.Reserved2);
                                    break;
                                }
                        }
                        #endregion

                        fullResourceDescriptor.PartialResourceDescriptors.Add(partialResourceDescriptor);
                    }

                    resourceList.FullResourceDescriptors.Add(fullResourceDescriptor);

                    string[] listOfItems = new string[3];
                    listOfItems[0] = ((int)frd.BusNumber).ToString();
                    string sInterface = RegResourceItem.GetInterfaceString(frd.InterfaceType);
                    listOfItems[1] = sInterface;
                    listOfItems[2] = frd.BusNumber.ToString() + sInterface;

                    if (ResourceListTable == null)
                    {
                        ResourceListTable = new Hashtable();
                        ResourceListTable.Add(listOfItems[2], fullResourceDescriptor);
                    }
                    else
                        ResourceListTable.Add(listOfItems[2], fullResourceDescriptor);

                    ListViewItem lvItem = new ListViewItem(listOfItems);
                    LWlvResourceList.Items.Add(lvItem);
                }
            }
            finally
            {
            }
        }