1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Merge pull request #1262 from tambry/frog

Lots of defect fixes
This commit is contained in:
Ivan 2015-11-11 23:18:36 +03:00
commit 231f322b60
24 changed files with 241 additions and 123 deletions

3
.gitignore vendored
View File

@ -51,9 +51,10 @@
/bin/*.exp
rpcs3/git-version.h
# Visual Studio Profiler Files
# Visual Studio Files
*.vspx
*.psess
*.VC.*
# Copyrighted files
/bin/data/

View File

@ -1,4 +1,5 @@
#include "stdafx.h"
#include "Utilities/Log.h"
#include "VirtualMemory.h"
#ifdef _WIN32
#include <Windows.h>
@ -15,27 +16,30 @@ namespace memory_helper
void* reserve_memory(size_t size)
{
#ifdef _WIN32
return VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS);
void* ret = VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS);
CHECK_ASSERTION(ret != NULL);
#else
return mmap(nullptr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
void* ret = mmap(nullptr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
CHECK_ASSERTION(ret != 0);
#endif
return ret;
}
void commit_page_memory(void* pointer, size_t page_size)
{
#ifdef _WIN32
VirtualAlloc((u8*)pointer, page_size, MEM_COMMIT, PAGE_READWRITE);
CHECK_ASSERTION(VirtualAlloc((u8*)pointer, page_size, MEM_COMMIT, PAGE_READWRITE) != NULL);
#else
mprotect((u8*)pointer, page_size, PROT_READ | PROT_WRITE);
CHECK_ASSERTION(mprotect((u8*)pointer, page_size, PROT_READ | PROT_WRITE) != -1);
#endif
}
void free_reserved_memory(void* pointer, size_t size)
{
#ifdef _WIN32
VirtualFree(pointer, 0, MEM_RELEASE);
CHECK_ASSERTION(VirtualFree(pointer, 0, MEM_RELEASE) != 0);
#else
munmap(pointer, size);
CHECK_ASSERTION(munmap(pointer, size) == 0);
#endif
}
}

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "restore_new.h"
#include "Utilities/Log.h"
#pragma warning(push)
#pragma message("TODO: remove wx dependency: <wx/image.h>")
#pragma warning(disable : 4996)
@ -9,6 +10,7 @@
#ifndef _WIN32
#include <dirent.h>
#include <errno.h>
#endif
#include "rPlatform.h"
@ -42,7 +44,8 @@ void rImage::SaveFile(const std::string& name, rImageType type)
std::string rPlatform::getConfigDir()
{
static std::string dir = ".";
if (dir == ".") {
if (dir == ".")
{
#ifdef _WIN32
dir = "";
//mkdir(dir.c_str());
@ -54,7 +57,11 @@ std::string rPlatform::getConfigDir()
else // Just in case
dir = "./config";
dir = dir + "/rpcs3/";
mkdir(dir.c_str(), 0777);
if (mkdir(dir.c_str(), 0777) == -1)
{
printf("An error occured during the creation of the configuration directory. (%d)", errno);
}
#endif
}
return dir;

View File

@ -253,11 +253,17 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
// Underflow.
if (buf_start < out)
{
delete[] tmp;
return -1;
}
// Overflow.
if (buf_end > end)
{
delete[] tmp;
return -1;
}
// Update offset.
offset = ((((int)(buf_end - out)) + 1) & 1) + 6;

View File

@ -164,16 +164,16 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
unsigned char empty_iv[0x10] = {};
// Decrypt the metadata.
int i;
for (i = 0; i < block_num; i++)
for (int i = 0; i < block_num; i++)
{
memset(hash_result, 0, 0x14);
if ((edat->flags & EDAT_COMPRESSED_FLAG) != 0)
{
metadata_sec_offset = metadata_offset + (unsigned long long) i * metadata_section_size;
in->seek(metadata_sec_offset);
CHECK_ASSERTION(in->seek(metadata_sec_offset) != -1);
unsigned char metadata[0x20];
memset(metadata, 0, 0x20);
in->read(metadata, 0x20);
@ -201,7 +201,7 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
{
// If FLAG 0x20, the metadata precedes each data block.
metadata_sec_offset = metadata_offset + (unsigned long long) i * (metadata_section_size + length);
in->seek(metadata_sec_offset);
CHECK_ASSERTION(in->seek(metadata_sec_offset) != -1);
unsigned char metadata[0x20];
memset(metadata, 0, 0x20);
@ -222,7 +222,7 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
else
{
metadata_sec_offset = metadata_offset + (unsigned long long) i * metadata_section_size;
in->seek(metadata_sec_offset);
CHECK_ASSERTION(in->seek(metadata_sec_offset) != -1);
in->read(hash_result, 0x10);
offset = metadata_offset + (unsigned long long) i * edat->block_size + (unsigned long long) block_num * metadata_section_size;
@ -244,7 +244,8 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
memset(hash, 0, 0x10);
memset(key_result, 0, 0x10);
in->seek(offset);
CHECK_ASSERTION(in->seek(offset) != -1);
in->read(enc_data, length);
// Generate a key for the current block.
@ -291,7 +292,10 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
{
if (verbose)
LOG_WARNING(LOADER, "EDAT: Block at offset 0x%llx has invalid hash!", (u64)offset);
delete[] enc_data;
delete[] dec_data;
delete[] b_key;
return 1;
}
}
@ -337,6 +341,7 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
delete[] enc_data;
delete[] dec_data;
delete[] b_key;
}
return 0;
@ -344,7 +349,7 @@ int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD
int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs::file* f, bool verbose)
{
f->seek(0);
CHECK_ASSERTION(f->seek(0) != -1);
unsigned char header[0xA0];
unsigned char empty_header[0xA0];
unsigned char header_hash[0x10];
@ -389,7 +394,8 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
f->read(header, 0xA0);
// Read in the header and metadata section hashes.
f->seek(0x90);
CHECK_ASSERTION(f->seek(0x90) != -1);
f->read(metadata_hash, 0x10);
f->read(header_hash, 0x10);
@ -445,7 +451,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
while (bytes_to_read > 0)
{
// Locate the metadata blocks.
f->seek(metadata_section_offset);
CHECK_ASSERTION(f->seek(metadata_section_offset) != -1);
// Read in the metadata.
f->read(metadata + bytes_read, metadata_section_size);
@ -492,9 +498,9 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
// Read in the metadata and header signatures.
f->seek(0xB0);
CHECK_ASSERTION(f->seek(0xB0) != -1);
f->read(metadata_signature, 0x28);
f->seek(0xD8);
CHECK_ASSERTION(f->seek(0xD8) != -1);
f->read(header_signature, 0x28);
// Checking metadata signature.
@ -510,7 +516,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
{
int metadata_buf_size = block_num * 0x10;
unsigned char *metadata_buf = new unsigned char[metadata_buf_size];
f->seek(metadata_offset);
CHECK_ASSERTION(f->seek(metadata_offset) != -1);
f->read(metadata_buf, metadata_buf_size);
sha1(metadata_buf, metadata_buf_size, signature_hash);
delete[] metadata_buf;
@ -543,7 +549,7 @@ int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs:
// Setup header signature hash.
memset(signature_hash, 0, 20);
unsigned char *header_buf = new unsigned char[0xD8];
f->seek(0x00);
CHECK_ASSERTION(f->seek(0x00) != -1);
f->read(header_buf, 0xD8);
sha1(header_buf, 0xD8, signature_hash );
delete[] header_buf;

View File

@ -86,7 +86,7 @@ bool UnpackPKG(const fs::file& pkg_f, const std::string& dir, volatile f64& prog
// Define decryption subfunction (`psp` arg selects the key for specific block)
auto decrypt = [&](u64 offset, u64 size, bool psp) -> u64
{
pkg_f.seek(start_offset + header.data_offset + offset);
CHECK_ASSERTION(pkg_f.seek(start_offset + header.data_offset + offset) != -1);
// Read the data and set available size
const u64 read = pkg_f.read(buf.get(), size);

View File

@ -698,7 +698,7 @@ SELFDecrypter::SELFDecrypter(vfsStream& s)
bool SELFDecrypter::LoadHeaders(bool isElf32)
{
// Read SCE header.
self_f.Seek(0);
CHECK_ASSERTION(self_f.Seek(0) != -1);
sce_hdr.Load(self_f);
// Check SCE magic.
@ -712,11 +712,12 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
self_hdr.Load(self_f);
// Read the APP INFO.
self_f.Seek(self_hdr.se_appinfooff);
CHECK_ASSERTION(self_f.Seek(self_hdr.se_appinfooff) != -1);
app_info.Load(self_f);
// Read ELF header.
self_f.Seek(self_hdr.se_elfoff);
CHECK_ASSERTION(self_f.Seek(self_hdr.se_elfoff) != -1);
if (isElf32)
elf32_hdr.Load(self_f);
else
@ -741,13 +742,16 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
else
{
phdr64_arr.clear();
if(elf64_hdr.e_phoff == 0 && elf64_hdr.e_phnum)
if (elf64_hdr.e_phoff == 0 && elf64_hdr.e_phnum)
{
LOG_ERROR(LOADER, "SELF: ELF program header offset is null!");
return false;
}
self_f.Seek(self_hdr.se_phdroff);
for(u32 i = 0; i < elf64_hdr.e_phnum; ++i)
CHECK_ASSERTION(self_f.Seek(self_hdr.se_phdroff) != -1);
for (u32 i = 0; i < elf64_hdr.e_phnum; ++i)
{
phdr64_arr.emplace_back();
phdr64_arr.back().Load(self_f);
@ -757,7 +761,7 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
// Read section info.
secinfo_arr.clear();
self_f.Seek(self_hdr.se_secinfoff);
CHECK_ASSERTION(self_f.Seek(self_hdr.se_secinfoff) != -1);
for(u32 i = 0; i < ((isElf32) ? elf32_hdr.e_phnum : elf64_hdr.e_phnum); ++i)
{
@ -766,12 +770,12 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
}
// Read SCE version info.
self_f.Seek(self_hdr.se_sceveroff);
CHECK_ASSERTION(self_f.Seek(self_hdr.se_sceveroff) != -1);
scev_info.Load(self_f);
// Read control info.
ctrlinfo_arr.clear();
self_f.Seek(self_hdr.se_controloff);
CHECK_ASSERTION(self_f.Seek(self_hdr.se_controloff) != -1);
u32 i = 0;
while(i < self_hdr.se_controlsize)
@ -786,12 +790,15 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
if (isElf32)
{
shdr32_arr.clear();
if(elf32_hdr.e_shoff == 0 && elf32_hdr.e_shnum)
if (elf32_hdr.e_shoff == 0 && elf32_hdr.e_shnum)
{
LOG_WARNING(LOADER, "SELF: ELF section header offset is null!");
return true;
}
self_f.Seek(self_hdr.se_shdroff);
CHECK_ASSERTION(self_f.Seek(self_hdr.se_shdroff) != -1);
for(u32 i = 0; i < elf32_hdr.e_shnum; ++i)
{
shdr32_arr.emplace_back();
@ -801,12 +808,14 @@ bool SELFDecrypter::LoadHeaders(bool isElf32)
else
{
shdr64_arr.clear();
if(elf64_hdr.e_shoff == 0 && elf64_hdr.e_shnum)
if (elf64_hdr.e_shoff == 0 && elf64_hdr.e_shnum)
{
LOG_WARNING(LOADER, "SELF: ELF section header offset is null!");
return true;
}
self_f.Seek(self_hdr.se_shdroff);
CHECK_ASSERTION(self_f.Seek(self_hdr.se_shdroff) != -1);
for(u32 i = 0; i < elf64_hdr.e_shnum; ++i)
{
shdr64_arr.emplace_back();
@ -941,11 +950,11 @@ bool SELFDecrypter::LoadMetadata()
u8 *metadata_headers = (u8 *)malloc(metadata_headers_size);
// Locate and read the encrypted metadata info.
self_f.Seek(sce_hdr.se_meta + sizeof(sce_hdr));
CHECK_ASSERTION(self_f.Seek(sce_hdr.se_meta + sizeof(sce_hdr)) != -1);
self_f.Read(metadata_info, metadata_info_size);
// Locate and read the encrypted metadata header and section header.
self_f.Seek(sce_hdr.se_meta + sizeof(sce_hdr) + metadata_info_size);
CHECK_ASSERTION(self_f.Seek(sce_hdr.se_meta + sizeof(sce_hdr) + metadata_info_size) != -1);
self_f.Read(metadata_headers, metadata_headers_size);
// Find the right keyset from the key vault.
@ -1048,7 +1057,7 @@ bool SELFDecrypter::DecryptData()
u8 *buf = (u8 *)malloc(meta_shdr[i].data_size);
// Seek to the section data offset and read the encrypted data.
self_f.Seek(meta_shdr[i].data_offset);
CHECK_ASSERTION(self_f.Seek(meta_shdr[i].data_offset) != -1);
self_f.Read(buf, meta_shdr[i].data_size);
// Zero out our ctr nonce.
@ -1077,7 +1086,7 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
{
// Create a new ELF file.
fs::file e(elf, fom::write | fom::create | fom::trunc);
if(!e)
if (!e)
{
LOG_ERROR(LOADER, "Could not create ELF file! (%s)", elf.c_str());
return false;
@ -1092,8 +1101,10 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
WriteEhdr(e, elf32_hdr);
// Write program headers.
for(u32 i = 0; i < elf32_hdr.e_phnum; ++i)
for (u32 i = 0; i < elf32_hdr.e_phnum; ++i)
{
WritePhdr(e, phdr32_arr[i]);
}
for (unsigned int i = 0; i < meta_hdr.section_count; i++)
{
@ -1101,7 +1112,8 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
if (meta_shdr[i].type == 2)
{
// Seek to the program header data offset and write the data.
e.seek(phdr32_arr[meta_shdr[i].program_idx].p_offset);
CHECK_ASSERTION(e.seek(phdr32_arr[meta_shdr[i].program_idx].p_offset) != -1);
e.write(data_buf + data_buf_offset, meta_shdr[i].data_size);
// Advance the data buffer offset by data size.
@ -1110,12 +1122,14 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
}
// Write section headers.
if(self_hdr.se_shdroff != 0)
if (self_hdr.se_shdroff != 0)
{
e.seek(elf32_hdr.e_shoff);
CHECK_ASSERTION(e.seek(elf32_hdr.e_shoff) != -1);
for(u32 i = 0; i < elf32_hdr.e_shnum; ++i)
for (u32 i = 0; i < elf32_hdr.e_shnum; ++i)
{
WriteShdr(e, shdr32_arr[i]);
}
}
}
else
@ -1124,8 +1138,10 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
WriteEhdr(e, elf64_hdr);
// Write program headers.
for(u32 i = 0; i < elf64_hdr.e_phnum; ++i)
for (u32 i = 0; i < elf64_hdr.e_phnum; ++i)
{
WritePhdr(e, phdr64_arr[i]);
}
// Write data.
for (unsigned int i = 0; i < meta_hdr.section_count; i++)
@ -1152,7 +1168,9 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
decomp_stream_out.CopyTo(decomp_buf, phdr64_arr[meta_shdr[i].program_idx].p_filesz);
// Seek to the program header data offset and write the data.
e.seek(phdr64_arr[meta_shdr[i].program_idx].p_offset);
CHECK_ASSERTION(e.seek(phdr64_arr[meta_shdr[i].program_idx].p_offset) != -1);
e.write(decomp_buf, phdr64_arr[meta_shdr[i].program_idx].p_filesz);
// Release the decompression buffer.
@ -1161,7 +1179,8 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
else
{
// Seek to the program header data offset and write the data.
e.seek(phdr64_arr[meta_shdr[i].program_idx].p_offset);
CHECK_ASSERTION(e.seek(phdr64_arr[meta_shdr[i].program_idx].p_offset) != -1);
e.write(data_buf + data_buf_offset, meta_shdr[i].data_size);
}
@ -1171,12 +1190,14 @@ bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
}
// Write section headers.
if(self_hdr.se_shdroff != 0)
if (self_hdr.se_shdroff != 0)
{
e.seek(elf64_hdr.e_shoff);
CHECK_ASSERTION(e.seek(elf64_hdr.e_shoff) != -1);
for(u32 i = 0; i < elf64_hdr.e_shnum; ++i)
for (u32 i = 0; i < elf64_hdr.e_shnum; ++i)
{
WriteShdr(e, shdr64_arr[i]);
}
}
}
@ -1246,7 +1267,9 @@ bool IsSelfElf32(const std::string& path)
// Locate the class byte and check it.
u8 elf_class[0x8];
f.Seek(sh.se_elfoff);
CHECK_ASSERTION(f.Seek(sh.se_elfoff) != -1);
f.Read(elf_class, 0x8);
return (elf_class[4] == 1);
@ -1257,34 +1280,37 @@ bool CheckDebugSelf(const std::string& self, const std::string& elf)
// Open the SELF file.
fs::file s(self);
if(!s)
if (!s)
{
LOG_ERROR(LOADER, "Could not open SELF file! (%s)", self.c_str());
return false;
}
// Get the key version.
s.seek(0x08);
CHECK_ASSERTION(s.seek(0x08) != -1);
u16 key_version;
s.read(&key_version, sizeof(key_version));
// Check for DEBUG version.
if(swap16(key_version) == 0x8000)
if (swap16(key_version) == 0x8000)
{
LOG_WARNING(LOADER, "Debug SELF detected! Removing fake header...");
// Get the real elf offset.
s.seek(0x10);
CHECK_ASSERTION(s.seek(0x10) != -1);
u64 elf_offset;
s.read(&elf_offset, sizeof(elf_offset));
// Start at the real elf offset.
elf_offset = swap64(elf_offset);
s.seek(elf_offset);
CHECK_ASSERTION(s.seek(elf_offset) != -1);
// Write the real ELF file back.
fs::file e(elf, fom::write | fom::create | fom::trunc);
if(!e)
if (!e)
{
LOG_ERROR(LOADER, "Could not create ELF file! (%s)", elf.c_str());
return false;
@ -1293,7 +1319,9 @@ bool CheckDebugSelf(const std::string& self, const std::string& elf)
// Copy the data.
char buf[2048];
while (ssize_t size = s.read(buf, 2048))
{
e.write(buf, size);
}
return true;
}

View File

@ -96,6 +96,7 @@ void hex_to_bytes(unsigned char *data, const char *hex_str, unsigned int str_len
// Copy back to our array.
memcpy(data, out, data_length);
free(out);
}
}

View File

@ -47,7 +47,9 @@ void vfsHDDManager::CreateHDD(const std::string& path, u64 size, u64 block_size)
}
u8 null = 0;
f.seek(hdr.block_count * hdr.block_size - sizeof(null));
CHECK_ASSERTION(f.seek(hdr.block_count * hdr.block_size - sizeof(null)) != -1);
f.write(&null, sizeof(null));
}
@ -68,17 +70,19 @@ bool vfsHDDFile::goto_block(u64 n)
return false;
}
m_hdd.Seek(m_info.data_block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(m_info.data_block * m_hdd_info.block_size) != -1);
block_info.next_block = m_info.data_block;
for (u64 i = 0; i<n; ++i)
for (u64 i = 0; i < n; ++i)
{
if (!block_info.next_block || !block_info.is_used || block_info.next_block >= m_hdd_info.block_count)
{
return false;
}
m_hdd.Seek(block_info.next_block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(block_info.next_block * m_hdd_info.block_size) != -1);
m_hdd.Read(&block_info, sizeof(vfsHDD_Block));
}
@ -101,31 +105,36 @@ void vfsHDDFile::RemoveBlocks(u64 start_block)
void vfsHDDFile::WriteBlock(u64 block, const vfsHDD_Block& data)
{
m_hdd.Seek(block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size) != -1);
m_hdd.Write(&data, sizeof(vfsHDD_Block));
}
void vfsHDDFile::ReadBlock(u64 block, vfsHDD_Block& data)
{
m_hdd.Seek(block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size) != -1);
m_hdd.Read(&data, sizeof(vfsHDD_Block));
}
void vfsHDDFile::WriteEntry(u64 block, const vfsHDD_Entry& data)
{
m_hdd.Seek(block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size) != -1);
m_hdd.Write(&data, sizeof(vfsHDD_Entry));
}
void vfsHDDFile::ReadEntry(u64 block, vfsHDD_Entry& data)
{
m_hdd.Seek(block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size) != -1);
m_hdd.Read(&data, sizeof(vfsHDD_Entry));
}
void vfsHDDFile::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name)
{
m_hdd.Seek(block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size) != -1);
m_hdd.Read(&data, sizeof(vfsHDD_Entry));
name.resize(GetMaxNameLen());
m_hdd.Read(&name.front(), GetMaxNameLen());
@ -133,14 +142,16 @@ void vfsHDDFile::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name)
void vfsHDDFile::ReadEntry(u64 block, std::string& name)
{
m_hdd.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry));
CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)) != -1);
name.resize(GetMaxNameLen());
m_hdd.Read(&name.front(), GetMaxNameLen());
}
void vfsHDDFile::WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name)
{
m_hdd.Seek(block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(block * m_hdd_info.block_size) != -1);
m_hdd.Write(&data, sizeof(vfsHDD_Entry));
m_hdd.Write(name.c_str(), std::min<size_t>(GetMaxNameLen() - 1, name.length() + 1));
}
@ -157,7 +168,7 @@ u64 vfsHDDFile::FindFreeBlock()
{
vfsHDD_Block block_info;
for (u64 i = 0; i<m_hdd_info.block_count; ++i)
for (u64 i = 0; i < m_hdd_info.block_count; ++i)
{
ReadBlock(i, block_info);
@ -183,7 +194,10 @@ bool vfsHDDFile::Seek(u64 pos)
void vfsHDDFile::SaveInfo()
{
m_hdd.Seek(m_info_block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(m_info_block * m_hdd_info.block_size) != -1);
CHECK_ASSERTION(m_hdd.Seek(m_info_block * m_hdd_info.block_size) != -1);
m_hdd.Write(&m_info, sizeof(vfsHDD_Entry));
}
@ -198,9 +212,13 @@ u64 vfsHDDFile::Read(void* dst, u64 size)
u64 rsize = std::min<u64>(block_size - m_position, size);
vfsHDD_Block cur_block_info;
m_hdd.Seek(m_cur_block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(m_cur_block * m_hdd_info.block_size) != -1);
m_hdd.Read(&cur_block_info, sizeof(vfsHDD_Block));
m_hdd.Seek(m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block)+m_position);
CHECK_ASSERTION(m_hdd.Seek(m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block) + m_position) != -1);
m_hdd.Read(dst, rsize);
size -= rsize;
m_position += rsize;
@ -221,7 +239,8 @@ u64 vfsHDDFile::Read(void* dst, u64 size)
m_cur_block = cur_block_info.next_block;
rsize = std::min<u64>(block_size, size);
m_hdd.Seek(cur_block_info.next_block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(cur_block_info.next_block * m_hdd_info.block_size) != -1);
m_hdd.Read(&cur_block_info, sizeof(vfsHDD_Block));
if (m_hdd.Read((u8*)dst + offset, rsize) != rsize)
@ -272,7 +291,8 @@ u64 vfsHDDFile::Write(const void* src, u64 size)
if (wsize)
{
m_hdd.Seek(m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block)+m_position);
CHECK_ASSERTION(m_hdd.Seek(m_cur_block * m_hdd_info.block_size + sizeof(vfsHDD_Block) + m_position) != -1);
m_hdd.Write(src, wsize);
size -= wsize;
m_info.size += wsize;
@ -302,7 +322,9 @@ u64 vfsHDDFile::Write(const void* src, u64 size)
wsize = std::min<u64>(block_size, size);
block_info.next_block = m_cur_block;
m_hdd.Seek(last_block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(last_block * m_hdd_info.block_size) != -1);
if (m_hdd.Write(&block_info, sizeof(vfsHDD_Block)) != sizeof(vfsHDD_Block))
{
m_position = 0;
@ -311,13 +333,16 @@ u64 vfsHDDFile::Write(const void* src, u64 size)
}
block_info.next_block = 0;
m_hdd.Seek(m_cur_block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd.Seek(m_cur_block * m_hdd_info.block_size) != -1);
if (m_hdd.Write(&block_info, sizeof(vfsHDD_Block)) != sizeof(vfsHDD_Block))
{
m_position = 0;
SaveInfo();
return offset;
}
if ((m_position = m_hdd.Write((u8*)src + offset, wsize)) != wsize)
{
m_info.size += wsize;
@ -361,7 +386,9 @@ vfsHDD::vfsHDD(vfsDevice* device, const std::string& hdd_path)
LOG_ERROR(HLE, "Bad block size!");
m_hdd_info.block_size = 2048;
}
m_hdd_file.Seek(m_cur_dir_block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd_file.Seek(m_cur_dir_block * m_hdd_info.block_size) != -1);
m_hdd_file.Read(&m_cur_dir, sizeof(vfsHDD_Entry));
}
@ -392,18 +419,25 @@ bool vfsHDD::SearchEntry(const std::string& name, u64& entry_block, u64* parent_
return false;
}
int vfsHDD::OpenDir(const std::string& name)
s32 vfsHDD::OpenDir(const std::string& name)
{
LOG_WARNING(HLE, "OpenDir(%s)", name.c_str());
u64 entry_block;
if (!SearchEntry(name, entry_block))
return -1;
m_hdd_file.Seek(entry_block * m_hdd_info.block_size);
if (!SearchEntry(name, entry_block))
{
return -1;
}
CHECK_ASSERTION(m_hdd_file.Seek(entry_block * m_hdd_info.block_size) != -1);
vfsHDD_Entry entry;
m_hdd_file.Read(&entry, sizeof(vfsHDD_Entry));
if (entry.type == vfsHDD_Entry_File)
{
return 1;
}
m_cur_dir_block = entry.data_block;
ReadEntry(m_cur_dir_block, m_cur_dir);
@ -430,7 +464,7 @@ u64 vfsHDD::FindFreeBlock()
{
vfsHDD_Block block_info;
for (u64 i = 0; i<m_hdd_info.block_count; ++i)
for (u64 i = 0; i < m_hdd_info.block_count; ++i)
{
ReadBlock(i, block_info);
@ -445,31 +479,36 @@ u64 vfsHDD::FindFreeBlock()
void vfsHDD::WriteBlock(u64 block, const vfsHDD_Block& data)
{
m_hdd_file.Seek(block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size) != -1);
m_hdd_file.Write(&data, sizeof(vfsHDD_Block));
}
void vfsHDD::ReadBlock(u64 block, vfsHDD_Block& data)
{
m_hdd_file.Seek(block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size) != -1);
m_hdd_file.Read(&data, sizeof(vfsHDD_Block));
}
void vfsHDD::WriteEntry(u64 block, const vfsHDD_Entry& data)
{
m_hdd_file.Seek(block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size) != -1);
m_hdd_file.Write(&data, sizeof(vfsHDD_Entry));
}
void vfsHDD::ReadEntry(u64 block, vfsHDD_Entry& data)
{
m_hdd_file.Seek(block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size) != -1);
m_hdd_file.Read(&data, sizeof(vfsHDD_Entry));
}
void vfsHDD::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name)
{
m_hdd_file.Seek(block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size) != -1);
m_hdd_file.Read(&data, sizeof(vfsHDD_Entry));
name.resize(GetMaxNameLen());
m_hdd_file.Read(&name.front(), GetMaxNameLen());
@ -477,14 +516,16 @@ void vfsHDD::ReadEntry(u64 block, vfsHDD_Entry& data, std::string& name)
void vfsHDD::ReadEntry(u64 block, std::string& name)
{
m_hdd_file.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry));
CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size + sizeof(vfsHDD_Entry)) != -1);
name.resize(GetMaxNameLen());
m_hdd_file.Read(&name.front(), GetMaxNameLen());
}
void vfsHDD::WriteEntry(u64 block, const vfsHDD_Entry& data, const std::string& name)
{
m_hdd_file.Seek(block * m_hdd_info.block_size);
CHECK_ASSERTION(m_hdd_file.Seek(block * m_hdd_info.block_size) != -1);
m_hdd_file.Write(&data, sizeof(vfsHDD_Entry));
m_hdd_file.Write(name.c_str(), std::min<size_t>(GetMaxNameLen() - 1, name.length() + 1));
}
@ -619,13 +660,13 @@ bool vfsHDD::Open(const std::string& path, u32 mode)
{
if (pos - from > 1)
{
int res = OpenDir(std::string(s + from, pos));
s32 res = OpenDir(std::string(s + from, pos));
if (res == -1)
{
return false;
}
if (res == 1)
else if (res == 1)
{
file_pos = from;
}

View File

@ -156,7 +156,7 @@ public:
bool SearchEntry(const std::string& name, u64& entry_block, u64* parent_block = nullptr);
int OpenDir(const std::string& name);
s32 OpenDir(const std::string& name);
bool Rename(const std::string& from, const std::string& to);

View File

@ -92,6 +92,8 @@ struct Mouse
: m_data()
, m_rawdata()
{
x_pos = 0;
y_pos = 0;
}
};

View File

@ -1,5 +1,7 @@
#pragma once
#include "Utilities/Log.h"
struct MemInfo
{
u32 addr;
@ -82,7 +84,13 @@ public:
u32 RealAddr(u32 addr)
{
u32 realAddr = 0;
getRealAddr(addr, realAddr);
if (!getRealAddr(addr, realAddr))
{
LOG_ERROR(HLE, "Getting the real address failed. (addr=0x%x)", addr);
return 0;
}
return realAddr;
}

View File

@ -116,7 +116,7 @@ std::string CgBinaryDisasm::GetSRCDisasm(const u32 n)
if (swizzle != f) ret += '.' + swizzle;
bool abs;
bool abs = false;
switch (n)
{

View File

@ -291,6 +291,7 @@ template<typename T> std::string FragmentProgramDecompiler::GetSRC(T src)
case 3: // ??? Used by a few games, what is it?
LOG_ERROR(RSX, "Src type 3 used, please report this to a developer.");
break;
default:
LOG_ERROR(RSX, "Bad src type %d", u32{ src.reg_type });

View File

@ -108,7 +108,7 @@ std::string VertexProgramDecompiler::GetSRC(const u32 n)
if (swizzle != f) ret += '.' + swizzle;
bool abs;
bool abs = false;
switch (n)
{

View File

@ -265,11 +265,11 @@ s32 cellFsReadWithOffset(u32 fd, u64 offset, vm::ptr<void> buf, u64 buffer_size,
const auto old_position = file->file->Tell();
file->file->Seek(offset);
CHECK_ASSERTION(file->file->Seek(offset) != -1);
const auto read = file->file->Read(buf.get_ptr(), buffer_size);
file->file->Seek(old_position);
CHECK_ASSERTION(file->file->Seek(old_position) != -1);
if (nread)
{
@ -296,11 +296,11 @@ s32 cellFsWriteWithOffset(u32 fd, u64 offset, vm::cptr<void> buf, u64 data_size,
const auto old_position = file->file->Tell();
file->file->Seek(offset);
CHECK_ASSERTION(file->file->Seek(offset) != -1);
const auto written = file->file->Write(buf.get_ptr(), data_size);
file->file->Seek(old_position);
CHECK_ASSERTION(file->file->Seek(old_position) != -1);
if (nwrite)
{
@ -508,9 +508,9 @@ s32 cellFsStReadStart(u32 fd, u64 offset, u64 size)
// read data
auto old = file->file->Tell();
file->file->Seek(offset + file->st_total_read);
CHECK_ASSERTION(file->file->Seek(offset + file->st_total_read) != -1);
auto res = file->file->Read(vm::base(position), file->st_block_size);
file->file->Seek(old);
CHECK_ASSERTION(file->file->Seek(old) != -1);
// notify
file->st_total_read += res;
@ -803,17 +803,27 @@ s32 sdata_unpack(const std::string& packed_file, const std::string& unpacked_fil
}
if (flags & 0x20)
packed_stream->Seek(0x100);
{
CHECK_ASSERTION(packed_stream->Seek(0x100) != -1);
}
else
packed_stream->Seek(startOffset);
{
CHECK_ASSERTION(packed_stream->Seek(startOffset) != -1);
}
for (u32 i = 0; i < blockCount; i++)
{
if (flags & 0x20)
packed_stream->Seek(packed_stream->Tell() + t1);
{
s64 cur;
CHECK_ASSERTION((cur = packed_stream->Tell()) != -1);
CHECK_ASSERTION(packed_stream->Seek(cur + t1) != -1);
}
if (!(blockCount - i - 1))
{
blockSize = (u32)(filesizeOutput - i * blockSize);
}
packed_stream->Read(buffer + 256, blockSize);
unpacked_stream->Write(buffer + 256, blockSize);
@ -883,11 +893,11 @@ void fsAio(vm::ptr<CellFsAio> aio, bool write, s32 xid, fs_aio_cb_t func)
const auto old_position = file->file->Tell();
file->file->Seek(aio->offset);
CHECK_ASSERTION(file->file->Seek(aio->offset) != -1);
result = write ? file->file->Write(aio->buf.get_ptr(), aio->size) : file->file->Read(aio->buf.get_ptr(), aio->size);
file->file->Seek(old_position);
CHECK_ASSERTION(file->file->Seek(old_position) != -1);
}
// should be executed directly by FS AIO thread

View File

@ -123,7 +123,7 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
free(pAddresses);
#else
struct ifaddrs *ifaddr, *ifa;
int family, n;
s32 family, n;
if (getifaddrs(&ifaddr) == -1)
{
@ -146,9 +146,7 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
if (family == AF_INET)
{
s32 fd, status;
fd = open("/proc/net/dev", O_RDONLY);
u32 fd = open("/proc/net/dev", O_RDONLY);
struct ifreq freq;
if (ioctl(fd, SIOCGIFMTU, &freq) == -1)
@ -212,7 +210,7 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
free(pAdapterInfo);
#else
struct ifaddrs *ifaddr, *ifa;
int family, n;
s32 family, n;
if (getifaddrs(&ifaddr) == -1)
{
@ -293,7 +291,7 @@ s32 cellNetCtlGetInfo(s32 code, vm::ptr<CellNetCtlInfo> info)
free(pAdapterInfo);
#else
struct ifaddrs *ifaddr, *ifa;
int family, n;
s32 family, n;
if (getifaddrs(&ifaddr) == -1)
{

View File

@ -351,7 +351,7 @@ s32 CalculateMaxColorBuffersSize()
{
if (s_rescInternalInstance->m_initConfig.supportModes & bufMode)
{
oneBufSize = CalculateSurfaceByteSize(bufMode, &(s_rescInternalInstance->m_rescDsts[GetRescDestsIndex(bufMode)]));
oneBufSize = CalculateSurfaceByteSize(bufMode, &(s_rescInternalInstance->m_rescDsts[GetRescDestsIndex(bufMode)]));
bufNum = cellRescGetNumColorBuffers(bufMode, s_rescInternalInstance->m_initConfig.palTemporalMode, 0);
totalBufSize = oneBufSize * bufNum;
maxBufSize = (maxBufSize > totalBufSize) ? maxBufSize : totalBufSize;

View File

@ -866,7 +866,8 @@ s32 cellSailPlayerRemoveDescriptor(vm::ptr<CellSailPlayer> pSelf, vm::ptr<CellSa
if (pSelf->descriptors > 0)
{
ppDesc = pSelf->registeredDescriptors[pSelf->descriptors];
delete &pSelf->registeredDescriptors[pSelf->descriptors];
// TODO: Figure out how properly free a descriptor. Use game specified memory dealloc function?
//delete &pSelf->registeredDescriptors[pSelf->descriptors];
pSelf->descriptors--;
}

View File

@ -224,8 +224,8 @@ s32 cellSysCacheMount(vm::ptr<CellSysCacheParam> param)
cellSysutil.Warning("cellSysCacheMount(param=*0x%x)", param);
// TODO: implement
char id[CELL_SYSCACHE_ID_SIZE];
strncpy(id, param->cacheId, CELL_SYSCACHE_ID_SIZE);
char id[CELL_SYSCACHE_ID_SIZE] = { '\0' };
strncpy(id, param->cacheId, CELL_SYSCACHE_ID_SIZE - 1);
strncpy(param->getCachePath, ("/dev_hdd1/cache/"s + id + "/").c_str(), CELL_SYSCACHE_PATH_MAX);
param->getCachePath[CELL_SYSCACHE_PATH_MAX - 1] = '\0';
Emu.GetVFS().CreateDir(param->getCachePath);

View File

@ -48,6 +48,7 @@ Emulator::Emulator()
: m_status(Stopped)
, m_mode(DisAsm)
, m_rsx_callback(0)
, m_cpu_thr_stop(0)
, m_thread_manager(new CPUThreadManager())
, m_pad_manager(new PadManager())
, m_keyboard_manager(new KeyboardManager())
@ -453,6 +454,7 @@ void Emulator::Stop()
}
m_rsx_callback = 0;
m_cpu_thr_stop = 0;
// TODO: check finalization order

View File

@ -79,7 +79,7 @@ void AutoPauseManagerDialog::LoadEntries(void)
u32 num;
size_t fmax = list.size();
size_t fcur = 0;
list.seek(0);
CHECK_ASSERTION(list.seek(0) != -1);
while (fcur <= fmax - sizeof(u32))
{
list.read(&num, sizeof(u32));
@ -99,7 +99,7 @@ void AutoPauseManagerDialog::SaveEntries(void)
fs::file list("pause.bin", fom::write | fom::create | fom::trunc);
//System calls ID and Function calls ID are all u32 iirc.
u32 num = 0;
list.seek(0);
CHECK_ASSERTION(list.seek(0) != -1);
for (size_t i = 0; i < m_entries.size(); ++i)
{
if (num == 0xFFFFFFFF) continue;

View File

@ -3,7 +3,7 @@
class GSFrame : public wxFrame, public GSFrameBase
{
u64 m_frames;
u64 m_frames = 0;
public:
GSFrame(const wxString& title);

View File

@ -262,7 +262,9 @@ void MainFrame::InstallPkg(wxCommandEvent& WXUNUSED(event))
// Fetch title ID from the header
char title_id[10] = "?????????";
pkg_f.seek(55);
CHECK_ASSERTION(pkg_f.seek(55) != -1);
pkg_f.read(title_id, 9);
pkg_f.seek(0);