ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

image.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS Kernel Streaming
00004  * FILE:            drivers/ksfilter/ks/allocators.c
00005  * PURPOSE:         KS Allocator functions
00006  * PROGRAMMER:      Johannes Anderwald
00007  */
00008 
00009 #include "priv.h"
00010 
00011 /*
00012     @implemented
00013 */
00014 KSDDKAPI
00015 NTSTATUS
00016 NTAPI
00017 KsLoadResource(
00018     IN  PVOID ImageBase,
00019     IN  POOL_TYPE PoolType,
00020     IN  ULONG_PTR ResourceName,
00021     IN  ULONG ResourceType,
00022     OUT PVOID* Resource,
00023     OUT PULONG ResourceSize)
00024 {
00025     NTSTATUS Status;
00026     LDR_RESOURCE_INFO ResourceInfo;
00027     PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry;
00028     PVOID Data;
00029     ULONG Size;
00030     PVOID Result = NULL;
00031 
00032     /* set up resource info */
00033     ResourceInfo.Type = ResourceType;
00034     ResourceInfo.Name = ResourceName;
00035     ResourceInfo.Language = 0;
00036 
00037     _SEH2_TRY
00038     {
00039         /* find the resource */
00040         Status = LdrFindResource_U(ImageBase, &ResourceInfo, RESOURCE_DATA_LEVEL, &ResourceDataEntry);
00041         if (NT_SUCCESS(Status))
00042         {
00043             /* try accessing it */
00044             Status = LdrAccessResource(ImageBase, ResourceDataEntry, &Data, &Size);
00045             if (NT_SUCCESS(Status))
00046             {
00047                 /* allocate resource buffer */
00048                 Result = AllocateItem(PoolType, Size);
00049                 if (Result)
00050                 {
00051                     /* copy resource */
00052                     RtlMoveMemory(Result, Data, Size);
00053                     /* store result */
00054                     *Resource = Result;
00055                     *ResourceSize = Size;
00056                 }
00057                 else
00058                 {
00059                     /* not enough memory */
00060                     Status = STATUS_INSUFFICIENT_RESOURCES;
00061                 }
00062             }
00063         }
00064     }
00065     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00066     {
00067         /* Exception, get the error code */
00068         Status = _SEH2_GetExceptionCode();
00069     }
00070     _SEH2_END;
00071 
00072     if (!NT_SUCCESS(Status))
00073     {
00074         /* failed */
00075         if (Result)
00076         {
00077             /* free resource buffer in case of a failure */
00078             FreeItem(Result);
00079         }
00080     }
00081     /* done */
00082     return Status;
00083 }
00084 
00085 
00086 NTSTATUS
00087 KspQueryRegValue(
00088     IN HANDLE KeyHandle,
00089     IN LPWSTR KeyName,
00090     IN PVOID Buffer,
00091     IN OUT PULONG BufferLength,
00092     OUT PULONG Type)
00093 {
00094     UNIMPLEMENTED
00095     return STATUS_NOT_IMPLEMENTED;
00096 }
00097 
00098 /*
00099     @implemented
00100 */
00101 KSDDKAPI
00102 NTSTATUS
00103 NTAPI
00104 KsGetImageNameAndResourceId(
00105     IN HANDLE RegKey,
00106     OUT PUNICODE_STRING ImageName,
00107     OUT PULONG_PTR ResourceId,
00108     OUT PULONG ValueType)
00109 {
00110     NTSTATUS Status;
00111     ULONG ImageLength;
00112     WCHAR ImagePath[] = {L"\\SystemRoot\\system32\\drivers\\"};
00113 
00114     /* first clear the provided ImageName */
00115     ImageName->Buffer = NULL;
00116     ImageName->Length = ImageName->MaximumLength = 0;
00117 
00118     ImageLength = 0;
00119     /* retrieve length of image name */
00120     Status = KspQueryRegValue(RegKey, L"Image", NULL, &ImageLength, NULL);
00121 
00122     if (Status != STATUS_BUFFER_OVERFLOW)
00123     {
00124         /* key value doesnt exist */
00125         return Status;
00126     }
00127 
00128     /* allocate image name buffer */
00129     ImageName->MaximumLength = sizeof(ImagePath) + ImageLength;
00130     ImageName->Buffer = AllocateItem(PagedPool, ImageName->MaximumLength);
00131 
00132     /* check for success */
00133     if (!ImageName->Buffer)
00134     {
00135         /* insufficient memory */
00136         return STATUS_INSUFFICIENT_RESOURCES;
00137     }
00138 
00139     /* copy image name */
00140     RtlCopyMemory(ImageName->Buffer, ImagePath, sizeof(ImagePath));
00141 
00142     /* retrieve image name */
00143     Status = KspQueryRegValue(RegKey, L"Image", &ImageName->Buffer[sizeof(ImagePath) / sizeof(WCHAR)], &ImageLength, NULL);
00144 
00145     if (!NT_SUCCESS(Status))
00146     {
00147         /* unexpected error */
00148         FreeItem(ImageName->Buffer);
00149         return Status;
00150     }
00151 
00152     /* now query for resource id length*/
00153    ImageLength = 0;
00154    Status = KspQueryRegValue(RegKey, L"ResourceId", NULL, &ImageLength, ValueType);
00155 
00156     /* allocate resource id buffer*/
00157     *ResourceId = (ULONG_PTR)AllocateItem(PagedPool, ImageLength);
00158 
00159     /* check for success */
00160     if (!*ResourceId)
00161     {
00162         /* insufficient memory */
00163         FreeItem(ImageName->Buffer);
00164         return STATUS_INSUFFICIENT_RESOURCES;
00165     }
00166     /* now query for resource id */
00167     Status = KspQueryRegValue(RegKey, L"ResourceId", (PVOID)*ResourceId, &ImageLength, ValueType);
00168 
00169     if (!NT_SUCCESS(Status))
00170     {
00171         /* unexpected error */
00172         FreeItem(ImageName->Buffer);
00173         FreeItem((PVOID)*ResourceId);
00174     }
00175 
00176     /* return result */
00177     return Status;
00178 }
00179 
00180 /*
00181     @implemented
00182 */
00183 KSDDKAPI
00184 NTSTATUS
00185 NTAPI
00186 KsMapModuleName(
00187     IN PDEVICE_OBJECT PhysicalDeviceObject,
00188     IN PUNICODE_STRING ModuleName,
00189     OUT PUNICODE_STRING ImageName,
00190     OUT PULONG_PTR ResourceId,
00191     OUT PULONG ValueType)
00192 {
00193     NTSTATUS Status;
00194     UNICODE_STRING SubKeyName;
00195     UNICODE_STRING Modules = RTL_CONSTANT_STRING(L"Modules\\");
00196     HANDLE hKey, hSubKey;
00197     OBJECT_ATTRIBUTES ObjectAttributes;
00198 
00199     /* first open device key */
00200     Status = IoOpenDeviceRegistryKey(PhysicalDeviceObject, PLUGPLAY_REGKEY_DEVICE, GENERIC_READ, &hKey);
00201 
00202     /* check for success */
00203     if (!NT_SUCCESS(Status))
00204     {
00205         /* invalid parameter */
00206         return STATUS_INVALID_PARAMETER;
00207     }
00208 
00209     /* initialize subkey buffer */
00210     SubKeyName.Length = 0;
00211     SubKeyName.MaximumLength = Modules.MaximumLength + ModuleName->MaximumLength;
00212     SubKeyName.Buffer = AllocateItem(PagedPool, SubKeyName.MaximumLength);
00213 
00214     /* check for success */
00215     if (!SubKeyName.Buffer)
00216     {
00217         /* not enough memory */
00218         ZwClose(hKey);
00219         return STATUS_NO_MEMORY;
00220     }
00221 
00222     /* build subkey string */
00223     RtlAppendUnicodeStringToString(&SubKeyName, &Modules);
00224     RtlAppendUnicodeStringToString(&SubKeyName, ModuleName);
00225 
00226     /* initialize subkey attributes */
00227     InitializeObjectAttributes(&ObjectAttributes, &SubKeyName, OBJ_CASE_INSENSITIVE, hKey, NULL);
00228 
00229     /* now open the subkey */
00230     Status = ZwOpenKey(&hSubKey, GENERIC_READ, &ObjectAttributes);
00231 
00232     /* check for success */
00233     if (NT_SUCCESS(Status))
00234     {
00235         /* defer work */
00236         Status = KsGetImageNameAndResourceId(hSubKey, ImageName, ResourceId, ValueType);
00237 
00238         /* close subkey */
00239         ZwClose(hSubKey);
00240     }
00241 
00242     /* free subkey string */
00243     FreeItem(SubKeyName.Buffer);
00244 
00245     /* close device key */
00246     ZwClose(hKey);
00247 
00248     /* return status */
00249     return Status;
00250 }
00251 
00252 
00253 

Generated on Sun May 27 2012 04:20:20 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.