[PATCH v3 ] programs/winedevice.exe: Use IoCreateDriver and IoDeleteDriver

Aric Stewart aric at codeweavers.com
Wed Aug 3 13:19:13 CDT 2016



On 8/3/16 11:54 AM, Sebastian Lackner wrote:
> On 29.07.2016 21:02, Aric Stewart wrote:
>> v2: Pass a proper driver name to IoCreateDriver and use generated keyname
>> v3: Remove global driver_name
>>
>> The two patches are not longer a set as each is independent of the other
>>
>> Signed-off-by: Aric Stewart <aric at codeweavers.com>
>> ---
>>  programs/winedevice/device.c | 179 +++++++++++++++++++++++--------------------
>>  1 file changed, 94 insertions(+), 85 deletions(-)
>>
>>
>>
>> 0002-programs-winedevice.exe-Use-IoCreateDriver-and-IoDelet.txt
>>
>>
>> diff --git a/programs/winedevice/device.c b/programs/winedevice/device.c
>> index 94132ed..df0fac3 100644
>> --- a/programs/winedevice/device.c
>> +++ b/programs/winedevice/device.c
...
>> -    UNICODE_STRING keypath;
>>      HKEY driver_hkey;
>>      HMODULE module;
>>      LPWSTR path = NULL, str;
>>      DWORD type, size;
>>  
>> -    str = HeapAlloc( GetProcessHeap(), 0, sizeof(servicesW) + strlenW(driver_name)*sizeof(WCHAR) );
>> -    lstrcpyW( str, servicesW );
>> -    lstrcatW( str, driver_name );
>> -
>> -    if (RegOpenKeyW( HKEY_LOCAL_MACHINE, str + 18 /* skip \registry\machine */, &driver_hkey ))
>> +    if (RegOpenKeyW( HKEY_LOCAL_MACHINE, keyname->Buffer + 18 /* skip \registry\machine */, &driver_hkey ))
> 
> Currently its hardcoded in ntoskrnl, but it would be better to check the prefix first.

The specifications for DriverEntry state that

"The registry path string pointed to by RegistryPath is of the form \Registry\Machine\System\CurrentControlSet\Services\DriverName. A driver can use this path to store driver-specific information; see Registry Keys for Drivers."

So it is reasonable to assume that the keyname will begin with that. I can check but it seems unnecessary.


> 
>>      {
>> -        WINE_ERR( "cannot open key %s, err=%u\n", wine_dbgstr_w(str), GetLastError() );
>> -        HeapFree( GetProcessHeap(), 0, str);
>> +        WINE_ERR( "cannot open key %s, err=%u\n", wine_dbgstr_w(keyname->Buffer), GetLastError() );
>>          return NULL;
>>      }
>> -    RtlInitUnicodeString( &keypath, str );
>>  
>>      /* read the executable path from memory */
>>      size = 0;
>> @@ -233,7 +165,6 @@ static HMODULE load_driver(void)
>>          HeapFree( GetProcessHeap(), 0, str );
>>          if (!path)
>>          {
>> -            RtlFreeUnicodeString( &keypath );
>>              RegCloseKey( driver_hkey );
>>              return NULL;
>>          }
>> @@ -276,19 +207,98 @@ static HMODULE load_driver(void)
>>  
>>      module = load_driver_module( str );
>>      HeapFree( GetProcessHeap(), 0, path );
>> -    if (!module)
>> +    return module;
>> +}
>> +
>> +/* call the driver init entry point */
>> +static NTSTATUS WINAPI init_driver( DRIVER_OBJECT *driver_object, UNICODE_STRING *keyname )
>> +{
>> +    unsigned int i;
>> +    NTSTATUS status;
>> +    const IMAGE_NT_HEADERS *nt;
>> +    const WCHAR *driver_name;
>> +
>> +    /* Retrieve driver name from the keyname */
>> +    driver_name = strrchrW(keyname->Buffer, '\\');
> 
> It would be better to test that this actually worked.
> 

Again see above...  I can test, but assuming does not seem unreasonable.

The rest seem like helpful updates and so I will submit a new version.

-aric




More information about the wine-devel mailing list