/* * Starboard 15 system identification and entropy on Sony PlayStation Vita. * * The platform MUST NOT impersonate a certified YouTube device or Nintendo * Switch. Unsupported property IDs return false. Randomness uses the genuine * Vita kernel CSPRNG and fails closed rather than using insecure rand(). */ #include #include "starboard/system.h" #ifndef YTV_DEVICE_IDENTITY_PS4 #define YTV_DEVICE_IDENTITY_PS4 1 // see SbSystemGetProperty #endif #include "starboard/log.h" #include "starboard/cpu_features.h" #include #include #include #include #include #include #include #include #include #include namespace { const char* const kLocales[] = { "ja_JP", "en_US", "fr_FR", "es_ES", "de_DE", "it_IT", "nl_NL", "pt_PT", "ru_RU", "ko_KR", "zh_TW", "zh_CN", "fi_FI", "sv_SE", "da_DK", "nb_NO", "pl_PL", "pt_BR", "en_GB", "tr_TR" }; bool get_console_parameter(int id,int* result) { if(!result)return false; // sceAppUtilSystemParamGetInt works in Vita3K's emulated system. // If unavailable, do not infer a user's region from their IP. return sceAppUtilSystemParamGetInt(id,result)>=0; } bool copy_value(const char* value,char* out,int cap) { if(!value || !out || cap<=0)return false; size_t len=strlen(value); if(len+1>static_cast(cap))return false; memcpy(out,value,len+1); return true; } } extern "C" { const char* SbSystemGetLocaleId() { int id=-1; if(get_console_parameter(SCE_SYSTEM_PARAM_ID_LANG,&id) && id>=0 && id<(int)(sizeof(kLocales)/sizeof(kLocales[0]))) return kLocales[id]; return "en_US"; // explicit safe default when system locale is unavailable } int64_t ytv_measured_total_memory = 0; // set by the ELF loader bool SbSystemGetProperty(SbSystemPropertyId id,char* out,int len) { const char* property=nullptr; switch(id) { #if YTV_DEVICE_IDENTITY_PS4 // Device identity presented to services (User-Agent device token). // Project owner's decision (2026-11-17): YouTube's /tv serves the // "not available on this device" page to "PlayStation Vita" and the // TVHTML5 app to "PlayStation 4". Only the identity strings change; no // certification scope or signing key is claimed (see below). case kSbSystemPropertyBrandName: property="Sony"; break; case kSbSystemPropertyModelName: property="PlayStation 4"; break; case kSbSystemPropertyModelYear: property="2013"; break; case kSbSystemPropertyFirmwareVersion: property="12.00"; break; case kSbSystemPropertyFriendlyName: property="PlayStation Vita"; break; #else case kSbSystemPropertyBrandName: property="Sony"; break; case kSbSystemPropertyModelName: property="PlayStation Vita"; break; case kSbSystemPropertyModelYear: property="2011"; break; case kSbSystemPropertyFriendlyName: property="PlayStation Vita"; break; #endif case kSbSystemPropertyPlatformName: property="PS Vita"; break; case kSbSystemPropertyDeviceType: property="GAME_CONSOLE"; break; // Deliberately DO NOT claim a certification scope, Speech API key, // chipset part number, ad ID, or system integrator. default: return false; } return copy_value(property,out,len); } bool SbSystemHasCapability(SbSystemCapabilityId id){ switch(id) { case kSbSystemCapabilityReversedEnterAndBack: { int button=-1; return get_console_parameter(SCE_SYSTEM_PARAM_ID_ENTER_BUTTON,&button) && button==SCE_SYSTEM_PARAM_ENTER_BUTTON_CIRCLE; } case kSbSystemCapabilityCanQueryGPUMemoryStats: return false; default:return false; } } extern "C" int ytv_vita_cpu_count(); int SbSystemGetNumberOfProcessors() { // Four Cortex-A9 cores; the 4th is usable only with CapUnlocker. return ytv_vita_cpu_count(); } int64_t SbSystemGetTotalCPUMemory() { // Budget measured by the loader at process start: the user RAM the system // granted under the VPK's param.sfo memory mode (ATTRIBUTE2=12, extended // memory, as in DeltaruneVita). Capped at 365 MiB; 365 MiB if unmeasured. extern int64_t ytv_measured_total_memory; const int64_t cap = 365LL*1024*1024; int64_t m = ytv_measured_total_memory; return (m > 0 && m < cap) ? m : cap; } int64_t SbSystemGetUsedCPUMemory(){ // VitaSDK provides no total resident-process-memory counter here. // Return zero instead of a fake measurement; do not claim it's measured. return 0; } bool SbCPUFeaturesGet(SbCPUFeatures* out) { if(!out)return false; memset(out,0,sizeof(*out)); out->architecture=kSbCPUFeaturesArchitectureArm; out->brand="ARM Cortex-A9 (PS Vita)"; out->icache_line_size=32; out->dcache_line_size=32; out->has_fpu=true; out->arm.implementer=0x41; out->arm.architecture_generation=7; out->arm.part=0xC09; out->arm.has_neon=true; // DIAGNOSTIC ONLY: the presence of ux0:data/youtubevita/diag_hide_neon.txt // hides NEON from Cobalt (BoringSSL then uses its generic C crypto), to // test whether a TLS failure comes from emulator NEON behaviour. Real // hardware has NEON; the file must never exist in a normal setup. { SceIoStat st; if(sceIoGetstat("ux0:data/youtubevita/diag_hide_neon.txt",&st)>=0){ out->arm.has_neon=false; SbLogRaw("YTV_DIAG_CPU_FEATURES neon hidden (diagnostic file present)\n"); } } out->arm.has_thumb2=true; out->arm.has_vfp=true; out->arm.has_vfp3=true; out->arm.has_vfp3_d32=true; // CPU variant, revision and unsupported instruction extensions remain // conservative zeros, not guessed from emulator host capabilities. return true; } void SbSystemGetRandomData(void* output,int bytes){ if(!output || bytes<=0)return; unsigned char* p=static_cast(output); int offset=0; while(offset64?64:bytes-offset; int status=sceKernelGetRandomNumber(p+offset,(SceSize)n); if(status<0){ memset(p,0,(size_t)bytes); SbLogRaw("ERROR: Vita CSPRNG unavailable; refusing insecure randomness\n"); abort(); } offset+=n; } } uint64_t SbSystemGetRandomUInt64(){ uint64_t random=0; SbSystemGetRandomData(&random,(int)sizeof(random)); return random; } SbSystemError SbSystemGetLastError() {return errno;} void SbSystemClearLastError() {errno=0;} int SbSystemGetErrorString(SbSystemError error,char* out,int size){ const char* message=strerror(error); if(!message)message="Unknown error"; int len=(int)strlen(message); if(out && size>0){ int n=len