Mercurial > msvpvf
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 |
rev | line source |
---|---|
1 | 1 /* Movie Studio / Vegas Pro version spoofer |
2 * by Paper | |
3 */ | |
4 | |
5 #include <stdio.h> | |
6 #include <unistd.h> | |
7 #include <getopt.h> | |
8 #include <inttypes.h> | |
9 #include <string.h> | |
10 #include <stdlib.h> | |
11 #if __STDC_VERSION__ >= 199901L | |
12 #include <stdbool.h> | |
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 | 15 #endif |
16 #ifdef _MSC_VER | |
17 #define strdup(p) _strdup(p) | |
18 #endif | |
19 | |
20 static struct option options_long[] = { | |
21 {"input", required_argument, NULL, 'i'}, | |
22 {"output", required_argument, NULL, 'o'}, | |
23 {"version", required_argument, NULL, 'v'}, | |
24 {"type", required_argument, NULL, 't'}, | |
25 {"help", 0, NULL, 'h'} | |
26 }; | |
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 | 39 void set_data(unsigned char magic[], uint16_t version, FILE* target) { |
40 int i; | |
41 fseek(target, 0x46, SEEK_SET); | |
42 fputc(version, target); | |
43 for (i=0; i<=sizeof(*magic); ++i) { | |
44 fseek(target, 0x18+i, SEEK_SET); | |
45 fputc(magic[i], target); | |
46 } | |
47 } | |
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 | 50 FILE *source, *target; |
51 | |
52 source = fopen(source_file, "rb"); | |
53 if (source == NULL) { | |
54 return 1; | |
55 } | |
56 target = fopen(target_file, "wb"); | |
57 if (target == NULL) { | |
58 return 1; | |
59 } | |
60 | |
61 size_t n, m; | |
62 unsigned char buff[8192]; | |
63 do { | |
64 n = fread(buff, 1, sizeof(buff), source); | |
65 if (n) m = fwrite(buff, 1, n, target); | |
66 else m = 0; | |
67 } while ((n > 0) && (n == m)); | |
68 | |
69 fclose(target); | |
70 fclose(source); | |
71 return 0; | |
72 } | |
73 | |
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 | 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 | 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 | 86 args.version = -1; |
3
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
87 strcpy(args.type, " "); |
1 | 88 |
89 while ((c = getopt_long(argc, argv, "i:o:v:t:h", options_long, &option_index)) != -1) | |
90 switch(c) { | |
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 | 93 break; |
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 | 96 break; |
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 | 99 break; |
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 | 102 break; |
103 case 'h': | |
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 | 159 if (strcmp(args.type, "veg") == 0) { |
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 | 164 } else if (strcmp(args.type, "vf") == 0) { |
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 | 169 } else { |
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 | 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 | 192 } |