CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/context/time-key.c
Views: 11766
1
/*
2
* Outputs the value of time(2) with the 16 least significant bits zeroed out.
3
* For use in context keyed payload encoding.
4
*
5
* Author: Dimitris Glynos <dimitris at census-labs.com>
6
*/
7
8
#include <stdlib.h>
9
#include <stdio.h>
10
#define __USE_XOPEN
11
#include <time.h>
12
13
char *app = NULL;
14
15
void croak_usage(void)
16
{
17
fprintf(stderr, "usage: %s [date & time]\n"
18
"\tSupported date & time format: 'YYYY-MM-DD HH:MM:SS'\n"
19
"\te.g. %s '2003-11-04 14:23:10'\n",
20
app, app);
21
exit(1);
22
}
23
24
time_t parse_time(const char *input)
25
{
26
struct tm t;
27
char *p;
28
29
p = strptime(input, "%Y-%m-%d %H:%M:%S", &t);
30
31
if ((!p) || (*p != '\0')) {
32
fprintf(stderr, "error while processing time spec!\n");
33
croak_usage();
34
}
35
36
return mktime(&t);
37
}
38
39
int main(int argc, char *argv[])
40
{
41
time_t t;
42
43
app = argv[0];
44
45
if (argc > 2)
46
croak_usage();
47
48
if (argc == 2)
49
t = parse_time(argv[1]);
50
else
51
t = time(NULL);
52
53
printf("%#.8lx\n", t & 0xffff0000);
54
return 0;
55
}
56
57