1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/********************************************************/
/* ntapi: Native API core library */
/* Copyright (C) 2013--2018 Z. Gilboa */
/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */
/********************************************************/
#include <psxtypes/psxtypes.h>
#include <ntapi/nt_status.h>
#include "ntapi_impl.h"
static void __tt_uintptr_to_mirrored_dec_utf8(
uintptr_t key,
unsigned char * buf,
ssize_t * arrlen)
{
unsigned i;
buf[0] = '0' + (key % 10);
key /= 10;
for (i=1; key; i++) {
buf[i] = '0' + (key % 10);
key /= 10;
}
*arrlen = i;
}
static int32_t __tt_uintptr_to_dec_utf16(
uintptr_t key,
wchar16_t * wstrbuf,
size_t buflen,
ssize_t * arrlen)
{
ssize_t i;
ssize_t slen;
unsigned char buf[24];
__tt_uintptr_to_mirrored_dec_utf8(
key,buf,arrlen);
if ((i = *arrlen) > (slen = buflen))
return NT_STATUS_BUFFER_TOO_SMALL;
for (--i; i>=0; i--)
*wstrbuf++ = buf[i];
return NT_STATUS_SUCCESS;
}
static int32_t __tt_uintptr_to_dec_utf8(
uintptr_t key,
unsigned char * strbuf,
size_t buflen,
ssize_t * arrlen)
{
ssize_t i;
ssize_t slen;
unsigned char buf[24];
__tt_uintptr_to_mirrored_dec_utf8(
key,buf,arrlen);
if ((i = *arrlen) > (slen = buflen))
return NT_STATUS_BUFFER_TOO_SMALL;
for (--i; i>=0; i--)
*strbuf++ = buf[i];
return NT_STATUS_SUCCESS;
}
int32_t __stdcall __ntapi_tt_uintptr_to_dec_utf16(
__in uintptr_t key,
__out wchar16_t * wstrbuf,
__in size_t buflen,
__out ssize_t * length)
{
int32_t status;
ssize_t arrlen;
buflen /= sizeof(wchar16_t);
status = __tt_uintptr_to_dec_utf16(
key,wstrbuf,
buflen,&arrlen);
*length = arrlen * sizeof(wchar16_t);
return status;
}
int32_t __stdcall __ntapi_tt_uintptr_to_dec_utf8(
__in uintptr_t key,
__out unsigned char * strbuf,
__in size_t buflen,
__out ssize_t * length)
{
return __tt_uintptr_to_dec_utf8(
key,strbuf,
buflen,length);
}
int32_t __stdcall __ntapi_tt_uintptr_to_dec_null_utf16(
__in uintptr_t key,
__out wchar16_t * wstrbuf,
__in size_t buflen,
__out ssize_t * length)
{
int32_t status;
ssize_t arrlen;
buflen -= sizeof(wchar16_t);
buflen /= sizeof(wchar16_t);
status = __tt_uintptr_to_dec_utf16(
key,wstrbuf,
buflen,&arrlen);
if (status == NT_STATUS_SUCCESS)
wstrbuf[arrlen] = 0;
*length = ++arrlen * sizeof(wchar16_t);
return status;
}
int32_t __stdcall __ntapi_tt_uintptr_to_dec_null_utf8(
__in uintptr_t key,
__out unsigned char * strbuf,
__in size_t buflen,
__out ssize_t * length)
{
int32_t status;
ssize_t arrlen;
status = __tt_uintptr_to_dec_utf8(
key,strbuf,
--buflen,&arrlen);
if (status == NT_STATUS_SUCCESS)
strbuf[arrlen] = 0;
*length = ++arrlen;
return status;
}
|