mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Net: Remove usage of Memory::WriteStruct().
This also validates pointer write size better.
This commit is contained in:
parent
3a372aa615
commit
8f96405ee5
4 changed files with 159 additions and 107 deletions
|
@ -785,11 +785,12 @@ static void sceNetEtherStrton(u32 bufferPtr, u32 macPtr) {
|
|||
// Write static data since we don't actually manage any memory for sceNet* yet.
|
||||
static int sceNetGetMallocStat(u32 statPtr) {
|
||||
VERBOSE_LOG(SCENET, "UNTESTED sceNetGetMallocStat(%x) at %08x", statPtr, currentMIPS->pc);
|
||||
if(Memory::IsValidAddress(statPtr))
|
||||
Memory::WriteStruct(statPtr, &netMallocStat);
|
||||
else
|
||||
ERROR_LOG(SCENET, "UNTESTED sceNetGetMallocStat(%x): tried to request invalid address!", statPtr);
|
||||
auto stat = PSPPointer<SceNetMallocStat>::Create(statPtr);
|
||||
if (!stat.IsValid())
|
||||
return hleLogError(SCENET, 0, "invalid address");
|
||||
|
||||
*stat = netMallocStat;
|
||||
stat.NotifyWrite("sceNetGetMallocStat");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -893,77 +894,128 @@ static int sceNetApctlGetInfo(int code, u32 pInfoAddr) {
|
|||
if (!netApctlInited)
|
||||
return hleLogError(SCENET, ERROR_NET_APCTL_NOT_IN_BSS, "apctl not in bss"); // Only have valid info after joining an AP and got an IP, right?
|
||||
|
||||
if (!Memory::IsValidAddress(pInfoAddr))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
|
||||
u8* info = Memory::GetPointerWrite(pInfoAddr); // FIXME: Points to a union instead of a struct thus each field have the same address
|
||||
|
||||
switch (code) {
|
||||
case PSP_NET_APCTL_INFO_PROFILE_NAME:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.name);
|
||||
if (!Memory::IsValidRange(pInfoAddr, APCTL_PROFILENAME_MAXLEN))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::MemcpyUnchecked(pInfoAddr, netApctlInfo.name, APCTL_PROFILENAME_MAXLEN);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, APCTL_PROFILENAME_MAXLEN, "NetApctlGetInfo");
|
||||
DEBUG_LOG(SCENET, "ApctlInfo - ProfileName: %s", netApctlInfo.name);
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_BSSID:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.bssid);
|
||||
if (!Memory::IsValidRange(pInfoAddr, ETHER_ADDR_LEN))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::MemcpyUnchecked(pInfoAddr, netApctlInfo.bssid, ETHER_ADDR_LEN);
|
||||
DEBUG_LOG(SCENET, "ApctlInfo - BSSID: %s", mac2str((SceNetEtherAddr*)&netApctlInfo.bssid).c_str());
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, ETHER_ADDR_LEN, "NetApctlGetInfo");
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_SSID:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.ssid);
|
||||
if (!Memory::IsValidRange(pInfoAddr, APCTL_SSID_MAXLEN))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::MemcpyUnchecked(pInfoAddr, netApctlInfo.ssid, APCTL_SSID_MAXLEN);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, APCTL_SSID_MAXLEN, "NetApctlGetInfo");
|
||||
DEBUG_LOG(SCENET, "ApctlInfo - SSID: %s", netApctlInfo.ssid);
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_SSID_LENGTH:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.ssidLength);
|
||||
if (!Memory::IsValidRange(pInfoAddr, 4))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::WriteUnchecked_U32(netApctlInfo.ssidLength, pInfoAddr);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, 4, "NetApctlGetInfo");
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_SECURITY_TYPE:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.securityType);
|
||||
if (!Memory::IsValidRange(pInfoAddr, 4))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::WriteUnchecked_U32(netApctlInfo.securityType, pInfoAddr);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, 4, "NetApctlGetInfo");
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_STRENGTH:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.strength);
|
||||
if (!Memory::IsValidRange(pInfoAddr, 1))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::WriteUnchecked_U8(netApctlInfo.strength, pInfoAddr);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, 1, "NetApctlGetInfo");
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_CHANNEL:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.channel);
|
||||
if (!Memory::IsValidRange(pInfoAddr, 1))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::WriteUnchecked_U8(netApctlInfo.channel, pInfoAddr);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, 1, "NetApctlGetInfo");
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_POWER_SAVE:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.powerSave);
|
||||
if (!Memory::IsValidRange(pInfoAddr, 1))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::WriteUnchecked_U8(netApctlInfo.powerSave, pInfoAddr);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, 1, "NetApctlGetInfo");
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_IP:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.ip);
|
||||
if (!Memory::IsValidRange(pInfoAddr, APCTL_IPADDR_MAXLEN))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::MemcpyUnchecked(pInfoAddr, netApctlInfo.ip, APCTL_IPADDR_MAXLEN);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, APCTL_IPADDR_MAXLEN, "NetApctlGetInfo");
|
||||
DEBUG_LOG(SCENET, "ApctlInfo - IP: %s", netApctlInfo.ip);
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_SUBNETMASK:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.subNetMask);
|
||||
if (!Memory::IsValidRange(pInfoAddr, APCTL_IPADDR_MAXLEN))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::MemcpyUnchecked(pInfoAddr, netApctlInfo.subNetMask, APCTL_IPADDR_MAXLEN);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, APCTL_IPADDR_MAXLEN, "NetApctlGetInfo");
|
||||
DEBUG_LOG(SCENET, "ApctlInfo - SubNet Mask: %s", netApctlInfo.subNetMask);
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_GATEWAY:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.gateway);
|
||||
if (!Memory::IsValidRange(pInfoAddr, APCTL_IPADDR_MAXLEN))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::MemcpyUnchecked(pInfoAddr, netApctlInfo.gateway, APCTL_IPADDR_MAXLEN);
|
||||
DEBUG_LOG(SCENET, "ApctlInfo - Gateway IP: %s", netApctlInfo.gateway);
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_PRIMDNS:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.primaryDns);
|
||||
if (!Memory::IsValidRange(pInfoAddr, APCTL_IPADDR_MAXLEN))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::MemcpyUnchecked(pInfoAddr, netApctlInfo.primaryDns, APCTL_IPADDR_MAXLEN);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, APCTL_IPADDR_MAXLEN, "NetApctlGetInfo");
|
||||
DEBUG_LOG(SCENET, "ApctlInfo - Primary DNS: %s", netApctlInfo.primaryDns);
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_SECDNS:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.secondaryDns);
|
||||
if (!Memory::IsValidRange(pInfoAddr, APCTL_IPADDR_MAXLEN))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::MemcpyUnchecked(pInfoAddr, netApctlInfo.secondaryDns, APCTL_IPADDR_MAXLEN);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, APCTL_IPADDR_MAXLEN, "NetApctlGetInfo");
|
||||
DEBUG_LOG(SCENET, "ApctlInfo - Secondary DNS: %s", netApctlInfo.secondaryDns);
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_USE_PROXY:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.useProxy);
|
||||
if (!Memory::IsValidRange(pInfoAddr, 4))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::WriteUnchecked_U32(netApctlInfo.useProxy, pInfoAddr);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, 4, "NetApctlGetInfo");
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_PROXY_URL:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.proxyUrl);
|
||||
if (!Memory::IsValidRange(pInfoAddr, APCTL_URL_MAXLEN))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::MemcpyUnchecked(pInfoAddr, netApctlInfo.proxyUrl, APCTL_URL_MAXLEN);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, APCTL_URL_MAXLEN, "NetApctlGetInfo");
|
||||
DEBUG_LOG(SCENET, "ApctlInfo - Proxy URL: %s", netApctlInfo.proxyUrl);
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_PROXY_PORT:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.proxyPort);
|
||||
if (!Memory::IsValidRange(pInfoAddr, 2))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::WriteUnchecked_U16(netApctlInfo.proxyPort, pInfoAddr);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, 2, "NetApctlGetInfo");
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_8021_EAP_TYPE:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.eapType);
|
||||
if (!Memory::IsValidRange(pInfoAddr, 4))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::WriteUnchecked_U32(netApctlInfo.eapType, pInfoAddr);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, 4, "NetApctlGetInfo");
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_START_BROWSER:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.startBrowser);
|
||||
if (!Memory::IsValidRange(pInfoAddr, 4))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::WriteUnchecked_U32(netApctlInfo.startBrowser, pInfoAddr);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, 4, "NetApctlGetInfo");
|
||||
break;
|
||||
case PSP_NET_APCTL_INFO_WIFISP:
|
||||
Memory::WriteStruct(pInfoAddr, &netApctlInfo.wifisp);
|
||||
if (!Memory::IsValidRange(pInfoAddr, 4))
|
||||
return hleLogError(SCENET, -1, "apctl invalid arg");
|
||||
Memory::WriteUnchecked_U32(netApctlInfo.wifisp, pInfoAddr);
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, pInfoAddr, 4, "NetApctlGetInfo");
|
||||
break;
|
||||
default:
|
||||
return hleLogError(SCENET, ERROR_NET_APCTL_INVALID_CODE, "apctl invalid code");
|
||||
|
@ -1234,28 +1286,28 @@ int NetApctl_GetBSSDescEntryUser(int entryId, int infoId, u32 resultAddr) {
|
|||
switch (infoId) {
|
||||
case PSP_NET_APCTL_DESC_IBSS: // IBSS, 6 bytes
|
||||
if (entryId == 0)
|
||||
Memory::WriteStruct(resultAddr, &netApctlInfo.bssid);
|
||||
Memory::Memcpy(resultAddr, netApctlInfo.bssid, sizeof(netApctlInfo.bssid), "GetBSSDescEntryUser");
|
||||
else {
|
||||
// Generate a BSSID/MAC address
|
||||
char dummyMAC[ETHER_ADDR_LEN];
|
||||
memset(dummyMAC, entryId, sizeof(dummyMAC));
|
||||
// Making sure the 1st 2-bits on the 1st byte of OUI are zero to prevent issue with some games (ie. Gran Turismo)
|
||||
dummyMAC[0] &= 0xfc;
|
||||
Memory::WriteStruct(resultAddr, &dummyMAC);
|
||||
Memory::Memcpy(resultAddr, dummyMAC, sizeof(dummyMAC), "GetBSSDescEntryUser");
|
||||
}
|
||||
break;
|
||||
case PSP_NET_APCTL_DESC_SSID_NAME:
|
||||
// Return 32 bytes
|
||||
if (entryId == 0)
|
||||
Memory::WriteStruct(resultAddr, &netApctlInfo.ssid);
|
||||
Memory::Memcpy(resultAddr, netApctlInfo.ssid, sizeof(netApctlInfo.ssid), "GetBSSDescEntryUser");
|
||||
else {
|
||||
Memory::WriteStruct(resultAddr, &dummySSID);
|
||||
Memory::Memcpy(resultAddr, dummySSID, sizeof(dummySSID), "GetBSSDescEntryUser");
|
||||
}
|
||||
break;
|
||||
case PSP_NET_APCTL_DESC_SSID_NAME_LENGTH:
|
||||
// Return one 32-bit value
|
||||
if (entryId == 0)
|
||||
Memory::WriteStruct(resultAddr, &netApctlInfo.ssidLength);
|
||||
Memory::Write_U32(netApctlInfo.ssidLength, resultAddr);
|
||||
else {
|
||||
// Calculate the SSID length
|
||||
Memory::Write_U32((u32)strlen(dummySSID), resultAddr);
|
||||
|
@ -1264,7 +1316,7 @@ int NetApctl_GetBSSDescEntryUser(int entryId, int infoId, u32 resultAddr) {
|
|||
case PSP_NET_APCTL_DESC_CHANNEL:
|
||||
// FIXME: Return one 1 byte value or may be 32-bit if this is not a channel?
|
||||
if (entryId == 0)
|
||||
Memory::WriteStruct(resultAddr, &netApctlInfo.channel);
|
||||
Memory::Write_U8(netApctlInfo.channel, resultAddr);
|
||||
else {
|
||||
// Generate channel for testing purposes, not even sure whether this is channel or not, MGS:PW seems to treat the data as u8
|
||||
Memory::Write_U8(entryId, resultAddr);
|
||||
|
@ -1273,7 +1325,7 @@ int NetApctl_GetBSSDescEntryUser(int entryId, int infoId, u32 resultAddr) {
|
|||
case PSP_NET_APCTL_DESC_SIGNAL_STRENGTH:
|
||||
// Return 1 byte
|
||||
if (entryId == 0)
|
||||
Memory::WriteStruct(resultAddr, &netApctlInfo.strength);
|
||||
Memory::Write_U8(netApctlInfo.strength, resultAddr);
|
||||
else {
|
||||
// Randomize signal strength between 1%~99% since games like MGS:PW are using signal strength to determine the strength of the recruit
|
||||
Memory::Write_U8((int)(((float)rand() / (float)RAND_MAX) * 99.0 + 1.0), resultAddr);
|
||||
|
@ -1281,7 +1333,7 @@ int NetApctl_GetBSSDescEntryUser(int entryId, int infoId, u32 resultAddr) {
|
|||
break;
|
||||
case PSP_NET_APCTL_DESC_SECURITY:
|
||||
// Return one 32-bit value
|
||||
Memory::WriteStruct(resultAddr, &netApctlInfo.securityType);
|
||||
Memory::Write_U32(netApctlInfo.securityType, resultAddr);
|
||||
break;
|
||||
default:
|
||||
return hleLogError(SCENET, ERROR_NET_APCTL_INVALID_CODE, "unknown info id");
|
||||
|
@ -1432,7 +1484,7 @@ const HLEFunction sceNet[] = {
|
|||
{0XD27961C9, &WrapV_UU<sceNetEtherStrton>, "sceNetEtherStrton", 'v', "xx" },
|
||||
{0X0BF0A3AE, &WrapU_U<sceNetGetLocalEtherAddr>, "sceNetGetLocalEtherAddr", 'x', "x" },
|
||||
{0X50647530, &WrapI_I<sceNetFreeThreadinfo>, "sceNetFreeThreadinfo", 'i', "i" },
|
||||
{0XCC393E48, &WrapI_U<sceNetGetMallocStat>, "sceNetGetMallocStat", 'i', "x" },
|
||||
{0XCC393E48, &WrapI_U<sceNetGetMallocStat>, "sceNetGetMallocStat", 'i', "p" },
|
||||
{0XAD6844C6, &WrapI_I<sceNetThreadAbort>, "sceNetThreadAbort", 'i', "i" },
|
||||
};
|
||||
|
||||
|
|
|
@ -1303,8 +1303,10 @@ static u32 sceNetAdhocctlInit(int stackSize, int prio, u32 productAddr) {
|
|||
if (netAdhocctlInited)
|
||||
return ERROR_NET_ADHOCCTL_ALREADY_INITIALIZED;
|
||||
|
||||
if (Memory::IsValidAddress(productAddr)) {
|
||||
Memory::ReadStruct(productAddr, &product_code);
|
||||
auto product = PSPPointer<SceNetAdhocctlAdhocId>::Create(productAddr);
|
||||
if (product.IsValid()) {
|
||||
product_code = *product;
|
||||
product.NotifyRead("NetAdhocctlInit");
|
||||
}
|
||||
|
||||
adhocctlEvents.clear();
|
||||
|
@ -1539,21 +1541,17 @@ static int sceNetAdhocctlGetParameter(u32 paramAddr) {
|
|||
}
|
||||
|
||||
// Library initialized
|
||||
if (netAdhocctlInited) {
|
||||
// Valid Arguments
|
||||
if (Memory::IsValidAddress(paramAddr)) {
|
||||
// Copy Parameter
|
||||
Memory::WriteStruct(paramAddr,¶meter);
|
||||
// Return Success
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Invalid Arguments
|
||||
return ERROR_NET_ADHOCCTL_INVALID_ARG;
|
||||
if (!netAdhocctlInited) {
|
||||
return hleLogError(SCENET, ERROR_NET_ADHOCCTL_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
// Library uninitialized
|
||||
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
|
||||
auto ptr = PSPPointer<SceNetAdhocctlParameter>::Create(paramAddr);
|
||||
if (!ptr.IsValid())
|
||||
return hleLogError(SCENET, ERROR_NET_ADHOCCTL_INVALID_ARG);
|
||||
|
||||
*ptr = parameter;
|
||||
ptr.NotifyWrite("NetAdhocctlGetParameter");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2258,25 +2256,17 @@ static int sceNetAdhocPdpDelete(int id, int unknown) {
|
|||
static int sceNetAdhocctlGetAdhocId(u32 productStructAddr) {
|
||||
INFO_LOG(SCENET, "sceNetAdhocctlGetAdhocId(%08x) at %08x", productStructAddr, currentMIPS->pc);
|
||||
|
||||
// Library initialized
|
||||
if (netAdhocctlInited)
|
||||
{
|
||||
// Valid Arguments
|
||||
if (Memory::IsValidAddress(productStructAddr))
|
||||
{
|
||||
// Copy Product ID
|
||||
Memory::WriteStruct(productStructAddr, &product_code);
|
||||
if (!netAdhocctlInited)
|
||||
return hleLogDebug(SCENET, ERROR_NET_ADHOCCTL_NOT_INITIALIZED, "not initialized");
|
||||
|
||||
// Return Success
|
||||
return hleLogDebug(SCENET, 0, "type = %d, code = %s", product_code.type, product_code.data);
|
||||
}
|
||||
|
||||
// Invalid Arguments
|
||||
auto productStruct = PSPPointer<SceNetAdhocctlAdhocId>::Create(productStructAddr);
|
||||
if (!productStruct.IsValid())
|
||||
return hleLogDebug(SCENET, ERROR_NET_ADHOCCTL_INVALID_ARG, "invalid arg");
|
||||
}
|
||||
|
||||
// Library uninitialized
|
||||
return hleLogDebug(SCENET, ERROR_NET_ADHOCCTL_NOT_INITIALIZED, "not initialized");
|
||||
*productStruct = product_code;
|
||||
productStruct.NotifyWrite("NetAdhocctlGetAdhocId");
|
||||
|
||||
return hleLogDebug(SCENET, 0, "type = %d, code = %s", product_code.type, product_code.data);
|
||||
}
|
||||
|
||||
// FIXME: Scan probably not a blocking function since there is ADHOCCTL_STATE_SCANNING state that can be polled by the game, right? But apparently it need to be delayed for Naruto Shippuden Ultimate Ninja Heroes 3
|
||||
|
|
|
@ -154,15 +154,15 @@ static int sceNpGetOnlineId(u32 idPtr)
|
|||
{
|
||||
WARN_LOG(SCENET, "UNTESTED %s(%08x)", __FUNCTION__, idPtr);
|
||||
|
||||
if (!Memory::IsValidAddress(idPtr))
|
||||
auto id = PSPPointer<SceNpOnlineId>::Create(idPtr);
|
||||
if (!id.IsValid())
|
||||
return hleLogError(SCENET, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg");
|
||||
|
||||
SceNpOnlineId dummyOnlineId{};
|
||||
truncate_cpy(dummyOnlineId.data, sizeof(dummyOnlineId.data), npOnlineId.c_str());
|
||||
memset((SceNpOnlineId *)id, 0, sizeof(SceNpOnlineId));
|
||||
truncate_cpy(id->data, sizeof(id->data), npOnlineId.c_str());
|
||||
id.NotifyWrite("NpGetOnlineId");
|
||||
|
||||
INFO_LOG(SCENET, "%s - Online ID: %s", __FUNCTION__, dummyOnlineId.data);
|
||||
|
||||
Memory::WriteStruct(idPtr, &dummyOnlineId);
|
||||
INFO_LOG(SCENET, "%s - Online ID: %s", __FUNCTION__, id->data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -177,20 +177,21 @@ static int sceNpGetNpId(u32 idPtr)
|
|||
{
|
||||
WARN_LOG(SCENET, "UNTESTED %s(%08x)", __FUNCTION__, idPtr);
|
||||
|
||||
if (!Memory::IsValidAddress(idPtr))
|
||||
auto id = PSPPointer<SceNpId>::Create(idPtr);
|
||||
if (!id.IsValid())
|
||||
return hleLogError(SCENET, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg");
|
||||
|
||||
SceNpId dummyNpId{};
|
||||
int retval = NpGetNpId(&dummyNpId);
|
||||
memset((SceNpId *)id, 0, sizeof(SceNpId));
|
||||
int retval = NpGetNpId(id);
|
||||
if (retval < 0)
|
||||
return hleLogError(SCENET, retval);
|
||||
|
||||
INFO_LOG(SCENET, "%s - Online ID: %s", __FUNCTION__, dummyNpId.handle.data);
|
||||
INFO_LOG(SCENET, "%s - Online ID: %s", __FUNCTION__, id->handle.data);
|
||||
std::string datahex;
|
||||
DataToHexString(dummyNpId.opt, sizeof(dummyNpId.opt), &datahex);
|
||||
DataToHexString(id->opt, sizeof(id->opt), &datahex);
|
||||
INFO_LOG(SCENET, "%s - Options?: %s", __FUNCTION__, datahex.c_str());
|
||||
|
||||
Memory::WriteStruct(idPtr, &dummyNpId);
|
||||
id.NotifyWrite("NpGetNpId");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -199,19 +200,21 @@ static int sceNpGetAccountRegion(u32 countryCodePtr, u32 regionCodePtr)
|
|||
{
|
||||
WARN_LOG(SCENET, "UNTESTED %s(%08x, %08x)", __FUNCTION__, countryCodePtr, regionCodePtr);
|
||||
|
||||
if (!Memory::IsValidAddress(countryCodePtr) || !Memory::IsValidAddress(regionCodePtr))
|
||||
auto countryCode = PSPPointer<SceNpCountryCode>::Create(countryCodePtr);
|
||||
auto regionCode = PSPPointer<SceNpCountryCode>::Create(regionCodePtr);
|
||||
if (!countryCode.IsValid() || !regionCode.IsValid())
|
||||
return hleLogError(SCENET, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg");
|
||||
|
||||
SceNpCountryCode dummyCountryCode{};
|
||||
memcpy(dummyCountryCode.data, npCountryCode, sizeof(dummyCountryCode.data));
|
||||
SceNpCountryCode dummyRegionCode{};
|
||||
memcpy(dummyRegionCode.data, npRegionCode, sizeof(dummyRegionCode.data));
|
||||
memset((SceNpCountryCode *)countryCode, 0, sizeof(SceNpCountryCode));
|
||||
memcpy(countryCode->data, npCountryCode, sizeof(countryCode->data));
|
||||
memset((SceNpCountryCode *)regionCode, 0, sizeof(SceNpCountryCode));
|
||||
memcpy(regionCode->data, npRegionCode, sizeof(regionCode->data));
|
||||
|
||||
INFO_LOG(SCENET, "%s - Country Code: %s", __FUNCTION__, dummyCountryCode.data);
|
||||
INFO_LOG(SCENET, "%s - Region? Code: %s", __FUNCTION__, dummyRegionCode.data);
|
||||
INFO_LOG(SCENET, "%s - Country Code: %s", __FUNCTION__, countryCode->data);
|
||||
INFO_LOG(SCENET, "%s - Region? Code: %s", __FUNCTION__, regionCode->data);
|
||||
|
||||
Memory::WriteStruct(countryCodePtr, &dummyCountryCode);
|
||||
Memory::WriteStruct(regionCodePtr, &dummyRegionCode);
|
||||
countryCode.NotifyWrite("NpGetAccountRegion");
|
||||
regionCode.NotifyWrite("NpGetAccountRegion");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -220,14 +223,16 @@ static int sceNpGetMyLanguages(u32 langListPtr)
|
|||
{
|
||||
WARN_LOG(SCENET, "UNTESTED %s(%08x)", __FUNCTION__, langListPtr);
|
||||
|
||||
if (!Memory::IsValidAddress(langListPtr))
|
||||
auto langList = PSPPointer<SceNpMyLanguages>::Create(langListPtr);
|
||||
if (!langList.IsValid())
|
||||
return hleLogError(SCENET, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg");
|
||||
|
||||
INFO_LOG(SCENET, "%s - Language1 Code: %d", __FUNCTION__, npMyLangList.language1);
|
||||
INFO_LOG(SCENET, "%s - Language2 Code: %d", __FUNCTION__, npMyLangList.language2);
|
||||
INFO_LOG(SCENET, "%s - Language3 Code: %d", __FUNCTION__, npMyLangList.language3);
|
||||
|
||||
Memory::WriteStruct(langListPtr, &npMyLangList);
|
||||
*langList = npMyLangList;
|
||||
langList.NotifyWrite("NpGetMyLanguages");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -236,20 +241,21 @@ static int sceNpGetUserProfile(u32 profilePtr)
|
|||
{
|
||||
WARN_LOG(SCENET, "UNTESTED %s(%08x)", __FUNCTION__, profilePtr);
|
||||
|
||||
auto profile = PSPPointer<SceNpUserInformation>::Create(profilePtr);
|
||||
if (!Memory::IsValidAddress(profilePtr))
|
||||
return hleLogError(SCENET, SCE_NP_ERROR_INVALID_ARGUMENT, "invalid arg");
|
||||
|
||||
SceNpUserInformation dummyProfile{};
|
||||
truncate_cpy(dummyProfile.userId.handle.data, sizeof(dummyProfile.userId.handle.data), npOnlineId.c_str());
|
||||
truncate_cpy(dummyProfile.icon.data, sizeof(dummyProfile.icon.data), npAvatarUrl.c_str());
|
||||
memset((SceNpUserInformation *)profile, 0, sizeof(SceNpUserInformation));
|
||||
truncate_cpy(profile->userId.handle.data, sizeof(profile->userId.handle.data), npOnlineId.c_str());
|
||||
truncate_cpy(profile->icon.data, sizeof(profile->icon.data), npAvatarUrl.c_str());
|
||||
|
||||
INFO_LOG(SCENET, "%s - Online ID: %s", __FUNCTION__, dummyProfile.userId.handle.data);
|
||||
INFO_LOG(SCENET, "%s - Online ID: %s", __FUNCTION__, profile->userId.handle.data);
|
||||
std::string datahex;
|
||||
DataToHexString(dummyProfile.userId.opt, sizeof(dummyProfile.userId.opt), &datahex);
|
||||
DataToHexString(profile->userId.opt, sizeof(profile->userId.opt), &datahex);
|
||||
INFO_LOG(SCENET, "%s - Options?: %s", __FUNCTION__, datahex.c_str());
|
||||
INFO_LOG(SCENET, "%s - Avatar URL: %s", __FUNCTION__, dummyProfile.icon.data);
|
||||
INFO_LOG(SCENET, "%s - Avatar URL: %s", __FUNCTION__, profile->icon.data);
|
||||
|
||||
Memory::WriteStruct(profilePtr, &dummyProfile);
|
||||
profile.NotifyWrite("NpGetUserProfile");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -295,10 +301,12 @@ int sceNpAuthGetMemoryStat(u32 memStatAddr)
|
|||
{
|
||||
ERROR_LOG(SCENET, "UNIMPL %s(%08x)", __FUNCTION__, memStatAddr);
|
||||
|
||||
if (!Memory::IsValidAddress(memStatAddr))
|
||||
auto memStat = PSPPointer<SceNpAuthMemoryStat>::Create(memStatAddr);
|
||||
if (!memStat.IsValid())
|
||||
return hleLogError(SCENET, SCE_NP_AUTH_ERROR_INVALID_ARGUMENT, "invalid arg");
|
||||
|
||||
Memory::WriteStruct(memStatAddr, &npAuthMemStat);
|
||||
*memStat = npAuthMemStat;
|
||||
memStat.NotifyWrite("NpAuthGetMemoryStat");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -386,7 +394,7 @@ int sceNpAuthGetTicket(u32 requestId, u32 bufferAddr, u32 length)
|
|||
return hleLogError(SCENET, SCE_NP_AUTH_ERROR_INVALID_ARGUMENT, "invalid arg");
|
||||
|
||||
int result = length;
|
||||
Memory::Memset(bufferAddr, 0, length);
|
||||
Memory::Memset(bufferAddr, 0, length, "NpAuthGetTicket");
|
||||
SceNpTicket ticket = {};
|
||||
// Dummy Login ticket returned as Login response. Dummy ticket contents were taken from https://www.psdevwiki.com/ps3/X-I-5-Ticket
|
||||
ticket.header.version = TICKET_VER_2_1;
|
||||
|
@ -415,14 +423,14 @@ int sceNpAuthGetTicket(u32 requestId, u32 bufferAddr, u32 length)
|
|||
ofs += writeTicketParam(buf + ofs, PARAM_TYPE_NULL);
|
||||
ticket.section.type = SECTION_TYPE_BODY;
|
||||
ticket.section.size = ofs;
|
||||
Memory::WriteStruct(bufferAddr, &ticket);
|
||||
Memory::Memcpy(bufferAddr, &ticket, sizeof(SceNpTicket), "NpAuthGetTicket");
|
||||
SceNpTicketSection footer = { SECTION_TYPE_FOOTER, 32 }; // footer section? ie. 32-bytes on version 2.1 containing 4-chars ASCII + 20-chars ASCII
|
||||
Memory::WriteStruct(bufferAddr + sizeof(ticket) + ofs, &footer);
|
||||
Memory::Memcpy(bufferAddr + sizeof(ticket) + ofs, &footer, sizeof(SceNpTicketSection), "NpAuthGetTicket");
|
||||
ofs += sizeof(footer);
|
||||
ofs += writeTicketParam(buf + ofs, PARAM_TYPE_STRING_ASCII, "\x34\xcd\x3c\xa9", 4);
|
||||
ofs += writeTicketParam(buf + ofs, PARAM_TYPE_STRING_ASCII, "\x3a\x4b\x42\x66\x92\xda\x6b\x7c\xb7\x4c\xe8\xd9\x4f\x2b\x77\x15\x91\xb8\xa4\xa9", 20); // 20 random letters, token key or SceNpSignature?
|
||||
u8 unknownBytes[36] = {}; // includes Language list?
|
||||
Memory::WriteStruct(bufferAddr + sizeof(ticket) + ofs, unknownBytes);
|
||||
// includes Language list?
|
||||
Memory::Memset(bufferAddr + sizeof(ticket) + ofs, 0, 36);
|
||||
|
||||
result = ticket.header.size + sizeof(ticket.header); // dummy ticket is 248 bytes
|
||||
|
||||
|
|
|
@ -280,10 +280,12 @@ static int sceNpMatching2GetMemoryStat(u32 memStatPtr)
|
|||
if (!npMatching2Inited)
|
||||
return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED);
|
||||
|
||||
if (!Memory::IsValidAddress(memStatPtr))
|
||||
auto memStat = PSPPointer<SceNpAuthMemoryStat>::Create(memStatPtr);
|
||||
if (!memStat.IsValid())
|
||||
return hleLogError(SCENET, SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT);
|
||||
|
||||
Memory::WriteStruct(memStatPtr, &npMatching2MemStat);
|
||||
*memStat = npMatching2MemStat;
|
||||
memStat.NotifyWrite("NpMatching2GetMemoryStat");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue