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 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" diff --git a/rpcs3/Crypto/unself.cpp b/rpcs3/Crypto/unself.cpp index c31d4af460..a6390c7ac5 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 (u64 size = s.read(buf, 2048)) // read returns u64. { e.write(buf, size); } 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)\