blob: b166f80e386bc314ce5bf102528dfc4d3f9067b5 (
plain)
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
58
59
|
#define _XOPEN_SOURCE 500
#include <ctype.h>
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#define COLOR(_n) (31 + (_n % 9))
#define BUFSIZE 16
void hexdump(uintmax_t address, size_t n, unsigned char buf[static n])
{
if (n > BUFSIZE) {
n = BUFSIZE;
}
unsigned char ch = buf[n - 1];
for (int c = 0; c < ch; c++) {
buf[n - 1] = c;
printf("\033[1m\r%015jx ", address);
for (size_t i = 0; i < n; i++) {
printf("\033[%hhdm%02hhx\033[0m ", COLOR(buf[i]), buf[i]);
//usleep(100 * buf[i]);
}
for (size_t i = n; i < BUFSIZE; i++) {
printf("-- ");
}
for (size_t i = 0; i < n; i++) {
printf("\033[%hhdm%c\033[0m", COLOR(buf[i]), isprint(buf[i]) ? buf[i] : '.');
usleep(100 * buf[i]);
}
for (size_t i = n; i < 16; i++) {
printf(".");
}
}
}
int main(void)
{
setvbuf(stdout, NULL, _IONBF, 0);
unsigned char buf[BUFSIZE];
uintmax_t address = 0;
srand(time(NULL));
for (;;) {
for (size_t i = 0; i <= sizeof(buf); i++) {
buf[i] = rand();
hexdump(address, i, buf);
}
printf("\n");
address += sizeof(buf);
}
}
|