Mercurial > msvpvf
annotate src/main.c @ 44:4f005d28d912
gah,,
author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
---|---|
date | Fri, 20 May 2022 06:33:29 -0400 |
parents | 9b309701420e |
children | d8ac17c6d6f2 |
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> | |
42
d873a04165f9
use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
16
diff
changeset
|
8 #include <libgen.h> |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
9 #ifdef _MSC_VER |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
10 #define strdup(p) _strdup(p) |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
11 #endif |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
12 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
13 static struct option options_long[] = { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
14 {"input", required_argument, NULL, 'i'}, |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
15 {"output", required_argument, NULL, 'o'}, |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
16 {"version", required_argument, NULL, 'v'}, |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
17 {"type", required_argument, NULL, 't'}, |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
18 {"help", 0, NULL, 'h'} |
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 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
21 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
|
22 size_t len = strlen(sub); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
23 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
|
24 char* p = str; |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
25 while ((p = strstr(p, sub)) != NULL) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
26 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
|
27 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
28 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
29 return str; |
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 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
32 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
|
33 int i; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
34 fseek(target, 0x46, SEEK_SET); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
35 fputc(version, target); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
36 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
|
37 fseek(target, 0x18+i, SEEK_SET); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
38 fputc(magic[i], target); |
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 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
42 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
|
43 FILE *source, *target; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
44 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
45 source = fopen(source_file, "rb"); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
46 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
47 if (source == NULL) return 1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
48 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
49 target = fopen(target_file, "wb"); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
50 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
51 if (target == NULL) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
52 fclose(source); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
53 return 1; |
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 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
56 size_t n, m; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
57 unsigned char buff[8192]; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
58 do { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
59 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
|
60 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
|
61 else m = 0; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
62 } while ((n > 0) && (n == m)); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
63 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
64 fclose(target); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
65 fclose(source); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
66 return 0; |
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 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
69 int main(int argc, char *argv[]) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
70 int c, option_index = 0; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
71 unsigned char magic[16]; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
72 FILE* outfile; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
73 struct arguments { |
9 | 74 char input[256]; |
75 char output[256]; | |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
76 int version; |
9 | 77 char type[256]; |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
78 } args; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
79 strcpy(args.input, " "); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
80 strcpy(args.output, " "); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
81 args.version = -1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
82 strcpy(args.type, " "); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
83 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
84 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
|
85 switch(c) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
86 case 'i': |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
87 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
|
88 break; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
89 case 'o': |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
90 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
|
91 break; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
92 case 'v': |
8
9d862edfd3cc
fix fgetc() call
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
6
diff
changeset
|
93 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
|
94 break; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
95 case 't': |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
96 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
|
97 break; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
98 case 'h': |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
99 default: |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
100 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
|
101 return 0; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
102 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
103 if (argc == 1) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
104 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
|
105 return 0; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
106 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
107 if (strcmp(args.input, " ") == 0) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
108 printf("Input file name?\n"); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
109 fflush(stdout); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
110 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
|
111 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
|
112 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
113 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
|
114 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
|
115 return 1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
116 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
117 FILE* input_file = fopen(args.input, "r"); |
8
9d862edfd3cc
fix fgetc() call
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
6
diff
changeset
|
118 if (fgetc(input_file) == EOF) { |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
119 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
|
120 fclose(input_file); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
121 return 1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
122 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
123 fseek(input_file, 0x46, SEEK_SET); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
124 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
|
125 fseek(input_file, 0x18, SEEK_SET); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
126 int file_version = fgetc(input_file); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 break; |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
138 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
139 int* ptr = &args.version; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
140 if (args.version == -1) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
141 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
|
142 fflush(stdout); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
143 scanf("%d", ptr); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
144 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
145 if (strcmp(args.type, " ") == 0) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
146 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
|
147 fflush(stdout); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
148 scanf("%3s", args.type); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
149 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
150 fflush(stdout); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
151 if (strcmp(args.output, " ") == 0) { /* string manipulation hell */ |
44
4f005d28d912
gah,,
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
43
diff
changeset
|
152 char temp* = (char*)calloc(256, sizeof(char)); |
43
9b309701420e
welcome to Ctec and will it compile?
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
42
diff
changeset
|
153 temp[0] = '\0'; |
9b309701420e
welcome to Ctec and will it compile?
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
42
diff
changeset
|
154 char str_version[16]; |
42
d873a04165f9
use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
16
diff
changeset
|
155 sprintf(str_version, "V%d", args.version); |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
156 strncat(temp, str_version, 2); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
157 strncat(temp, "_", 1); |
42
d873a04165f9
use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
16
diff
changeset
|
158 strncat(temp, basename(args.input), 248); |
d873a04165f9
use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
16
diff
changeset
|
159 strcpy(temp, strremove(temp, strrchr(basename(args.input), ('.')))); /* remove file extension */ |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
160 strncat(temp, ".", 1); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
161 strncat(temp, args.type, 3); |
9 | 162 strncpy(args.output, temp, 255); |
44
4f005d28d912
gah,,
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
43
diff
changeset
|
163 free(temp); |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
164 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
165 if (strcmp(args.type, "veg") == 0) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
166 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
|
167 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
|
168 magic[option_index] = T[option_index]; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
169 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
170 } 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
|
171 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
|
172 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
|
173 magic[option_index] = T[option_index]; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
174 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
175 } else { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
176 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
|
177 return 1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
178 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
179 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
|
180 #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
|
181 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
|
182 #elif defined(__unix__) |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
183 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
|
184 #else |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
185 if (NULL) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
186 #endif |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
187 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
|
188 return 1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
189 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
190 outfile = fopen(args.output, "r+b"); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
191 if (outfile == NULL) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
192 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
|
193 return 1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
194 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
195 set_data(magic, args.version, outfile); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
196 fclose(outfile); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
197 return 0; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
198 } |