ReactOS  0.4.15-dev-5459-gb85f005
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 
30 WCHAR
31 NTAPI
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 
51 WCHAR
52 NTAPI
55 {
57 }
58 
61 NTAPI
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 
92 NTAPI
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 
105 NTSTATUS
106 NTAPI
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;
135  UnicodeString++;
136  }
137  }
138 
139  return STATUS_SUCCESS;
140 }
141 
143 NTSTATUS
144 NTAPI
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 
158 WCHAR
159 NTAPI
161  _In_ WCHAR Source)
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 
174 WCHAR
175 NTAPI
177  _In_ WCHAR Source)
178 {
180 }
181 
183 NTSTATUS
184 NTAPI
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  {
207  UpcaseChar = RtlpUpcaseUnicodeChar(*UnicodeString);
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++;
221  UnicodeString++;
222  }
223 
224  return STATUS_SUCCESS;
225 }
226 
227 CHAR
228 NTAPI
230  _In_ CHAR Source)
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 
261 NTSTATUS
262 NTAPI
265  _In_ ULONG OemSize,
266  _Out_opt_ PULONG ResultSize,
268  _In_ ULONG UnicodeSize)
269 {
270  if (OemSize)
271  *OemString = ANSI_NULL;
272 
273  if (ResultSize)
274  *ResultSize = 0;
275 
276  return STATUS_NOT_IMPLEMENTED;
277 }
278 
280 NTSTATUS
281 NTAPI
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 
295  return STATUS_NOT_IMPLEMENTED;
296 }
297 
299 NTSTATUS
300 NTAPI
303  _In_ ULONG OemSize,
304  _Out_opt_ PULONG ResultSize,
306  _In_ ULONG UnicodeSize)
307 {
308  if (OemSize)
309  *OemString = ANSI_NULL;
310 
311  if (ResultSize)
312  *ResultSize = 0;
313 
314  return STATUS_NOT_IMPLEMENTED;
315 }
316 
317 /* EOF */
signed char * PCHAR
Definition: retypes.h:7
CONST WCHAR * PCWCH
Definition: ntbasedef.h:411
*BytesInOemString PCHAR OemString
Definition: rtlfuncs.h:1560
PUSHORT NlsOemToUnicodeTable
Definition: nlsboot.c:20
_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
#define _Out_
Definition: ms_sal.h:345
_Use_decl_annotations_ NTSTATUS NTAPI RtlMultiByteToUnicodeSize(_Out_ PULONG UnicodeSize, _In_ PCCH MbString, _In_ ULONG MbSize)
Definition: nlsboot.c:93
PCHAR NlsUnicodeToOemTable
Definition: nlsboot.c:21
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
_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
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
_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
USHORT NlsUnicodeDefaultChar
Definition: nlsboot.c:26
uint16_t * PWCHAR
Definition: typedefs.h:56
#define _Use_decl_annotations_
Definition: ms_sal.h:275
return STATUS_NOT_IMPLEMENTED
#define L(x)
Definition: ntvdm.h:50
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_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
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
#define ANSI_NULL
short SHORT
Definition: pedump.c:59
PUSHORT NlsUnicodeToMbOemTable
Definition: nlsboot.c:22
unsigned char BOOLEAN
#define _In_
Definition: ms_sal.h:308
_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
USHORT NlsOemDefaultChar
Definition: nlsboot.c:25
WCHAR NTAPI RtlUpcaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:176
CHAR NTAPI RtlUpperChar(_In_ CHAR Source)
Definition: nlsboot.c:229
CONST CHAR * PCCH
Definition: ntbasedef.h:392
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR NTAPI RtlDowncaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:53
WCHAR * PWCH
Definition: ntbasedef.h:410
_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
PUSHORT NlsOemLeadByteInfo
Definition: nlsboot.c:23
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
BOOLEAN NlsMbOemCodePageTag
Definition: nlsboot.c:19
WCHAR NTAPI RtlpDowncaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:32
BOOLEAN NlsMbCodePageTag
Definition: nlsboot.c:17
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
unsigned short USHORT
Definition: pedump.c:61
WCHAR NTAPI RtlpUpcaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:160
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToMultiByteSize(_Out_ PULONG MbSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:145
#define _Out_opt_
Definition: ms_sal.h:346
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
#define STATUS_SUCCESS
Definition: shellext.h:65
#define CHAR(Char)
unsigned short * PUSHORT
Definition: retypes.h:2