mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-09 22:56:35 +00:00
libstrat: automatically detect+format rawdata structs correctly.
This commit is contained in:
parent
2f7224edce
commit
6ef34d80a0
16 changed files with 147 additions and 76 deletions
|
@ -96,7 +96,7 @@ Result FsMitmService::OpenDataStorageByCurrentProcess(Out<std::shared_ptr<IStora
|
|||
}
|
||||
|
||||
/* Add redirection for System Data Archives to the SD card. */
|
||||
Result FsMitmService::OpenDataStorageByDataId(Out<std::shared_ptr<IStorageInterface>> out_storage, u64 sid, u64 data_id) {
|
||||
Result FsMitmService::OpenDataStorageByDataId(Out<std::shared_ptr<IStorageInterface>> out_storage, u64 data_id, u8 sid) {
|
||||
FsStorageId storage_id = (FsStorageId)sid;
|
||||
FsStorage data_storage;
|
||||
FsFile data_file;
|
||||
|
|
|
@ -47,7 +47,7 @@ class FsMitmService : public IMitmServiceObject {
|
|||
protected:
|
||||
/* Overridden commands. */
|
||||
Result OpenDataStorageByCurrentProcess(Out<std::shared_ptr<IStorageInterface>> out);
|
||||
Result OpenDataStorageByDataId(Out<std::shared_ptr<IStorageInterface>> out, u64 storage_id, u64 data_id);
|
||||
Result OpenDataStorageByDataId(Out<std::shared_ptr<IStorageInterface>> out, u64 data_id, u8 storage_id);
|
||||
public:
|
||||
DEFINE_SERVICE_DISPATCH_TABLE {
|
||||
MakeServiceCommandMeta<FspSrvCmd_OpenDataStorageByCurrentProcess, &FsMitmService::OpenDataStorageByCurrentProcess>(),
|
||||
|
|
|
@ -174,19 +174,83 @@ struct RawSizeElementAdder {
|
|||
};
|
||||
|
||||
template<typename Ts>
|
||||
struct GetRawDataSize;
|
||||
struct RawDataHelper;
|
||||
|
||||
template<typename... Ts>
|
||||
struct GetRawDataSize<std::tuple<Ts...>> {
|
||||
static constexpr size_t Size() {
|
||||
if constexpr (sizeof...(Ts) == 0) {
|
||||
return 0;
|
||||
struct RawDataHelper<std::tuple<Ts...>> {
|
||||
/* https://referencesource.microsoft.com/#System.Core/System/Linq/Enumerable.cs,2604 */
|
||||
static constexpr void QuickSort(std::array<size_t, sizeof...(Ts)> &map, std::array<size_t, sizeof...(Ts)> &values, int left, int right) {
|
||||
do {
|
||||
int i = left;
|
||||
int j = right;
|
||||
int x = map[i + ((j - i) >> 1)];
|
||||
do {
|
||||
while (i < static_cast<int>(sizeof...(Ts)) && values[x] > values[map[i]]) i++;
|
||||
while (j >= 0 && values[x] < values[map[j]]) j--;
|
||||
if (i > j) break;
|
||||
if (i < j) {
|
||||
const size_t temp = map[i];
|
||||
map[i] = map[j];
|
||||
map[j] = temp;
|
||||
}
|
||||
i++;
|
||||
j--;
|
||||
} while (i <= j);
|
||||
if (j - left <= right - i) {
|
||||
if (left < j) QuickSort(map, values, left, j);
|
||||
left = i;
|
||||
} else {
|
||||
size_t s = 0;
|
||||
size_t ends[] = { RawSizeElementAdder<Ts>::GetUpdateElementSize(s)... };
|
||||
return (ends[sizeof...(Ts)-1] + 3) & ~3;
|
||||
if (i < right) QuickSort(map, values, i, right);
|
||||
right = j;
|
||||
}
|
||||
} while (left < right);
|
||||
}
|
||||
|
||||
static constexpr void StableSort(std::array<size_t, sizeof...(Ts)> &map, std::array<size_t, sizeof...(Ts)> &values) {
|
||||
/* First, quicksort a copy of the map. */
|
||||
std::array<size_t, sizeof...(Ts)> map_unstable(map);
|
||||
QuickSort(map_unstable, values, 0, sizeof...(Ts)-1);
|
||||
|
||||
/* Now, create stable sorted map from unstably quicksorted indices (via repeated insertion sort on element runs). */
|
||||
for (size_t i = 0; i < sizeof...(Ts); i++) {
|
||||
map[i] = map_unstable[i];
|
||||
for (ssize_t j = i-1; j >= 0 && values[map[j]] == values[map[j+1]] && map[j] > map[j+1]; j--) {
|
||||
const size_t temp = map[j];
|
||||
map[j] = map[j+1];
|
||||
map[j+1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr std::array<size_t, sizeof...(Ts)+1> GetOffsets() {
|
||||
std::array<size_t, sizeof...(Ts)+1> offsets = {};
|
||||
offsets[0] = 0;
|
||||
if constexpr (sizeof...(Ts) > 0) {
|
||||
/* Get size, alignment for each type. */
|
||||
std::array<size_t, sizeof...(Ts)> sizes = { RawDataHelper<Ts>::size... };
|
||||
std::array<size_t, sizeof...(Ts)> aligns = { RawDataHelper<Ts>::align... };
|
||||
|
||||
/* We want to sort...by alignment. */
|
||||
std::array<size_t, sizeof...(Ts)> map = {};
|
||||
for (size_t i = 0; i < sizeof...(Ts); i++) { map[i] = i; }
|
||||
StableSort(map, aligns);
|
||||
|
||||
/* Iterate over sorted types. */
|
||||
size_t cur_offset = 0;
|
||||
for (size_t i = 0; i < sizeof...(Ts); i++) {
|
||||
const size_t align = aligns[map[i]];
|
||||
if (cur_offset % align != 0) {
|
||||
cur_offset += align - (cur_offset % align);
|
||||
}
|
||||
offsets[map[i]] = cur_offset;
|
||||
cur_offset += sizes[map[i]];
|
||||
}
|
||||
offsets[sizeof...(Ts)] = cur_offset;
|
||||
}
|
||||
return offsets;
|
||||
}
|
||||
|
||||
static constexpr std::array<size_t, sizeof...(Ts)+1> offsets = GetOffsets();
|
||||
};
|
||||
|
||||
template <typename _Args, typename _ReturnType>
|
||||
|
@ -236,10 +300,12 @@ struct CommandMetaInfo<std::tuple<_Args...>, _ReturnType> {
|
|||
static_assert(NumInHandles <= 8, "Methods can take in <= 8 Handles!");
|
||||
static_assert(NumOutHandles + NumOutSessions <= 8, "Methods can only return <= 8 Handles+Sessions!");
|
||||
|
||||
static constexpr size_t InRawArgSize = GetRawDataSize<InDatas>::Size();
|
||||
static constexpr std::array<size_t, NumInDatas+1> InDataOffsets = RawDataHelper<InDatas>::offsets;
|
||||
static constexpr size_t InRawArgSize = InDataOffsets[NumInDatas];
|
||||
static constexpr size_t InRawArgSizeWithOutPointers = ((InRawArgSize + NumClientSizeOutPointers * sizeof(u16)) + 3) & ~3;
|
||||
|
||||
static constexpr size_t OutRawArgSize = GetRawDataSize<OutDatas>::Size();
|
||||
static constexpr std::array<size_t, NumOutDatas+1> OutDataOffsets = RawDataHelper<OutDatas>::offsets;
|
||||
static constexpr size_t OutRawArgSize = OutDataOffsets[NumOutDatas];
|
||||
};
|
||||
|
||||
|
||||
|
@ -335,10 +401,11 @@ struct Validator {
|
|||
/* ================================================================================= */
|
||||
|
||||
/* Decoder. */
|
||||
template<typename MetaInfo>
|
||||
struct Decoder {
|
||||
|
||||
template<typename T>
|
||||
static constexpr T DecodeCommandArgument(IpcResponseContext *ctx, size_t& a_index, size_t& b_index, size_t& x_index, size_t& c_index, size_t& in_h_index, size_t& out_h_index, size_t& out_obj_index, size_t& in_rd_offset, size_t& out_rd_offset, size_t& pb_offset, size_t& c_sz_offset) {
|
||||
static constexpr T DecodeCommandArgument(IpcResponseContext *ctx, size_t& a_index, size_t& b_index, size_t& x_index, size_t& c_index, size_t& in_h_index, size_t& out_h_index, size_t& out_obj_index, size_t& in_data_index, size_t& out_data_index, size_t& pb_offset, size_t& c_sz_offset) {
|
||||
constexpr ArgType argT = GetArgType<T>();
|
||||
if constexpr (argT == ArgType::InBuffer) {
|
||||
const T& value = T(ctx->request.Buffers[a_index], ctx->request.BufferSizes[a_index], ctx->request.BufferTypes[a_index]);
|
||||
|
@ -357,36 +424,18 @@ struct Decoder {
|
|||
} else if constexpr (argT == ArgType::OutHandle) {
|
||||
return T(&ctx->out_handles[out_h_index++]);
|
||||
} else if constexpr (argT == ArgType::PidDesc) {
|
||||
constexpr size_t t_align = RawDataHelper<T>::align;
|
||||
constexpr size_t t_size = RawDataHelper<T>::size;
|
||||
if (in_rd_offset % t_align) {
|
||||
in_rd_offset += (t_align - (in_rd_offset % t_align));
|
||||
}
|
||||
uintptr_t ptr = ((uintptr_t)ctx->request.Raw + 0x10 + in_rd_offset);
|
||||
in_rd_offset += t_size;
|
||||
uintptr_t ptr = ((uintptr_t)ctx->request.Raw + 0x10 + MetaInfo::InDataOffsets[in_data_index++]);
|
||||
*(u64 *)ptr = ctx->request.Pid;
|
||||
return T(ctx->request.Pid);
|
||||
} else if constexpr (argT == ArgType::InData) {
|
||||
constexpr size_t t_align = RawDataHelper<T>::align;
|
||||
constexpr size_t t_size = RawDataHelper<T>::size;
|
||||
if (in_rd_offset % t_align) {
|
||||
in_rd_offset += (t_align - (in_rd_offset % t_align));
|
||||
}
|
||||
uintptr_t ptr = ((uintptr_t)ctx->request.Raw + 0x10 + in_rd_offset);
|
||||
in_rd_offset += t_size;
|
||||
uintptr_t ptr = ((uintptr_t)ctx->request.Raw + 0x10 + MetaInfo::InDataOffsets[in_data_index++]);
|
||||
if constexpr (std::is_same_v<bool, T>) {
|
||||
return *((u8 *)ptr) & 1;
|
||||
} else {
|
||||
return *((T *)ptr);
|
||||
}
|
||||
} else if constexpr (argT == ArgType::OutData) {
|
||||
constexpr size_t t_align = RawDataHelper<T>::align;
|
||||
constexpr size_t t_size = RawDataHelper<T>::size;
|
||||
if (out_rd_offset % t_align) {
|
||||
out_rd_offset += (t_align - (out_rd_offset % t_align));
|
||||
}
|
||||
uintptr_t ptr = ((uintptr_t)ctx->out_data + out_rd_offset);
|
||||
out_rd_offset += t_size;
|
||||
uintptr_t ptr = ((uintptr_t)ctx->out_data + MetaInfo::OutDataOffsets[out_data_index++]);
|
||||
return T(reinterpret_cast<typename OutHelper<T>::type *>(ptr));
|
||||
} else if constexpr (argT == ArgType::OutPointerClientSize || argT == ArgType::OutPointerServerSize) {
|
||||
u16 sz;
|
||||
|
@ -418,21 +467,20 @@ struct Decoder {
|
|||
|
||||
template <typename ...Ts>
|
||||
struct DecodeTuple<std::tuple<Ts...>> {
|
||||
static constexpr std::tuple<Ts...> GetArgs(IpcResponseContext *ctx, size_t& a_index, size_t& b_index, size_t& x_index, size_t& c_index, size_t& in_h_index, size_t& out_h_index, size_t& out_obj_index, size_t& in_rd_offset, size_t& out_rd_offset, size_t& pb_offset, size_t& c_sz_offset) {
|
||||
static constexpr std::tuple<Ts...> GetArgs(IpcResponseContext *ctx, size_t& a_index, size_t& b_index, size_t& x_index, size_t& c_index, size_t& in_h_index, size_t& out_h_index, size_t& out_obj_index, size_t& in_data_index, size_t& out_data_index, size_t& pb_offset, size_t& c_sz_offset) {
|
||||
return std::tuple<Ts... > {
|
||||
DecodeCommandArgument<Ts>(ctx, a_index, b_index, x_index, c_index, in_h_index, out_h_index, out_obj_index, in_rd_offset, out_rd_offset, pb_offset, c_sz_offset)
|
||||
DecodeCommandArgument<Ts>(ctx, a_index, b_index, x_index, c_index, in_h_index, out_h_index, out_obj_index, in_data_index, out_data_index, pb_offset, c_sz_offset)
|
||||
...
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename MetaInfo>
|
||||
static constexpr typename MetaInfo::Args Decode(IpcResponseContext *ctx) {
|
||||
size_t a_index = 0, b_index = MetaInfo::NumInBuffers, x_index = 0, c_index = 0, in_h_index = 0, out_h_index = 0, out_obj_index = 0;
|
||||
size_t in_rd_offset = 0x0, out_rd_offset = 0, pb_offset = 0;
|
||||
size_t in_data_index = 0x0, out_data_index = 0, pb_offset = 0;
|
||||
size_t c_sz_offset = MetaInfo::InRawArgSize + (0x10 - ((uintptr_t)ctx->request.Raw - (uintptr_t)ctx->request.RawWithoutPadding));
|
||||
return DecodeTuple<typename MetaInfo::Args>::GetArgs(ctx, a_index, b_index, x_index, c_index, in_h_index, out_h_index, out_obj_index, in_rd_offset, out_rd_offset, pb_offset, c_sz_offset);
|
||||
return DecodeTuple<typename MetaInfo::Args>::GetArgs(ctx, a_index, b_index, x_index, c_index, in_h_index, out_h_index, out_obj_index, in_data_index, out_data_index, pb_offset, c_sz_offset);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -594,7 +642,7 @@ constexpr Result WrapIpcCommandImpl(IpcResponseContext *ctx) {
|
|||
};
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
auto args = Decoder::Decode<CommandMetaData>(ctx);
|
||||
auto args = Decoder<CommandMetaData>::Decode(ctx);
|
||||
|
||||
if constexpr (CommandMetaData::ReturnsResult) {
|
||||
rc = std::apply( [=](auto&&... args) { return (this_ptr->*IpcCommandImpl)(args...); }, args);
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
#include "ldr_launch_queue.hpp"
|
||||
#include "ldr_registration.hpp"
|
||||
|
||||
Result DebugMonitorService::AddTitleToLaunchQueue(u64 args_size, u64 tid, InPointer<char> args) {
|
||||
fprintf(stderr, "Add to launch queue: %p, %zX\n", args.pointer, std::min(args_size, args.num_elements));
|
||||
return LaunchQueue::Add(tid, args.pointer, std::min(args_size, args.num_elements));
|
||||
Result DebugMonitorService::AddTitleToLaunchQueue(u64 tid, InPointer<char> args, u32 args_size) {
|
||||
if (args.num_elements < args_size) args_size = args.num_elements;
|
||||
return LaunchQueue::Add(tid, args.pointer, args_size);
|
||||
}
|
||||
|
||||
void DebugMonitorService::ClearLaunchQueue() {
|
||||
|
|
|
@ -29,7 +29,7 @@ enum DebugMonitorServiceCmd {
|
|||
class DebugMonitorService final : public IServiceObject {
|
||||
private:
|
||||
/* Actual commands. */
|
||||
Result AddTitleToLaunchQueue(u64 args_size, u64 tid, InPointer<char> args);
|
||||
Result AddTitleToLaunchQueue(u64 tid, InPointer<char> args, u32 args_size);
|
||||
void ClearLaunchQueue();
|
||||
Result GetNsoInfo(Out<u32> count, OutPointerWithClientSize<Registration::NsoInfo> out, u64 pid);
|
||||
public:
|
||||
|
|
|
@ -22,13 +22,13 @@
|
|||
#include "ldr_content_management.hpp"
|
||||
#include "ldr_npdm.hpp"
|
||||
|
||||
Result ProcessManagerService::CreateProcess(Out<MovedHandle> proc_h, u64 flags, u64 index, CopiedHandle reslimit_h) {
|
||||
Result ProcessManagerService::CreateProcess(Out<MovedHandle> proc_h, u64 index, u32 flags, CopiedHandle reslimit_h) {
|
||||
Result rc;
|
||||
Registration::TidSid tid_sid;
|
||||
LaunchQueue::LaunchItem *launch_item;
|
||||
char nca_path[FS_MAX_PATH] = {0};
|
||||
|
||||
fprintf(stderr, "CreateProcess(%016lx, %016lx, %08x);\n", flags, index, reslimit_h.handle);
|
||||
fprintf(stderr, "CreateProcess(%016lx, %08x, %08x);\n", index, flags, reslimit_h.handle);
|
||||
|
||||
rc = Registration::GetRegisteredTidSid(index, &tid_sid);
|
||||
if (R_FAILED(rc)) {
|
||||
|
@ -54,7 +54,7 @@ Result ProcessManagerService::CreateProcess(Out<MovedHandle> proc_h, u64 flags,
|
|||
return rc;
|
||||
}
|
||||
|
||||
Result ProcessManagerService::GetProgramInfo(Registration::TidSid tid_sid, OutPointerWithServerSize<ProcessManagerService::ProgramInfo, 0x1> out_program_info) {
|
||||
Result ProcessManagerService::GetProgramInfo(OutPointerWithServerSize<ProcessManagerService::ProgramInfo, 0x1> out_program_info, Registration::TidSid tid_sid) {
|
||||
Result rc;
|
||||
char nca_path[FS_MAX_PATH] = {0};
|
||||
/* Zero output. */
|
||||
|
|
|
@ -45,8 +45,8 @@ class ProcessManagerService final : public IServiceObject {
|
|||
static_assert(sizeof(ProcessManagerService::ProgramInfo) == 0x400, "Incorrect ProgramInfo definition.");
|
||||
private:
|
||||
/* Actual commands. */
|
||||
Result CreateProcess(Out<MovedHandle> proc_h, u64 flags, u64 index, CopiedHandle reslimit_h);
|
||||
Result GetProgramInfo(Registration::TidSid tid_sid, OutPointerWithServerSize<ProcessManagerService::ProgramInfo, 0x1> out_program_info);
|
||||
Result CreateProcess(Out<MovedHandle> proc_h, u64 index, u32 flags, CopiedHandle reslimit_h);
|
||||
Result GetProgramInfo(OutPointerWithServerSize<ProcessManagerService::ProgramInfo, 0x1> out_program_info, Registration::TidSid tid_sid);
|
||||
Result RegisterTitle(Out<u64> index, Registration::TidSid tid_sid);
|
||||
Result UnregisterTitle(u64 index);
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
#include "ldr_launch_queue.hpp"
|
||||
#include "ldr_content_management.hpp"
|
||||
|
||||
Result ShellService::AddTitleToLaunchQueue(u64 args_size, u64 tid, InPointer<char> args) {
|
||||
fprintf(stderr, "Add to launch queue: %p, %zX\n", args.pointer, std::min(args_size, args.num_elements));
|
||||
return LaunchQueue::Add(tid, args.pointer, std::min(args_size, args.num_elements));
|
||||
Result ShellService::AddTitleToLaunchQueue(u64 tid, InPointer<char> args, u32 args_size) {
|
||||
if (args.num_elements < args_size) args_size = args.num_elements;
|
||||
return LaunchQueue::Add(tid, args.pointer, args_size);
|
||||
}
|
||||
|
||||
void ShellService::ClearLaunchQueue() {
|
||||
|
|
|
@ -28,7 +28,7 @@ enum ShellServiceCmd {
|
|||
class ShellService final : public IServiceObject {
|
||||
private:
|
||||
/* Actual commands. */
|
||||
Result AddTitleToLaunchQueue(u64 args_size, u64 tid, InPointer<char> args);
|
||||
Result AddTitleToLaunchQueue(u64 tid, InPointer<char> args, u32 args_size);
|
||||
void ClearLaunchQueue();
|
||||
|
||||
/* Atmosphere commands. */
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
static bool g_is_maintenance_boot = false;
|
||||
|
||||
void BootModeService::GetBootMode(Out<bool> out) {
|
||||
void BootModeService::GetBootMode(Out<u32> out) {
|
||||
out.SetValue(g_is_maintenance_boot);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ enum BootModeCmd {
|
|||
class BootModeService final : public IServiceObject {
|
||||
private:
|
||||
/* Actual commands. */
|
||||
void GetBootMode(Out<bool> out);
|
||||
void GetBootMode(Out<u32> out);
|
||||
void SetMaintenanceBoot();
|
||||
public:
|
||||
DEFINE_SERVICE_DISPATCH_TABLE {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
static bool g_has_boot_finished = false;
|
||||
|
||||
Result ShellService::LaunchProcess(Out<u64> pid, u64 launch_flags, Registration::TidSid tid_sid) {
|
||||
Result ShellService::LaunchProcess(Out<u64> pid, Registration::TidSid tid_sid, u32 launch_flags) {
|
||||
return Registration::LaunchProcessByTidSid(tid_sid, launch_flags, pid.GetPointer());
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ enum ShellCmd_5X {
|
|||
class ShellService final : public IServiceObject {
|
||||
private:
|
||||
/* Actual commands. */
|
||||
Result LaunchProcess(Out<u64> pid, u64 launch_flags, Registration::TidSid tid_sid);
|
||||
Result LaunchProcess(Out<u64> pid, Registration::TidSid tid_sid, u32 launch_flags);
|
||||
Result TerminateProcessId(u64 pid);
|
||||
Result TerminateTitleId(u64 tid);
|
||||
void GetProcessWaitEvent(Out<CopiedHandle> event);
|
||||
|
|
22
stratosphere/sm/source/sm_types.hpp
Normal file
22
stratosphere/sm/source/sm_types.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
struct SmServiceName {
|
||||
char name[sizeof(u64)];
|
||||
};
|
||||
|
||||
static_assert(__alignof__(SmServiceName) == 1, "SmServiceName definition!");
|
|
@ -25,17 +25,17 @@ Result UserService::Initialize(PidDescriptor pid) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
Result UserService::GetService(Out<MovedHandle> out_h, u64 service) {
|
||||
Result UserService::GetService(Out<MovedHandle> out_h, SmServiceName service) {
|
||||
Handle session_h = 0;
|
||||
Result rc = 0x415;
|
||||
|
||||
#ifdef SM_ENABLE_SMHAX
|
||||
if (!this->has_initialized) {
|
||||
rc = Registration::GetServiceForPid(Registration::GetInitialProcessId(), service, &session_h);
|
||||
rc = Registration::GetServiceForPid(Registration::GetInitialProcessId(), smEncodeName(service.name), &session_h);
|
||||
}
|
||||
#endif
|
||||
if (this->has_initialized) {
|
||||
rc = Registration::GetServiceForPid(this->pid, service, &session_h);
|
||||
rc = Registration::GetServiceForPid(this->pid, smEncodeName(service.name), &session_h);
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
|
@ -44,16 +44,16 @@ Result UserService::GetService(Out<MovedHandle> out_h, u64 service) {
|
|||
return rc;
|
||||
}
|
||||
|
||||
Result UserService::RegisterService(Out<MovedHandle> out_h, u64 service, u8 is_light, u32 max_sessions) {
|
||||
Result UserService::RegisterService(Out<MovedHandle> out_h, SmServiceName service, u32 max_sessions, bool is_light) {
|
||||
Handle service_h = 0;
|
||||
Result rc = 0x415;
|
||||
#ifdef SM_ENABLE_SMHAX
|
||||
if (!this->has_initialized) {
|
||||
rc = Registration::RegisterServiceForPid(Registration::GetInitialProcessId(), service, max_sessions, (is_light & 1) != 0, &service_h);
|
||||
rc = Registration::RegisterServiceForPid(Registration::GetInitialProcessId(), smEncodeName(service.name), max_sessions, (is_light & 1) != 0, &service_h);
|
||||
}
|
||||
#endif
|
||||
if (this->has_initialized) {
|
||||
rc = Registration::RegisterServiceForPid(this->pid, service, max_sessions, (is_light & 1) != 0, &service_h);
|
||||
rc = Registration::RegisterServiceForPid(this->pid, smEncodeName(service.name), max_sessions, (is_light & 1) != 0, &service_h);
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
|
@ -62,25 +62,25 @@ Result UserService::RegisterService(Out<MovedHandle> out_h, u64 service, u8 is_l
|
|||
return rc;
|
||||
}
|
||||
|
||||
Result UserService::UnregisterService(u64 service) {
|
||||
Result UserService::UnregisterService(SmServiceName service) {
|
||||
Result rc = 0x415;
|
||||
#ifdef SM_ENABLE_SMHAX
|
||||
if (!this->has_initialized) {
|
||||
rc = Registration::UnregisterServiceForPid(Registration::GetInitialProcessId(), service);
|
||||
rc = Registration::UnregisterServiceForPid(Registration::GetInitialProcessId(), smEncodeName(service.name));
|
||||
}
|
||||
#endif
|
||||
if (this->has_initialized) {
|
||||
rc = Registration::UnregisterServiceForPid(this->pid, service);
|
||||
rc = Registration::UnregisterServiceForPid(this->pid, smEncodeName(service.name));
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result UserService::AtmosphereInstallMitm(Out<MovedHandle> srv_h, Out<MovedHandle> qry_h, u64 service) {
|
||||
Result UserService::AtmosphereInstallMitm(Out<MovedHandle> srv_h, Out<MovedHandle> qry_h, SmServiceName service) {
|
||||
Handle service_h = 0;
|
||||
Handle query_h = 0;
|
||||
Result rc = 0x415;
|
||||
if (this->has_initialized) {
|
||||
rc = Registration::InstallMitmForPid(this->pid, service, &service_h, &query_h);
|
||||
rc = Registration::InstallMitmForPid(this->pid, smEncodeName(service.name), &service_h, &query_h);
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
|
@ -90,10 +90,10 @@ Result UserService::AtmosphereInstallMitm(Out<MovedHandle> srv_h, Out<MovedHandl
|
|||
return rc;
|
||||
}
|
||||
|
||||
Result UserService::AtmosphereUninstallMitm(u64 service) {
|
||||
Result UserService::AtmosphereUninstallMitm(SmServiceName service) {
|
||||
Result rc = 0x415;
|
||||
if (this->has_initialized) {
|
||||
rc = Registration::UninstallMitmForPid(this->pid, service);
|
||||
rc = Registration::UninstallMitmForPid(this->pid, smEncodeName(service.name));
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#pragma once
|
||||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
#include "sm_types.hpp"
|
||||
|
||||
enum UserServiceCmd {
|
||||
User_Cmd_Initialize = 0,
|
||||
|
@ -36,13 +37,13 @@ class UserService final : public IServiceObject {
|
|||
|
||||
/* Actual commands. */
|
||||
virtual Result Initialize(PidDescriptor pid);
|
||||
virtual Result GetService(Out<MovedHandle> out_h, u64 service);
|
||||
virtual Result RegisterService(Out<MovedHandle> out_h, u64 service, u8 is_light, u32 max_sessions);
|
||||
virtual Result UnregisterService(u64 service);
|
||||
virtual Result GetService(Out<MovedHandle> out_h, SmServiceName service);
|
||||
virtual Result RegisterService(Out<MovedHandle> out_h, SmServiceName service, u32 max_sessions, bool is_light);
|
||||
virtual Result UnregisterService(SmServiceName service);
|
||||
|
||||
/* Atmosphere commands. */
|
||||
virtual Result AtmosphereInstallMitm(Out<MovedHandle> srv_h, Out<MovedHandle> qry_h, u64 service);
|
||||
virtual Result AtmosphereUninstallMitm(u64 service);
|
||||
virtual Result AtmosphereInstallMitm(Out<MovedHandle> srv_h, Out<MovedHandle> qry_h, SmServiceName service);
|
||||
virtual Result AtmosphereUninstallMitm(SmServiceName service);
|
||||
virtual Result AtmosphereAssociatePidTidForMitm(u64 pid, u64 tid);
|
||||
public:
|
||||
DEFINE_SERVICE_DISPATCH_TABLE {
|
||||
|
|
Loading…
Reference in a new issue