comparison msvpvf.c @ 3:87c7d43b03ff

Add support for runtime inputs
author Paper <mrpapersonic@gmail.com>
date Thu, 20 Jan 2022 23:00:18 -0500
parents 528b95e1e24f
children 78a0ecd756da
comparison
equal deleted inserted replaced
2:ce1e494aeb0e 3:87c7d43b03ff
1 /* Movie Studio / Vegas Pro version spoofer 1 /* Movie Studio / Vegas Pro version spoofer
2 * by Paper 2 * by Paper
3 *
4 * You should have received a copy of the MIT License along with this program.
5 * If not, you can access it at https://opensource.org/licenses/MIT.
6 */ 3 */
7 4
8 #include <stdio.h> 5 #include <stdio.h>
9 #include <unistd.h> 6 #include <unistd.h>
10 #include <getopt.h> 7 #include <getopt.h>
12 #include <string.h> 9 #include <string.h>
13 #include <stdlib.h> 10 #include <stdlib.h>
14 #if __STDC_VERSION__ >= 199901L 11 #if __STDC_VERSION__ >= 199901L
15 #include <stdbool.h> 12 #include <stdbool.h>
16 #else 13 #else
17 typedef enum { false, true } bool; /* less than C99 */ 14 typedef enum { false, true } bool; /* less than C99 */
18 #endif 15 #endif
19 #ifdef _MSC_VER 16 #ifdef _MSC_VER
20 #define strdup(p) _strdup(p) 17 #define strdup(p) _strdup(p)
21 #endif 18 #endif
22 19
26 {"version", required_argument, NULL, 'v'}, 23 {"version", required_argument, NULL, 'v'},
27 {"type", required_argument, NULL, 't'}, 24 {"type", required_argument, NULL, 't'},
28 {"help", 0, NULL, 'h'} 25 {"help", 0, NULL, 'h'}
29 }; 26 };
30 27
28 char* strremove(char* str, const char* sub) {
29 size_t len = strlen(sub);
30 if (len > 0) {
31 char *p = str;
32 while ((p = strstr(p, sub)) != NULL) {
33 memmove(p, p + len, strlen(p + len) + 1);
34 }
35 }
36 return str;
37 }
38
31 void set_data(unsigned char magic[], uint16_t version, FILE* target) { 39 void set_data(unsigned char magic[], uint16_t version, FILE* target) {
32 int i; 40 int i;
33 fseek(target, 0x46, SEEK_SET); 41 fseek(target, 0x46, SEEK_SET);
34 fputc(version, target); 42 fputc(version, target);
35 for (i=0; i<=sizeof(*magic); ++i) { 43 for (i=0; i<=sizeof(*magic); ++i) {
36 fseek(target, 0x18+i, SEEK_SET); 44 fseek(target, 0x18+i, SEEK_SET);
37 fputc(magic[i], target); 45 fputc(magic[i], target);
38 } 46 }
39 } 47 }
40 48
41 int copy_file(const char* source_file, const char* target_file) { 49 int copy_file(char* source_file, char* target_file) {
42 FILE *source, *target; 50 FILE *source, *target;
43 51
44 source = fopen(source_file, "rb"); 52 source = fopen(source_file, "rb");
45 if (source == NULL) { 53 if (source == NULL) {
46 return 1; 54 return 1;
62 fclose(source); 70 fclose(source);
63 return 0; 71 return 0;
64 } 72 }
65 73
66 int main(int argc, char *argv[]) { 74 int main(int argc, char *argv[]) {
67 int c, temp, option_index = 0; 75 int c, option_index = 0;
68 char buf[127]; 76 unsigned char magic[16];
77 FILE* outfile;
69 struct arguments { 78 struct arguments {
70 const char* input; 79 char input[128];
71 const char* output; 80 char output[128];
72 uint16_t version; 81 int version;
73 const char* type; 82 char type[128];
74 } args; 83 } args;
75 args.input = " "; 84 strcpy(args.input, " ");
76 args.output = " "; 85 strcpy(args.output, " ");
77 args.version = -1; 86 args.version = -1;
78 args.type = " "; 87 strcpy(args.type, " ");
79 88
80 while ((c = getopt_long(argc, argv, "i:o:v:t:h", options_long, &option_index)) != -1) 89 while ((c = getopt_long(argc, argv, "i:o:v:t:h", options_long, &option_index)) != -1)
81 switch(c) { 90 switch(c) {
82 case 'i': 91 case 'i':
83 args.input = strdup(optarg); 92 strncpy(args.input, optarg, sizeof(args.input)-1); /* subtract 1 to make sure it's "null-safe" */
84 break; 93 break;
85 case 'o': 94 case 'o':
86 args.output = strdup(optarg); 95 strncpy(args.output, optarg, sizeof(args.input)-1);
87 break; 96 break;
88 case 'v': 97 case 'v':
89 args.version = abs(atoi(strdup(optarg))); /* abs() for possible negative inputs */ 98 args.version = abs(atoi(strdup(optarg))); /* abs() for possible negative inputs */
90 break; 99 break;
91 case 't': 100 case 't':
92 args.type = strdup(optarg); 101 strncpy(args.type, optarg, sizeof(args.input)-1);
93 break; 102 break;
94 case 'h': 103 case 'h':
95 default: 104 default:
96 fprintf(stderr, "msvpvf by Paper\nusage: %s -i infile [-o outfile] -v version -t [vf, veg]", argv[0]); 105 printf("msvpvf by Paper\nusage: %s (-i/--input) infile [(-o/--output) outfile] (-v/--version) version (-t/--type) [vf, veg]", argv[0]);
97 return 1; 106 return 0;
98 } 107 }
99 copy_file(args.input, args.output); 108 int* ptr = &args.version;
100 FILE* outfile = fopen(args.output, "r+b"); 109 if (argc <= 5) {
110 if (strcmp(args.input, " ") == 0) {
111 printf("Input file name?\n");
112 fflush(stdout);
113 fgets(args.input, sizeof(args.input)-1, stdin);
114 args.input[strcspn(args.input, "\r\n")] = 0;
115 }
116 if (strcmp(args.output, " ") == 0) {
117 char* temp;
118 temp = strncat(strncat("PRO_V", (char*)(intptr_t)args.version, 7), args.input, 127);
119 char* file_extension = strrchr(args.input, ('.')); /* this won't work if your path is /path.to/file but why would you do that in the first place */
120 strncpy(args.output, strncat(strncat(strremove(temp, file_extension), ".", 127), args.type, 127), 127);
121 }
122 if (args.version == -1) {
123 printf("What version would you like to convert to?\n");
124 fflush(stdout);
125 scanf("%d", ptr);
126 }
127 if (strcmp(args.type, " ") == 0) {
128 printf("Which type of project file would you like to use?[veg/vf]:\n");
129 fflush(stdout);
130 fgets(args.type, sizeof(args.input)-1, stdin);
131 args.type[strcspn(args.type, "\r\n")] = 0;
132 }
133 if (argc == 1) {
134 printf("msvpvf by Paper\nusage: %s -i infile [-o outfile] -v version -t [vf, veg]", argv[0]);
135 return 0;
136 }
137 }
138 if (access(args.input, F_OK) != 0) { /* input file doesn't exist */
139 fprintf(stderr, "Input file %s doesn't exist! Exiting.", args.input);
140 return 1;
141 }
142 if (fgetc(fopen(args.input, "r")) == EOF) { /* input file is empty */
143 fprintf(stderr, "Input file %s is empty.", args.input);
144 return 1;
145 }
101 if (strcmp(args.type, "veg") == 0) { 146 if (strcmp(args.type, "veg") == 0) {
102 unsigned char T[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A}; 147 unsigned char T[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A};
103 set_data(T, args.version, outfile); 148 for (option_index = 0; option_index <= 15; option_index++) {
149 magic[option_index] = T[option_index];
150 }
104 } else if (strcmp(args.type, "vf") == 0) { 151 } else if (strcmp(args.type, "vf") == 0) {
105 unsigned char T[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F}; 152 unsigned char T[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F};
106 set_data(T, args.version, outfile); 153 for (option_index = 0; option_index <= 15; option_index++) {
154 magic[option_index] = T[option_index];
155 }
107 } else { 156 } else {
108 fprintf(stderr, "Type %s is invalid!", args.type); 157 fprintf(stderr, "Type %s is invalid!", args.type);
109 goto exit; 158 return 1;
110 } 159 }
111 exit: 160 copy_file(args.input, args.output);
112 if (&outfile) fclose(outfile); 161 outfile = fopen(args.output, "r+b");
113 if (&args) { 162 set_data(magic, args.version, outfile);
114 free((char*)args.input); 163 fclose(outfile);
115 free((char*)args.output); 164 return 0;
116 free((char*)args.type);
117 }
118 return 0;
119 } 165 }