static void read_dg(sc_card_t *card, unsigned char sfid, const char *dg_str, unsigned char **dg, size_t *dg_len) { int r = read_binary_rec(card, sfid, dg, dg_len); if (r < 0) fprintf(stderr, "Coult not read DG %02u %s (%s)\n", sfid, dg_str, sc_strerror(r)); else { fprintf(stdout, "Read "); bin_print(stdout, dg_str, *dg, *dg_len); } }
void bitmap_print(const bitmap_t bitmap, uint32_t size) { int i; printf("Bitmap size normal %d\n", BITMAP_SIZE_LONGS(size)); printf("Bitmap size roundup %d\n", BITMAP_SIZE_LONGS_ROUNDUP(size)); for(i = 0; i < BITMAP_SIZE_LONGS_ROUNDUP(size)*4; i++) { bin_print(*(((uint8_t *) bitmap)+i)); printf("\n"); } }
VOID util_bindmp(FILE *fp, UINT8 *ptr, INT32 count, INT32 off, CHAR obase) { INT32 whole_lines; INT32 num_last; INT32 line, byte, base; CHAR *format; INT32 bytes_per_line = 4; switch (obase) { case 'x': format = hex_format; break; case 'X': format = heX_format; break; case 'd': case 'D': format = dec_format; break; case 'o': case 'O': format = oct_format; break; default: format = hex_format; } num_last = count % bytes_per_line; whole_lines = (count - num_last) / bytes_per_line; for (line = 0; line < whole_lines; line++) { fprintf(fp, format, off); base = line*bytes_per_line; for (byte = 0; byte < bytes_per_line; byte++) { bin_print(fp, ptr[byte+base]); } off += bytes_per_line; fprintf(fp, "\n"); } if (num_last != 0) { fprintf(fp, format, off); base = line*bytes_per_line; for (byte = 0; byte < num_last; byte++) { bin_print(fp, ptr[byte+base]); } fprintf(fp, "\n"); } }
int npa_translate_apdus(sc_card_t *card, FILE *input) { u8 buf[4 + 3 + 0xffff + 3]; char *read = NULL; size_t readlen = 0, apdulen; sc_apdu_t apdu; ssize_t linelen; int r; memset(&apdu, 0, sizeof apdu); while (1) { if (input == stdin) printf("Enter unencrypted C-APDU (empty line to exit)\n"); linelen = getline(&read, &readlen, input); if (linelen <= 1) { if (linelen < 0) { r = SC_ERROR_INTERNAL; sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE_TOOL, "Could not read line"); } else { r = SC_SUCCESS; printf("Thanks for flying with ccid\n"); } break; } read[linelen - 1] = 0; apdulen = sizeof buf; if (sc_hex_to_bin(read, buf, &apdulen) < 0) { sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE_TOOL, "Could not format binary string"); continue; } if (input != stdin) bin_print(stdout, "Unencrypted C-APDU", buf, apdulen); r = sc_bytes2apdu(card->ctx, buf, apdulen, &apdu); if (r < 0) { bin_log(card->ctx, SC_LOG_DEBUG_NORMAL, "Invalid C-APDU", buf, apdulen); continue; } apdu.resp = buf; apdu.resplen = sizeof buf; r = sc_transmit_apdu(card, &apdu); if (r < 0) { sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE_TOOL, "Could not send C-APDU: %s", sc_strerror(r)); continue; } printf("Decrypted R-APDU sw1=%02x sw2=%02x\n", apdu.sw1, apdu.sw2); bin_print(stdout, "Decrypted R-APDU response data", apdu.resp, apdu.resplen); printf("======================================================================\n"); } if (read) free(read); return r; }