# HG changeset patch # User Mychaela Falconia # Date 1611464988 0 # Node ID 91486a77643ea9c309d1270d0c50d19f28d21ac2 # Parent 2a0d1d5b93135bb08c890651268026272f68030d fc-simtool: implement hex display of full SIM responses diff -r 2a0d1d5b9313 -r 91486a77643e simtool/Makefile --- a/simtool/Makefile Sun Jan 24 03:43:01 2021 +0000 +++ b/simtool/Makefile Sun Jan 24 05:09:48 2021 +0000 @@ -1,7 +1,8 @@ CC= gcc CFLAGS= -O2 -I/usr/include/PCSC PROG= fc-simtool -OBJS= apdu.o atr.o cardconnect.o dispatch.o globals.o main.o names.o select.o +OBJS= apdu.o atr.o cardconnect.o dispatch.o globals.o hexdump.o main.o \ + names.o select.o all: ${PROG} diff -r 2a0d1d5b9313 -r 91486a77643e simtool/dispatch.c --- a/simtool/dispatch.c Sun Jan 24 03:43:01 2021 +0000 +++ b/simtool/dispatch.c Sun Jan 24 05:09:48 2021 +0000 @@ -14,6 +14,8 @@ extern int cmd_select(); +extern int display_sim_resp_in_hex(); + cmd_exit() { SCardDisconnect(hCard, SCARD_UNPOWER_CARD); @@ -30,6 +32,7 @@ {"exit", 0, 0, cmd_exit}, {"quit", 0, 0, cmd_exit}, {"select", 1, 1, cmd_select}, + {"sim-resp", 0, 0, display_sim_resp_in_hex}, {0, 0, 0, 0} }; diff -r 2a0d1d5b9313 -r 91486a77643e simtool/hexdump.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/hexdump.c Sun Jan 24 05:09:48 2021 +0000 @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#include "globals.h" + +display_sim_resp_in_hex() +{ + unsigned off, cc, n, c; + + for (off = 0; off < sim_resp_data_len; off += cc) { + printf("%02X:", off); + cc = 16; + if (sim_resp_data_len - off < cc) + cc = sim_resp_data_len - off; + for (n = 0; n < 16; n++) { + if (n == 0 || n == 8) + putchar(' '); + putchar(' '); + if (n < cc) + printf("%02X", sim_resp_data[off + n]); + else { + putchar(' '); + putchar(' '); + } + } + putchar(' '); + putchar(' '); + for (n = 0; n < cc; n++) { + c = sim_resp_data[off + n]; + if (c < 0x20 || c > 0x7E) + c = '.'; + putchar(c); + } + putchar('\n'); + } + return(0); +}