[Kernel] Added option to load provided XAM for resource usage
- Added XEX1 key - Removed annoying assertion from xeXamEnumerate - Added returning hmodule_ptr for resource locator
This commit is contained in:
committed by
Radosław Gliński
parent
97a45315e3
commit
f4b854e484
@@ -50,6 +50,9 @@ DEFINE_bool(
|
||||
|
||||
DECLARE_bool(allow_plugins);
|
||||
|
||||
static constexpr uint8_t xe_xex1_retail_key[16] = {
|
||||
0xA2, 0x6C, 0x10, 0xF7, 0x1F, 0xD9, 0x35, 0xE9,
|
||||
0x8B, 0x99, 0x92, 0x2C, 0xE9, 0x32, 0x15, 0x72};
|
||||
static constexpr uint8_t xe_xex2_retail_key[16] = {
|
||||
0x20, 0xB1, 0x85, 0xA5, 0x9D, 0x28, 0xFD, 0xC3,
|
||||
0x40, 0x58, 0x3F, 0xBB, 0x08, 0x96, 0xBF, 0x91};
|
||||
@@ -506,12 +509,12 @@ int XexModule::ApplyPatch(XexModule* module) {
|
||||
}
|
||||
|
||||
int XexModule::ReadImage(const void* xex_addr, size_t xex_length,
|
||||
bool use_dev_key) {
|
||||
const uint8_t* key) {
|
||||
if (!opt_file_format_info()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
is_dev_kit_ = use_dev_key;
|
||||
is_dev_kit_ = key[0] == 0x00;
|
||||
|
||||
if (is_patch()) {
|
||||
// Make a copy of patch data for other XEX's to use with ApplyPatch()
|
||||
@@ -526,8 +529,7 @@ int XexModule::ReadImage(const void* xex_addr, size_t xex_length,
|
||||
memory()->LookupHeap(base_address_)->Reset();
|
||||
|
||||
aes_decrypt_buffer(
|
||||
use_dev_key ? xe_xex2_devkit_key : xe_xex2_retail_key,
|
||||
reinterpret_cast<const uint8_t*>(xex_security_info()->aes_key), 16,
|
||||
key, reinterpret_cast<const uint8_t*>(xex_security_info()->aes_key), 16,
|
||||
session_key_, 16);
|
||||
|
||||
int result_code = 0;
|
||||
@@ -971,16 +973,21 @@ bool XexModule::Load(const std::string_view name, const std::string_view path,
|
||||
|
||||
// Load in the XEX basefile
|
||||
// We'll try using both XEX2 keys to see if any give a valid PE
|
||||
int result_code = ReadImage(xex_addr, xex_length, false);
|
||||
int result_code = ReadImage(xex_addr, xex_length, xe_xex2_retail_key);
|
||||
if (result_code) {
|
||||
XELOGW("XEX load failed with code {}, trying with devkit encryption key...",
|
||||
result_code);
|
||||
|
||||
result_code = ReadImage(xex_addr, xex_length, true);
|
||||
result_code = ReadImage(xex_addr, xex_length, xe_xex2_devkit_key);
|
||||
if (result_code) {
|
||||
XELOGE("XEX load failed with code {}, tried both encryption keys",
|
||||
XELOGE("XEX load failed with code {}, trying with xex1 encryption key...",
|
||||
result_code);
|
||||
return false;
|
||||
|
||||
result_code = ReadImage(xex_addr, xex_length, xe_xex1_retail_key);
|
||||
if (result_code) {
|
||||
XELOGE("XEX load failed with code {}", result_code);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ class XexModule : public xe::cpu::Module {
|
||||
friend struct XexInfoCache;
|
||||
void ReadSecurityInfo();
|
||||
|
||||
int ReadImage(const void* xex_addr, size_t xex_length, bool use_dev_key);
|
||||
int ReadImage(const void* xex_addr, size_t xex_length, const uint8_t* key);
|
||||
int ReadImageUncompressed(const void* xex_addr, size_t xex_length);
|
||||
int ReadImageBasicCompressed(const void* xex_addr, size_t xex_length);
|
||||
int ReadImageCompressed(const void* xex_addr, size_t xex_length);
|
||||
|
||||
@@ -587,6 +587,12 @@ X_STATUS Emulator::LaunchXexFile(const std::filesystem::path& path) {
|
||||
// System related symlinks
|
||||
file_system_->RegisterSymbolicLink("media:", mount_path);
|
||||
file_system_->RegisterSymbolicLink("font:", mount_path);
|
||||
|
||||
auto module = kernel_state_->LoadUserModule("xam.xex");
|
||||
|
||||
if (module) {
|
||||
result = kernel_state_->FinishLoadingUserModule(module, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -29,8 +29,6 @@ namespace xam {
|
||||
uint32_t xeXamEnumerate(uint32_t handle, uint32_t flags, lpvoid_t buffer_ptr,
|
||||
uint32_t buffer_size, uint32_t* items_returned,
|
||||
uint32_t overlapped_ptr) {
|
||||
assert_true(flags == 0);
|
||||
|
||||
auto e = kernel_state()->object_table()->LookupObject<XEnumerator>(handle);
|
||||
if (!e) {
|
||||
return X_ERROR_INVALID_HANDLE;
|
||||
|
||||
@@ -163,8 +163,10 @@ dword_result_t XamBuildGamercardResourceLocator_entry(lpu16string_t filename,
|
||||
|
||||
// If you're running an app that'll need them, make sure to extract xam.xex
|
||||
// resources with xextool ("xextool -d . xam.xex") and add a .xzp extension.
|
||||
const auto xam_module = kernel_state()->GetModule("xam", true);
|
||||
|
||||
return keXamBuildResourceLocator(0, u"gamercrd", filename.value(), buffer_ptr,
|
||||
return keXamBuildResourceLocator(xam_module ? xam_module->hmodule_ptr() : 0,
|
||||
u"gamercrd", filename.value(), buffer_ptr,
|
||||
buffer_count);
|
||||
}
|
||||
DECLARE_XAM_EXPORT1(XamBuildGamercardResourceLocator, kNone, kImplemented);
|
||||
@@ -172,8 +174,11 @@ DECLARE_XAM_EXPORT1(XamBuildGamercardResourceLocator, kNone, kImplemented);
|
||||
dword_result_t XamBuildSharedSystemResourceLocator_entry(lpu16string_t filename,
|
||||
lpvoid_t buffer_ptr,
|
||||
dword_t buffer_count) {
|
||||
const auto xam_module = kernel_state()->GetModule("xam", true);
|
||||
|
||||
// see notes inside XamBuildGamercardResourceLocator above
|
||||
return keXamBuildResourceLocator(0, u"shrdres", filename.value(), buffer_ptr,
|
||||
return keXamBuildResourceLocator(xam_module ? xam_module->hmodule_ptr() : 0,
|
||||
u"shrdres", filename.value(), buffer_ptr,
|
||||
buffer_count);
|
||||
}
|
||||
DECLARE_XAM_EXPORT1(XamBuildSharedSystemResourceLocator, kNone, kImplemented);
|
||||
|
||||
Reference in New Issue
Block a user