-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
41 lines (38 loc) · 832 Bytes
/
main.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
//
// Created by me on 22.01.2021.
//
#include <stdio.h>
#include <stdbool.h>
#include <inttypes.h>
#include "spectre.h"
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "Usage: %s <data> [<output>]\n", argv[0]);
return -1;
}
char *data = argv[1];
bool from_file = false;
if (argc == 3) {
from_file = true;
output = fopen(argv[2], "w");
if (output == NULL) {
perror("Cannot open file");
return -1;
}
} else {
output = stdout;
}
init_spectre();
char *read = read_byte_string_at((uint64_t) data);
fprintf(output, "Read: %s\n", read);
if(strlen(read) != strlen(data)) {
fprintf(output, "Lengths mismatch! Attack failed!\n");
}
free(read);
if (from_file) {
fclose(output);
if (errno) {
perror("Could not close file");
}
}
}