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