win-pvdrivers

changeset 567:de0fb547dcf0

have to commit this or it won't let me remove the other files
author James Harper <james.harper@bendigoit.com.au>
date Sun May 10 20:19:51 2009 +1000 (2009-05-10)
parents 003c946e756a
children 21b13cbeb94e
files xenhide/makefile xenhide/makefile.inc xenhide/sources xenhide/xenhide.c xenhide/xenhide.h xenhide/xenhide.inx
line diff
     1.1 --- a/xenhide/makefile	Sun May 10 20:19:28 2009 +1000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,1 +0,0 @@
     1.4 -!INCLUDE $(NTMAKEENV)\makefile.def
     1.5 \ No newline at end of file
     2.1 --- a/xenhide/sources	Sun May 10 20:19:28 2009 +1000
     2.2 +++ b/xenhide/sources	Sun May 10 20:19:51 2009 +1000
     2.3 @@ -1,6 +1,5 @@
     2.4  !include "..\common.inc"
     2.5 -!UNDEF KMDF_VERSION
     2.6 -!UNDEF KMDF_VERSION_MAJOR
     2.7 +KMDF_VERSION_MAJOR=1
     2.8  TARGETNAME=xenhide
     2.9  TARGETTYPE=DRIVER
    2.10  SOURCES=xenhide.c
     3.1 --- a/xenhide/xenhide.c	Sun May 10 20:19:28 2009 +1000
     3.2 +++ b/xenhide/xenhide.c	Sun May 10 20:19:51 2009 +1000
     3.3 @@ -25,6 +25,241 @@ static BOOLEAN need_gplpv_filter;
     3.4  static BOOLEAN gplpv_interrogated;
     3.5  
     3.6  static NTSTATUS
     3.7 +XenHide_EvtDeviceFilterRemoveResourceRequirements(WDFDEVICE device, WDFIORESREQLIST irrl)
     3.8 +{
     3.9 +  ULONG i;
    3.10 +  WDFIORESLIST irl;
    3.11 +  
    3.12 +  UNREFERENCED_PARAMETER(device);
    3.13 +  
    3.14 +  FUNCTION_ENTER();
    3.15 +  
    3.16 +  for (i = 0; i < WdfIoResourceRequirementsListGetCount(irrl); i++)
    3.17 +  {
    3.18 +    KdPrint((__DRIVER_NAME "     Processing irrl #%d\n", i));
    3.19 +    irl = WdfIoResourceRequirementsListGetIoResList(irrl, i);
    3.20 +    while(WdfIoResourceListGetCount(irl) > 0)
    3.21 +    {
    3.22 +      KdPrint((__DRIVER_NAME "     Removing irl\n"));
    3.23 +      WdfIoResourceListRemove(irl, 0);
    3.24 +    }
    3.25 +  }
    3.26 +  
    3.27 +  FUNCTION_EXIT();
    3.28 +  
    3.29 +  return STATUS_SUCCESS;
    3.30 +}
    3.31 +
    3.32 +/*
    3.33 +static NTSTATUS
    3.34 +XenHide_EvtDeviceD0Entry(WDFDEVICE device, WDF_POWER_DEVICE_STATE previous_state)
    3.35 +{
    3.36 +  NTSTATUS status = STATUS_UNSUCCESSFUL;
    3.37 +  
    3.38 +  UNREFERENCED_PARAMETER(device);
    3.39 +  UNREFERENCED_PARAMETER(previous_state);
    3.40 +
    3.41 +  FUNCTION_ENTER();
    3.42 +  WdfDeviceSetFailed(device, WdfDeviceFailedNoRestart);
    3.43 +  FUNCTION_EXIT();
    3.44 +  return status;
    3.45 +}
    3.46 +*/
    3.47 +
    3.48 +NTSTATUS
    3.49 +XenHide_EvtDevicePrepareHardware (WDFDEVICE device, WDFCMRESLIST resources_raw, WDFCMRESLIST resources_translated)
    3.50 +{
    3.51 +  UNREFERENCED_PARAMETER(device);
    3.52 +  UNREFERENCED_PARAMETER(resources_raw);
    3.53 +  UNREFERENCED_PARAMETER(resources_translated);
    3.54 +  FUNCTION_ENTER();
    3.55 +  FUNCTION_EXIT();
    3.56 +  return STATUS_SUCCESS; //UNSUCCESSFUL;
    3.57 +}
    3.58 +
    3.59 +/*
    3.60 +NTSTATUS
    3.61 +XenHide_EvtDeviceReleaseHardware(WDFDEVICE device, WDFCMRESLIST resources_translated)
    3.62 +{
    3.63 +  UNREFERENCED_PARAMETER(device);
    3.64 +  UNREFERENCED_PARAMETER(resources_translated);
    3.65 +  
    3.66 +  FUNCTION_ENTER();
    3.67 +  FUNCTION_EXIT();
    3.68 +  
    3.69 +  return STATUS_SUCCESS;
    3.70 +}
    3.71 +*/
    3.72 +
    3.73 +
    3.74 +static BOOLEAN
    3.75 +XenHide_IdSuffixMatches(PWDFDEVICE_INIT device_init, PWCHAR matching_id)
    3.76 +{
    3.77 +  NTSTATUS status;
    3.78 +  WDFMEMORY memory;
    3.79 +  ULONG remaining;
    3.80 +  size_t string_length;
    3.81 +  PWCHAR ids;
    3.82 +  PWCHAR ptr;
    3.83 +  size_t ids_length;
    3.84 +  ULONG properties[] = {DevicePropertyCompatibleIDs, DevicePropertyHardwareID};
    3.85 +  int i;
    3.86 +  
    3.87 +//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    3.88 +  for (i = 0; i < ARRAY_SIZE(properties); i++)
    3.89 +  {
    3.90 +
    3.91 +    status = WdfFdoInitAllocAndQueryProperty(device_init, properties[i], NonPagedPool, WDF_NO_OBJECT_ATTRIBUTES, &memory);
    3.92 +    if (!NT_SUCCESS(status))
    3.93 +      continue;
    3.94 +    ids = WdfMemoryGetBuffer(memory, &ids_length);
    3.95 +
    3.96 +    if (!NT_SUCCESS(status))
    3.97 +    {
    3.98 +//      KdPrint((__DRIVER_NAME "     i = %d, status = %x, ids_length = %d\n", i, status, ids_length));
    3.99 +      continue;
   3.100 +    }
   3.101 +    
   3.102 +    remaining = ids_length / 2;
   3.103 +    for (ptr = ids; *ptr != 0; ptr += string_length + 1)
   3.104 +    {
   3.105 +      RtlStringCchLengthW(ptr, remaining, &string_length);
   3.106 +      remaining -= (ULONG)string_length + 1;
   3.107 +      if (string_length >= wcslen(matching_id))
   3.108 +      {
   3.109 +        ptr += string_length - wcslen(matching_id);
   3.110 +        string_length = wcslen(matching_id);
   3.111 +      }
   3.112 +//      KdPrint((__DRIVER_NAME "     Comparing '%S' and '%S'\n", ptr, matching_id));
   3.113 +      if (wcscmp(ptr, matching_id) == 0)
   3.114 +      {
   3.115 +        //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (Match)\n"));
   3.116 +        WdfObjectDelete(memory);
   3.117 +        return TRUE;
   3.118 +      }
   3.119 +    }
   3.120 +    WdfObjectDelete(memory);
   3.121 +  }
   3.122 +//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (No match)\n"));
   3.123 +  return FALSE;
   3.124 +}
   3.125 +
   3.126 +static NTSTATUS
   3.127 +XenHide_EvtDeviceAdd(WDFDRIVER driver, PWDFDEVICE_INIT device_init)
   3.128 +{
   3.129 +  NTSTATUS status;
   3.130 +  WDFMEMORY memory;
   3.131 +  PWCHAR device_description;
   3.132 +  WDF_PNPPOWER_EVENT_CALLBACKS pnp_power_callbacks;
   3.133 +  WDF_FDO_EVENT_CALLBACKS fdo_callbacks;
   3.134 +  WDF_OBJECT_ATTRIBUTES device_attributes;
   3.135 +  UNICODE_STRING dir_name;
   3.136 +  OBJECT_ATTRIBUTES oa;
   3.137 +  HANDLE handle;
   3.138 +  BOOLEAN hide_required = FALSE;
   3.139 +  WDFDEVICE device;
   3.140 +  //PXENHIDE_DEVICE_DATA xhdd;
   3.141 +
   3.142 +  UNREFERENCED_PARAMETER(driver);
   3.143 +#if 0
   3.144 +  PDEVICE_OBJECT deviceObject = NULL;
   3.145 +  ULONG length;
   3.146 +  WCHAR device_description[256];
   3.147 +  USHORT hide_type;
   3.148 +#endif
   3.149 +
   3.150 +  FUNCTION_ENTER();
   3.151 +
   3.152 +  if (!gplpv_interrogated)
   3.153 +  {
   3.154 +    gplpv_interrogated = TRUE;
   3.155 +    RtlInitUnicodeString(&dir_name, L"\\NEED_GPLPV_FILTER");
   3.156 +    InitializeObjectAttributes(&oa, &dir_name, OBJ_KERNEL_HANDLE, NULL, NULL);
   3.157 +    status = ZwOpenDirectoryObject(&handle, DIRECTORY_QUERY, &oa);
   3.158 +    KdPrint((__DRIVER_NAME "     ZwOpenDirectoryObject = %08x\n", status));
   3.159 +    if (NT_SUCCESS(status))
   3.160 +    {
   3.161 +      need_gplpv_filter = TRUE;
   3.162 +      ZwClose(handle);
   3.163 +    }
   3.164 +  }
   3.165 +  
   3.166 +  status = WdfFdoInitAllocAndQueryProperty(device_init, DevicePropertyDeviceDescription, NonPagedPool, WDF_NO_OBJECT_ATTRIBUTES, &memory);
   3.167 +  if (NT_SUCCESS(status))
   3.168 +  {
   3.169 +    device_description = WdfMemoryGetBuffer(memory, NULL);
   3.170 +  }
   3.171 +  else
   3.172 +  {
   3.173 +    device_description = L"<unknown device>";
   3.174 +  }
   3.175 +
   3.176 +  if (need_gplpv_filter)
   3.177 +  {
   3.178 +    /* hide only specific devices */
   3.179 +    if (XenHide_IdSuffixMatches(device_init, L"VEN_8086&DEV_7010")) // Qemu IDE
   3.180 +    {
   3.181 +      hide_required = TRUE;
   3.182 +    }
   3.183 +    else if (XenHide_IdSuffixMatches(device_init, L"VEN_1000&DEV_0012"))// Qemu SCSI
   3.184 +    {
   3.185 +      hide_required = TRUE;
   3.186 +    }
   3.187 +    else if (XenHide_IdSuffixMatches(device_init, L"VEN_10EC&DEV_8139")) // Qemu Network
   3.188 +    {
   3.189 +      hide_required = TRUE;
   3.190 +    }
   3.191 +  }
   3.192 +
   3.193 +  if (!hide_required)
   3.194 +  {
   3.195 +    WdfObjectDelete(memory);
   3.196 +    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (filter not required for %S)\n", device_description));
   3.197 +    return STATUS_SUCCESS;
   3.198 +  }
   3.199 +  
   3.200 +  KdPrint((__DRIVER_NAME "     Installing Filter for %S\n", device_description));
   3.201 +
   3.202 +  WdfFdoInitSetFilter(device_init);
   3.203 +  WdfDeviceInitSetDeviceType(device_init, FILE_DEVICE_UNKNOWN);
   3.204 +  WdfDeviceInitSetExclusive(device_init, FALSE);
   3.205 +
   3.206 +  WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnp_power_callbacks);
   3.207 +  pnp_power_callbacks.EvtDevicePrepareHardware = XenHide_EvtDevicePrepareHardware;
   3.208 +  //pnp_power_callbacks.EvtDeviceReleaseHardware = XenHide_EvtDeviceReleaseHardware;
   3.209 +  //pnp_power_callbacks.EvtDeviceD0Entry = XenHide_EvtDeviceD0Entry;
   3.210 +  //pnp_power_callbacks.EvtDeviceD0Exit = XenHide_EvtDeviceD0Exit;
   3.211 +  WdfDeviceInitSetPnpPowerEventCallbacks(device_init, &pnp_power_callbacks);
   3.212 +  
   3.213 +  WDF_FDO_EVENT_CALLBACKS_INIT(&fdo_callbacks);
   3.214 +  fdo_callbacks.EvtDeviceFilterRemoveResourceRequirements = XenHide_EvtDeviceFilterRemoveResourceRequirements;
   3.215 +  WdfFdoInitSetEventCallbacks(device_init, &fdo_callbacks);
   3.216 +
   3.217 +  //WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&device_attributes, XENHIDE_DEVICE_DATA);
   3.218 +  WDF_OBJECT_ATTRIBUTES_INIT(&device_attributes);
   3.219 +  status = WdfDeviceCreate(&device_init, &device_attributes, &device);
   3.220 +  if (!NT_SUCCESS(status))
   3.221 +  {
   3.222 +    KdPrint(("Error creating device %08x\n", status));
   3.223 +    WdfObjectDelete(memory);
   3.224 +    FUNCTION_EXIT();
   3.225 +    return status;
   3.226 +  }
   3.227 +
   3.228 +  //xhdd = GetXhdd(device);
   3.229 +
   3.230 +  //xhdd->filter_do = deviceObject;
   3.231 +
   3.232 +  WdfObjectDelete(memory);
   3.233 +  FUNCTION_EXIT();
   3.234 +
   3.235 +  return status;
   3.236 +}
   3.237 +
   3.238 +
   3.239 +
   3.240 +#if 0
   3.241 +static NTSTATUS
   3.242  XenHide_Power(PDEVICE_OBJECT device_object, PIRP irp)
   3.243  {
   3.244    NTSTATUS status;
   3.245 @@ -323,26 +558,38 @@ XenHide_Pnp(PDEVICE_OBJECT device_object
   3.246  
   3.247    return status;
   3.248  }
   3.249 +#endif
   3.250 +
   3.251 +static VOID
   3.252 +XenHide_EvtDriverUnload(WDFDRIVER driver)
   3.253 +{
   3.254 +  UNREFERENCED_PARAMETER(driver);
   3.255 +  
   3.256 +  FUNCTION_ENTER();
   3.257 +  FUNCTION_EXIT();
   3.258 +}
   3.259  
   3.260  NTSTATUS
   3.261  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
   3.262  {
   3.263    NTSTATUS status = STATUS_SUCCESS;
   3.264 -  int i;
   3.265 -  
   3.266 -  UNREFERENCED_PARAMETER(RegistryPath);
   3.267 +  WDF_DRIVER_CONFIG config;
   3.268 +  WDFDRIVER driver;
   3.269 +  PDRIVER_OBJECT wdm_driver;
   3.270  
   3.271    FUNCTION_ENTER();
   3.272  
   3.273    need_gplpv_filter = FALSE;
   3.274    gplpv_interrogated = FALSE;
   3.275    
   3.276 -  for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
   3.277 -    DriverObject->MajorFunction[i] = XenHide_Pass;
   3.278 -  DriverObject->MajorFunction[IRP_MJ_PNP] = XenHide_Pnp;
   3.279 -  DriverObject->MajorFunction[IRP_MJ_POWER] = XenHide_Power;
   3.280 -  DriverObject->DriverExtension->AddDevice = XenHide_AddDevice;
   3.281 -
   3.282 +  WDF_DRIVER_CONFIG_INIT(&config, XenHide_EvtDeviceAdd);
   3.283 +  config.EvtDriverUnload = XenHide_EvtDriverUnload;
   3.284 +  status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, &driver);
   3.285 +  if (NT_SUCCESS(status))
   3.286 +  {
   3.287 +    wdm_driver = WdfDriverWdmGetDriverObject(driver);
   3.288 +    ObReferenceObject(wdm_driver);
   3.289 +  }
   3.290    FUNCTION_EXIT();
   3.291  
   3.292    return status;
     4.1 --- a/xenhide/xenhide.h	Sun May 10 20:19:28 2009 +1000
     4.2 +++ b/xenhide/xenhide.h	Sun May 10 20:19:51 2009 +1000
     4.3 @@ -21,7 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fi
     4.4  
     4.5  #include <ntifs.h>
     4.6  #include <ntddk.h>
     4.7 -#include <wdm.h>
     4.8 +#include <wdf.h>
     4.9  #include <initguid.h>
    4.10  #include <wdmguid.h>
    4.11  #include <errno.h>
    4.12 @@ -41,16 +41,16 @@ Foundation, Inc., 51 Franklin Street, Fi
    4.13  //{CD433FE7-954F-4D51-BE29-D8A38DFA1108}
    4.14  //DEFINE_GUID(GUID_XENHIDE_IFACE, 0xCD433FE7, 0x954F, 0x4D51, 0xBE, 0x29, 0xD8, 0xA3, 0x8D, 0xFA, 0x11, 0x08);
    4.15  
    4.16 -#define XENHIDE_TYPE_NONE 0
    4.17 -#define XENHIDE_TYPE_DEVICE 1
    4.18 -#define XENHIDE_TYPE_PCI_BUS 2
    4.19 -
    4.20 +#if 0
    4.21  typedef struct {
    4.22 -  PDEVICE_OBJECT filter_do;
    4.23 -  PDEVICE_OBJECT pdo;
    4.24 -  PDEVICE_OBJECT lower_do;
    4.25 -  IO_REMOVE_LOCK RemoveLock;
    4.26 +  //PDEVICE_OBJECT filter_do;
    4.27 +  //PDEVICE_OBJECT pdo;
    4.28 +  //PDEVICE_OBJECT lower_do;
    4.29 +  //IO_REMOVE_LOCK RemoveLock;
    4.30    USHORT hide_type;
    4.31  } XENHIDE_DEVICE_DATA, *PXENHIDE_DEVICE_DATA;
    4.32  
    4.33 +WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENHIDE_DEVICE_DATA, GetXhdd)
    4.34  #endif
    4.35 +
    4.36 +#endif
     5.1 --- a/xenhide/xenhide.inx	Sun May 10 20:19:28 2009 +1000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,68 +0,0 @@
     5.4 -[Version]
     5.5 -Signature="$WINDOWS NT$"
     5.6 -Class=System
     5.7 -ClassGuid={4d36e97d-e325-11ce-bfc1-08002be10318}
     5.8 -Provider=%JAMESHARPER%
     5.9 -
    5.10 -[ControlFlags]
    5.11 -ExcludeFromSelect = *
    5.12 -
    5.13 -[DestinationDirs]
    5.14 -DefaultDestDir = 12
    5.15 -
    5.16 -[Manufacturer]
    5.17 -%JAMESHARPER%=JAMESHARPER,NTx86
    5.18 -%JAMESHARPER%=JAMESHARPER,NTamd64
    5.19 -
    5.20 -[JAMESHARPER]
    5.21 -%XenHide.DRVDESC%=XenHide_Inst, *PNP0A03
    5.22 -
    5.23 -[JAMESHARPER.NTx86]
    5.24 -%XenHide.DRVDESC%=XenHide_Inst, *PNP0A03
    5.25 -
    5.26 -[JAMESHARPER.NTamd64]
    5.27 -%XenHide.DRVDESC%=XenHide_Inst, *PNP0A03
    5.28 -
    5.29 -[XenHide_Inst.NT]
    5.30 -Include=machine.inf
    5.31 -Needs=PCI_DRV_ROOT.NT
    5.32 -CopyFiles=XenHide.CopyFiles
    5.33 -
    5.34 -[XenHide_Inst.NT.HW]
    5.35 -AddReg = XenHide_Inst_HW_AddReg
    5.36 -Include=machine.inf
    5.37 -Needs=PCI_DRV_ROOT.HW
    5.38 -
    5.39 -[XenHide_Inst_HW_AddReg]
    5.40 -HKR,,"LowerFilters",0x00010000,"XenHide"
    5.41 -
    5.42 -[XenHide.CopyFiles]
    5.43 -xenhide.sys
    5.44 -
    5.45 -[SourceDisksFiles]
    5.46 -xenhide.sys=1
    5.47 -
    5.48 -[SourceDisksNames.x86]
    5.49 -1 = %DISK_NAME%,,,.\i386
    5.50 -
    5.51 -[SourceDisksNames.amd64]
    5.52 -1 = %DISK_NAME%,,,.\amd64
    5.53 -
    5.54 -[XenHide_Inst.NT.Services]
    5.55 -AddService=XenHide,,XenHide_Service_Inst
    5.56 -Include=Machine.inf
    5.57 -Needs=PCI_DRV_ROOT.Services
    5.58 -
    5.59 -[XenHide_Service_Inst]
    5.60 -DisplayName    = %XenHide.SVCDESC%
    5.61 -ServiceType    = 1
    5.62 -StartType      = 0
    5.63 -ErrorControl   = 1
    5.64 -ServiceBinary  = %12%\xenhide.sys
    5.65 -LoadOrderGroup = Boot Bus Extender
    5.66 -
    5.67 -[Strings]
    5.68 -JAMESHARPER = "James Harper"
    5.69 -XenHide.SVCDESC = "Xen PCI Device Hider Driver"
    5.70 -XenHide.DRVDESC = "Xen PCI Device Hider Driver"
    5.71 -DISK_NAME = "Xen PCI Device Driver Hider Install Disk"