ReactOS 0.4.15-dev-7994-gb388cb6
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 159 of file file.c.

160{
163 BITMAPFILEHEADER *pbmfh;
165 PVOID pvBits;
166 HBITMAP hbmp = 0;
167
168 DPRINT("Enter UserLoadImage(%ls)\n", pwszName);
169
170 /* Open the file */
171 hFile = W32kOpenFile(pwszName, FILE_READ_DATA);
172 if (!hFile)
173 {
174 return NULL;
175 }
176
177 /* Create a section */
179 ZwClose(hFile);
180 if (!hSection)
181 {
182 return NULL;
183 }
184
185 /* Map the section */
188 if (!pbmfh)
189 {
190 return NULL;
191 }
192
193 /* Get a pointer to the BITMAPINFO */
194 pbmi = (LPBITMAPINFO)(pbmfh + 1);
195
197 {
198 ProbeForRead(&pbmfh->bfSize, sizeof(DWORD), 1);
199 ProbeForRead(pbmfh, pbmfh->bfSize, 1);
200 }
202 {
204 }
206
207 if(!NT_SUCCESS(Status))
208 {
209 DPRINT1("Bad File?\n");
210 goto leave;
211 }
212
213 if (pbmfh->bfType == 0x4D42 /* 'BM' */)
214 {
215 /* Could be BITMAPCOREINFO */
216 BITMAPINFO* pConvertedInfo;
217 HDC hdc;
218
219 pvBits = (PVOID)((PCHAR)pbmfh + pbmfh->bfOffBits);
220
221 pConvertedInfo = DIB_ConvertBitmapInfo(pbmi, DIB_RGB_COLORS);
222 if(!pConvertedInfo)
223 {
224 DPRINT1("Unable to convert the bitmap Info\n");
225 goto leave;
226 }
227
229
231 pConvertedInfo->bmiHeader.biWidth,
232 pConvertedInfo->bmiHeader.biHeight,
233 CBM_INIT,
234 pvBits,
235 pConvertedInfo,
237 0,
238 pbmfh->bfSize - pbmfh->bfOffBits,
239 0);
240
242 DIB_FreeConvertedBitmapInfo(pConvertedInfo, pbmi, -1);
243 }
244 else
245 {
246 DPRINT1("Unknown file type!\n");
247 }
248
249leave:
250 /* Unmap our section, we don't need it anymore */
251 ZwUnmapViewOfSection(NtCurrentProcess(), pbmfh);
252
253 DPRINT("Leaving UserLoadImage, hbmp = %p\n", hbmp);
254 return hbmp;
255}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
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:1718
#define leave
Definition: btrfs_drv.h:138
HBITMAP hbmp
HDC FASTCALL IntGdiCreateDC(PUNICODE_STRING Driver, PUNICODE_STRING pustrDevice, PVOID pUMdhpdev, CONST PDEVMODEW pdmInit, BOOL CreateAsIC)
Definition: dclife.c:1040
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PAGE_READONLY
Definition: compat.h:138
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
_In_ HANDLE hFile
Definition: mswsock.h:90
#define SEC_COMMIT
Definition: mmtypes.h:100
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define FILE_READ_DATA
Definition: nt_native.h:628
#define NtCurrentProcess()
Definition: nt_native.h:1657
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteObjectApp(_In_ HANDLE hobj)
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
void * PVOID
Definition: typedefs.h:50
char * PCHAR
Definition: typedefs.h:51
BITMAPINFO *FASTCALL DIB_ConvertBitmapInfo(CONST BITMAPINFO *bmi, DWORD Usage)
Definition: dibobj.c:2238
VOID FASTCALL DIB_FreeConvertedBitmapInfo(BITMAPINFO *converted, BITMAPINFO *orig, DWORD Usage)
Definition: dibobj.c:2302
HANDLE NTAPI W32kOpenFile(PCWSTR pwszFileName, DWORD dwDesiredAccess)
Definition: file.c:43
PVOID NTAPI W32kMapViewOfSection(HANDLE hSection, DWORD dwPageProtect, ULONG_PTR ulSectionOffset)
Definition: file.c:125
HANDLE NTAPI W32kCreateFileSection(HANDLE hFile, ULONG flAllocation, DWORD flPageProtection, ULONGLONG ullMaxSize)
Definition: file.c:84
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3239
#define DIB_RGB_COLORS
Definition: wingdi.h:367
struct tagBITMAPINFO * LPBITMAPINFO
#define CBM_INIT
Definition: wingdi.h:365

Referenced by SpiSetWallpaper().

◆ W32kCreateFileSection()

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

Definition at line 84 of file file.c.

88{
91 ACCESS_MASK amDesiredAccess;
92
93 /* Set access mask */
95
96 /* Check if write access is requested */
97 if (flPageProtection == PAGE_READWRITE)
98 {
99 /* Add it to access mask */
100 amDesiredAccess |= SECTION_MAP_WRITE;
101 }
102
103 /* Now create the actual section */
104 Status = ZwCreateSection(&hSection,
105 amDesiredAccess,
106 NULL,
107 NULL,
108 flPageProtection,
109 flAllocation,
110 hFile);
111 if (!NT_SUCCESS(Status))
112 {
114 hSection = NULL;
115 }
116
117 DPRINT("Leaving W32kCreateFileSection, Status=0x%lx, hSection=0x%p\n", Status, hSection);
118
119 /* Return section handle */
120 return hSection;
121}
#define SECTION_MAP_READ
Definition: compat.h:139
#define SECTION_MAP_WRITE
Definition: nt_native.h:1288
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define SECTION_QUERY
Definition: nt_native.h:1287
#define STANDARD_RIGHTS_REQUIRED
Definition: nt_native.h:63
VOID FASTCALL SetLastNtError(_In_ NTSTATUS Status)
Definition: error.c:31

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
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define L(x)
Definition: ntvdm.h:50

◆ W32kMapViewOfSection()

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

Definition at line 125 of file file.c.

129{
131 LARGE_INTEGER liSectionOffset;
132 ULONG_PTR ulViewSize;
133 PVOID pvBase = NULL;
134
135 liSectionOffset.QuadPart = ulViewSize = ulSectionOffset;
136 Status = ZwMapViewOfSection(hSection,
138 &pvBase,
139 0,
140 0,
141 &liSectionOffset,
142 &ulViewSize,
143 ViewShare,
144 0,
145 dwPageProtect);
146 if (!NT_SUCCESS(Status))
147 {
149 pvBase = NULL;
150 }
151
152 DPRINT("Leaving W32kMapViewOfSection, Status=0x%lx, pvBase=0x%p\n", Status, pvBase);
153
154 return pvBase;
155}
@ ViewShare
Definition: nt_native.h:1278
uint32_t ULONG_PTR
Definition: typedefs.h:65
LONGLONG QuadPart
Definition: typedefs.h:114

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 &ustrFile,
58 NULL,
59 NULL);
60
61 Status = ZwCreateFile(&hFile,
62 dwDesiredAccess,
65 NULL,
67 0,
70 NULL,
71 0);
72 if (!NT_SUCCESS(Status))
73 {
75 hFile = NULL;
76 }
77
78 DPRINT("Leaving W32kOpenFile, Status=0x%lx, hFile=0x%p\n", Status, hFile);
79 return hFile;
80}
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_OPEN
Definition: from_kernel.h:54
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

Referenced by UserLoadImage().