diff options
author | midipix <writeonce@midipix.org> | 2018-06-14 07:51:51 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2018-06-14 07:49:38 -0400 |
commit | aac1ecb7acc5196664ef65a2467cbe45c097841c (patch) | |
tree | e1fefcedf6fc20a83251a30ab64da44d8377857f /src | |
parent | f7c707fbe9b789803030fe278e3177cd79c0d3cf (diff) | |
download | ntapi-aac1ecb7acc5196664ef65a2467cbe45c097841c.tar.bz2 ntapi-aac1ecb7acc5196664ef65a2467cbe45c097841c.tar.xz |
string helper api's: added ntapi_tt_uintptr_to_dec{_null}_utf{8|16}().
Diffstat (limited to 'src')
-rw-r--r-- | src/internal/ntapi.c | 4 | ||||
-rw-r--r-- | src/internal/ntapi_fnapi.h | 4 | ||||
-rw-r--r-- | src/string/ntapi_tt_uintptr_to_dec.c | 148 |
3 files changed, 156 insertions, 0 deletions
diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c index a53ca80..6f6b9ce 100644 --- a/src/internal/ntapi.c +++ b/src/internal/ntapi.c @@ -271,6 +271,10 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) __ntapi->tt_uint32_to_hex_utf8 = __ntapi_tt_uint32_to_hex_utf8; __ntapi->tt_uint64_to_hex_utf8 = __ntapi_tt_uint64_to_hex_utf8; __ntapi->tt_uintptr_to_hex_utf8 = __ntapi_tt_uintptr_to_hex_utf8; + __ntapi->tt_uintptr_to_dec_utf16 = __ntapi_tt_uintptr_to_dec_utf16; + __ntapi->tt_uintptr_to_dec_utf8 = __ntapi_tt_uintptr_to_dec_utf8; + __ntapi->tt_uintptr_to_dec_null_utf16 = __ntapi_tt_uintptr_to_dec_null_utf16; + __ntapi->tt_uintptr_to_dec_null_utf8 = __ntapi_tt_uintptr_to_dec_null_utf8; /* nt_guid.h */ __ntapi->tt_guid_copy = __ntapi_tt_guid_copy; diff --git a/src/internal/ntapi_fnapi.h b/src/internal/ntapi_fnapi.h index 8280f55..9157dc1 100644 --- a/src/internal/ntapi_fnapi.h +++ b/src/internal/ntapi_fnapi.h @@ -133,6 +133,10 @@ ntapi_tt_uint16_to_hex_utf8 __ntapi_tt_uint16_to_hex_utf8; ntapi_tt_uint32_to_hex_utf8 __ntapi_tt_uint32_to_hex_utf8; ntapi_tt_uint64_to_hex_utf8 __ntapi_tt_uint64_to_hex_utf8; ntapi_tt_uintptr_to_hex_utf8 __ntapi_tt_uintptr_to_hex_utf8; +ntapi_tt_uintptr_to_dec_utf16 __ntapi_tt_uintptr_to_dec_utf16; +ntapi_tt_uintptr_to_dec_utf8 __ntapi_tt_uintptr_to_dec_utf8; +ntapi_tt_uintptr_to_dec_null_utf16 __ntapi_tt_uintptr_to_dec_null_utf16; +ntapi_tt_uintptr_to_dec_null_utf8 __ntapi_tt_uintptr_to_dec_null_utf8; ntapi_wcslen __ntapi_tt_wcslen; /* nt_guid.h */ diff --git a/src/string/ntapi_tt_uintptr_to_dec.c b/src/string/ntapi_tt_uintptr_to_dec.c new file mode 100644 index 0000000..c496247 --- /dev/null +++ b/src/string/ntapi_tt_uintptr_to_dec.c @@ -0,0 +1,148 @@ +/********************************************************/ +/* 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> + +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; +} |