예제 #1
0
        public static string GetDriverProperty(Session session, Guid searchGuid, string searchHardwareId,
                                               NativeMethods.DEVPROPKEY prop)
        {
            string result   = "";
            bool   devmatch = false;

            //Guid sysGuid = Guid.Parse("{4d36e97d-e325-11ce-bfc1-08002be10318}");
            NativeMethods.SP_DEVINFO_DATA deviceInfoData = new NativeMethods.SP_DEVINFO_DATA();
            deviceInfoData.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(deviceInfoData);
            var   dataBuffer   = new byte[4096];
            ulong propertyType = 0;
            var   requiredSize = 0;
            //var type = 0;
            IntPtr deviceInfoSet = NativeMethods.SetupDiGetClassDevs(ref searchGuid, null, 0, 0);

            for (int i = 0; !devmatch && NativeMethods.SetupDiEnumDeviceInfo(deviceInfoSet, i, ref deviceInfoData); i++)
            {
                //session.Log($"ITER {i}");
                if (NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet, ref deviceInfoData, ref NativeMethods.DEVPKEY_Device_InstanceId, ref propertyType,
                                                           dataBuffer, dataBuffer.Length, ref requiredSize, 0))
                {
                    string currentInstanceId = dataBuffer.ToUTF16String();
                    session.Log($"Search device {currentInstanceId}");
                    if (currentInstanceId.Equals(searchHardwareId))
                    {
                        devmatch = true;
                    }
                }
            }

            if (devmatch)
            {
                //session.Log("FOUND MATCH");
                if (NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet, ref deviceInfoData, ref prop, ref propertyType,
                                                           dataBuffer, dataBuffer.Length, ref requiredSize, 0))
                {
                    result = dataBuffer.ToUTF16String();
                }
            }

            if (deviceInfoSet.ToInt64() != NativeMethods.INVALID_HANDLE_VALUE)
            {
                NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet);
            }

            return(result);
        }
예제 #2
0
 public static string FakerInputDevProp(Session session, NativeMethods.DEVPROPKEY prop)
 {
     return(GetDriverProperty(session, sysGuid, FakerInputInstanceId(), prop));
 }