2017-04-13 18:30:25 +02:00
|
|
|
#include "stdafx.h"
|
2018-09-29 00:12:00 +02:00
|
|
|
#include "sys_ss.h"
|
|
|
|
|
|
2019-11-01 20:21:15 +01:00
|
|
|
#include "sys_process.h"
|
2020-02-20 21:10:49 +01:00
|
|
|
#include "Emu/IdManager.h"
|
2017-04-13 18:30:25 +02:00
|
|
|
#include "Emu/Cell/PPUThread.h"
|
|
|
|
|
|
2017-09-25 17:52:34 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
#include <Windows.h>
|
2020-02-29 10:09:39 +01:00
|
|
|
#include <bcrypt.h>
|
2017-09-25 17:52:34 +02:00
|
|
|
#endif
|
|
|
|
|
|
2020-02-20 21:10:49 +01:00
|
|
|
template<>
|
|
|
|
|
void fmt_class_string<sys_ss_rng_error>::format(std::string& out, u64 arg)
|
|
|
|
|
{
|
|
|
|
|
format_enum(out, arg, [](auto error)
|
|
|
|
|
{
|
|
|
|
|
switch (error)
|
|
|
|
|
{
|
|
|
|
|
STR_CASE(SYS_SS_RNG_ERROR_INVALID_PKG);
|
|
|
|
|
STR_CASE(SYS_SS_RNG_ERROR_ENOMEM);
|
|
|
|
|
STR_CASE(SYS_SS_RNG_ERROR_EAGAIN);
|
|
|
|
|
STR_CASE(SYS_SS_RNG_ERROR_EFAULT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return unknown;
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-04-13 18:30:25 +02:00
|
|
|
|
2018-08-25 14:39:00 +02:00
|
|
|
LOG_CHANNEL(sys_ss);
|
2017-04-13 18:30:25 +02:00
|
|
|
|
2020-02-20 21:10:49 +01:00
|
|
|
error_code sys_ss_random_number_generator(u64 pkg_id, vm::ptr<void> buf, u64 size)
|
2017-09-25 17:52:34 +02:00
|
|
|
{
|
2020-02-20 21:10:49 +01:00
|
|
|
sys_ss.warning("sys_ss_random_number_generator(pkg_id=%u, buf=*0x%x, size=0x%x)", pkg_id, buf, size);
|
2017-09-25 17:52:34 +02:00
|
|
|
|
2020-02-20 21:10:49 +01:00
|
|
|
if (pkg_id != 2)
|
2017-09-25 17:52:34 +02:00
|
|
|
{
|
2020-02-20 21:10:49 +01:00
|
|
|
if (pkg_id == 1)
|
|
|
|
|
{
|
|
|
|
|
if (!g_ps3_process_info.has_root_perm())
|
|
|
|
|
{
|
|
|
|
|
return CELL_ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sys_ss.todo("sys_ss_random_number_generator(): pkg_id=1");
|
|
|
|
|
std::memset(buf.get_ptr(), 0, 0x18);
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SYS_SS_RNG_ERROR_INVALID_PKG;
|
2017-09-25 17:52:34 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-20 21:10:49 +01:00
|
|
|
// TODO
|
2017-09-25 17:52:34 +02:00
|
|
|
if (size > 0x10000000)
|
|
|
|
|
{
|
2020-02-20 21:10:49 +01:00
|
|
|
return SYS_SS_RNG_ERROR_ENOMEM;
|
2017-09-25 17:52:34 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-20 21:10:49 +01:00
|
|
|
std::unique_ptr<u8[]> temp(new u8[size]);
|
|
|
|
|
|
2017-09-25 17:52:34 +02:00
|
|
|
#ifdef _WIN32
|
2020-02-29 10:09:39 +01:00
|
|
|
if (auto ret = BCryptGenRandom(nullptr, temp.get(), size, BCRYPT_USE_SYSTEM_PREFERRED_RNG))
|
|
|
|
|
{
|
|
|
|
|
fmt::throw_exception("sys_ss_random_number_generator(): BCryptGenRandom failed (0x%08x)" HERE, ret);
|
|
|
|
|
}
|
2017-09-25 17:52:34 +02:00
|
|
|
#else
|
2017-10-04 07:03:24 +02:00
|
|
|
fs::file rnd{"/dev/urandom"};
|
2017-09-25 17:52:34 +02:00
|
|
|
|
2020-02-20 21:10:49 +01:00
|
|
|
if (!rnd || rnd.read(temp.get(), size) != size)
|
2017-09-25 17:52:34 +02:00
|
|
|
{
|
2020-02-20 21:10:49 +01:00
|
|
|
fmt::throw_exception("sys_ss_random_number_generator(): Failed to generate pseudo-random numbers" HERE);
|
2017-09-25 17:52:34 +02:00
|
|
|
}
|
2020-02-29 10:09:39 +01:00
|
|
|
#endif
|
2017-09-25 17:52:34 +02:00
|
|
|
|
2020-02-20 21:10:49 +01:00
|
|
|
std::memcpy(buf.get_ptr(), temp.get(), size);
|
2017-09-25 17:52:34 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-01 20:21:15 +01:00
|
|
|
error_code sys_ss_access_control_engine(u64 pkg_id, u64 a2, u64 a3)
|
|
|
|
|
{
|
|
|
|
|
sys_ss.todo("sys_ss_access_control_engine(pkg_id=0x%llx, a2=0x%llx, a3=0x%llx)", pkg_id, a2, a3);
|
|
|
|
|
|
2020-02-19 18:03:59 +01:00
|
|
|
const u64 authid = g_ps3_process_info.self_info.valid ?
|
2019-11-01 20:21:15 +01:00
|
|
|
g_ps3_process_info.self_info.app_info.authid : 0;
|
|
|
|
|
|
|
|
|
|
switch (pkg_id)
|
|
|
|
|
{
|
|
|
|
|
case 0x1:
|
|
|
|
|
{
|
|
|
|
|
if (!g_ps3_process_info.debug_or_root())
|
|
|
|
|
{
|
|
|
|
|
return CELL_ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!a2)
|
|
|
|
|
{
|
|
|
|
|
return CELL_ESRCH;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 18:03:59 +01:00
|
|
|
verify(HERE), a2 == static_cast<u64>(process_getpid());
|
2020-02-07 10:31:33 +01:00
|
|
|
vm::write64(vm::cast(a3), authid);
|
2019-11-01 20:21:15 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 0x2:
|
|
|
|
|
{
|
2020-02-07 10:31:33 +01:00
|
|
|
vm::write64(vm::cast(a2), authid);
|
2019-11-01 20:21:15 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 0x3:
|
|
|
|
|
{
|
|
|
|
|
if (!g_ps3_process_info.debug_or_root())
|
|
|
|
|
{
|
|
|
|
|
return CELL_ENOSYS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return 0x8001051du;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 15:49:37 +01:00
|
|
|
s32 sys_ss_get_console_id(vm::ptr<u8> buf)
|
2017-04-13 18:30:25 +02:00
|
|
|
{
|
|
|
|
|
sys_ss.todo("sys_ss_get_console_id(buf=*0x%x)", buf);
|
|
|
|
|
|
|
|
|
|
// TODO: Return some actual IDPS?
|
|
|
|
|
*buf = 0;
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 15:49:37 +01:00
|
|
|
s32 sys_ss_get_open_psid(vm::ptr<CellSsOpenPSID> psid)
|
2017-04-13 18:30:25 +02:00
|
|
|
{
|
|
|
|
|
sys_ss.warning("sys_ss_get_open_psid(psid=*0x%x)", psid);
|
|
|
|
|
|
|
|
|
|
psid->high = 0;
|
|
|
|
|
psid->low = 0;
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
2020-02-07 10:31:33 +01:00
|
|
|
|
|
|
|
|
error_code sys_ss_appliance_info_manager(u32 code, vm::ptr<u8> buffer)
|
|
|
|
|
{
|
|
|
|
|
sys_ss.todo("sys_ss_appliance_info_manager(code=0x%x, buffer=*0x%x)", code, buffer);
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error_code sys_ss_get_cache_of_product_mode(vm::ptr<u8> ptr)
|
|
|
|
|
{
|
|
|
|
|
sys_ss.todo("sys_ss_get_cache_of_product_mode(ptr=*0x%x)", ptr);
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error_code sys_ss_secure_rtc(u64 cmd, u64 a2, u64 a3, u64 a4)
|
|
|
|
|
{
|
|
|
|
|
sys_ss.todo("sys_ss_secure_rtc(cmd=0x%llx, a2=0x%x, a3=0x%x, a4=0x%x)", cmd, a2, a3, a4);
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error_code sys_ss_get_cache_of_flash_ext_flag(vm::ptr<u64> flag)
|
|
|
|
|
{
|
|
|
|
|
sys_ss.todo("sys_ss_get_cache_of_flash_ext_flag(flag=*0x%x)", flag);
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error_code sys_ss_get_boot_device(vm::ptr<u64> dev)
|
|
|
|
|
{
|
|
|
|
|
sys_ss.todo("sys_ss_get_boot_device(dev=*0x%x)", dev);
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error_code sys_ss_update_manager(u64 pkg_id, u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 a6)
|
|
|
|
|
{
|
|
|
|
|
sys_ss.todo("sys_ss_update_manager(pkg=0x%llx, a1=0x%x, a2=0x%x, a3=0x%x, a4=0x%x, a5=0x%x, a6=0x%x)", pkg_id, a1, a2, a3, a4, a5, a6);
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error_code sys_ss_virtual_trm_manager(u64 pkg_id, u64 a1, u64 a2, u64 a3, u64 a4)
|
|
|
|
|
{
|
|
|
|
|
sys_ss.todo("sys_ss_virtual_trm_manager(pkg=0x%llx, a1=0x%llx, a2=0x%llx, a3=0x%llx, a4=0x%llx)", pkg_id, a1, a2, a3, a4);
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|