# HG changeset patch # User Mychaela Falconia # Date 1611539683 0 # Node ID 454ff8bd0b83d3e4413f232cd4a2d74a77803f59 # Parent fa7005185b8408d38e152023293a81cc60b385e0 fc-simtool: update-bin command implemented diff -r fa7005185b84 -r 454ff8bd0b83 simtool/Makefile --- a/simtool/Makefile Mon Jan 25 01:23:54 2021 +0000 +++ b/simtool/Makefile Mon Jan 25 01:54:43 2021 +0000 @@ -1,9 +1,9 @@ CC= gcc CFLAGS= -O2 -I/usr/include/PCSC PROG= fc-simtool -OBJS= apdu.o atr.o cardconnect.o dispatch.o globals.o hexdump.o hlread.o \ - main.o names.o readcmd.o readops.o saverestore.o select.o telsum.o \ - writeops.o +OBJS= apdu.o atr.o cardconnect.o dispatch.o globals.o hexdump.o hexread.o \ + hlread.o main.o names.o readcmd.o readops.o saverestore.o select.o \ + telsum.o writecmd.o writeops.o all: ${PROG} diff -r fa7005185b84 -r 454ff8bd0b83 simtool/dispatch.c --- a/simtool/dispatch.c Mon Jan 25 01:23:54 2021 +0000 +++ b/simtool/dispatch.c Mon Jan 25 01:54:43 2021 +0000 @@ -21,6 +21,7 @@ extern int cmd_savebin(); extern int cmd_select(); extern int cmd_telecom_sum(); +extern int cmd_update_bin(); extern int display_sim_resp_in_hex(); @@ -49,6 +50,7 @@ {"select", 1, 1, cmd_select}, {"sim-resp", 0, 0, display_sim_resp_in_hex}, {"telecom-sum", 0, 0, cmd_telecom_sum}, + {"update-bin", 2, 2, cmd_update_bin}, {0, 0, 0, 0} }; diff -r fa7005185b84 -r 454ff8bd0b83 simtool/hexread.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/hexread.c Mon Jan 25 01:54:43 2021 +0000 @@ -0,0 +1,67 @@ +/* + * This module contains the function for reading hex files, + * to be used in the implementation of manual write commands. + */ + +#include +#include +#include +#include +#include +#include + +decode_hex_digit(c) +{ + if (c >= '0' && c <= '9') + return(c - '0'); + if (c >= 'A' && c <= 'F') + return(c - 'A' + 10); + if (c >= 'a' && c <= 'f') + return(c - 'a' + 10); + return(-1); +} + +read_hex_data_file(filename, databuf) + char *filename; + u_char *databuf; +{ + FILE *inf; + unsigned count; + int c, c2; + + inf = fopen(filename, "r"); + if (!inf) { + perror(filename); + return(-1); + } + for (count = 0; ; count++) { + do + c = getc(inf); + while (isspace(c)); + if (c < 0) + break; + if (!isxdigit(c)) { +inv_input: fprintf(stderr, "%s: invalid hex file input\n", + filename); + fclose(inf); + return(-1); + } + c2 = getc(inf); + if (!isxdigit(c2)) + goto inv_input; + if (count >= 255) { + fprintf(stderr, "%s: hex input data is too long\n", + filename); + fclose(inf); + return(-1); + } + databuf[count] = (decode_hex_digit(c) << 4) | + decode_hex_digit(c2); + } + fclose(inf); + if (!count) { + fprintf(stderr, "%s: no hex data input found\n", filename); + return(-1); + } + return(count); +} diff -r fa7005185b84 -r 454ff8bd0b83 simtool/writecmd.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simtool/writecmd.c Mon Jan 25 01:54:43 2021 +0000 @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include +#include "globals.h" + +cmd_update_bin(argc, argv) + char **argv; +{ + unsigned offset, len; + u_char data[255]; + int rc; + + offset = strtoul(argv[1], 0, 0); + if (offset > 0xFFFF) { + fprintf(stderr, "error: offset argument is out of range\n"); + return(-1); + } + rc = read_hex_data_file(argv[2], data); + if (rc < 0) + return(rc); + len = rc; + return update_bin_op(offset, data, len); +}