📄 readbinary.cpp
字号:
#include "SCcommand.h"
//
// +-----+-----+----------+----------+-----+
// | CLA | INS | P1 | P2 | Le |
// +-----+-----+----------+----------+-----+
// | 00 | B0 | 0xxxxxxx | xxxxxxxx | Le |00 B0 00 00 40
// +-----+-----+----------+----------+-----+
// P1P2 = Offset byte.
// Le = Length of data to be read.
//
LONG ReadBinary ( SCARDHANDLE hCard,
WORD wOffset,
INT iLen,
BYTE * pData )
{
LONG _lResult;
SCARD_IO_REQUEST _ioSendPci;
SCARD_IO_REQUEST _ioRecvPci;
BYTE _CAPDU [300];
DWORD _dwCAPDULen;
BYTE _RAPDU [300];
DWORD _dwRAPDULen=0;
_CAPDU [ CLA ] = 0x00; //CLA_NORMAL;
_CAPDU [ INS ] = 0xB0; //DSA_READ_BINARY
_CAPDU [ P1 ] = (BYTE)(wOffset >> 8 );
_CAPDU [ P2 ] = (BYTE)(wOffset);
_CAPDU [ LE ] = (BYTE)iLen;
_dwCAPDULen = 5;
_dwRAPDULen = 300;
_ioSendPci.dwProtocol = SCARD_PROTOCOL_T1;
_ioSendPci.cbPciLength = sizeof ( _ioSendPci );
_ioRecvPci.dwProtocol = SCARD_PROTOCOL_T1;
_ioRecvPci.cbPciLength = sizeof ( _ioRecvPci );
_lResult = SCardTransmit ( hCard, &_ioSendPci, _CAPDU, _dwCAPDULen, &_ioRecvPci, _RAPDU, &_dwRAPDULen );
if ( _lResult == SCARD_S_SUCCESS )
{
#ifdef _DEBUG
DumpBuf ( "<Read Binary> ", (char *) _CAPDU, (int) _dwCAPDULen, 0 );
DumpBuf ( "R = ", (char *) _RAPDU, (int) _dwRAPDULen, 1 );
#endif
if ( ProcessSW ( _RAPDU, _dwRAPDULen ) == FALSE ){
_lResult = ICC_ERR_SW1SW2;
}
//restore the DATAE to response data buffer
for ( DWORD i = 0; i <_dwRAPDULen-2; i++ )
pData [ i ] = _RAPDU [ i ];
}
return ( _lResult );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -