From dd89bb8ad4fe184a34b5dbdda237e640fc82121b Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 27 Jul 2015 04:01:18 -0400 Subject: entered advanced internal development stage. --- src/string/ntapi_tt_uintptr_to_hex_utf16.c | 87 ++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/string/ntapi_tt_uintptr_to_hex_utf16.c (limited to 'src/string/ntapi_tt_uintptr_to_hex_utf16.c') diff --git a/src/string/ntapi_tt_uintptr_to_hex_utf16.c b/src/string/ntapi_tt_uintptr_to_hex_utf16.c new file mode 100644 index 0000000..59e063f --- /dev/null +++ b/src/string/ntapi_tt_uintptr_to_hex_utf16.c @@ -0,0 +1,87 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013,2014,2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include + +static void __fastcall __ntapi_tt_uint_to_hex_utf16( + __in uint64_t key, + __out wchar16_t * buffer, + __in unsigned bits) +{ + unsigned i; + uint32_t hex_buf[4]; + unsigned char * hex_chars; + unsigned char * uch; + unsigned offset; + unsigned bytes; + + hex_buf[0] = ('3' << 24) | ('2' << 16) | ('1' << 8) | '0'; + hex_buf[1] = ('7' << 24) | ('6' << 16) | ('5' << 8) | '4'; + hex_buf[2] = ('b' << 24) | ('a' << 16) | ('9' << 8) | '8'; + hex_buf[3] = ('f' << 24) | ('e' << 16) | ('d' << 8) | 'c'; + + uch = (unsigned char *)&key; + hex_chars = (unsigned char *)&hex_buf; + + bytes = bits / 8; + offset = bits / 4; + + for (i = 0; i < bytes; i++) { + buffer[offset - 1 - (i*2)] = hex_chars[uch[i] % 16]; + buffer[offset - 2 - (i*2)] = hex_chars[uch[i] / 16]; + } +} + + +void __fastcall __ntapi_tt_uint16_to_hex_utf16( + __in uint32_t key, + __out wchar16_t * formatted_key) +{ + __ntapi_tt_uint_to_hex_utf16( + key, + formatted_key, + 16); +} + + +void __fastcall __ntapi_tt_uint32_to_hex_utf16( + __in uint32_t key, + __out wchar16_t * formatted_key) +{ + __ntapi_tt_uint_to_hex_utf16( + key, + formatted_key, + 32); +} + + +void __fastcall __ntapi_tt_uint64_to_hex_utf16( + __in uint64_t key, + __out wchar16_t * formatted_key) +{ + __ntapi_tt_uint_to_hex_utf16( + key, + formatted_key, + 64); +} + + +void __fastcall __ntapi_tt_uintptr_to_hex_utf16( + __in uintptr_t key, + __out wchar16_t * formatted_key) +{ + #if defined (__NT32) + __ntapi_tt_uint_to_hex_utf16( + key, + formatted_key, + 32); + #elif defined (__NT64) + __ntapi_tt_uint_to_hex_utf16( + key, + formatted_key, + 64); + #endif +} -- cgit v1.2.3