]>
Commit | Line | Data |
---|---|---|
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" | |
21 | ||
22 | #include <stdio.h> | |
23 | ||
24 | void dump_buffer_simple(const unsigned char *ptr, size_t len, FILE *f) | |
25 | { | |
26 | int i; | |
27 | ||
28 | if (!f) | |
29 | f = stdout; | |
30 | ||
31 | for (i = 0; i < len; i ++) | |
32 | fprintf(f, "%s%02hhX", i ? " " : "", ptr[i]); | |
33 | } | |
34 | ||
35 | void dump_buffer(const unsigned char *ptr, size_t len, FILE *f) | |
36 | { | |
37 | int i, j; | |
38 | ||
39 | if (!f) | |
40 | f = stdout; | |
41 | ||
42 | for (i = 0; i < len; i += 16) { | |
43 | fprintf(f, "\t%02x:", i); | |
44 | for (j = 0; j < 16; j++) { | |
45 | if (i + j < len) | |
46 | fprintf(f, " %02hhx", ptr[i + j]); | |
47 | else | |
48 | fprintf(f, " "); | |
49 | } | |
50 | fprintf(f, " |"); | |
51 | for (j = 0; j < 16 && i + j < len; j++) { | |
52 | fprintf(f, "%c", (ptr[i+j] >= 0x20 && ptr[i+j] < 0x7f) ? ptr[i+j] : '.' ); | |
53 | } | |
54 | fprintf(f, "\n"); | |
55 | } | |
56 | } | |
57 |