ReactOS 0.4.15-dev-7961-gdcf9eb0
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
24
27
28/* FUNCTIONS *****************************************************************/
29
34{
35 USHORT Offset = 0;
36
37 if (Source < L'A')
38 return Source;
39
40 if (Source <= L'Z')
41 return Source + (L'a' - L'A');
42
43#if 0
44 if (Source < 0x80)
45 return Source;
46#endif
47
48 return Source + (SHORT)Offset;
49}
50
55{
57}
58
64 _In_ ULONG UnicodeSize,
65 _Out_opt_ PULONG ResultSize,
66 _In_ PCCH MbString,
67 _In_ ULONG MbSize)
68{
69 ULONG Size = 0;
70 ULONG i;
71
72 /* single-byte code page */
73 if (MbSize > (UnicodeSize / sizeof(WCHAR)))
74 Size = UnicodeSize / sizeof(WCHAR);
75 else
76 Size = MbSize;
77
78 if (ResultSize)
79 *ResultSize = Size * sizeof(WCHAR);
80
81 for (i = 0; i < Size; i++)
82 {
83 /* Trivially zero-extend */
84 UnicodeString[i] = (WCHAR)MbString[i];
85 }
86
87 return STATUS_SUCCESS;
88}
89
94 _Out_ PULONG UnicodeSize,
95 _In_ PCCH MbString,
96 _In_ ULONG MbSize)
97{
98 /* single-byte code page */
99 *UnicodeSize = MbSize * sizeof(WCHAR);
100
101 return STATUS_SUCCESS;
102}
103
106NTAPI
108 _Out_ PCHAR MbString,
109 _In_ ULONG MbSize,
110 _Out_opt_ PULONG ResultSize,
112 _In_ ULONG UnicodeSize)
113{
114 ULONG Size = 0;
115 ULONG i;
116
117 /* single-byte code page */
118 Size = (UnicodeSize > (MbSize * sizeof(WCHAR)))
119 ? MbSize : (UnicodeSize / sizeof(WCHAR));
120
121 if (ResultSize)
122 *ResultSize = Size;
123
124 for (i = 0; i < Size; i++)
125 {
126 /* Check for characters that cannot be trivially demoted to ANSI */
127 if (*((PCHAR)UnicodeString + 1) == 0)
128 {
129 *MbString++ = (CHAR)*UnicodeString++;
130 }
131 else
132 {
133 /* Invalid character, use default */
134 *MbString++ = NlsOemDefaultChar;
136 }
137 }
138
139 return STATUS_SUCCESS;
140}
141
144NTAPI
146 _Out_ PULONG MbSize,
148 _In_ ULONG UnicodeSize)
149{
150 ULONG UnicodeLength = UnicodeSize / sizeof(WCHAR);
151
152 /* single-byte code page */
153 *MbSize = UnicodeLength;
154
155 return STATUS_SUCCESS;
156}
157
158WCHAR
159NTAPI
162{
163 USHORT Offset = 0;
164
165 if (Source < 'a')
166 return Source;
167
168 if (Source <= 'z')
169 return (Source - ('a' - 'A'));
170
171 return Source + (SHORT)Offset;
172}
173
174WCHAR
175NTAPI
178{
180}
181
184NTAPI
186 _Out_ PCHAR MbString,
187 _In_ ULONG MbSize,
188 _Out_opt_ PULONG ResultSize,
190 _In_ ULONG UnicodeSize)
191{
192 WCHAR UpcaseChar;
193 ULONG Size = 0;
194 ULONG i;
195
196 /* single-byte code page */
197 if (UnicodeSize > (MbSize * sizeof(WCHAR)))
198 Size = MbSize;
199 else
200 Size = UnicodeSize / sizeof(WCHAR);
201
202 if (ResultSize)
203 *ResultSize = Size;
204
205 for (i = 0; i < Size; i++)
206 {
208
209 /* Check for characters that cannot be trivially demoted to ANSI */
210 if (*((PCHAR)&UpcaseChar + 1) == 0)
211 {
212 *MbString = (CHAR)UpcaseChar;
213 }
214 else
215 {
216 /* Invalid character, use default */
217 *MbString = NlsOemDefaultChar;
218 }
219
220 MbString++;
222 }
223
224 return STATUS_SUCCESS;
225}
226
227CHAR
228NTAPI
231{
232 /* Check for simple ANSI case */
233 if (Source <= 'z')
234 {
235 /* Check for simple downcase a-z case */
236 if (Source >= 'a')
237 {
238 /* Just XOR with the difference */
239 return Source ^ ('a' - 'A');
240 }
241 else
242 {
243 /* Otherwise return the same char, it's already upcase */
244 return Source;
245 }
246 }
247 else
248 {
249 /* single-byte code page */
251 }
252}
253
254
262NTAPI
265 _In_ ULONG OemSize,
266 _Out_opt_ PULONG ResultSize,
268 _In_ ULONG UnicodeSize)
269{
270 if (OemSize)
272
273 if (ResultSize)
274 *ResultSize = 0;
275
277}
278
281NTAPI
284 _In_ ULONG UnicodeSize,
285 _Out_opt_ PULONG ResultSize,
287 _In_ ULONG OemSize)
288{
289 if (UnicodeString)
291
292 if (ResultSize)
293 *ResultSize = 0;
294
296}
297
300NTAPI
303 _In_ ULONG OemSize,
304 _Out_opt_ PULONG ResultSize,
306 _In_ ULONG UnicodeSize)
307{
308 if (OemSize)
310
311 if (ResultSize)
312 *ResultSize = 0;
313
315}
316
317/* EOF */
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define CHAR(Char)
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
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
#define _Out_opt_
Definition: ms_sal.h:346
#define _Use_decl_annotations_
Definition: ms_sal.h:275
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
WCHAR NTAPI RtlpUpcaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:160
USHORT NlsOemDefaultChar
Definition: nlsboot.c:25
WCHAR NTAPI RtlpDowncaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:32
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:185
_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:263
_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:107
WCHAR NTAPI RtlUpcaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:176
_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:301
PUSHORT NlsOemLeadByteInfo
Definition: nlsboot.c:23
USHORT NlsUnicodeDefaultChar
Definition: nlsboot.c:26
BOOLEAN NlsMbOemCodePageTag
Definition: nlsboot.c:19
WCHAR NTAPI RtlDowncaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:53
PUSHORT NlsOemToUnicodeTable
Definition: nlsboot.c:20
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToMultiByteSize(_Out_ PULONG MbSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:145
_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:62
_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:282
CHAR NTAPI RtlUpperChar(_In_ CHAR Source)
Definition: nlsboot.c:229
PCHAR NlsUnicodeToOemTable
Definition: nlsboot.c:21
_Use_decl_annotations_ NTSTATUS NTAPI RtlMultiByteToUnicodeSize(_Out_ PULONG UnicodeSize, _In_ PCCH MbString, _In_ ULONG MbSize)
Definition: nlsboot.c:93
BOOLEAN NlsMbCodePageTag
Definition: nlsboot.c:17
WCHAR * PWCH
Definition: ntbasedef.h:410
CONST WCHAR * PCWCH
Definition: ntbasedef.h:411
#define UNICODE_NULL
#define ANSI_NULL
CONST CHAR * PCCH
Definition: ntbasedef.h:392
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define L(x)
Definition: ntvdm.h:50
short SHORT
Definition: pedump.c:59
unsigned short USHORT
Definition: pedump.c:61
#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:4533
*BytesInOemString PCHAR OemString
Definition: rtlfuncs.h:1560
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175