Mercurial > msvpvf
annotate 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 |
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 } |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
108 int* ptr = &args.version; |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
109 if (argc <= 5) { |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
110 if (strcmp(args.input, " ") == 0) { |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
111 printf("Input file name?\n"); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
112 fflush(stdout); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
113 fgets(args.input, sizeof(args.input)-1, stdin); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
114 args.input[strcspn(args.input, "\r\n")] = 0; |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
115 } |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
116 if (strcmp(args.output, " ") == 0) { |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
117 char* temp; |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
118 temp = strncat(strncat("PRO_V", (char*)(intptr_t)args.version, 7), args.input, 127); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
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 */ |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
120 strncpy(args.output, strncat(strncat(strremove(temp, file_extension), ".", 127), args.type, 127), 127); |
1 | 121 } |
3
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
122 if (args.version == -1) { |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
123 printf("What version would you like to convert to?\n"); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
124 fflush(stdout); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
125 scanf("%d", ptr); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
126 } |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
127 if (strcmp(args.type, " ") == 0) { |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
128 printf("Which type of project file would you like to use?[veg/vf]:\n"); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
129 fflush(stdout); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
130 fgets(args.type, sizeof(args.input)-1, stdin); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
131 args.type[strcspn(args.type, "\r\n")] = 0; |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
132 } |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
133 if (argc == 1) { |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
134 printf("msvpvf by Paper\nusage: %s -i infile [-o outfile] -v version -t [vf, veg]", argv[0]); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
135 return 0; |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
136 } |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
137 } |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
138 if (access(args.input, F_OK) != 0) { /* input file doesn't exist */ |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
139 fprintf(stderr, "Input file %s doesn't exist! Exiting.", args.input); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
140 return 1; |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
141 } |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
142 if (fgetc(fopen(args.input, "r")) == EOF) { /* input file is empty */ |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
143 fprintf(stderr, "Input file %s is empty.", args.input); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
144 return 1; |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
145 } |
1 | 146 if (strcmp(args.type, "veg") == 0) { |
147 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
|
148 for (option_index = 0; option_index <= 15; option_index++) { |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
149 magic[option_index] = T[option_index]; |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
150 } |
1 | 151 } else if (strcmp(args.type, "vf") == 0) { |
152 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
|
153 for (option_index = 0; option_index <= 15; option_index++) { |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
154 magic[option_index] = T[option_index]; |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
155 } |
1 | 156 } else { |
157 fprintf(stderr, "Type %s is invalid!", args.type); | |
3
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
158 return 1; |
1 | 159 } |
3
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
160 copy_file(args.input, args.output); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
161 outfile = fopen(args.output, "r+b"); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
162 set_data(magic, args.version, outfile); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
163 fclose(outfile); |
87c7d43b03ff
Add support for runtime inputs
Paper <mrpapersonic@gmail.com>
parents:
1
diff
changeset
|
164 return 0; |
1 | 165 } |