Blame src/string/ntapi_tt_uintptr_to_hex_utf8.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
4256e2
/*  Copyright (C) 2013--2016  Z. Gilboa                 */
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_utf8(
dd89bb
	__in	uint64_t	key,
dd89bb
	__out	unsigned char *	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
	/* avoid using .rdata for that one */
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
dd89bb
void __fastcall __ntapi_tt_uint16_to_hex_utf8(
dd89bb
	__in	uint32_t	key,
dd89bb
	__out	unsigned char *	buffer)
dd89bb
{
dd89bb
	__ntapi_tt_uint_to_hex_utf8(key,buffer,16);
dd89bb
}
dd89bb
dd89bb
dd89bb
void __fastcall __ntapi_tt_uint32_to_hex_utf8(
dd89bb
	__in	uint32_t	key,
dd89bb
	__out	unsigned char *	buffer)
dd89bb
{
dd89bb
	__ntapi_tt_uint_to_hex_utf8(key,buffer,32);
dd89bb
}
dd89bb
dd89bb
dd89bb
void __fastcall __ntapi_tt_uint64_to_hex_utf8(
dd89bb
	__in	uint64_t	key,
dd89bb
	__out	unsigned char *	buffer)
dd89bb
{
dd89bb
	__ntapi_tt_uint_to_hex_utf8(key,buffer,64);
dd89bb
}
dd89bb
dd89bb
dd89bb
void __fastcall __ntapi_tt_uintptr_to_hex_utf8(
dd89bb
	__in	uintptr_t	key,
dd89bb
	__out	unsigned char *	buffer)
dd89bb
{
7f8d50
	#if (__SIZEOF_POINTER__ == 4)
dd89bb
		__ntapi_tt_uint_to_hex_utf8(key,buffer,32);
7f8d50
	#elif (__SIZEOF_POINTER__ == 8)
dd89bb
		__ntapi_tt_uint_to_hex_utf8(key,buffer,64);
dd89bb
	#endif
dd89bb
}