comparison src/main.c @ 6:d1e5b8390cd3

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