-
Notifications
You must be signed in to change notification settings - Fork 3
/
iat_encode.c
58 lines (50 loc) · 1.34 KB
/
iat_encode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* A dirty and undocumented hack to encode data as IAT values searated by commas.
* License: GPLv3, see `LICENSE' file.
*
* This script can be used as a parameter for the CCEAP client.
*
* Use the following form:
* $ ./client -t `./iat_encode [input file] [low time value (ms)] [high time value (ms)]`
* e.g.:
* $ ./client -t `./iat_encode message.txt 10 20`
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#define PRINT_COMMA putchar(',');
#define CHK_BIT(x) if (x) { printf("%s", low); } else { printf("%s", high); }
int main(int argc, char *argv[])
{
FILE *fp;
char byte[1];
char *low = NULL;
char *high = NULL;
int first = 1;
extern char *__progname;
if (argc <= 3) {
fprintf(stderr, "usage: %s [input filename] [low_time (ms)] [high_time (ms)]\n", __progname);
exit(1);
}
if ((fp = fopen(argv[1], "r")) == NULL) {
perror("fopen");
exit(1);
}
low = argv[2];
high = argv[3];
while (fread(byte, 1, 1, fp)) {
if (first)
first = 0;
else
PRINT_COMMA /* comma behind every new value */
CHK_BIT (byte[0] & 0x01) PRINT_COMMA
CHK_BIT (byte[0] & 0x02) PRINT_COMMA
CHK_BIT (byte[0] & 0x04) PRINT_COMMA
CHK_BIT (byte[0] & 0x08) PRINT_COMMA
CHK_BIT (byte[0] & 0x10) PRINT_COMMA
CHK_BIT (byte[0] & 0x20) PRINT_COMMA
CHK_BIT (byte[0] & 0x40) PRINT_COMMA
CHK_BIT (byte[0] & 0x80)
}
fclose(fp);
return 0;
}