示例#1
0
tFileInfo CPkiCard::SelectFile(const std::string & csPath, bool bReturnFileInfo)
{
	CByteArray oResp;
    tFileInfo xFileInfo = {0};

    unsigned long ulPathLen = (unsigned long) csPath.size();
    if (ulPathLen % 4 != 0 || ulPathLen == 0)
        throw CMWEXCEPTION(EIDMW_ERR_BAD_PATH);
    ulPathLen /= 2;

    unsigned char ucP2 = bReturnFileInfo ? 0x00 : 0x0C;

    CAutoLock autolock(this);

	if (m_selectAppletMode == ALW_SELECT_APPLET)
	{
		SelectApplet();
        oResp = SelectByPath(csPath, bReturnFileInfo);
	}
	else
	{
		// First try to select the file by ID, assuming we're in the correct DF

		CByteArray oPath(ulPathLen);
		oPath.Append(Hex2Byte(csPath, ulPathLen - 2));
		oPath.Append(Hex2Byte(csPath, ulPathLen - 1));

		// Select File
		oResp = SendAPDU(0xA4, 0x02, ucP2, oPath);
		unsigned long ulSW12 = getSW12(oResp);
		if (ulSW12 == 0x6A82 || ulSW12 == 0x6A86)
		{
			if (ulPathLen == 2)
				throw CMWEXCEPTION(m_poContext->m_oPCSC.SW12ToErr(ulSW12));

			// The file wasn't found in this DF, so let's select by full path
			oResp = SelectByPath(csPath, bReturnFileInfo);
		}
		else
		{
			getSW12(oResp, 0x9000);
		}
	}

    if (bReturnFileInfo)
        xFileInfo = ParseFileInfo(oResp);

    return xFileInfo;
}
示例#2
0
CByteArray::CByteArray(const std::string & csData, bool bIsHex)
{
	if (!bIsHex)
	{
		const unsigned char *data = reinterpret_cast<const unsigned char *>(csData.c_str()); 
		MakeArray(data, static_cast<unsigned int>(csData.length()));
	}
	else
	{
		const char *csHexData = csData.c_str();
		unsigned long ulHexLen = (int) csData.size();
		m_ulCapacity = ulHexLen / 2;
		MakeArray(NULL, 0, m_ulCapacity);
		if (!m_bMallocError)
		{
			unsigned char uc = 0;
			bool bSecondHexDigit = true;
			for (unsigned long i = 0; i < ulHexLen; i++)
			{
				if (IsHexDigit(csHexData[i]))
				{
					uc = 16 * uc + Hex2Byte(csHexData[i]);
					bSecondHexDigit = !bSecondHexDigit;
					if (bSecondHexDigit)
						m_pucData[m_ulSize++] = uc;
				}
			}
		}
	}
}
示例#3
0
// Only called from SelectFile(), no locking is done here
CByteArray CPkiCard::SelectByPath(const std::string & csPath, bool bReturnFileInfo)
{
    unsigned char ucP2 = bReturnFileInfo ? 0x00 : 0x0C;

    unsigned long ulPathLen = (unsigned long) (csPath.size() / 2);

    CByteArray oPath(ulPathLen);
    for (unsigned long i = 0; i < ulPathLen; i++)
        oPath.Append(Hex2Byte(csPath, i));

    CByteArray oResp = SendAPDU(0xA4, 0x80, ucP2, oPath);
	if (ShouldSelectApplet(0xA4, getSW12(oResp)))
	{
		// The file still wasn't found, so let's first try to select the applet
		if (SelectApplet())
		{
			m_selectAppletMode = ALW_SELECT_APPLET;
			oResp = SendAPDU(0xA4, 0x80, ucP2, oPath);		}
	}

	getSW12(oResp, 0x9000);

	return oResp;
}
示例#4
0
文件: aml-build.c 项目: J-Liu/qemu
/*
 * ACPI 3.0: 17.5.124 ToUUID (Convert String to UUID Macro)
 * e.g. UUID: aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
 * call aml_touuid("aabbccdd-eeff-gghh-iijj-kkllmmnnoopp");
 */
Aml *aml_touuid(const char *uuid)
{
    Aml *var = aml_bundle(0x11 /* BufferOp */, AML_BUFFER);

    assert(strlen(uuid) == 36);
    assert(uuid[8] == '-');
    assert(uuid[13] == '-');
    assert(uuid[18] == '-');
    assert(uuid[23] == '-');

    build_append_byte(var->buf, Hex2Byte(uuid + 6));  /* dd - at offset 00 */
    build_append_byte(var->buf, Hex2Byte(uuid + 4));  /* cc - at offset 01 */
    build_append_byte(var->buf, Hex2Byte(uuid + 2));  /* bb - at offset 02 */
    build_append_byte(var->buf, Hex2Byte(uuid + 0));  /* aa - at offset 03 */

    build_append_byte(var->buf, Hex2Byte(uuid + 11)); /* ff - at offset 04 */
    build_append_byte(var->buf, Hex2Byte(uuid + 9));  /* ee - at offset 05 */

    build_append_byte(var->buf, Hex2Byte(uuid + 16)); /* hh - at offset 06 */
    build_append_byte(var->buf, Hex2Byte(uuid + 14)); /* gg - at offset 07 */

    build_append_byte(var->buf, Hex2Byte(uuid + 19)); /* ii - at offset 08 */
    build_append_byte(var->buf, Hex2Byte(uuid + 21)); /* jj - at offset 09 */

    build_append_byte(var->buf, Hex2Byte(uuid + 24)); /* kk - at offset 10 */
    build_append_byte(var->buf, Hex2Byte(uuid + 26)); /* ll - at offset 11 */
    build_append_byte(var->buf, Hex2Byte(uuid + 28)); /* mm - at offset 12 */
    build_append_byte(var->buf, Hex2Byte(uuid + 30)); /* nn - at offset 13 */
    build_append_byte(var->buf, Hex2Byte(uuid + 32)); /* oo - at offset 14 */
    build_append_byte(var->buf, Hex2Byte(uuid + 34)); /* pp - at offset 15 */

    return var;
}
示例#5
0
文件: pov1.c 项目: Laxa/quals-2016
int main(void)
{

char buffer[100];
int i;
unsigned char byteval;
int pov_type;
unsigned int type2_addr;
unsigned int type2_length;
unsigned int type2_size;
unsigned int new_offset_value;
int count;

	// negotiate a type 2 POV
	pov_type = 2;

	if (write(3, &pov_type, sizeof(pov_type)) == -1)
		_terminate(-1);

	if (receive_bytes(3, &type2_addr, sizeof(type2_addr)) == -1)
		_terminate(-1);

	if (receive_bytes(3, &type2_size, sizeof(type2_size)) == -1)
		_terminate(-1);

	if (receive_bytes(3, &type2_length, sizeof(type2_length)) == -1)
		_terminate(-1);

	// get the welcome string
	receive_bytes(STDIN, buffer, 36);

    receive_bytes(STDIN, buffer, 6);

    write(STDOUT, "huesped\n", 8);

    receive_bytes(STDIN, buffer, 10);

    write(STDOUT, "madera\n", 7);

    receive_bytes(STDIN, buffer, 15);

	// get the menu
	receive_bytes(STDIN, buffer, 76);
	
	// goto word maintenance
	write(STDOUT, "3\n", 2);

	// maintenance menu
	receive_bytes(STDIN, buffer, 86);

	// first delete any existing words in the database

	write(STDOUT, "2\n", 2);

	// eat the prompt for the word to delete
	receive_bytes(STDIN, buffer, 22);

	// // delete all the words using a wildcard 

	write(STDOUT, "*\n", 2);

	count = 0;

	getline(buffer, sizeof(buffer));

	while(buffer[0] != 0 ) {

		++count;
		receive_bytes(STDIN, buffer, 33);
		write(STDOUT, "y\n", 2);
		getline(buffer, sizeof(buffer));

	}

	// maintenance menu
	receive_bytes(STDIN, buffer, 86);

	// add new words 
	write(STDOUT, "1\n", 2);

	for (i=0; i < 0x10000; ++i ) {

		// enter infinitive form
		receive_bytes(STDIN, buffer, 22);

		printf("@04x\n", i);

		receive_bytes(STDIN, buffer, 22);
		printf("@04x\n", i);		

		receive_bytes(STDIN, buffer, 1);

	}

	receive_bytes(STDIN, buffer, 22);

	write(STDOUT, "\n", 1);


	// maintenance menu
	receive_bytes(STDIN, buffer, 87);

	// exit the maintenance menu
	write(STDOUT, "5\n", 2);


	// get the main menu
	receive_bytes(STDIN, buffer, 77);

	write(STDOUT, "1\n", 2);


	receive_bytes(STDIN, buffer, 39);

	// eat the newline
	receive_bytes(STDIN, buffer, 1);

	// read in the returned value and the newline
	receive_bytes(STDIN, buffer, 5);

	// because of endianess, convert the second byte first
	byteval = Hex2Byte(buffer+2);

	// write it to the scoring server
	write(3, &byteval, 1);

	// now the first byte
	byteval = Hex2Byte(buffer);

	write(3, &byteval, 1);

	// hit "enter" to continue
	write(STDOUT, "\n", 1);

	// This is the "english meaning".  Read in the value, but no need to keep it.
	receive_bytes(STDIN, buffer, 7);


	// read in the returned value for the second word
	receive_bytes(STDIN, buffer, 5);

	// again, convert the second byte first
	byteval = Hex2Byte(buffer+2);

	write(3, &byteval, 1);

	// and the first byte, which makes the 4 we need for a win
	byteval = Hex2Byte(buffer);

	write(3, &byteval, 1);

	// quit flashcards
	write(STDOUT, "q\n", 2);

	// read in the value, but no need to keep it.
	receive_bytes(STDIN, buffer, 6);

	// get the main menu
	receive_bytes(STDIN, buffer, 77);

	// terminate the application
	write(STDOUT,"4\n", 2);


}