- added missing files
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@113 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
daf877fadd
commit
f09933657a
|
@ -0,0 +1,56 @@
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
void print_binary(FILE *f, const u8 *buf, int count)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
unsigned char c = buf[i];
|
||||||
|
const char *format;
|
||||||
|
if (!isalnum(c) && !ispunct(c) && !isspace(c))
|
||||||
|
format = "\\x%02X";
|
||||||
|
else
|
||||||
|
format = "%c";
|
||||||
|
fprintf(f, format, c);
|
||||||
|
}
|
||||||
|
(void) fflush(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hex_dump(FILE *f, const u8 *in, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
fprintf(f, "%02X ", in[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hex_dump_asc(FILE *f, const u8 *in, size_t count)
|
||||||
|
{
|
||||||
|
int lines = 0;
|
||||||
|
|
||||||
|
while (count) {
|
||||||
|
char ascbuf[17];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < count && i < 16; i++) {
|
||||||
|
fprintf(f, "%02X ", *in);
|
||||||
|
if (isprint(*in))
|
||||||
|
ascbuf[i] = *in;
|
||||||
|
else
|
||||||
|
ascbuf[i] = '.';
|
||||||
|
in++;
|
||||||
|
}
|
||||||
|
count -= i;
|
||||||
|
ascbuf[i] = 0;
|
||||||
|
for (; i < 16 && lines; i++)
|
||||||
|
fprintf(f, " ");
|
||||||
|
fprintf(f, "%s\n", ascbuf);
|
||||||
|
lines++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef UTIL_H
|
||||||
|
#define UTIL_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <opensc.h>
|
||||||
|
|
||||||
|
void print_binary(FILE *f, const u8 *buf, int count);
|
||||||
|
void hex_dump(FILE *f, const u8 *in, int len);
|
||||||
|
void hex_dump_asc(FILE *f, const u8 *in, size_t count);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue