proxmark3/client/emv/dump.c

58 lines
1.6 KiB
C
Raw Normal View History

2017-11-11 03:08:28 +08:00
/*
* libopenemv - a library to work with EMV family of smart cards
* Copyright (C) 2015 Dmitry Eremin-Solenikov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "dump.h"
2019-04-08 16:16:57 +08:00
#ifndef PRINT_INDENT
# define PRINT_INDENT(level) {for (int myi = 0; myi < (level); myi++) fprintf(f, " ");}
#endif
void dump_buffer_simple(const unsigned char *ptr, size_t len, FILE *f) {
2019-03-10 06:35:06 +08:00
int i;
2017-11-11 03:08:28 +08:00
2019-03-10 06:35:06 +08:00
if (!f)
f = stdout;
2017-11-11 03:08:28 +08:00
2019-03-10 06:35:06 +08:00
for (i = 0; i < len; i ++)
fprintf(f, "%s%02hhX", i ? " " : "", ptr[i]);
2017-11-11 03:08:28 +08:00
}
void dump_buffer(const unsigned char *ptr, size_t len, FILE *f, int level) {
2019-03-10 06:35:06 +08:00
int i, j;
if (!f)
f = stdout;
for (i = 0; i < len; i += 16) {
PRINT_INDENT(level);
fprintf(f, "\t%02x:", i);
for (j = 0; j < 16; j++) {
if (i + j < len)
fprintf(f, " %02hhx", ptr[i + j]);
else
fprintf(f, " ");
}
fprintf(f, " |");
for (j = 0; j < 16 && i + j < len; j++) {
2019-03-10 07:00:59 +08:00
fprintf(f, "%c", (ptr[i + j] >= 0x20 && ptr[i + j] < 0x7f) ? ptr[i + j] : '.');
2019-03-10 06:35:06 +08:00
}
fprintf(f, "\n");
}
2017-11-11 03:08:28 +08:00
}