mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-21 18:29:05 +02:00
More explicit error checking
This commit is contained in:
1 parent
3c81d6b121
commit
5dfeaed63b
5 files changed
+58
-33
No files matched your search
@@ -20,13 +20,14 @@
|
||||
|
||||
#include "Core/HLE/FunctionWrappers.h"
|
||||
#include "Core/HLE/HLE.h"
|
||||
#include "Core/Core.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
|
||||
// This is one of the firmware modules (pspnet.prx), the official PSP games can't call these funcs
|
||||
|
||||
|
||||
// Ugh, this is ugly.
|
||||
u32 sceNetStrtoul(const char *str, u32 strEndAddrPtr, int base) {
|
||||
// Redirect that to libc
|
||||
char* str_end = nullptr;
|
||||
@@ -34,15 +35,19 @@ u32 sceNetStrtoul(const char *str, u32 strEndAddrPtr, int base) {
|
||||
|
||||
// Remap the pointer
|
||||
u32 psp_str_end = Memory::GetAddressFromHostPointer(str_end);
|
||||
Memory::Write_U32(psp_str_end, strEndAddrPtr);
|
||||
|
||||
if (Memory::IsValid4AlignedAddress(psp_str_end)) {
|
||||
Memory::WriteUnchecked_U32(psp_str_end, strEndAddrPtr);
|
||||
}
|
||||
return hleLogDebug(Log::sceNet, res);
|
||||
}
|
||||
|
||||
u32 sceNetMemmove(void* dest, u32 srcPtr, u32 count) {
|
||||
if (!Memory::IsValidAddress(srcPtr)) {
|
||||
return hleLogError(Log::sceNet, -1, "sceNetMemmove: Invalid source pointer 0x%08X", srcPtr);
|
||||
}
|
||||
// Redirect that to libc
|
||||
void* host_ptr = std::memmove(
|
||||
dest, Memory::GetPointer(srcPtr), count
|
||||
dest, Memory::GetPointerUnchecked(srcPtr), count
|
||||
);
|
||||
|
||||
// Remap the pointer
|
||||
|
||||
@@ -40,21 +40,18 @@ std::string getHeaderString(std::istringstream &headers) {
|
||||
|
||||
// FIXME: Is it allowed for fieldName to be null/0 or empty string ? JPCSP seems to ignore it
|
||||
static int sceParseHttpResponseHeader(u32 headerAddr, int headerLength, const char *fieldName, u32 valueAddr, u32 valueLengthAddr) {
|
||||
WARN_LOG(Log::sceNet, "UNTESTED sceParseHttpResponseHeader(%x, %i, %s, %x, %x[%i]) at %08x", headerAddr, headerLength, fieldName, valueAddr, valueLengthAddr, Memory::Read_U32(valueLengthAddr), currentMIPS->pc);
|
||||
if (!Memory::IsValidRange(headerAddr, headerLength))
|
||||
return hleLogError(Log::sceNet, -1, "invalid arg");
|
||||
|
||||
if (!Memory::IsValidRange(valueLengthAddr, 4))
|
||||
return hleLogError(Log::sceNet, -1, "invalid arg");
|
||||
|
||||
// FIXME: Not sure whether valuerAddr can be null or not (in case the game just need to get the size to allocate the value buffer first)
|
||||
// FIXME: Not sure whether valueAddr can be null or not (in case the game just need to get the size to allocate the value buffer first)
|
||||
// Note: Based on the outputted value address from JPCSP, the address seems to be within the input headers address range, thus no need to allocate output value buffer
|
||||
if (!Memory::IsValidRange(valueAddr, Memory::Read_U32(valueLengthAddr)))
|
||||
if (!Memory::IsValidRange(valueAddr, Memory::ReadUnchecked_U32(valueLengthAddr)))
|
||||
return hleLogError(Log::sceNet, -1, "invalid arg");
|
||||
|
||||
std::string field = "";
|
||||
if (fieldName != nullptr)
|
||||
field = std::string(fieldName);
|
||||
std::string field = fieldName ? fieldName : "";
|
||||
field = StripSpaces(field);
|
||||
std::string headers(Memory::GetCharPointer(headerAddr), headerLength);
|
||||
std::istringstream hdrs(headers);
|
||||
@@ -66,7 +63,7 @@ static int sceParseHttpResponseHeader(u32 headerAddr, int headerLength, const ch
|
||||
const std::string delim = ":"; // JPCSP use ": " delimiter
|
||||
size_t delimpos = headerString.find(delim);
|
||||
std::string key = headerString.substr(0, delimpos); // the key part
|
||||
if (equalsNoCase(StripSpaces(key), field.c_str())) {
|
||||
if (equalsNoCase(StripSpaces(key), field)) {
|
||||
found = true;
|
||||
int offset = hdrs.tellg();
|
||||
if (offset >= 0) {
|
||||
|
||||
+32
-17
@@ -27,37 +27,53 @@
|
||||
#include "Core/HLE/FunctionWrappers.h"
|
||||
#include "Common/File/FileUtil.h"
|
||||
|
||||
static int scePauth_F7AA47F6(u32 srcPtr, int srcLength, u32 destLengthPtr, u32 workArea)
|
||||
{
|
||||
auto src = Memory::GetPointerWrite(srcPtr);
|
||||
auto key = Memory::GetPointer(workArea);
|
||||
// workarea is actually the key?
|
||||
static int scePauth_F7AA47F6(u32 srcPtr, int srcLength, u32 destLengthPtr, u32 workArea) {
|
||||
if (!Memory::IsValidRange(srcPtr, srcLength)) {
|
||||
return hleLogError(Log::HLE, -1, "invalid source range");
|
||||
}
|
||||
if (!Memory::IsValidRange(workArea, 16)) { // guess about the key size
|
||||
return hleLogError(Log::HLE, -1, "invalid work area pointer");
|
||||
}
|
||||
if (!Memory::IsValid4AlignedAddress(destLengthPtr)) {
|
||||
return hleLogError(Log::HLE, -1, "invalid dest length pointer");
|
||||
}
|
||||
|
||||
u8 *src = Memory::GetPointerWriteUnchecked(srcPtr);
|
||||
const u8 *key = Memory::GetPointerUnchecked(workArea);
|
||||
|
||||
const auto decryptResult = pspDecryptPRX(src, src, srcLength, key);
|
||||
|
||||
if (decryptResult < 0)
|
||||
{
|
||||
if (decryptResult < 0) {
|
||||
ERROR_LOG(Log::HLE, "Pauth decryption failed 0x%08X", decryptResult);
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
Memory::Write_U32(decryptResult, destLengthPtr);
|
||||
Memory::WriteUnchecked_U32(decryptResult, destLengthPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int scePauth_98B83B5D(u32 srcPtr, int srcLength, u32 destLengthPtr, u32 workArea)
|
||||
{
|
||||
auto src = Memory::GetPointerWrite(srcPtr);
|
||||
auto key = Memory::GetPointer(workArea);
|
||||
static int scePauth_98B83B5D(u32 srcPtr, int srcLength, u32 destLengthPtr, u32 workArea) {
|
||||
if (!Memory::IsValidRange(srcPtr, srcLength)) {
|
||||
return hleLogError(Log::HLE, -1, "invalid source range");
|
||||
}
|
||||
if (!Memory::IsValidRange(workArea, 16)) { // guess about the key size
|
||||
return hleLogError(Log::HLE, -1, "invalid work area pointer");
|
||||
}
|
||||
if (!Memory::IsValid4AlignedAddress(destLengthPtr)) {
|
||||
return hleLogError(Log::HLE, -1, "invalid dest length pointer");
|
||||
}
|
||||
|
||||
u8 *src = Memory::GetPointerWriteUnchecked(srcPtr);
|
||||
const u8 *key = Memory::GetPointerUnchecked(workArea);
|
||||
|
||||
const auto decryptResult = pspDecryptPRX(src, src, srcLength, key);
|
||||
|
||||
if (decryptResult < 0)
|
||||
{
|
||||
if (decryptResult < 0) {
|
||||
ERROR_LOG(Log::HLE, "Pauth decryption failed 0x%08X", decryptResult);
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
Memory::Write_U32(decryptResult, destLengthPtr);
|
||||
Memory::WriteUnchecked_U32(decryptResult, destLengthPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -66,7 +82,6 @@ const HLEFunction scePauth[] = {
|
||||
{0X98B83B5D, &WrapI_UIUU<scePauth_98B83B5D>, "scePauth_98B83B5D", 'i', "xixx"},
|
||||
};
|
||||
|
||||
void Register_scePauth()
|
||||
{
|
||||
void Register_scePauth() {
|
||||
RegisterHLEModule("scePauth", ARRAY_SIZE(scePauth), scePauth);
|
||||
}
|
||||
+12
-4
@@ -409,16 +409,24 @@ static int sceKernelVolatileMemLock(int type, u32 paddr, u32 psize) {
|
||||
case SCE_KERNEL_ERROR_CAN_NOT_WAIT:
|
||||
{
|
||||
WARN_LOG(Log::HLE, "sceKernelVolatileMemLock(%i, %08x, %08x): dispatch disabled", type, paddr, psize);
|
||||
Memory::Write_U32(0x08400000, paddr);
|
||||
Memory::Write_U32(0x00400000, psize);
|
||||
if (Memory::IsValid4AlignedAddress(paddr)) {
|
||||
Memory::WriteUnchecked_U32(0x08400000, paddr);
|
||||
}
|
||||
if (Memory::IsValid4AlignedAddress(psize)) {
|
||||
Memory::WriteUnchecked_U32(0x00400000, psize);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_KERNEL_ERROR_ILLEGAL_CONTEXT:
|
||||
{
|
||||
WARN_LOG(Log::HLE, "sceKernelVolatileMemLock(%i, %08x, %08x): in interrupt", type, paddr, psize);
|
||||
Memory::Write_U32(0x08400000, paddr);
|
||||
Memory::Write_U32(0x00400000, psize);
|
||||
if (Memory::IsValid4AlignedAddress(paddr)) {
|
||||
Memory::WriteUnchecked_U32(0x08400000, paddr);
|
||||
}
|
||||
if (Memory::IsValid4AlignedAddress(psize)) {
|
||||
Memory::WriteUnchecked_U32(0x00400000, psize);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ static void error(const std::string &message) {
|
||||
// only support read/writes that refer to the name of a memory region.
|
||||
static int r32(int address) {
|
||||
if (Memory::IsValid4AlignedAddress(address)) {
|
||||
return Memory::Read_U32(address);
|
||||
return Memory::ReadUnchecked_U32(address);
|
||||
} else {
|
||||
g_lua.Print(LogLineType::Error, StringFromFormat("r32: bad address %08x", address));
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user