ios - APDU response read Binary to Objective-C String -


unsigned char get_cplc_command2[] = {0x00, 0xa4, 0x00, 0x00, 0x02, 0x02, 0x03}; receive_length = sizeof(receive_buffer);  ret = scardtransmit(card,                     &sendpci,                     get_cplc_command2,                     sizeof(get_cplc_command2),                     null,                     receive_buffer,                     &receive_length);  log(@"scardtransmit 0x%08x", ret);  if (ret == scard_w_removed_card) {     goto retry; } else if (ret != scard_s_success) {     [err_text setstring:@"scardtransmit failed on cplc (w/ le > 0)"];     goto cleanup; }   // response unsigned char get_cplc_command3[] = {0x00, 0xc0, 0x00, 0x00, 0x12}; receive_length = sizeof(receive_buffer);  ret = scardtransmit(card,                     &sendpci,                     get_cplc_command3,                     sizeof(get_cplc_command3),                     null,                     receive_buffer,                     &receive_length);  log(@"scardtransmit 0x%08x", ret);   if (ret == scard_w_removed_card) {     goto retry; } else if (ret != scard_s_success) {     [err_text setstring:@"scardtransmit failed on cplc (w/ le > 0)"];     goto cleanup; }  nsmutablestring* cplc = [[nsmutablestring alloc]init];  if (receive_buffer[receive_length-2] == 0x90 &&      receive_buffer[receive_length-1] == 0x00) {      unsigned char* p = receive_buffer + 3;                nsuinteger size = sizeof(p);      nsmutablestring *mutstring =[[nsmutablestring alloc] init];      for(int i=0;i<=size-1;i++)     {         [mutstring appendstring:[nsstring stringwithformat:@"%02x",p[i]]];     }      nsstring * str = mutstring; //@"8510000002030100043dc000c0000000006a9000";     nsmutablestring *newstring = [[[nsmutablestring alloc] init] autorelease];     int = 0;     while (i < [str length])     {         nsstring * hexchar = [str substringwithrange: nsmakerange(i, 2)];         int value = 0;         sscanf([hexchar cstringusingencoding:nsasciistringencoding], "%x", &value);         [newstring appendformat:@"%c", (char)value];         i+=2;     }  } 

i trying read smart card,have got success response after response command. trying read receive_buffer data , convert nsstring. getting junk string "=aaj" newstring. please me how read receive_buffer.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -