ReactOS  0.4.14-dev-41-g31d7680
file.c File Reference
#include <win32k.h>
#include <debug.h>
Include dependency graph for file.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOL NTAPI W32kDosPathNameToNtPathName (IN PCWSTR pwszDosPathName, OUT PUNICODE_STRING pustrNtPathName)
 
HANDLE NTAPI W32kOpenFile (PCWSTR pwszFileName, DWORD dwDesiredAccess)
 
HANDLE NTAPI W32kCreateFileSection (HANDLE hFile, ULONG flAllocation, DWORD flPageProtection, ULONGLONG ullMaxSize)
 
PVOID NTAPI W32kMapViewOfSection (HANDLE hSection, DWORD dwPageProtect, ULONG_PTR ulSectionOffset)
 
HBITMAP NTAPI UserLoadImage (PCWSTR pwszName)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file file.c.

Function Documentation

◆ UserLoadImage()

HBITMAP NTAPI UserLoadImage ( PCWSTR  pwszName)

Definition at line 155 of file file.c.

156 {
159  BITMAPFILEHEADER *pbmfh;
161  PVOID pvBits;
162  HBITMAP hbmp = 0;
163 
164  DPRINT("Enter UserLoadImage(%ls)\n", pwszName);
165 
166  /* Open the file */
167  hFile = W32kOpenFile(pwszName, FILE_READ_DATA);
168  if (!hFile)
169  {
170  return NULL;
171  }
172 
173  /* Create a section */
175  ZwClose(hFile);
176  if (!hSection)
177  {
178  return NULL;
179  }
180 
181  /* Map the section */
183  ZwClose(hSection);
184  if (!pbmfh)
185  {
186  return NULL;
187  }
188 
189  /* Get a pointer to the BITMAPINFO */
190  pbmi = (LPBITMAPINFO)(pbmfh + 1);
191 
192  _SEH2_TRY
193  {
194  ProbeForRead(&pbmfh->bfSize, sizeof(DWORD), 1);
195  ProbeForRead(pbmfh, pbmfh->bfSize, 1);
196  }
198  {
200  }
201  _SEH2_END
202 
203  if(!NT_SUCCESS(Status))
204  {
205  DPRINT1("Bad File?\n");
206  goto leave;
207  }
208 
209  if (pbmfh->bfType == 0x4D42 /* 'BM' */)
210  {
211  /* Could be BITMAPCOREINFO */
212  BITMAPINFO* pConvertedInfo;
213  HDC hdc;
214 
215  pvBits = (PVOID)((PCHAR)pbmfh + pbmfh->bfOffBits);
216 
217  pConvertedInfo = DIB_ConvertBitmapInfo(pbmi, DIB_RGB_COLORS);
218  if(!pConvertedInfo)
219  {
220  DPRINT1("Unable to convert the bitmap Info\n");
221  goto leave;
222  }
223 
225 
227  pConvertedInfo->bmiHeader.biWidth,
228  pConvertedInfo->bmiHeader.biHeight,
229  CBM_INIT,
230  pvBits,
231  pConvertedInfo,
233  0,
234  pbmfh->bfSize - pbmfh->bfOffBits,
235  0);
236 
238  DIB_FreeConvertedBitmapInfo(pConvertedInfo, pbmi, -1);
239  }
240  else
241  {
242  DPRINT1("Unknown file type!\n");
243  }
244 
245 leave:
246  /* Unmap our section, we don't need it anymore */
247  ZwUnmapViewOfSection(NtCurrentProcess(), pbmfh);
248 
249  DPRINT("Leaving UserLoadImage, hbmp = %p\n", hbmp);
250  return hbmp;
251 }
signed char * PCHAR
Definition: retypes.h:7
VOID FASTCALL DIB_FreeConvertedBitmapInfo(BITMAPINFO *converted, BITMAPINFO *orig, DWORD Usage)
Definition: dibobj.c:2116
HANDLE NTAPI W32kCreateFileSection(HANDLE hFile, ULONG flAllocation, DWORD flPageProtection, ULONGLONG ullMaxSize)
Definition: file.c:80
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1471
static PVOID
Definition: file.c:43
struct tagBITMAPINFO * LPBITMAPINFO
PVOID NTAPI W32kMapViewOfSection(HANDLE hSection, DWORD dwPageProtect, ULONG_PTR ulSectionOffset)
Definition: file.c:121
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
LONG NTSTATUS
Definition: precomp.h:26
static HDC
Definition: imagelist.c:92
_SEH2_TRY
Definition: create.c:4250
#define CBM_INIT
Definition: wingdi.h:364
#define SEC_COMMIT
Definition: mmtypes.h:99
#define FILE_READ_DATA
Definition: nt_native.h:628
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NtCurrentProcess()
Definition: nt_native.h:1657
HBITMAP hbmp
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
HBITMAP NTAPI GreCreateDIBitmapInternal(IN HDC hDc, IN INT cx, IN INT cy, IN DWORD fInit, IN OPTIONAL LPBYTE pjInit, IN OPTIONAL PBITMAPINFO pbmi, IN DWORD iUsage, IN FLONG fl, IN UINT cjMaxBits, IN HANDLE hcmXform)
Definition: dibobj.c:1531
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
HDC hdc
Definition: main.c:9
_In_ HANDLE hFile
Definition: mswsock.h:90
Status
Definition: gdiplustypes.h:24
HANDLE NTAPI W32kOpenFile(PCWSTR pwszFileName, DWORD dwDesiredAccess)
Definition: file.c:43
_SEH2_END
Definition: create.c:4424
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteObjectApp(_In_ HANDLE hobj)
HDC FASTCALL IntGdiCreateDC(PUNICODE_STRING Driver, PUNICODE_STRING pustrDevice, PVOID pUMdhpdev, CONST PDEVMODEW pdmInit, BOOL CreateAsIC)
Definition: dclife.c:1043
#define PAGE_READONLY
Definition: compat.h:127
#define DPRINT1
Definition: precomp.h:8
BITMAPINFO *FASTCALL DIB_ConvertBitmapInfo(CONST BITMAPINFO *bmi, DWORD Usage)
Definition: dibobj.c:2052
static HBITMAP
Definition: button.c:44
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define DIB_RGB_COLORS
Definition: wingdi.h:366
return STATUS_SUCCESS
Definition: btrfs.c:2966
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3234

Referenced by SpiSetWallpaper().

◆ W32kCreateFileSection()

HANDLE NTAPI W32kCreateFileSection ( HANDLE  hFile,
ULONG  flAllocation,
DWORD  flPageProtection,
ULONGLONG  ullMaxSize 
)

Definition at line 80 of file file.c.

84 {
87  ACCESS_MASK amDesiredAccess;
88 
89  /* Set access mask */
91 
92  /* Check if write access is requested */
93  if (flPageProtection == PAGE_READWRITE)
94  {
95  /* Add it to access mask */
96  amDesiredAccess |= SECTION_MAP_WRITE;
97  }
98 
99  /* Now create the actual section */
100  Status = ZwCreateSection(&hSection,
101  amDesiredAccess,
102  NULL,
103  NULL,
104  flPageProtection,
105  flAllocation,
106  hFile);
107  if (!NT_SUCCESS(Status))
108  {
110  hSection = NULL;
111  }
112 
113  DPRINT("Leaving W32kCreateFileSection, Status=0x%lx, hSection=0x%p\n", Status, hSection);
114 
115  /* Return section handle */
116  return hSection;
117 }
#define SECTION_QUERY
Definition: nt_native.h:1287
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define SECTION_MAP_WRITE
Definition: nt_native.h:1288
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SECTION_MAP_READ
Definition: compat.h:128
_In_ HANDLE hFile
Definition: mswsock.h:90
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
Status
Definition: gdiplustypes.h:24
#define STANDARD_RIGHTS_REQUIRED
Definition: nt_native.h:63
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3234
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by UserLoadImage().

◆ W32kDosPathNameToNtPathName()

BOOL NTAPI W32kDosPathNameToNtPathName ( IN PCWSTR  pwszDosPathName,
OUT PUNICODE_STRING  pustrNtPathName 
)

Definition at line 16 of file file.c.

19 {
21 
22  /* Prepend "\??\" */
23  pustrNtPathName->Length = 0;
24  Status = RtlAppendUnicodeToString(pustrNtPathName, L"\\??\\");
25  if (!NT_SUCCESS(Status))
26  {
27  return FALSE;
28  }
29 
30  /* Append the dos name */
31  Status = RtlAppendUnicodeToString(pustrNtPathName, pwszDosPathName);
32  if (!NT_SUCCESS(Status))
33  {
34  return FALSE;
35  }
36 
37  return TRUE;
38 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24

◆ W32kMapViewOfSection()

PVOID NTAPI W32kMapViewOfSection ( HANDLE  hSection,
DWORD  dwPageProtect,
ULONG_PTR  ulSectionOffset 
)

Definition at line 121 of file file.c.

125 {
127  LARGE_INTEGER liSectionOffset;
128  ULONG_PTR ulViewSize;
129  PVOID pvBase = NULL;
130 
131  liSectionOffset.QuadPart = ulViewSize = ulSectionOffset;
132  Status = ZwMapViewOfSection(hSection,
134  &pvBase,
135  0,
136  0,
137  &liSectionOffset,
138  &ulViewSize,
139  ViewShare,
140  0,
141  dwPageProtect);
142  if (!NT_SUCCESS(Status))
143  {
145  pvBase = NULL;
146  }
147 
148  DPRINT("Leaving W32kMapViewOfSection, Status=0x%lx, pvBase=0x%p\n", Status, pvBase);
149 
150  return pvBase;
151 }
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
Status
Definition: gdiplustypes.h:24
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3234
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by UserLoadImage().

◆ W32kOpenFile()

HANDLE NTAPI W32kOpenFile ( PCWSTR  pwszFileName,
DWORD  dwDesiredAccess 
)

Definition at line 43 of file file.c.

44 {
45  UNICODE_STRING ustrFile;
50 
51  DPRINT("W32kOpenFile(%S)\n", pwszFileName);
52 
53  RtlInitUnicodeString(&ustrFile, pwszFileName);
54 
56 
57  Status = ZwCreateFile(&hFile,
58  dwDesiredAccess,
61  NULL,
63  0,
64  FILE_OPEN,
66  NULL,
67  0);
68  if (!NT_SUCCESS(Status))
69  {
71  hFile = NULL;
72  }
73 
74  DPRINT("Leaving W32kOpenFile, Status=0x%lx, hFile=0x%p\n", Status, hFile);
75  return hFile;
76 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
_In_ HANDLE hFile
Definition: mswsock.h:90
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106

Referenced by UserLoadImage().