mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-05 14:37:08 +00:00
wxFile removed (rFile -> rfile_t)
This commit is contained in:
parent
2cafa84b75
commit
ab405901ee
43 changed files with 814 additions and 973 deletions
|
|
@ -13,54 +13,63 @@
|
|||
#include "Utilities/rFile.h"
|
||||
|
||||
// Decryption.
|
||||
bool CheckHeader(rFile& pkg_f, PKGHeader* m_header)
|
||||
bool CheckHeader(const rfile_t& pkg_f, PKGHeader* m_header)
|
||||
{
|
||||
if (m_header->pkg_magic != 0x7F504B47) {
|
||||
if (m_header->pkg_magic != 0x7F504B47)
|
||||
{
|
||||
LOG_ERROR(LOADER, "PKG: Not a package file!");
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ((u32)m_header->pkg_type)
|
||||
switch (const u16 type = m_header->pkg_type)
|
||||
{
|
||||
case PKG_RELEASE_TYPE_DEBUG: break;
|
||||
case PKG_RELEASE_TYPE_RELEASE: break;
|
||||
default:
|
||||
LOG_ERROR(LOADER, "PKG: Unknown PKG type!");
|
||||
{
|
||||
LOG_ERROR(LOADER, "PKG: Unknown PKG type (0x%x)", type);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
switch ((u32)m_header->pkg_platform)
|
||||
switch (const u16 platform = m_header->pkg_platform)
|
||||
{
|
||||
case PKG_PLATFORM_TYPE_PS3: break;
|
||||
case PKG_PLATFORM_TYPE_PSP: break;
|
||||
default:
|
||||
LOG_ERROR(LOADER, "PKG: Unknown PKG type!");
|
||||
{
|
||||
LOG_ERROR(LOADER, "PKG: Unknown PKG platform (0x%x)", platform);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_header->header_size != PKG_HEADER_SIZE)
|
||||
{
|
||||
LOG_ERROR(LOADER, "PKG: Wrong header size (0x%x)", m_header->header_size);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_header->header_size != PKG_HEADER_SIZE) {
|
||||
LOG_ERROR(LOADER, "PKG: Wrong header size!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_header->pkg_size != pkg_f.Length()) {
|
||||
LOG_WARNING(LOADER, "PKG: File size mismatch.");
|
||||
if (m_header->pkg_size != pkg_f.size())
|
||||
{
|
||||
LOG_ERROR(LOADER, "PKG: File size mismatch (pkg_size=0x%x)", m_header->pkg_size);
|
||||
//return false;
|
||||
}
|
||||
|
||||
if (m_header->data_size + m_header->data_offset + 0x60 != pkg_f.Length()) {
|
||||
LOG_WARNING(LOADER, "PKG: Data size mismatch.");
|
||||
if (m_header->data_size + m_header->data_offset + 0x60 != pkg_f.size())
|
||||
{
|
||||
LOG_ERROR(LOADER, "PKG: Data size mismatch (data_size=0x%x, offset=0x%x)", m_header->data_size, m_header->data_offset);
|
||||
//return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoadHeader(rFile& pkg_f, PKGHeader* m_header)
|
||||
bool LoadHeader(const rfile_t& pkg_f, PKGHeader* m_header)
|
||||
{
|
||||
pkg_f.Seek(0);
|
||||
pkg_f.seek(0);
|
||||
|
||||
if (pkg_f.Read(m_header, sizeof(PKGHeader)) != sizeof(PKGHeader)) {
|
||||
if (pkg_f.read(m_header, sizeof(PKGHeader)) != sizeof(PKGHeader))
|
||||
{
|
||||
LOG_ERROR(LOADER, "PKG: Package file is too short!");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -71,10 +80,12 @@ bool LoadHeader(rFile& pkg_f, PKGHeader* m_header)
|
|||
return true;
|
||||
}
|
||||
|
||||
int Decrypt(rFile& pkg_f, rFile& dec_pkg_f, PKGHeader* m_header)
|
||||
int Decrypt(const rfile_t& pkg_f, const rfile_t& dec_pkg_f, PKGHeader* m_header)
|
||||
{
|
||||
if (!LoadHeader(pkg_f, m_header))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
aes_context c;
|
||||
u8 iv[HASH_LEN];
|
||||
|
|
@ -89,7 +100,7 @@ int Decrypt(rFile& pkg_f, rFile& dec_pkg_f, PKGHeader* m_header)
|
|||
memcpy(key+0x10, &m_header->qa_digest[8], 8); // &data[0x68]
|
||||
memcpy(key+0x18, &m_header->qa_digest[8], 8); // &data[0x68]
|
||||
|
||||
pkg_f.Seek(m_header->data_offset);
|
||||
pkg_f.seek(m_header->data_offset);
|
||||
u32 parts = (m_header->data_size + BUF_SIZE - 1) / BUF_SIZE;
|
||||
|
||||
wxProgressDialog pdlg("PKG Decrypter / Installer", "Please wait, decrypting...", parts, 0, wxPD_AUTO_HIDE | wxPD_APP_MODAL);
|
||||
|
|
@ -100,7 +111,7 @@ int Decrypt(rFile& pkg_f, rFile& dec_pkg_f, PKGHeader* m_header)
|
|||
for (u32 i=0; i<parts; i++)
|
||||
{
|
||||
memset(buf, 0, sizeof(buf));
|
||||
u32 length = pkg_f.Read(buf, BUF_SIZE);
|
||||
u32 length = pkg_f.read(buf, BUF_SIZE);
|
||||
u32 bits = (length + HASH_LEN - 1) / HASH_LEN;
|
||||
|
||||
if (m_header->pkg_type == PKG_RELEASE_TYPE_DEBUG)
|
||||
|
|
@ -136,7 +147,7 @@ int Decrypt(rFile& pkg_f, rFile& dec_pkg_f, PKGHeader* m_header)
|
|||
buf[j] ^= ctr[j];
|
||||
}
|
||||
}
|
||||
dec_pkg_f.Write(buf, length);
|
||||
dec_pkg_f.write(buf, length);
|
||||
pdlg.Update(i);
|
||||
}
|
||||
pdlg.Update(parts);
|
||||
|
|
@ -144,12 +155,13 @@ int Decrypt(rFile& pkg_f, rFile& dec_pkg_f, PKGHeader* m_header)
|
|||
}
|
||||
|
||||
// Unpacking.
|
||||
bool LoadEntries(rFile& dec_pkg_f, PKGHeader* m_header, PKGEntry *m_entries)
|
||||
bool LoadEntries(const rfile_t& dec_pkg_f, PKGHeader* m_header, PKGEntry* m_entries)
|
||||
{
|
||||
dec_pkg_f.Seek(0);
|
||||
dec_pkg_f.Read(m_entries, sizeof(PKGEntry) * m_header->file_count);
|
||||
dec_pkg_f.seek(0);
|
||||
dec_pkg_f.read(m_entries, sizeof(PKGEntry) * m_header->file_count);
|
||||
|
||||
if (m_entries->name_offset / sizeof(PKGEntry) != m_header->file_count) {
|
||||
if (m_entries->name_offset / sizeof(PKGEntry) != m_header->file_count)
|
||||
{
|
||||
LOG_ERROR(LOADER, "PKG: Entries are damaged!");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -157,12 +169,12 @@ bool LoadEntries(rFile& dec_pkg_f, PKGHeader* m_header, PKGEntry *m_entries)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool UnpackEntry(rFile& dec_pkg_f, const PKGEntry& entry, std::string dir)
|
||||
bool UnpackEntry(const rfile_t& dec_pkg_f, const PKGEntry& entry, std::string dir)
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
|
||||
dec_pkg_f.Seek(entry.name_offset);
|
||||
dec_pkg_f.Read(buf, entry.name_size);
|
||||
dec_pkg_f.seek(entry.name_offset);
|
||||
dec_pkg_f.read(buf, entry.name_size);
|
||||
buf[entry.name_size] = 0;
|
||||
|
||||
switch (entry.type.data() >> 24)
|
||||
|
|
@ -172,30 +184,33 @@ bool UnpackEntry(rFile& dec_pkg_f, const PKGEntry& entry, std::string dir)
|
|||
case PKG_FILE_ENTRY_SDAT:
|
||||
case PKG_FILE_ENTRY_REGULAR:
|
||||
{
|
||||
rFile out;
|
||||
auto path = dir + std::string(buf, entry.name_size);
|
||||
|
||||
if (rExists(path))
|
||||
{
|
||||
LOG_WARNING(LOADER, "PKG Loader: File is overwritten: %s", path.c_str());
|
||||
LOG_WARNING(LOADER, "PKG Loader: '%s' is overwritten", path);
|
||||
}
|
||||
|
||||
if (out.Create(path, true /* overwriting */))
|
||||
{
|
||||
dec_pkg_f.Seek(entry.file_offset);
|
||||
rfile_t out;
|
||||
|
||||
for (u64 size = 0; size < entry.file_size;) {
|
||||
size += dec_pkg_f.Read(buf, BUF_SIZE);
|
||||
if (out.open(path, o_write | o_create | o_trunc))
|
||||
{
|
||||
dec_pkg_f.seek(entry.file_offset);
|
||||
|
||||
for (u64 size = 0; size < entry.file_size;)
|
||||
{
|
||||
size += dec_pkg_f.read(buf, BUF_SIZE);
|
||||
if (size > entry.file_size)
|
||||
out.Write(buf, BUF_SIZE - (size - entry.file_size));
|
||||
out.write(buf, BUF_SIZE - (size - entry.file_size));
|
||||
else
|
||||
out.Write(buf, BUF_SIZE);
|
||||
out.write(buf, BUF_SIZE);
|
||||
}
|
||||
out.Close();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR(LOADER, "PKG Loader: Could not create file: %s", path.c_str());
|
||||
LOG_ERROR(LOADER, "PKG Loader: Could not create file '%s'", path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -220,41 +235,44 @@ bool UnpackEntry(rFile& dec_pkg_f, const PKGEntry& entry, std::string dir)
|
|||
}
|
||||
}
|
||||
|
||||
int Unpack(rFile& pkg_f, std::string src, std::string dst)
|
||||
int Unpack(const rfile_t& pkg_f, std::string src, std::string dst)
|
||||
{
|
||||
PKGHeader* m_header = (PKGHeader*) malloc (sizeof(PKGHeader));
|
||||
|
||||
rFile dec_pkg_f;
|
||||
// TODO: This shouldn't use current dir
|
||||
std::string decryptedFile = "./dev_hdd1/" + src + ".dec";
|
||||
|
||||
dec_pkg_f.Create(decryptedFile, true);
|
||||
rfile_t dec_pkg_f(decryptedFile, o_read | o_write | o_create | o_trunc);
|
||||
|
||||
if (Decrypt(pkg_f, dec_pkg_f, m_header) < 0)
|
||||
{
|
||||
return -1;
|
||||
|
||||
dec_pkg_f.Close();
|
||||
}
|
||||
|
||||
rFile n_dec_pkg_f(decryptedFile, rFile::read);
|
||||
dec_pkg_f.seek(0);
|
||||
|
||||
std::vector<PKGEntry> m_entries;
|
||||
m_entries.resize(m_header->file_count);
|
||||
|
||||
PKGEntry *m_entries_ptr = &m_entries[0];
|
||||
if (!LoadEntries(n_dec_pkg_f, m_header, m_entries_ptr))
|
||||
auto m_entries_ptr = m_entries.data();
|
||||
|
||||
if (!LoadEntries(dec_pkg_f, m_header, m_entries_ptr))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
wxProgressDialog pdlg("PKG Decrypter / Installer", "Please wait, unpacking...", m_entries.size(), 0, wxPD_AUTO_HIDE | wxPD_APP_MODAL);
|
||||
|
||||
for (const PKGEntry& entry : m_entries)
|
||||
for (const auto& entry : m_entries)
|
||||
{
|
||||
UnpackEntry(n_dec_pkg_f, entry, dst + src + "/");
|
||||
UnpackEntry(dec_pkg_f, entry, dst + src + "/");
|
||||
pdlg.Update(pdlg.GetValue() + 1);
|
||||
}
|
||||
|
||||
pdlg.Update(m_entries.size());
|
||||
|
||||
n_dec_pkg_f.Close();
|
||||
wxRemoveFile(decryptedFile);
|
||||
dec_pkg_f.close();
|
||||
rRemoveFile(decryptedFile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue