Blame src/string/ntapi_tt_uintptr_to_hex_utf16.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
64e606
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
dd89bb
static void __fastcall __ntapi_tt_uint_to_hex_utf16(
b1f553
	__in	const uint64_t	key,
dd89bb
	__out	wchar16_t *	buffer,
dd89bb
	__in	unsigned	bits)
dd89bb
{
dd89bb
	unsigned	i;
dd89bb
	uint32_t	hex_buf[4];
dd89bb
	unsigned char *	hex_chars;
dd89bb
	unsigned char *	uch;
dd89bb
	unsigned	offset;
dd89bb
	unsigned	bytes;
dd89bb
dd89bb
	hex_buf[0] = ('3' << 24) | ('2' << 16) | ('1' << 8) | '0';
dd89bb
	hex_buf[1] = ('7' << 24) | ('6' << 16) | ('5' << 8) | '4';
dd89bb
	hex_buf[2] = ('b' << 24) | ('a' << 16) | ('9' << 8) | '8';
dd89bb
	hex_buf[3] = ('f' << 24) | ('e' << 16) | ('d' << 8) | 'c';
dd89bb
dd89bb
	uch = (unsigned char *)&ke;;
dd89bb
	hex_chars = (unsigned char *)&hex_buf;
dd89bb
dd89bb
	bytes  = bits / 8;
dd89bb
	offset = bits / 4;
dd89bb
dd89bb
	for (i = 0; i < bytes; i++) {
dd89bb
		buffer[offset - 1 - (i*2)] =	hex_chars[uch[i] % 16];
dd89bb
		buffer[offset - 2 - (i*2)] =	hex_chars[uch[i] / 16];
dd89bb
	}
dd89bb
}
dd89bb
dd89bb
766a63
__attr_protected__
dd89bb
void __fastcall __ntapi_tt_uint16_to_hex_utf16(
b1f553
	__in	const uint32_t	key,
dd89bb
	__out	wchar16_t *	formatted_key)
dd89bb
{
dd89bb
	__ntapi_tt_uint_to_hex_utf16(
dd89bb
		key,
dd89bb
		formatted_key,
dd89bb
		16);
dd89bb
}
dd89bb
dd89bb
766a63
__attr_protected__
dd89bb
void __fastcall __ntapi_tt_uint32_to_hex_utf16(
b1f553
	__in	const uint32_t	key,
dd89bb
	__out	wchar16_t *	formatted_key)
dd89bb
{
dd89bb
	__ntapi_tt_uint_to_hex_utf16(
dd89bb
		key,
dd89bb
		formatted_key,
dd89bb
		32);
dd89bb
}
dd89bb
dd89bb
766a63
__attr_protected__
dd89bb
void __fastcall __ntapi_tt_uint64_to_hex_utf16(
b1f553
	__in	const uint64_t	key,
dd89bb
	__out	wchar16_t *	formatted_key)
dd89bb
{
dd89bb
	__ntapi_tt_uint_to_hex_utf16(
dd89bb
		key,
dd89bb
		formatted_key,
dd89bb
		64);
dd89bb
}
dd89bb
dd89bb
766a63
__attr_protected__
dd89bb
void __fastcall __ntapi_tt_uintptr_to_hex_utf16(
b1f553
	__in	const uintptr_t	key,
dd89bb
	__out	wchar16_t *	formatted_key)
dd89bb
{
7f8d50
	#if (__SIZEOF_POINTER__ == 4)
dd89bb
		__ntapi_tt_uint_to_hex_utf16(
dd89bb
			key,
dd89bb
			formatted_key,
dd89bb
			32);
7f8d50
	#elif (__SIZEOF_POINTER__ == 8)
dd89bb
		__ntapi_tt_uint_to_hex_utf16(
dd89bb
			key,
dd89bb
			formatted_key,
dd89bb
			64);
dd89bb
	#endif
dd89bb
}