ReactOS 0.4.17-dev-37-g0bfb40d
nlsboot.c
Go to the documentation of this file.
1/*
2 * PROJECT: FreeLoader
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: "Poor-man" boot-time National Language Support (NLS) functions.
5 * COPYRIGHT: Copyright 2022 Hermès Bélusca-Maïto
6 *
7 * NOTE: This code is used at boot-time when no NLS tables are loaded.
8 * Adapted from lib/rtl/nls.c
9 */
10
11/* INCLUDES ******************************************************************/
12
13#include <rtl.h>
14
15/* GLOBALS *******************************************************************/
16
18
25
28
29/* FUNCTIONS *****************************************************************/
30
35{
36 USHORT Offset = 0;
37
38 if (Source < L'A')
39 return Source;
40
41 if (Source <= L'Z')
42 return Source + (L'a' - L'A');
43
44#if 0
45 if (Source < 0x80)
46 return Source;
47#endif
48
49 return Source + (SHORT)Offset;
50}
51
56{
58}
59
65 _In_ ULONG UnicodeSize,
66 _Out_opt_ PULONG ResultSize,
67 _In_ PCCH MbString,
68 _In_ ULONG MbSize)
69{
70 ULONG Size = 0;
71 ULONG i;
72
73 /* single-byte code page */
74 if (MbSize > (UnicodeSize / sizeof(WCHAR)))
75 Size = UnicodeSize / sizeof(WCHAR);
76 else
77 Size = MbSize;
78
79 if (ResultSize)
80 *ResultSize = Size * sizeof(WCHAR);
81
82 for (i = 0; i < Size; i++)
83 {
84 /* Trivially zero-extend */
85 UnicodeString[i] = (WCHAR)MbString[i];
86 }
87
88 return STATUS_SUCCESS;
89}
90
95 _Out_ PULONG UnicodeSize,
96 _In_ PCCH MbString,
97 _In_ ULONG MbSize)
98{
99 /* single-byte code page */
100 *UnicodeSize = MbSize * sizeof(WCHAR);
101
102 return STATUS_SUCCESS;
103}
104
107NTAPI
109 _Out_ PCHAR MbString,
110 _In_ ULONG MbSize,
111 _Out_opt_ PULONG ResultSize,
113 _In_ ULONG UnicodeSize)
114{
115 ULONG Size = 0;
116 ULONG i;
117
118 /* single-byte code page */
119 Size = (UnicodeSize > (MbSize * sizeof(WCHAR)))
120 ? MbSize : (UnicodeSize / sizeof(WCHAR));
121
122 if (ResultSize)
123 *ResultSize = Size;
124
125 for (i = 0; i < Size; i++)
126 {
127 /* Check for characters that cannot be trivially demoted to ANSI */
128 if (*((PCHAR)UnicodeString + 1) == 0)
129 {
130 *MbString++ = (CHAR)*UnicodeString++;
131 }
132 else
133 {
134 /* Invalid character, use default */
135 *MbString++ = NlsOemDefaultChar;
137 }
138 }
139
140 return STATUS_SUCCESS;
141}
142
145NTAPI
147 _Out_ PULONG MbSize,
149 _In_ ULONG UnicodeSize)
150{
151 ULONG UnicodeLength = UnicodeSize / sizeof(WCHAR);
152
153 /* single-byte code page */
154 *MbSize = UnicodeLength;
155
156 return STATUS_SUCCESS;
157}
158
159WCHAR
160NTAPI
163{
164 USHORT Offset = 0;
165
166 if (Source < 'a')
167 return Source;
168
169 if (Source <= 'z')
170 return (Source - ('a' - 'A'));
171
172 return Source + (SHORT)Offset;
173}
174
175WCHAR
176NTAPI
179{
181}
182
185NTAPI
187 _Out_ PCHAR MbString,
188 _In_ ULONG MbSize,
189 _Out_opt_ PULONG ResultSize,
191 _In_ ULONG UnicodeSize)
192{
193 WCHAR UpcaseChar;
194 ULONG Size = 0;
195 ULONG i;
196
197 /* single-byte code page */
198 if (UnicodeSize > (MbSize * sizeof(WCHAR)))
199 Size = MbSize;
200 else
201 Size = UnicodeSize / sizeof(WCHAR);
202
203 if (ResultSize)
204 *ResultSize = Size;
205
206 for (i = 0; i < Size; i++)
207 {
209
210 /* Check for characters that cannot be trivially demoted to ANSI */
211 if (*((PCHAR)&UpcaseChar + 1) == 0)
212 {
213 *MbString = (CHAR)UpcaseChar;
214 }
215 else
216 {
217 /* Invalid character, use default */
218 *MbString = NlsOemDefaultChar;
219 }
220
221 MbString++;
223 }
224
225 return STATUS_SUCCESS;
226}
227
228CHAR
229NTAPI
232{
233 /* Check for simple ANSI case */
234 if (Source <= 'z')
235 {
236 /* Check for simple downcase a-z case */
237 if (Source >= 'a')
238 {
239 /* Just XOR with the difference */
240 return Source ^ ('a' - 'A');
241 }
242 else
243 {
244 /* Otherwise return the same char, it's already upcase */
245 return Source;
246 }
247 }
248 else
249 {
250 /* single-byte code page */
252 }
253}
254
255
263NTAPI
266 _In_ ULONG OemSize,
267 _Out_opt_ PULONG ResultSize,
269 _In_ ULONG UnicodeSize)
270{
271 if (OemSize)
273
274 if (ResultSize)
275 *ResultSize = 0;
276
278}
279
282NTAPI
285 _In_ ULONG UnicodeSize,
286 _Out_opt_ PULONG ResultSize,
288 _In_ ULONG OemSize)
289{
290 if (UnicodeString)
292
293 if (ResultSize)
294 *ResultSize = 0;
295
297}
298
301NTAPI
304 _In_ ULONG OemSize,
305 _Out_opt_ PULONG ResultSize,
307 _In_ ULONG UnicodeSize)
308{
309 if (OemSize)
311
312 if (ResultSize)
313 *ResultSize = 0;
314
316}
317
318/* EOF */
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
#define CHAR(Char)
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define L(x)
Definition: resources.c:13
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
WCHAR NTAPI RtlpUpcaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:161
USHORT NlsOemDefaultChar
Definition: nlsboot.c:26
WCHAR NTAPI RtlpDowncaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:33
PUSHORT NlsUnicodeToMbOemTable
Definition: nlsboot.c:22
_Use_decl_annotations_ NTSTATUS NTAPI RtlUpcaseUnicodeToMultiByteN(_Out_ PCHAR MbString, _In_ ULONG MbSize, _Out_opt_ PULONG ResultSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:186
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToOemN(_Out_ PCHAR OemString, _In_ ULONG OemSize, _Out_opt_ PULONG ResultSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:264
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToMultiByteN(_Out_ PCHAR MbString, _In_ ULONG MbSize, _Out_opt_ PULONG ResultSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:108
WCHAR NTAPI RtlUpcaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:177
_Use_decl_annotations_ NTSTATUS NTAPI RtlUpcaseUnicodeToOemN(_Out_ PCHAR OemString, _In_ ULONG OemSize, _Out_opt_ PULONG ResultSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:302
PUSHORT NlsOemLeadByteInfo
Definition: nlsboot.c:24
USHORT NlsUnicodeDefaultChar
Definition: nlsboot.c:27
BOOLEAN NlsMbOemCodePageTag
Definition: nlsboot.c:19
PUSHORT NlsLeadByteInfo
Definition: nlsboot.c:23
WCHAR NTAPI RtlDowncaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:54
PUSHORT NlsOemToUnicodeTable
Definition: nlsboot.c:20
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToMultiByteSize(_Out_ PULONG MbSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:146
_Use_decl_annotations_ NTSTATUS NTAPI RtlMultiByteToUnicodeN(_Out_ PWCH UnicodeString, _In_ ULONG UnicodeSize, _Out_opt_ PULONG ResultSize, _In_ PCCH MbString, _In_ ULONG MbSize)
Definition: nlsboot.c:63
_Use_decl_annotations_ NTSTATUS NTAPI RtlOemToUnicodeN(_Out_ PWCHAR UnicodeString, _In_ ULONG UnicodeSize, _Out_opt_ PULONG ResultSize, _In_ PCCH OemString, _In_ ULONG OemSize)
Definition: nlsboot.c:283
CHAR NTAPI RtlUpperChar(_In_ CHAR Source)
Definition: nlsboot.c:230
PCHAR NlsUnicodeToOemTable
Definition: nlsboot.c:21
_Use_decl_annotations_ NTSTATUS NTAPI RtlMultiByteToUnicodeSize(_Out_ PULONG UnicodeSize, _In_ PCCH MbString, _In_ ULONG MbSize)
Definition: nlsboot.c:94
BOOLEAN NlsMbCodePageTag
Definition: nlsboot.c:17
#define _Out_opt_
Definition: no_sal2.h:214
#define _Use_decl_annotations_
Definition: no_sal2.h:92
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
WCHAR * PWCH
Definition: ntbasedef.h:422
CONST WCHAR * PCWCH
Definition: ntbasedef.h:423
#define UNICODE_NULL
#define ANSI_NULL
CONST CHAR * PCCH
Definition: ntbasedef.h:404
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
short WCHAR
Definition: pedump.c:58
short SHORT
Definition: pedump.c:59
unsigned short USHORT
Definition: pedump.c:61
char CHAR
Definition: pedump.c:57
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
uint16_t * PUSHORT
Definition: typedefs.h:56
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_opt_ PCUNICODE_STRING UnicodeString
Definition: wdfstring.h:64
*BytesInOemString PCHAR OemString
Definition: rtlfuncs.h:1577