CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/context/stat-key.c
Views: 1904
1
/*
2
* Given a filename, outputs a 32bit key for use in
3
* context keyed payload encoding. The key is derived from
4
* XOR-ing the st_size and st_mtime fields of the
5
* relevant struct stat for this file.
6
*
7
* Author: Dimitris Glynos <dimitris at census-labs.com>
8
*/
9
10
#include <stdio.h>
11
#include <sys/stat.h>
12
#include <sys/types.h>
13
#include <unistd.h>
14
15
int main(int argc, char *argv[])
16
{
17
char *filename;
18
struct stat stat_buf;
19
20
if (argc != 2) {
21
fprintf(stderr, "usage: %s <filename>\n", argv[0]);
22
return 1;
23
}
24
25
filename = argv[1];
26
27
if (stat(filename, &stat_buf) == -1) {
28
perror("error while stat(2)-ing file");
29
return 1;
30
}
31
32
printf("%#.8lx\n", stat_buf.st_mtime ^ stat_buf.st_size);
33
return 0;
34
}
35
36