summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/src/main.c b/src/main.c
index dd4db27..a9f9167 100644
--- a/src/main.c
+++ b/src/main.c
@@ -35,6 +35,8 @@
#include <unistd.h>
#include <info.h>
+#define DEFAULT_FILENAME "fob"
+
#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
#error "Big endian machines not supported yet"
#endif
@@ -59,7 +61,6 @@ read_file(const char *fname, size_t *size_out)
size_t bufsize;
if (access(fname, F_OK) != 0) {
- fprintf(stderr, "%s does not exist!\n", fname);
return NULL;
}
@@ -110,9 +111,9 @@ is_sse2_supported(void)
static inline bool
is_avx_supported(void)
{
- uint32_t ecx, unused;
- cpuid(0x0000001, unused, unused, ecx, unused);
- return (ecx & (1 << 28)) != 0;
+ uint32_t ebx, unused;
+ cpuid(0x0000001, unused, ebx, unused, unused);
+ return (ebx & (1 << 5)) != 0;
}
static void
@@ -143,7 +144,7 @@ amd64_cpu_tests(struct cpu_info *info)
#endif /* defined(__x86_64__) */
static char *
-encrypt(const struct cpu_info *info, char *buf, size_t buf_size)
+obfuscate(const struct cpu_info *info, char *buf, size_t buf_size)
{
size_t current_pos;
size_t step;
@@ -216,29 +217,44 @@ encrypt(const struct cpu_info *info, char *buf, size_t buf_size)
}
int
-main(int argc, const char **argv)
+main(int argc, char **argv)
{
size_t buf_size;
char *buf;
struct cpu_info info = { 0 };
+ int8_t opt;
+ char *output = DEFAULT_FILENAME;
+ char *input = NULL;
+
+ while ((opt = getopt(argc, (char *const *)argv, "o:")) != -1)
+ {
+ if (opt == 'o') {
+ output = optarg;
+ }
+ }
+
+ input = argv[optind];
- if (argc < 2) {
+ if (input == NULL) {
fprintf(stderr, "Usage: %s <file>\n", argv[0]);
return 1;
}
+ buf = read_file(input, &buf_size);
+ if (buf == NULL) {
+ fprintf(stderr, "Failed to read %s. Does it exist?\n", input);
+ return 1;
+ }
+
#if defined(__x86_64__)
amd64_cpu_tests(&info);
#endif /* __x86_64__ */
- buf = read_file(argv[1], &buf_size);
- if (buf == NULL) {
- return 1;
- }
+ obfuscate(&info, buf, buf_size);
+ writeback_file(output, buf, buf_size);
- encrypt(&info, buf, buf_size);
- writeback_file(argv[1], buf, buf_size);
- free(buf);
+ fprintf(stdout, "Written to %s\n", output);
+ free(buf);
return 0;
}