mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-08-02 22:30:39 +00:00
MakeELF: Replaced wx streams with zlib functions
This commit is contained in:
parent
23f03a19e8
commit
e7fc5228d5
1 changed files with 30 additions and 20 deletions
|
@ -5,10 +5,12 @@
|
||||||
#include "Emu/FS/vfsLocalFile.h"
|
#include "Emu/FS/vfsLocalFile.h"
|
||||||
#include "unself.h"
|
#include "unself.h"
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma message("TODO: remove wx dependencies: <wx/mstream.h> <wx/zstream.h>")
|
#pragma message("TODO: remove wx dependencies: See comment below.")
|
||||||
#pragma warning(disable : 4996)
|
#pragma warning(disable : 4996)
|
||||||
#include <wx/mstream.h>
|
|
||||||
#include <wx/zstream.h>
|
// TODO: Still reliant on wxWidgets for zlib functions. Alternative solutions?
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
||||||
force_inline u8 Read8(vfsStream& f)
|
force_inline u8 Read8(vfsStream& f)
|
||||||
|
@ -1150,29 +1152,37 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
|
||||||
// Decompress if necessary.
|
// Decompress if necessary.
|
||||||
if (meta_shdr[i].compressed == 2)
|
if (meta_shdr[i].compressed == 2)
|
||||||
{
|
{
|
||||||
// Allocate a buffer for decompression.
|
/// Removed all wxWidget dependent code. Replaced with zlib functions.
|
||||||
u8 *decomp_buf = (u8 *)malloc(phdr64_arr[meta_shdr[i].program_idx].p_filesz);
|
/// Also changed local mallocs to unique_ptrs.
|
||||||
|
|
||||||
// Set up memory streams for input/output.
|
// Store the length in writeable memory space.
|
||||||
wxMemoryInputStream decomp_stream_in(data_buf + data_buf_offset, meta_shdr[i].data_size);
|
std::unique_ptr<uLongf> decomp_buf_length(new uLongf);
|
||||||
wxMemoryOutputStream decomp_stream_out;
|
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.
|
/// Create a pointer to a buffer for decompression.
|
||||||
wxZlibInputStream* z_stream = new wxZlibInputStream(decomp_stream_in);
|
std::unique_ptr<u8[]> decomp_buf(new u8[phdr64_arr[meta_shdr[i].program_idx].p_filesz]);
|
||||||
z_stream->Read(decomp_stream_out);
|
|
||||||
delete z_stream;
|
|
||||||
|
|
||||||
// Copy the decompressed result from the stream.
|
// Create a buffer separate from data_buf to uncompress.
|
||||||
decomp_stream_out.CopyTo(decomp_buf, phdr64_arr[meta_shdr[i].program_idx].p_filesz);
|
std::unique_ptr<u8[]> 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.
|
// 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);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -1316,7 +1326,7 @@ bool CheckDebugSelf(const std::string& self, const std::string& elf)
|
||||||
|
|
||||||
// Copy the data.
|
// Copy the data.
|
||||||
char buf[2048];
|
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);
|
e.write(buf, size);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue