annotate msvpvf.c @ 4:78a0ecd756da

Add automated output filename creation
author Paper <mrpapersonic@gmail.com>
date Fri, 21 Jan 2022 01:40:57 -0500
parents 87c7d43b03ff
children 92ec47e63923
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 /* Movie Studio / Vegas Pro version spoofer
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 * by Paper
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 */
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 #include <stdio.h>
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include <unistd.h>
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7 #include <getopt.h>
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 #include <inttypes.h>
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 #include <string.h>
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 #include <stdlib.h>
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 #if __STDC_VERSION__ >= 199901L
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 #include <stdbool.h>
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 #else
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
14 typedef enum { false, true } bool; /* less than C99 */
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 #endif
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 #ifdef _MSC_VER
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 #define strdup(p) _strdup(p)
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 #endif
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 static struct option options_long[] = {
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 {"input", required_argument, NULL, 'i'},
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 {"output", required_argument, NULL, 'o'},
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 {"version", required_argument, NULL, 'v'},
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 {"type", required_argument, NULL, 't'},
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 {"help", 0, NULL, 'h'}
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 };
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
28 char* strremove(char* str, const char* sub) {
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
29 size_t len = strlen(sub);
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
30 if (len > 0) {
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
31 char *p = str;
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
32 while ((p = strstr(p, sub)) != NULL) {
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
33 memmove(p, p + len, strlen(p + len) + 1);
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
34 }
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
35 }
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
36 return str;
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
37 }
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
38
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39 void set_data(unsigned char magic[], uint16_t version, FILE* target) {
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 int i;
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41 fseek(target, 0x46, SEEK_SET);
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42 fputc(version, target);
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43 for (i=0; i<=sizeof(*magic); ++i) {
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44 fseek(target, 0x18+i, SEEK_SET);
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 fputc(magic[i], target);
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46 }
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47 }
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
49 int copy_file(char* source_file, char* target_file) {
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 FILE *source, *target;
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
52 source = fopen(source_file, "rb");
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
53 if (source == NULL) {
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54 return 1;
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
55 }
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 target = fopen(target_file, "wb");
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
57 if (target == NULL) {
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58 return 1;
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59 }
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
60
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
61 size_t n, m;
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
62 unsigned char buff[8192];
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
63 do {
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
64 n = fread(buff, 1, sizeof(buff), source);
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
65 if (n) m = fwrite(buff, 1, n, target);
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
66 else m = 0;
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
67 } while ((n > 0) && (n == m));
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
68
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
69 fclose(target);
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
70 fclose(source);
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
71 return 0;
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
72 }
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
73
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
74 int main(int argc, char *argv[]) {
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
75 int c, option_index = 0;
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
76 unsigned char magic[16];
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
77 FILE* outfile;
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
78 struct arguments {
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
79 char input[128];
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
80 char output[128];
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
81 int version;
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
82 char type[128];
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
83 } args;
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
84 strcpy(args.input, " ");
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
85 strcpy(args.output, " ");
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
86 args.version = -1;
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
87 strcpy(args.type, " ");
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
88
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
89 while ((c = getopt_long(argc, argv, "i:o:v:t:h", options_long, &option_index)) != -1)
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
90 switch(c) {
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
91 case 'i':
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
92 strncpy(args.input, optarg, sizeof(args.input)-1); /* subtract 1 to make sure it's "null-safe" */
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
93 break;
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
94 case 'o':
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
95 strncpy(args.output, optarg, sizeof(args.input)-1);
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
96 break;
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
97 case 'v':
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
98 args.version = abs(atoi(strdup(optarg))); /* abs() for possible negative inputs */
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
99 break;
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
100 case 't':
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
101 strncpy(args.type, optarg, sizeof(args.input)-1);
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
102 break;
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
103 case 'h':
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
104 default:
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
105 printf("msvpvf by Paper\nusage: %s (-i/--input) infile [(-o/--output) outfile] (-v/--version) version (-t/--type) [vf, veg]", argv[0]);
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
106 return 0;
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
107 }
4
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
108 if (strcmp(args.input, " ") == 0) {
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
109 printf("Input file name?\n");
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
110 fflush(stdout);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
111 fgets(args.input, sizeof(args.input)-1, stdin);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
112 args.input[strcspn(args.input, "\r\n")] = 0;
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
113 }
4
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
114 if (access(args.input, F_OK) != 0) {
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
115 fprintf(stderr, "Input file \"%s\" doesn't exist! Exiting.", args.input);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
116 return 1;
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
117 }
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
118 if (fgetc(fopen(args.input, "r")) == EOF) {
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
119 fprintf(stderr, "Input file \"%s\" is empty.", args.input);
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
120 return 1;
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
121 }
4
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
122 FILE* input_file = fopen(args.input, "r");
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
123 fseek(input_file, 0x46, SEEK_SET);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
124 printf("Input file version: %d\n", fgetc(input_file));
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
125 fseek(input_file, 0x18, SEEK_SET);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
126 int file_version = fgetc(input_file);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
127 printf("Input file type: ");
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
128 if (file_version == 0xEF) {
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
129 printf("VEGAS Pro\n\n");
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
130 } else if (file_version == 0xF6) {
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
131 printf("Movie Studio\n\n");
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
132 } else {
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
133 printf("Unknown\n\n");
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
134 }
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
135 int* ptr = &args.version;
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
136 if (args.version == -1) {
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
137 printf("What version of VEGAS would you like to spoof to?: ");
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
138 fflush(stdout);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
139 scanf("%d", ptr);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
140 }
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
141 if (strcmp(args.type, " ") == 0) {
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
142 printf("Would you like it to be VEGAS Pro or Movie Studio? [veg/vf]: ");
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
143 fflush(stdout);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
144 scanf("%3s", args.type);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
145 }
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
146 fflush(stdout);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
147 if (strcmp(args.output, " ") == 0) { /* string manipulation hell */
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
148 char temp[128] = {'V'};
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
149 char str_version[16] = {};
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
150 sprintf(str_version, "%d", args.version);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
151 strncat(temp, str_version, 2);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
152 strncat(temp, "_", 1);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
153 strncat(temp, args.input, 120);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
154 strcpy(temp, strremove(temp, strrchr(args.input, ('.')))); /* remove file extension */
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
155 strncat(temp, ".", 1);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
156 strncat(temp, args.type, 3);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
157 strncpy(args.output, temp, 127);
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
158 }
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
159 if (strcmp(args.type, "veg") == 0) {
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
160 unsigned char T[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A};
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
161 for (option_index = 0; option_index <= 15; option_index++) {
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
162 magic[option_index] = T[option_index];
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
163 }
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
164 } else if (strcmp(args.type, "vf") == 0) {
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
165 unsigned char T[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F};
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
166 for (option_index = 0; option_index <= 15; option_index++) {
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
167 magic[option_index] = T[option_index];
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
168 }
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
169 } else {
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
170 fprintf(stderr, "Type %s is invalid!", args.type);
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
171 return 1;
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
172 }
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
173 copy_file(args.input, args.output);
4
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
174 #ifdef _WIN32
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
175 if (strcspn(args.input, "<>:\"/\\|?*") == strlen(args.input)+1) {
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
176 #elif defined(__unix__)
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
177 if (strcspn(args.input, "/") == strlen(args.input)+1) {
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
178 #else
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
179 if (NULL) {
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
180 #endif
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
181 fprintf(stderr, "Invalid output filename detected! Exiting...")
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
182 return 1;
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
183 }
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
184 outfile = fopen(args.output, "r+b");
4
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
185 if (outfile == NULL) {
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
186 fprintf(stderr, "Failed to open file %s! Is the filename invalid?", args.output);
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
187 return 1;
78a0ecd756da Add automated output filename creation
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
188 }
3
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
189 set_data(magic, args.version, outfile);
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
190 fclose(outfile);
87c7d43b03ff Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
191 return 0;
1
528b95e1e24f Add source and makefile
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
192 }