From 2060f026366c0242730ad0b3ec5c6e26ac6edae4 Mon Sep 17 00:00:00 2001 From: mpm11011 Date: Fri, 18 Mar 2016 23:14:52 -0400 Subject: [PATCH 1/5] End of Line Normalization --- .gitattributes | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..c08ac139ed --- /dev/null +++ b/.gitattributes @@ -0,0 +1,24 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Source files +*.c text +*.cpp text +*.h text + +# Windows CRLF files + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain From 23f03a19e8794c3d00fb772c0b6d5639371cf277 Mon Sep 17 00:00:00 2001 From: mpm11011 Date: Fri, 18 Mar 2016 23:33:17 -0400 Subject: [PATCH 2/5] Added zlib directory to include dirs in props --- rpcs3_default.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpcs3_default.props b/rpcs3_default.props index f2039b1838..3361d6d67c 100644 --- a/rpcs3_default.props +++ b/rpcs3_default.props @@ -3,7 +3,7 @@ - .\;..\;..\asmjit\src\asmjit;..\wxWidgets\include\msvc;..\wxWidgets\include;..\ffmpeg\WindowsInclude;..\ffmpeg\Windows\x86_64\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);$(UniversalCRT_IncludePath);..\minidx12\Include;..\glm;..\GSL\include;..\libpng + .\;..\;..\asmjit\src\asmjit;..\wxWidgets\include\msvc;..\wxWidgets\include;..\wxWidgets\src\zlib;..\ffmpeg\WindowsInclude;..\ffmpeg\Windows\x86_64\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);$(UniversalCRT_IncludePath);..\minidx12\Include;..\glm;..\GSL\include;..\libpng $(SolutionDir)lib\$(Configuration)-$(Platform)\ $(SolutionDir)lib\$(Configuration)-$(Platform)\;$(UniversalCRT_LibraryPath_x64);$(LibraryPath) $(SolutionDir)tmp\$(ProjectName)-$(Configuration)-$(Platform)\ From e7fc5228d592822ab32722301418ed74660b710a Mon Sep 17 00:00:00 2001 From: mpm11011 Date: Fri, 18 Mar 2016 23:36:08 -0400 Subject: [PATCH 3/5] MakeELF: Replaced wx streams with zlib functions --- rpcs3/Crypto/unself.cpp | 50 ++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/rpcs3/Crypto/unself.cpp b/rpcs3/Crypto/unself.cpp index c31d4af460..6cb45691de 100644 --- a/rpcs3/Crypto/unself.cpp +++ b/rpcs3/Crypto/unself.cpp @@ -5,10 +5,12 @@ #include "Emu/FS/vfsLocalFile.h" #include "unself.h" #pragma warning(push) -#pragma message("TODO: remove wx dependencies: ") +#pragma message("TODO: remove wx dependencies: See comment below.") #pragma warning(disable : 4996) -#include -#include + +// TODO: Still reliant on wxWidgets for zlib functions. Alternative solutions? +#include + #pragma warning(pop) force_inline u8 Read8(vfsStream& f) @@ -1150,29 +1152,37 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32) // Decompress if necessary. if (meta_shdr[i].compressed == 2) { - // Allocate a buffer for decompression. - u8 *decomp_buf = (u8 *)malloc(phdr64_arr[meta_shdr[i].program_idx].p_filesz); + /// Removed all wxWidget dependent code. Replaced with zlib functions. + /// Also changed local mallocs to unique_ptrs. - // Set up memory streams for input/output. - wxMemoryInputStream decomp_stream_in(data_buf + data_buf_offset, meta_shdr[i].data_size); - wxMemoryOutputStream decomp_stream_out; + // Store the length in writeable memory space. + std::unique_ptr decomp_buf_length(new uLongf); + memcpy(decomp_buf_length.get(), &phdr64_arr[meta_shdr[i].program_idx].p_filesz, sizeof(uLongf)); - // Create a Zlib stream, read the data and flush the stream. - wxZlibInputStream* z_stream = new wxZlibInputStream(decomp_stream_in); - z_stream->Read(decomp_stream_out); - delete z_stream; + /// Create a pointer to a buffer for decompression. + std::unique_ptr decomp_buf(new u8[phdr64_arr[meta_shdr[i].program_idx].p_filesz]); - // Copy the decompressed result from the stream. - decomp_stream_out.CopyTo(decomp_buf, phdr64_arr[meta_shdr[i].program_idx].p_filesz); + // Create a buffer separate from data_buf to uncompress. + std::unique_ptr zlib_buf(new u8[data_buf_length]); + memcpy(zlib_buf.get(), data_buf, data_buf_length); + + // Use zlib uncompress on the new buffer. + // decomp_buf_length changes inside the call to uncompress, so it must be a pointer to correct type (in writeable mem space). + int rv = uncompress(decomp_buf.get(), decomp_buf_length.get(), zlib_buf.get() + data_buf_offset, data_buf_length); + + // Check for errors (TODO: Probably safe to remove this once these changes have passed testing.) + switch (rv) + { + case Z_MEM_ERROR: LOG_ERROR(LOADER, "MakeELF encountered a Z_MEM_ERROR!"); break; + case Z_BUF_ERROR: LOG_ERROR(LOADER, "MakeELF encountered a Z_BUF_ERROR!"); break; + case Z_DATA_ERROR: LOG_ERROR(LOADER, "MakeELF encountered a Z_DATA_ERROR!"); break; + default: break; + } // Seek to the program header data offset and write the data. - CHECK_ASSERTION(e.seek(phdr64_arr[meta_shdr[i].program_idx].p_offset) != -1); + e.write(decomp_buf.get(), phdr64_arr[meta_shdr[i].program_idx].p_filesz); - e.write(decomp_buf, phdr64_arr[meta_shdr[i].program_idx].p_filesz); - - // Release the decompression buffer. - free(decomp_buf); } else { @@ -1316,7 +1326,7 @@ bool CheckDebugSelf(const std::string& self, const std::string& elf) // Copy the data. char buf[2048]; - while (ssize_t size = s.read(buf, 2048)) + while (size_t size = s.read(buf, 2048)) // Did size need to be of type ssize_t? { e.write(buf, size); } From 6adf086ed15a938d42da0321710649ac5e7331b9 Mon Sep 17 00:00:00 2001 From: mpm11011 Date: Sat, 19 Mar 2016 10:49:40 -0400 Subject: [PATCH 4/5] Adding zlib to rpcs3/CMakeLists.txt Fix zlib location in cmakelists Potential fix to zlib include dir(s) --- rpcs3/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/rpcs3/CMakeLists.txt b/rpcs3/CMakeLists.txt index e6fc5c5639..9eff077212 100644 --- a/rpcs3/CMakeLists.txt +++ b/rpcs3/CMakeLists.txt @@ -103,6 +103,7 @@ endif() include_directories( ${GLEW_INCLUDE_DIR} ${wxWidgets_INCLUDE_DIRS} +${ZLIB_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR} ${LLVM_INCLUDE_DIRS} "${RPCS3_SRC_DIR}/../ffmpeg/${PLATFORM_ARCH}/include" From 617a488a0a775b4b433fc89fc79f2ee909f60477 Mon Sep 17 00:00:00 2001 From: mpm11011 Date: Sat, 19 Mar 2016 21:48:56 -0400 Subject: [PATCH 5/5] Change size to u64 --- rpcs3/Crypto/unself.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpcs3/Crypto/unself.cpp b/rpcs3/Crypto/unself.cpp index 6cb45691de..a6390c7ac5 100644 --- a/rpcs3/Crypto/unself.cpp +++ b/rpcs3/Crypto/unself.cpp @@ -1326,7 +1326,7 @@ bool CheckDebugSelf(const std::string& self, const std::string& elf) // Copy the data. char buf[2048]; - while (size_t size = s.read(buf, 2048)) // Did size need to be of type ssize_t? + while (u64 size = s.read(buf, 2048)) // read returns u64. { e.write(buf, size); }