⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 legacy.c

📁 串口Windows驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
                                 &interfaceType,
                                 &busZero,
                                 NULL,
                                 NULL,
                                 NULL,
                                 NULL,
                                 SerialItemCallBack,
                                 &foundOne
                                 );

         if (foundOne) {

            defaultInterfaceType = (ULONG)interfaceType;
            if (defaultInterfaceType == MicroChannel) {

               defaultInterruptMode = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;

               //
               // Microchannel machines can permit the interrupt to be
               // shared system wide.
               //

               userData.DefaultPermitSystemWideShare = TRUE;

            }

            break;

         }

      }

   }

   //
   // Gonna get the user data now.  Allocate the
   // structures that we will be using throughout
   // the search for user data.  We will deallocate
   // them before we leave this routine.
   //

   userData.UserSymbolicLink.Buffer = NULL;
   parametersPath.Buffer = NULL;

   //
   // Allocate the rtl query table.  This should have an entry for each value
   // we retrieve from the registry as well as a terminating zero entry as
   // well the first "goto subkey" entry.
   //

   parameters = ExAllocatePool(
                              PagedPool,
                              sizeof(RTL_QUERY_REGISTRY_TABLE)*22
                              );

   if (!parameters) {

      SerialLogError(
                    DriverObject,
                    NULL,
                    SerialPhysicalZero,
                    SerialPhysicalZero,
                    0,
                    0,
                    0,
                    74,
                    STATUS_SUCCESS,
                    SERIAL_INSUFFICIENT_RESOURCES,
                    0,
                    NULL,
                    0,
                    NULL
                    );
      SerialDbgPrintEx(SERERRORS, "Couldn't allocate table for rtl query\n"
                       "to parameters for %wZ", RegistryPath);

      goto LegacyInitLeave;

   }

   RtlZeroMemory(
                parameters,
                sizeof(RTL_QUERY_REGISTRY_TABLE)*22
                );

   //
   // Allocate the place where the user's symbolic link name
   // for the port will go.
   //

   //
   // We will initially allocate space for 257 wchars.
   // we will then set the maximum size to 256
   // This way the rtl routine could return a 256
   // WCHAR wide string with no null terminator.
   // We'll remember that the buffer is one WCHAR
   // longer then it says it is so that we can always
   // have a NULL terminator at the end.
   //

   RtlInitUnicodeString(&userData.UserSymbolicLink, NULL);
   userData.UserSymbolicLink.MaximumLength = sizeof(WCHAR) * 256;
   userData.UserSymbolicLink.Buffer = ExAllocatePool(PagedPool, sizeof(WCHAR)
                                                     * 257);

   if (!userData.UserSymbolicLink.Buffer) {

      SerialLogError(
                    DriverObject,
                    NULL,
                    SerialPhysicalZero,
                    SerialPhysicalZero,
                    0,
                    0,
                    0,
                    75,
                    STATUS_SUCCESS,
                    SERIAL_INSUFFICIENT_RESOURCES,
                    0,
                    NULL,
                    0,
                    NULL
                    );
      SerialDbgPrintEx(SERERRORS, "Couldn't allocate buffer for the symbolic "
                       "link\nfor parameters items in %wZ", RegistryPath);

      goto LegacyInitLeave;

   }





   //
   // We will initially allocate space for 257 wchars.
   // we will then set the maximum size to 256
   // This way the rtl routine could return a 256
   // WCHAR wide string with no null terminator.
   // We'll remember that the buffer is one WCHAR
   // longer then it says it is so that we can always
   // have a NULL terminator at the end.
   //

   RtlInitUnicodeString(&PnPID, NULL);
   PnPID.MaximumLength = sizeof(WCHAR) * 256;
   PnPID.Buffer = ExAllocatePool(PagedPool, sizeof(WCHAR) * 257);

   if (PnPID.Buffer == 0) {

      SerialLogError(
                    DriverObject,
                    NULL,
                    SerialPhysicalZero,
                    SerialPhysicalZero,
                    0,
                    0,
                    0,
                    76,
                    STATUS_SUCCESS,
                    SERIAL_INSUFFICIENT_RESOURCES,
                    0,
                    NULL,
                    0,
                    NULL
                    );
      SerialDbgPrintEx(SERERRORS, "Couldn't allocate buffer for the PnP ID\n"
                       "for parameters items in %wZ", RegistryPath);

      goto LegacyInitLeave;

   }


   // Initialize the legacy key buffer
   RtlInitUnicodeString(&legacyKeys, NULL);
   legacyKeys.MaximumLength = sizeof(WCHAR) * 256;
   legacyKeys.Buffer = ExAllocatePool(PagedPool, sizeof(WCHAR) * 257);

   if (!legacyKeys.Buffer) {

      SerialLogError(
                    DriverObject,
                    NULL,
                    SerialPhysicalZero,
                    SerialPhysicalZero,
                    0,
                    0,
                    0,
                    77,
                    STATUS_SUCCESS,
                    SERIAL_INSUFFICIENT_RESOURCES,
                    0,
                    NULL,
                    0,
                    NULL
                    );

      SerialDbgPrintEx(SERERRORS, "Couldn't allocate buffer for the legacy"
                             " keys\n");

      goto LegacyInitLeave;

   }

   resourceList = ExAllocatePool(PagedPool, sizeof(CM_RESOURCE_LIST)
                                 + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 2);

   if (resourceList == NULL) {
      SerialLogError(
                    DriverObject,
                    NULL,
                    userData.UserPort,
                    SerialPhysicalZero,
                    0,
                    0,
                    0,
                    78,
                    STATUS_SUCCESS,
                    SERIAL_INSUFFICIENT_RESOURCES,
                    0,
                    NULL,
                    0,
                    NULL
                    );
      goto LegacyInitLeave;
   }

   trResourceList = ExAllocatePool(PagedPool, sizeof(CM_RESOURCE_LIST)
                                   + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)
                                   * 2);

   if (trResourceList == NULL) {
      SerialLogError(
                    DriverObject,
                    NULL,
                    userData.UserPort,
                    SerialPhysicalZero,
                    0,
                    0,
                    0,
                    79,
                    STATUS_SUCCESS,
                    SERIAL_INSUFFICIENT_RESOURCES,
                    0,
                    NULL,
                    0,
                    NULL
                    );
      goto LegacyInitLeave;
   }


   pRequiredList
      = ExAllocatePool(PagedPool, sizeof(IO_RESOURCE_REQUIREMENTS_LIST)
                       + sizeof(IO_RESOURCE_DESCRIPTOR) * 2);

   if (pRequiredList == NULL) {
      SerialLogError(
                    DriverObject,
                    NULL,
                    userData.UserPort,
                    SerialPhysicalZero,
                    0,
                    0,
                    0,
                    80,
                    STATUS_SUCCESS,
                    SERIAL_INSUFFICIENT_RESOURCES,
                    0,
                    NULL,
                    0,
                    NULL
                    );

      goto LegacyInitLeave;
   }


   //
   // Form a path to our drivers Parameters subkey.
   //

   RtlInitUnicodeString(
                       &parametersPath,
                       NULL
                       );

   parametersPath.MaximumLength = RegistryPath->Length +
                                  sizeof(L"\\") +
                                  sizeof(L"Parameters");

   parametersPath.Buffer = ExAllocatePool(
                                         PagedPool,
                                         parametersPath.MaximumLength
                                         );

   if (!parametersPath.Buffer) {

      SerialLogError(
                    DriverObject,
                    NULL,
                    SerialPhysicalZero,
                    SerialPhysicalZero,
                    0,
                    0,
                    0,
                    81,
                    STATUS_SUCCESS,
                    SERIAL_INSUFFICIENT_RESOURCES,
                    0,
                    NULL,
                    0,
                    NULL
                    );
      SerialDbgPrintEx(SERERRORS, "Couldn't allocate string for path\n"
                       "to parameters for %wZ", RegistryPath);

      goto LegacyInitLeave;

   }

   //
   // Form the parameters path.
   //

   RtlZeroMemory(
                parametersPath.Buffer,
                parametersPath.MaximumLength
                );
   RtlAppendUnicodeStringToString(
                                 &parametersPath,
                                 RegistryPath
                                 );
   RtlAppendUnicodeToString(
                           &parametersPath,
                           L"\\"
                           );
   RtlAppendUnicodeToString(
                           &parametersPath,
                           L"Parameters"
                           );

   //
   // Form the start of the legacy keys string
   //
   RtlZeroMemory(legacyKeys.Buffer, legacyKeys.MaximumLength);
   RtlAppendUnicodeStringToString(&legacyKeys, &parametersPath);


   userSubKey = ExAllocatePool(
                              PagedPool,
                              sizeof(KEY_BASIC_INFORMATION)+(sizeof(WCHAR)*256)
                              );

   if (!userSubKey) {

      SerialLogError(
                    DriverObject,
                    NULL,
                    SerialPhysicalZero,
                    SerialPhysicalZero,
                    0,
                    0,
                    0,
                    82,
                    STATUS_SUCCESS,
                    SERIAL_INSUFFICIENT_RESOURCES,
                    0,
                    NULL,
                    0,
                    NULL
                    );
      SerialDbgPrintEx(SERERRORS, "Couldn't allocate memory basic information\n"
                       "structure to enumerate subkeys for %wZ",
                       &parametersPath);

      goto LegacyInitLeave;

   }

   //
   // Open the key given by our registry path & Parameters.
   //

   InitializeObjectAttributes(
                             &parametersAttributes,
                             &parametersPath,
                             OBJ_CASE_INSENSITIVE,
                             NULL,
                             NULL
                             );

   if (!NT_SUCCESS(ZwOpenKey(
                            &parametersKey,
                            MAXIMUM_ALLOWED,
                            &parametersAttributes
                            ))) {

      SerialLogError(
                    DriverObject,
                    NULL,
                    SerialPhysicalZero,
                    SerialPhysicalZero,
                    0,
                    0,
                    0,
                    83,
                    STATUS_SUCCESS,
                    SERIAL_NO_PARAMETERS_INFO,
                    0,
                    NULL,
                    0,
                    NULL
                    );
      SerialDbgPrintEx(SERERRORS, "Couldn't open the drivers Parameters key "
                       "%wZ\n", RegistryPath);

      goto LegacyInitLeave;

   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -