From f66c1b26cc444dd38d0db421e1ad294c2b292135 Mon Sep 17 00:00:00 2001 From: AnalogMan151 Date: Wed, 24 Jul 2019 09:36:05 -0400 Subject: [PATCH 01/11] Fixed compile warnings Fixed compile warnings, updated gitignore. --- .gitignore | 5 +++++ main.c | 2 +- sha1.c | 2 +- sha1.h | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d31fe79 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ + +aes.o +main.o +sha1.o +vita-mcr2vmp.exe diff --git a/main.c b/main.c index c1c2ace..9561579 100644 --- a/main.c +++ b/main.c @@ -39,7 +39,7 @@ static void usage(char *argv[]) } -int main(int argc, const char **argv) +int main(int argc, char **argv) { if (argc != 2) { usage(argv); diff --git a/sha1.c b/sha1.c index c2bf174..75fd1af 100644 --- a/sha1.c +++ b/sha1.c @@ -282,7 +282,7 @@ void SHA1Final( void SHA1( char *hash_out, const char *str, - int len) + unsigned int len) { SHA1_CTX ctx; unsigned int ii; diff --git a/sha1.h b/sha1.h index 96bb008..c406d2a 100644 --- a/sha1.h +++ b/sha1.h @@ -39,6 +39,6 @@ void SHA1Final( void SHA1( char *hash_out, const char *str, - int len); + unsigned int len); #endif /* SHA1_H */ From cce3b65909e85cba4ce8d557997289019324abfb Mon Sep 17 00:00:00 2001 From: AnalogMan151 Date: Wed, 24 Jul 2019 10:17:13 -0400 Subject: [PATCH 02/11] Added MAGIC check for input file FCheck input file MAGIC before processing. Some formatting fixes. Added success message. --- main.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index 9561579..2a4d3d8 100644 --- a/main.c +++ b/main.c @@ -22,12 +22,11 @@ uint8_t iv[0x10] = {0xB3, 0x0F, 0xFE, 0xED, 0xB7, 0xDC, 0x5E, 0xB7, 0x13, 0x3D, #define PMV_MAGIC 0x564D5000 #define FILE_SZ 0x20080 - void XorWithByte(uint8_t* buf, uint8_t byte, int length) +void XorWithByte(uint8_t* buf, uint8_t byte, int length) { - for (int i = 0; i < length; ++i) - { - buf[i] ^= byte; - } + for (int i = 0; i < length; ++i) { + buf[i] ^= byte; + } } @@ -46,12 +45,25 @@ int main(int argc, char **argv) return 1; } FILE *fin, *fout; + char magic[4] = {0x4D, 0x43, 0x00, 0x00}; + char buf[4]; fin = fopen(argv[1], "rb"); if (!fin) { perror("Failed to open input file"); goto error; } + // Check MAGIC + fseek(fin, 0, SEEK_SET); + fread(buf, 1, 4, fin); + if (memcmp(buf, magic, 4) != 0) { + perror("File is not a MCR!"); + goto error; + } + + // Passes check, writes MCR with signed VMP header + fseek(fin, 0, SEEK_SET); + size_t sz = FILE_SZ; uint8_t *input = (unsigned char*) calloc (1, sz); uint32_t *input_ptr = (uint32_t*) input; @@ -59,7 +71,7 @@ int main(int argc, char **argv) input_ptr[1] = MCR_OFFSET; fseek(fin, 0, SEEK_SET); - fread(input + MCR_OFFSET,sz,1,fin); + fread(input + MCR_OFFSET, sz, 1, fin); struct AES_ctx aes_ctx; AES_init_ctx_iv(&aes_ctx, key, iv); @@ -128,6 +140,7 @@ int main(int argc, char **argv) goto error; } fwrite(input, 1, FILE_SZ, fout); + printf("VMP created successfully.\n"); error: if (fin) fclose(fin); From f31349f65aba175247b317495d3862a11600e6cb Mon Sep 17 00:00:00 2001 From: AnalogMan151 Date: Wed, 24 Jul 2019 11:21:51 -0400 Subject: [PATCH 03/11] Added MCR export ability. Updated Usage, ReadME, and added ability to export MCR if provided a VMP file. --- README.md | 24 +++++--- main.c | 175 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 120 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index 8428703..a9a25b8 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,25 @@ # vita-mcr2vmp -by @dots_tb - signs psx mcr files for use with the vita's psp emulator +by [@dots_tb](https://github.com/dots-tb) - signs PSOne MCR files to create VMP files for use with Sony Vita/PSP With help from the CBPS (https://discord.gg/2nDCbxJ) , especially: - - @AnalogMan151 - - @teakhanirons + [@AnalogMan151](https://github.com/AnalogMan151) + [@teakhanirons](https://github.com/teakhanirons) ## Usage: -Drag and drop a PSX MCR save file onto the exe. It will generate a VMP that you may use with your Vita's PSP emulator. +Drag and drop a PSOne MCR save file onto the program. It will generate a VMP that you may use with your Vita/PSP. +You may also drag and drop a VMP file and extract the contained MCR file for editing or sharing. Or use CMD: - ./vita-mcr2vmp mem.mcr + ./vita-mcr2vmp + +## Further Instructions: + +### I wanna edit my PSX Save Data from the vita! + + 1. Grab your save data from here: ux0:/pspemu/PSP/SAVEDATA//SCEVMC<0|1>.VMP + 2. Open your save data on the computer with a hexeditor and delete the first 0x80, this will convert it to an MCR. + 3. Save it as .MCR. + 4. You may now use it with your save editor or emulators(I think) of choice. + 5. Follow the USAGE section to convert it back to a VMP. Make sure you place it back to the same location with the same file name. + 6. ENJOY! \ No newline at end of file diff --git a/main.c b/main.c index 2a4d3d8..ecdd21d 100644 --- a/main.c +++ b/main.c @@ -7,6 +7,7 @@ #include #include #include +#include #define CBC 1 @@ -21,6 +22,7 @@ uint8_t iv[0x10] = {0xB3, 0x0F, 0xFE, 0xED, 0xB7, 0xDC, 0x5E, 0xB7, 0x13, 0x3D, #define MCR_OFFSET 0x80 #define PMV_MAGIC 0x564D5000 #define FILE_SZ 0x20080 +#define MC_SZ 0x20000 void XorWithByte(uint8_t* buf, uint8_t byte, int length) { @@ -32,115 +34,144 @@ void XorWithByte(uint8_t* buf, uint8_t byte, int length) static void usage(char *argv[]) { - printf("vita-mcr2vmp by @dots_tb\n"); - printf("With CBPS help especially: Analog Man and @teakhanirons\n"); - printf("%s memorycard.mcr",argv[0]); + printf("\nvita-mcr2vmp by @dots_tb\nWith CBPS help especially: @AnalogMan151 and @teakhanirons\n"); + printf("Converts PSOne MCRs into signed VMPs for use on PSP/Vita and also\n"); + printf("extracts MCR files from Sony's PSP VMP save file format.\n\n"); + printf("Usage: %s \n",argv[0]); } int main(int argc, char **argv) { + printf("\n=====Vita MCR2VMP by @dots_tb=====\n\n"); if (argc != 2) { usage(argv); return 1; } + FILE *fin, *fout; - char magic[4] = {0x4D, 0x43, 0x00, 0x00}; + char mc_magic[4] = {0x4D, 0x43, 0x00, 0x00}; + char vmp_magic[4] = {0x00, 0x50, 0x4D, 0x56}; char buf[4]; + bool mcr, vmp = false; fin = fopen(argv[1], "rb"); if (!fin) { perror("Failed to open input file"); goto error; } - + // Check MAGIC fseek(fin, 0, SEEK_SET); fread(buf, 1, 4, fin); - if (memcmp(buf, magic, 4) != 0) { - perror("File is not a MCR!"); + if (memcmp(buf, mc_magic, 4) == 0) { + mcr = true; + } else if (memcmp(buf, vmp_magic, 4) == 0) { + vmp = true; + } else { + perror("File is not supported"); + usage(argv); goto error; } - // Passes check, writes MCR with signed VMP header - fseek(fin, 0, SEEK_SET); - - size_t sz = FILE_SZ; - uint8_t *input = (unsigned char*) calloc (1, sz); - uint32_t *input_ptr = (uint32_t*) input; - input_ptr[0] = PMV_MAGIC; - input_ptr[1] = MCR_OFFSET; - - fseek(fin, 0, SEEK_SET); - fread(input + MCR_OFFSET, sz, 1, fin); - - struct AES_ctx aes_ctx; - AES_init_ctx_iv(&aes_ctx, key, iv); - + // Passes check, strips VMP header and writes MCR + if (vmp) { + char mcbuf[0x20000]; + fseek(fin, MCR_OFFSET, SEEK_SET); + fread(mcbuf, 1, MC_SZ, fin); + fclose(fin); + char output_path[128]; + sprintf(output_path,"%s.mcr",argv[1]); + fout = fopen(output_path, "wb"); + if (!fout) { + perror("Failed to open output file"); + goto error; + } + fwrite(mcbuf, 1, 0x20000, fout); + printf("MCR file successfully extracted.\n"); + } - uint8_t salt[0x40]; - uint8_t work_buf[0x14]; - - uint8_t *salt_seed = input + SEED_OFFSET; - - memcpy(work_buf, salt_seed, 0x10); - AES_ECB_decrypt(&aes_ctx, work_buf); - memcpy(salt, work_buf, 0x10); + // Passes check, writes MCR with signed VMP header + if (mcr) { + fseek(fin, 0, SEEK_SET); + + size_t sz = FILE_SZ; + uint8_t *input = (unsigned char*) calloc (1, sz); + uint32_t *input_ptr = (uint32_t*) input; + input_ptr[0] = PMV_MAGIC; + input_ptr[1] = MCR_OFFSET; + + fseek(fin, 0, SEEK_SET); + fread(input + MCR_OFFSET, sz, 1, fin); + + struct AES_ctx aes_ctx; + AES_init_ctx_iv(&aes_ctx, key, iv); + - memcpy(work_buf, salt_seed, 0x10); - AES_ECB_encrypt(&aes_ctx, work_buf); - memcpy(salt + 0x10, work_buf, 0x10); + uint8_t salt[0x40]; + uint8_t work_buf[0x14]; + + uint8_t *salt_seed = input + SEED_OFFSET; + + memcpy(work_buf, salt_seed, 0x10); + AES_ECB_decrypt(&aes_ctx, work_buf); + memcpy(salt, work_buf, 0x10); - - XorWithIv(salt, iv); - - memset(work_buf, 0xFF, sizeof(work_buf)); - memcpy(work_buf, salt_seed + 0x10, 0x4); - XorWithIv(salt + 0x10, work_buf); + memcpy(work_buf, salt_seed, 0x10); + AES_ECB_encrypt(&aes_ctx, work_buf); + memcpy(salt + 0x10, work_buf, 0x10); - - memset(salt + 0x14, 0, sizeof(salt) - 0x14); - XorWithByte(salt, 0x36, 0x40); - - SHA1_CTX sha1_ctx_1; - SHA1Init(&sha1_ctx_1); - + + XorWithIv(salt, iv); + + memset(work_buf, 0xFF, sizeof(work_buf)); + memcpy(work_buf, salt_seed + 0x10, 0x4); + XorWithIv(salt + 0x10, work_buf); + + memset(salt + 0x14, 0, sizeof(salt) - 0x14); + XorWithByte(salt, 0x36, 0x40); + + SHA1_CTX sha1_ctx_1; + SHA1Init(&sha1_ctx_1); - SHA1Update( &sha1_ctx_1, salt, 0x40); - - memset(input + 0x20, 0, 0x14); - SHA1Update( &sha1_ctx_1, input, sz); + SHA1Update( &sha1_ctx_1, salt, 0x40); + - XorWithByte(salt, 0x6A, 0x40); + memset(input + 0x20, 0, 0x14); + SHA1Update( &sha1_ctx_1, input, sz); + + + XorWithByte(salt, 0x6A, 0x40); - SHA1Final(work_buf, &sha1_ctx_1); + SHA1Final(work_buf, &sha1_ctx_1); - SHA1_CTX sha1_ctx_2; - SHA1Init(&sha1_ctx_2); - SHA1Update( &sha1_ctx_2, salt, 0x40); - SHA1Update( &sha1_ctx_2, work_buf, 0x14); + SHA1_CTX sha1_ctx_2; + SHA1Init(&sha1_ctx_2); + SHA1Update( &sha1_ctx_2, salt, 0x40); + SHA1Update( &sha1_ctx_2, work_buf, 0x14); - SHA1Final(input + HASH_OFFSET, &sha1_ctx_2); - - printf("Generated key: "); - for(int i = 0; i < 0x14; i++ ) { - printf("%02x ", work_buf[i]); - } - printf("\n"); - - char output_path[128]; - sprintf(output_path,"%s.vmp",argv[1]); - fout = fopen(output_path, "wb"); - if (!fout) { - perror("Failed to open output file"); - goto error; + SHA1Final(input + HASH_OFFSET, &sha1_ctx_2); + + printf("Generated key: "); + for(int i = 0; i < 0x14; i++ ) { + printf("%02x ", work_buf[i]); + } + printf("\n"); + + char output_path[128]; + sprintf(output_path,"%s.VMP",argv[1]); + fout = fopen(output_path, "wb"); + if (!fout) { + perror("Failed to open output file"); + goto error; + } + fwrite(input, 1, FILE_SZ, fout); + printf("VMP created successfully.\n"); } - fwrite(input, 1, FILE_SZ, fout); - printf("VMP created successfully.\n"); error: if (fin) fclose(fin); From 40b1dee0906a6d9541541d249cec8341c9df66dd Mon Sep 17 00:00:00 2001 From: AnalogMan151 Date: Wed, 24 Jul 2019 11:25:04 -0400 Subject: [PATCH 04/11] Fixed output of calculated SHA1 HMAC --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index ecdd21d..f01532a 100644 --- a/main.c +++ b/main.c @@ -158,7 +158,7 @@ int main(int argc, char **argv) printf("Generated key: "); for(int i = 0; i < 0x14; i++ ) { - printf("%02x ", work_buf[i]); + printf("%02X ", input[HASH_OFFSET + i]); } printf("\n"); From 966f55b9e0ec448f474d5a7b1f29e646170f5dba Mon Sep 17 00:00:00 2001 From: AnalogMan151 Date: Wed, 24 Jul 2019 11:26:21 -0400 Subject: [PATCH 05/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9a25b8..4018afc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # vita-mcr2vmp -by [@dots_tb](https://github.com/dots-tb) - signs PSOne MCR files to create VMP files for use with Sony Vita/PSP +by [@dots_tb](https://github.com/dots-tb) - signs PSOne MCR files to create VMP files for use with Sony Vita/PSP and exports MCR files from VMP With help from the CBPS (https://discord.gg/2nDCbxJ) , especially: [@AnalogMan151](https://github.com/AnalogMan151) From aa6aefe96a6acf15558a2d5f65923644fbc4ace4 Mon Sep 17 00:00:00 2001 From: AnalogMan151 Date: Wed, 24 Jul 2019 11:28:15 -0400 Subject: [PATCH 06/11] Update README.md --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4018afc..1c02867 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,7 @@ Or use CMD: ### I wanna edit my PSX Save Data from the vita! 1. Grab your save data from here: ux0:/pspemu/PSP/SAVEDATA//SCEVMC<0|1>.VMP - 2. Open your save data on the computer with a hexeditor and delete the first 0x80, this will convert it to an MCR. - 3. Save it as .MCR. - 4. You may now use it with your save editor or emulators(I think) of choice. - 5. Follow the USAGE section to convert it back to a VMP. Make sure you place it back to the same location with the same file name. - 6. ENJOY! \ No newline at end of file + 2. Run VMP file through program to export MCR. + 3. You may now use it with your save editor or emulators of choice. + 4. Follow the USAGE section to convert it back to a VMP. Make sure you place it back to the same location with the same file name. + 5. ENJOY! \ No newline at end of file From 3e9ddb28b246ddad95e446fa9e68fdb65d4f1bce Mon Sep 17 00:00:00 2001 From: AnalogMan151 Date: Wed, 24 Jul 2019 11:29:33 -0400 Subject: [PATCH 07/11] Update .gitignore --- .gitignore | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d31fe79..9e933fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ - -aes.o -main.o -sha1.o -vita-mcr2vmp.exe +*.o +vita-mcr2vmp* From dceea990045242c7ca9ca721d98893ccf0f12c00 Mon Sep 17 00:00:00 2001 From: AnalogMan151 Date: Wed, 24 Jul 2019 12:09:15 -0400 Subject: [PATCH 08/11] Updated Makefile and project folder structure. Plus some formatting fixes. --- .gitignore | 4 +-- Makefile | 49 +++++++++++++++++++++++-------------- aes.h => include/aes.h | 0 sha1.h => include/sha1.h | 0 aes.c => src/aes.c | 0 main.c => src/main.c | 53 ++++++++++++++-------------------------- sha1.c => src/sha1.c | 0 7 files changed, 52 insertions(+), 54 deletions(-) rename aes.h => include/aes.h (100%) rename sha1.h => include/sha1.h (100%) rename aes.c => src/aes.c (100%) rename main.c => src/main.c (83%) rename sha1.c => src/sha1.c (100%) diff --git a/.gitignore b/.gitignore index 9e933fa..5acb669 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -*.o -vita-mcr2vmp* +build +.vscode diff --git a/Makefile b/Makefile index fbd4bd0..dabb3fd 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,41 @@ -TARGET = vita-mcr2vmp +TARGET_EXEC ?= vita-mcr2vmp -OBJS = aes.o main.o sha1.o +BUILD_DIR ?= ./build +SRC_DIRS ?= ./src ./include +SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s) +OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) +DEPS := $(OBJS:.o=.d) -LIBS = -lz +INC_DIRS := $(shell find $(SRC_DIRS) -type d) +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) -CFLAGS = -s -static -Wall -Wextra -std=c99 -all: $(TARGET) +CPPFLAGS ?= $(INC_FLAGS) -s -static -Wall -Wextra -std=c99 -$(TARGET): $(OBJS) - @echo "Creating binary $(TARGET)" - $(CXX) $(OBJS) -o $@ $(LIBS) -static -static-libgcc +$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) + $(CC) $(OBJS) -o $@ $(LDFLAGS) -%.o: %.cpp - @echo "Compiling $^" - $(CXX) $(CFLAGS) -c $^ -o $@ -static -static-libgcc +# assembly +$(BUILD_DIR)/%.s.o: %.s + $(MKDIR_P) $(dir $@) + $(AS) $(ASFLAGS) -c $< -o $@ + +# c source +$(BUILD_DIR)/%.c.o: %.c + $(MKDIR_P) $(dir $@) + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ + +# c++ source +$(BUILD_DIR)/%.cpp.o: %.cpp + $(MKDIR_P) $(dir $@) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ + + +.PHONY: clean clean: - @echo "Removing all the .o files" - @$(RM) $(OBJS) + $(RM) -r $(BUILD_DIR) -mrproper: clean - @echo "Removing binary" - @$(RM) $(TARGET) +-include $(DEPS) -install: all - @cp $(TARGET) ../bin +MKDIR_P ?= mkdir -p \ No newline at end of file diff --git a/aes.h b/include/aes.h similarity index 100% rename from aes.h rename to include/aes.h diff --git a/sha1.h b/include/sha1.h similarity index 100% rename from sha1.h rename to include/sha1.h diff --git a/aes.c b/src/aes.c similarity index 100% rename from aes.c rename to src/aes.c diff --git a/main.c b/src/main.c similarity index 83% rename from main.c rename to src/main.c index f01532a..07fdef5 100644 --- a/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ -//vita-mcr2vmp by @dots_tb - signs psx mcr files for use with the vita's psp emulator +//vita-mcr2vmp by @dots_tb - signs PSOne MCR files to create VMP files for use with Sony Vita/PSP and exports MCR files from VMP //With help from the CBPS (https://discord.gg/2nDCbxJ) , especially: -// Analog Man +// @AnalogMan151 // @teakhanirons #include @@ -9,8 +9,6 @@ #include #include -#define CBC 1 - #include "aes.h" #include "sha1.h" @@ -21,7 +19,7 @@ uint8_t iv[0x10] = {0xB3, 0x0F, 0xFE, 0xED, 0xB7, 0xDC, 0x5E, 0xB7, 0x13, 0x3D, #define HASH_OFFSET 0x20 #define MCR_OFFSET 0x80 #define PMV_MAGIC 0x564D5000 -#define FILE_SZ 0x20080 +#define VMP_SZ 0x20080 #define MC_SZ 0x20000 void XorWithByte(uint8_t* buf, uint8_t byte, int length) @@ -31,7 +29,6 @@ void XorWithByte(uint8_t* buf, uint8_t byte, int length) } } - static void usage(char *argv[]) { printf("\nvita-mcr2vmp by @dots_tb\nWith CBPS help especially: @AnalogMan151 and @teakhanirons\n"); @@ -40,7 +37,6 @@ static void usage(char *argv[]) printf("Usage: %s \n",argv[0]); } - int main(int argc, char **argv) { printf("\n=====Vita MCR2VMP by @dots_tb=====\n\n"); @@ -52,7 +48,7 @@ int main(int argc, char **argv) FILE *fin, *fout; char mc_magic[4] = {0x4D, 0x43, 0x00, 0x00}; char vmp_magic[4] = {0x00, 0x50, 0x4D, 0x56}; - char buf[4]; + char magic_buf[4]; bool mcr, vmp = false; fin = fopen(argv[1], "rb"); if (!fin) { @@ -62,10 +58,10 @@ int main(int argc, char **argv) // Check MAGIC fseek(fin, 0, SEEK_SET); - fread(buf, 1, 4, fin); - if (memcmp(buf, mc_magic, 4) == 0) { + fread(magic_buf, 1, 4, fin); + if (memcmp(magic_buf, mc_magic, 4) == 0) { mcr = true; - } else if (memcmp(buf, vmp_magic, 4) == 0) { + } else if (memcmp(magic_buf, vmp_magic, 4) == 0) { vmp = true; } else { perror("File is not supported"); @@ -75,7 +71,7 @@ int main(int argc, char **argv) // Passes check, strips VMP header and writes MCR if (vmp) { - char mcbuf[0x20000]; + char mcbuf[MC_SZ]; fseek(fin, MCR_OFFSET, SEEK_SET); fread(mcbuf, 1, MC_SZ, fin); fclose(fin); @@ -86,27 +82,23 @@ int main(int argc, char **argv) perror("Failed to open output file"); goto error; } - fwrite(mcbuf, 1, 0x20000, fout); + fwrite(mcbuf, 1, MC_SZ, fout); printf("MCR file successfully extracted.\n"); } // Passes check, writes MCR with signed VMP header if (mcr) { - fseek(fin, 0, SEEK_SET); - - size_t sz = FILE_SZ; - uint8_t *input = (unsigned char*) calloc (1, sz); + uint8_t *input = (unsigned char*) calloc (1, VMP_SZ); uint32_t *input_ptr = (uint32_t*) input; input_ptr[0] = PMV_MAGIC; input_ptr[1] = MCR_OFFSET; fseek(fin, 0, SEEK_SET); - fread(input + MCR_OFFSET, sz, 1, fin); + fread(input + MCR_OFFSET, MC_SZ, 1, fin); struct AES_ctx aes_ctx; AES_init_ctx_iv(&aes_ctx, key, iv); - uint8_t salt[0x40]; uint8_t work_buf[0x14]; @@ -120,39 +112,31 @@ int main(int argc, char **argv) AES_ECB_encrypt(&aes_ctx, work_buf); memcpy(salt + 0x10, work_buf, 0x10); - XorWithIv(salt, iv); memset(work_buf, 0xFF, sizeof(work_buf)); memcpy(work_buf, salt_seed + 0x10, 0x4); XorWithIv(salt + 0x10, work_buf); - memset(salt + 0x14, 0, sizeof(salt) - 0x14); XorWithByte(salt, 0x36, 0x40); SHA1_CTX sha1_ctx_1; SHA1Init(&sha1_ctx_1); + SHA1Update(&sha1_ctx_1, salt, 0x40); - - SHA1Update( &sha1_ctx_1, salt, 0x40); - - memset(input + 0x20, 0, 0x14); - SHA1Update( &sha1_ctx_1, input, sz); - - + SHA1Update(&sha1_ctx_1, input, VMP_SZ); + XorWithByte(salt, 0x6A, 0x40); SHA1Final(work_buf, &sha1_ctx_1); SHA1_CTX sha1_ctx_2; SHA1Init(&sha1_ctx_2); - SHA1Update( &sha1_ctx_2, salt, 0x40); - SHA1Update( &sha1_ctx_2, work_buf, 0x14); - - + SHA1Update(&sha1_ctx_2, salt, 0x40); + SHA1Update(&sha1_ctx_2, work_buf, 0x14); SHA1Final(input + HASH_OFFSET, &sha1_ctx_2); @@ -169,14 +153,15 @@ int main(int argc, char **argv) perror("Failed to open output file"); goto error; } - fwrite(input, 1, FILE_SZ, fout); + fwrite(input, 1, VMP_SZ, fout); printf("VMP created successfully.\n"); } + error: if (fin) fclose(fin); if (fout) fclose(fout); - exit(0); + return 0; } diff --git a/sha1.c b/src/sha1.c similarity index 100% rename from sha1.c rename to src/sha1.c From c72f97fae69851ae8f715a362717cc10de51d488 Mon Sep 17 00:00:00 2001 From: AnalogMan151 Date: Wed, 24 Jul 2019 12:16:04 -0400 Subject: [PATCH 09/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a9313e..ac312c2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Drag and drop a PSOne MCR save file onto the program. It will generate a VMP tha You may also drag and drop a VMP file and extract the contained MCR file for editing or sharing. Or use CMD: - ./vita-mcr2vmp mem.mcr + ./vita-mcr2vmp ## Further Instructions: From 400f8db723fa3c0090f30ed5be44c46934134e88 Mon Sep 17 00:00:00 2001 From: AnalogMan151 Date: Wed, 24 Jul 2019 12:30:53 -0400 Subject: [PATCH 10/11] Replaced set value with define Freed input for good practice. --- src/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 07fdef5..93c5995 100644 --- a/src/main.c +++ b/src/main.c @@ -126,7 +126,7 @@ int main(int argc, char **argv) SHA1Update(&sha1_ctx_1, salt, 0x40); - memset(input + 0x20, 0, 0x14); + memset(input + HASH_OFFSET, 0, 0x14); SHA1Update(&sha1_ctx_1, input, VMP_SZ); XorWithByte(salt, 0x6A, 0x40); @@ -154,6 +154,7 @@ int main(int argc, char **argv) goto error; } fwrite(input, 1, VMP_SZ, fout); + free(input); printf("VMP created successfully.\n"); } From 5afe2455ed6cbf1d6bfbc3d154dba2dbaeeceb5f Mon Sep 17 00:00:00 2001 From: AnalogMan151 Date: Wed, 24 Jul 2019 12:37:52 -0400 Subject: [PATCH 11/11] Update Makefile --- Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index dabb3fd..e1da464 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,14 @@ -TARGET_EXEC ?= vita-mcr2vmp +ifeq ($(OS),Windows_NT) + TARGET_EXEC ?= vita-mcr2vmp-win +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + TARGET_EXEC ?= vita-mcr2vmp-linux + endif + ifeq ($(UNAME_S),Darwin) + TARGET_EXEC ?= vita-mcr2vmp-macos + endif +endif BUILD_DIR ?= ./build SRC_DIRS ?= ./src ./include