]> git.zerfleddert.de Git - proxmark3-svn/blame - client/emv/dump.c
fix: hf mf mifare - populate keylist (#568)
[proxmark3-svn] / client / emv / dump.c
CommitLineData
a2bb2735 1/*
2 * libopenemv - a library to work with EMV family of smart cards
3 * Copyright (C) 2015 Dmitry Eremin-Solenikov
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 */
15
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "dump.h"
a2bb2735 21#include <stdio.h>
3c5fce2b 22#include <string.h>
a2bb2735 23
43912d63 24#define PRINT_INDENT(level) {for (int i = 0; i < (level); i++) fprintf(f, "\t");}
25
a2bb2735 26void dump_buffer_simple(const unsigned char *ptr, size_t len, FILE *f)
27{
28 int i;
29
30 if (!f)
31 f = stdout;
32
33 for (i = 0; i < len; i ++)
34 fprintf(f, "%s%02hhX", i ? " " : "", ptr[i]);
35}
36
43912d63 37void dump_buffer(const unsigned char *ptr, size_t len, FILE *f, int level)
a2bb2735 38{
39 int i, j;
40
41 if (!f)
42 f = stdout;
43
44 for (i = 0; i < len; i += 16) {
43912d63 45 PRINT_INDENT(level);
a2bb2735 46 fprintf(f, "\t%02x:", i);
47 for (j = 0; j < 16; j++) {
48 if (i + j < len)
49 fprintf(f, " %02hhx", ptr[i + j]);
50 else
51 fprintf(f, " ");
52 }
53 fprintf(f, " |");
54 for (j = 0; j < 16 && i + j < len; j++) {
55 fprintf(f, "%c", (ptr[i+j] >= 0x20 && ptr[i+j] < 0x7f) ? ptr[i+j] : '.' );
56 }
57 fprintf(f, "\n");
58 }
59}
60
Impressum, Datenschutz