This repository has been archived by the owner on Jul 25, 2021. It is now read-only.
forked from jakibaki/hid-mitm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed a bug where the controller isn't connected
- Loading branch information
1 parent
452d40f
commit fa9a0cd
Showing
11 changed files
with
1,413 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
#include "hid_custom.h" | ||
|
||
#include <stdio.h> | ||
|
||
Mutex shmem_mutex; | ||
u64 AppletResourceUserId; | ||
|
||
static Result _customHidCreateAppletResource(Service *srv, Service *out_iappletresource) { | ||
appletGetAppletResourceUserId(&AppletResourceUserId); | ||
|
||
return serviceDispatchIn(srv, 0, AppletResourceUserId, | ||
.in_send_pid = true, | ||
.out_num_objects = 1, | ||
.out_objects = out_iappletresource, ); | ||
} | ||
|
||
static Result _customHidGetSharedMemoryHandle(Service *srv, Handle *handle_out) { | ||
return serviceDispatch(srv, 0, | ||
.out_handle_attrs = {SfOutHandleAttr_HipcCopy}, | ||
.out_handles = handle_out, ); | ||
} | ||
|
||
void customHidSetup(Service* hid_service, Service* out_iappletresource, SharedMemory* out_real_shmem, SharedMemory* out_fake_shmem) | ||
{ | ||
Result rc; | ||
rc = _customHidCreateAppletResource(hid_service, out_iappletresource); // Executes the original ipc | ||
if (R_FAILED(rc)) | ||
fatalThrow(rc); | ||
|
||
Handle sharedMemHandle; | ||
|
||
rc = _customHidGetSharedMemoryHandle(out_iappletresource, &sharedMemHandle); | ||
if (R_FAILED(rc)) | ||
fatalThrow(rc); | ||
|
||
shmemLoadRemote(out_real_shmem, sharedMemHandle, 0x40000, Perm_R); | ||
rc = shmemMap(out_real_shmem); | ||
if (R_FAILED(rc)) | ||
fatalThrow(rc); | ||
|
||
shmemCreate(out_fake_shmem, sizeof(HidSharedMemory), Perm_Rw, Perm_R); | ||
shmemMap(out_fake_shmem); | ||
|
||
} | ||
|
||
void customHidExit(Service* iappletresource, SharedMemory* real_shmem, SharedMemory* fake_shmem) | ||
{ | ||
mutexLock(&shmem_mutex); | ||
shmemUnmap(real_shmem); | ||
shmemClose(real_shmem); | ||
|
||
shmemUnmap(fake_shmem); | ||
shmemClose(fake_shmem); | ||
mutexUnlock(&shmem_mutex); | ||
|
||
serviceClose(iappletresource); | ||
} | ||
|
||
void customHidInitialize() | ||
{ | ||
mutexInit(&shmem_mutex); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
#include <switch.h> | ||
|
||
void customHidSetup(Service *hid_service, Service *out_iappletresource, SharedMemory *out_real_shmem, SharedMemory *out_fake_shmem); | ||
void customHidExit(Service *iappletresource, SharedMemory *real_shmem, SharedMemory *fake_shmem); | ||
void customHidInitialize(); | ||
|
||
extern Mutex shmem_mutex; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
Oops, something went wrong.