Mercurial > msvpvf
changeset 3:87c7d43b03ff
Add support for runtime inputs
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 20 Jan 2022 23:00:18 -0500 |
parents | ce1e494aeb0e |
children | 78a0ecd756da |
files | Makefile msvpvf.c |
diffstat | 2 files changed, 82 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Mon Jan 17 17:02:16 2022 -0500 +++ b/Makefile Thu Jan 20 23:00:18 2022 -0500 @@ -1,5 +1,6 @@ -CC=gcc -CC_FLAGS=-static -O2 +CC=clang # clang cause gcc throws compiling errors that i don't know how to fix +CC_FLAGS=-Wall -static -O2 +LD_FLAGS=-ffunction-sections %.o : %.c $(CC) -c $(CC_FLAGS) $< -o $@
--- a/msvpvf.c Mon Jan 17 17:02:16 2022 -0500 +++ b/msvpvf.c Thu Jan 20 23:00:18 2022 -0500 @@ -1,8 +1,5 @@ /* Movie Studio / Vegas Pro version spoofer * by Paper - * - * You should have received a copy of the MIT License along with this program. - * If not, you can access it at https://opensource.org/licenses/MIT. */ #include <stdio.h> @@ -14,7 +11,7 @@ #if __STDC_VERSION__ >= 199901L #include <stdbool.h> #else -typedef enum { false, true } bool; /* less than C99 */ +typedef enum { false, true } bool; /* less than C99 */ #endif #ifdef _MSC_VER #define strdup(p) _strdup(p) @@ -28,6 +25,17 @@ {"help", 0, NULL, 'h'} }; +char* strremove(char* str, const char* sub) { + size_t len = strlen(sub); + if (len > 0) { + char *p = str; + while ((p = strstr(p, sub)) != NULL) { + memmove(p, p + len, strlen(p + len) + 1); + } + } + return str; +} + void set_data(unsigned char magic[], uint16_t version, FILE* target) { int i; fseek(target, 0x46, SEEK_SET); @@ -38,7 +46,7 @@ } } -int copy_file(const char* source_file, const char* target_file) { +int copy_file(char* source_file, char* target_file) { FILE *source, *target; source = fopen(source_file, "rb"); @@ -64,56 +72,94 @@ } int main(int argc, char *argv[]) { - int c, temp, option_index = 0; - char buf[127]; + int c, option_index = 0; + unsigned char magic[16]; + FILE* outfile; struct arguments { - const char* input; - const char* output; - uint16_t version; - const char* type; + char input[128]; + char output[128]; + int version; + char type[128]; } args; - args.input = " "; - args.output = " "; + strcpy(args.input, " "); + strcpy(args.output, " "); args.version = -1; - args.type = " "; + strcpy(args.type, " "); while ((c = getopt_long(argc, argv, "i:o:v:t:h", options_long, &option_index)) != -1) switch(c) { case 'i': - args.input = strdup(optarg); + strncpy(args.input, optarg, sizeof(args.input)-1); /* subtract 1 to make sure it's "null-safe" */ break; case 'o': - args.output = strdup(optarg); + strncpy(args.output, optarg, sizeof(args.input)-1); break; case 'v': - args.version = abs(atoi(strdup(optarg))); /* abs() for possible negative inputs */ + args.version = abs(atoi(strdup(optarg))); /* abs() for possible negative inputs */ break; case 't': - args.type = strdup(optarg); + strncpy(args.type, optarg, sizeof(args.input)-1); break; case 'h': default: - fprintf(stderr, "msvpvf by Paper\nusage: %s -i infile [-o outfile] -v version -t [vf, veg]", argv[0]); - return 1; + printf("msvpvf by Paper\nusage: %s (-i/--input) infile [(-o/--output) outfile] (-v/--version) version (-t/--type) [vf, veg]", argv[0]); + return 0; + } + int* ptr = &args.version; + if (argc <= 5) { + if (strcmp(args.input, " ") == 0) { + printf("Input file name?\n"); + fflush(stdout); + fgets(args.input, sizeof(args.input)-1, stdin); + args.input[strcspn(args.input, "\r\n")] = 0; + } + if (strcmp(args.output, " ") == 0) { + char* temp; + temp = strncat(strncat("PRO_V", (char*)(intptr_t)args.version, 7), args.input, 127); + 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 */ + strncpy(args.output, strncat(strncat(strremove(temp, file_extension), ".", 127), args.type, 127), 127); } - copy_file(args.input, args.output); - FILE* outfile = fopen(args.output, "r+b"); + if (args.version == -1) { + printf("What version would you like to convert to?\n"); + fflush(stdout); + scanf("%d", ptr); + } + if (strcmp(args.type, " ") == 0) { + printf("Which type of project file would you like to use?[veg/vf]:\n"); + fflush(stdout); + fgets(args.type, sizeof(args.input)-1, stdin); + args.type[strcspn(args.type, "\r\n")] = 0; + } + if (argc == 1) { + printf("msvpvf by Paper\nusage: %s -i infile [-o outfile] -v version -t [vf, veg]", argv[0]); + return 0; + } + } + if (access(args.input, F_OK) != 0) { /* input file doesn't exist */ + fprintf(stderr, "Input file %s doesn't exist! Exiting.", args.input); + return 1; + } + if (fgetc(fopen(args.input, "r")) == EOF) { /* input file is empty */ + fprintf(stderr, "Input file %s is empty.", args.input); + return 1; + } if (strcmp(args.type, "veg") == 0) { unsigned char T[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A}; - set_data(T, args.version, outfile); + for (option_index = 0; option_index <= 15; option_index++) { + magic[option_index] = T[option_index]; + } } else if (strcmp(args.type, "vf") == 0) { unsigned char T[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F}; - set_data(T, args.version, outfile); + for (option_index = 0; option_index <= 15; option_index++) { + magic[option_index] = T[option_index]; + } } else { fprintf(stderr, "Type %s is invalid!", args.type); - goto exit; + return 1; } - exit: - if (&outfile) fclose(outfile); - if (&args) { - free((char*)args.input); - free((char*)args.output); - free((char*)args.type); - } - return 0; + copy_file(args.input, args.output); + outfile = fopen(args.output, "r+b"); + set_data(magic, args.version, outfile); + fclose(outfile); + return 0; }