2010年10月21日 星期四

Driver file replacement

In my case study, the target application will replace some drivers under \Windows folder. Those drivers are run by device.exe when boot up.

In my backup and restore study, although I can copy the driver file into backup image, but I cannot simply write it back to device.

My first plan is develop a program run before device.exe and replace those files. The program only needs file system APIs, and the APIs are ready in early of filesys.exe, so I guess it should work.

But as my test result on [HKLM\init and database status], I go problem to run any application before device.exe, even service.exe. And I cannot find solution for it until now.

So, here is the second solution I got:

First, find the sub-key(s) in “HKLM\Drivers\Active” which using the driver file. In my case: camera.dll, I found it at “HKLM\Drivers\Active\38”. Here is the entries in that registry key:

Hnd 3490960
Name CAM1:
Key Drivers\BuiltIn\CameraDriver
BusParent 206896
InterfaceType 0
BusName BuiltIn_0_13_0
ClientInfo 0

Three keys you need to pay attention:

Hnd HANDLE of running device. You will need it to deactive the device for release driver file.
Key The registry location which store the driver settings for device.exe. You need it for device active API.
ClientInfo Driver’s init parameter. If device.exe active driver with parameter, it will put it in this registry. You will need it when you want to active the device again.
If the registry key not exists, ignore it.

After found that registry, all information needs for my testing application to replace driver are ready. Here is the procedure of camera.dll:

  1. Deactive camera device by “DeactiveDevice(3490960)” to release camera.dll. (In my case, only one device using camera.dll)
  2. Copy camera.dll from backup image to \Windows folder
  3. Active camera device by “ActiveDevice(_T(“Drivers\BuiltIn\CameraDriver”), 0)”. The second parameter is ClientInfo, if your driver does not use it, pass 0 for it

I think most of drivers can use this procedure to replace, but I still think it’s too complex.

Cause that means after I scan all files does not in ROM image ([Windows Mobile File system Study]), I need to differentiate which files are used by device.exe and using different way to perform backup & restore function for them.

And here is anther issue about this solution: When I de-active the device, something device will popup “device.exe failure” error screen. Although that does not cause any problem for our backup & restore operation, but the user experience is bad for user to see that screen.

沒有留言:

張貼留言