root/honeytrap/trunk/tools/bin2hex.c

Revision 1350, 1.2 kB (checked in by till, 1 year ago)

- bin2hex: convert binary input to hex
- ngtrie: trie-based string similarity computation using n-grams

  • Property svn:executable set to *
Line 
1 /* bin2hex.c
2  * Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de>
3  *
4  * This file is free software; as a special exception the author gives
5  * unlimited permission to copy and/or distribute it, with or without
6  * modifications, as long as this notice is preserved.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  *
13  * This file is part of the honeytrap tools collection.
14  *
15  * bin2hex reads a file bytewise and write its hex values to stdout.
16  */
17
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <errno.h>
22
23 int main(int argc, char *argv[]) {
24         u_char byte;
25         int retval;
26         FILE *file;
27
28         if (argc < 2) {
29                 fprintf(stderr, "Error - No filename given.\n");
30                 exit(1);
31         }
32
33         /* open file */
34         if ((file = fopen(argv[1], "r")) == NULL) {
35                 fprintf(stderr, "Error - Unable to open file: %s.\n", strerror(errno));
36                 exit(1);
37         }
38
39         errno = 0;
40         while((retval = fscanf(file, "%c", &byte)) > 0) fprintf(stdout, "\\x%02x", byte);
41         if ((retval = EOF) && errno) fprintf(stderr, "Error - Unable to read from file: %s.\n", strerror(errno));
42
43         fclose(file);
44         return(0);
45 }
Note: See TracBrowser for help on using the browser.