Exemplo n.º 1
0
void libemv_debug_buffer(char* strPre, unsigned char* buf, int size, char* strPost)
{
	int i;
	libemv_printf(strPre);
	for (i = 0; i < size; i++)
	{
		libemv_printf("%02X", buf[i] & 0xFF);
		if (i != size - 1)
			libemv_printf(", ");
	}
	libemv_printf(strPost);
}
Exemplo n.º 2
0
LIBEMV_API void libemv_destroy(void)
{
	if (libemv_debug_enabled)
		libemv_printf("Destroy allocated data...\n");
	libemv_destroy_tlv_buffer();
	libemv_destroy_settings();
}
Exemplo n.º 3
0
Arquivo: tlv.c Projeto: ardzeii/libemv
static void check_and_reserve_buffer(int incrSize)
{
	if (tlv_length + incrSize <= tlv_allocated)
		return;

	if (tlv_allocated == 0)
	{
		// Init size
		tlv_allocated = 2 * 1024;
		tlv_buffer = libemv_malloc(tlv_allocated);
	} else
	{
		// incrSize musn't very big, but just in case
		while (tlv_length + incrSize > tlv_allocated)
			tlv_allocated *= 2;
		// Realloc must copy old data
		tlv_buffer = libemv_realloc(tlv_buffer, tlv_allocated);
	}

	// Unable allocate
	if (tlv_buffer == 0)
	{
		if (libemv_debug_enabled)
			libemv_printf("Unable allocate memory\n");
	}
}
Exemplo n.º 4
0
Arquivo: tlv.c Projeto: ardzeii/libemv
LIBEMV_API unsigned char* libemv_get_tag(unsigned short tag, int* outSize)
{
	unsigned char* currBuf;
	int currPos;	

	currBuf = tlv_buffer;
	currPos = 0;
	while (currPos < tlv_length)
	{
		unsigned short currTag;
		int currLength;

		// Corrupted buffer
		if (currPos + (int) sizeof(unsigned short) + (int) sizeof(int) > tlv_length)
		{
			if (libemv_debug_enabled)
				libemv_printf("tlv buffer malfunc\n");
			break;
		}

		memcpy(&currTag, currBuf, sizeof(unsigned short));
		currBuf += sizeof(unsigned short);
		currPos += sizeof(unsigned short);
		memcpy(&currLength, currBuf, sizeof(int));
		currBuf += sizeof(int);
		currPos += sizeof(int);
		if (currTag == tag)
		{
			*outSize = currLength;
			return currBuf;
		}
		currBuf += currLength;
		currPos += currLength;
	}

	// Not found
	return 0;
}