taiHEN  1.0
CFW framework for PS Vita
taihen.h
1 
4 #ifndef TAI_HEADER
5 #define TAI_HEADER
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 #include <psp2kern/types.h>
12 #include <stdint.h>
13 
34 #define KERNEL_PID 0x10005
35 
37 #define TAI_ANY_LIBRARY 0xFFFFFFFF
38 
40 #define TAI_IGNORE_MODULE_NID 0xFFFFFFFF
41 
43 #define TAI_MAIN_MODULE ((void *)0)
44 
46 #define HELPER inline static __attribute__((unused))
47 
53 typedef struct _tai_module_info {
54  size_t size;
55  SceUID modid;
56  uint32_t module_nid;
57  char name[27];
58  uintptr_t exports_start;
59  uintptr_t exports_end;
60  uintptr_t imports_start;
61  uintptr_t imports_end;
63 
67 typedef struct _tai_hook_args {
68  size_t size;
69  const char *module;
70  uint32_t library_nid;
71  uint32_t func_nid;
72  const void *hook_func;
74 
78 typedef struct _tai_offset_args {
79  size_t size;
80  SceUID modid;
81  int segidx;
82  uint32_t offset;
83  int thumb;
84  const void *source;
85  size_t source_size;
87 
91 typedef struct _tai_module_args {
92  size_t size;
93  SceUID pid;
94  size_t args;
95  void *argp;
96  int flags;
98 
215 typedef uintptr_t tai_hook_ref_t;
216 
221  uintptr_t next;
222  void *func;
223  void *old;
224 };
225 
230 SceUID taiHookFunctionAbs(SceUID pid, tai_hook_ref_t *p_hook, void *dest_func, const void *hook_func);
231 SceUID taiHookFunctionExportForKernel(SceUID pid, tai_hook_ref_t *p_hook, const char *module, uint32_t library_nid, uint32_t func_nid, const void *hook_func);
232 SceUID taiHookFunctionImportForKernel(SceUID pid, tai_hook_ref_t *p_hook, const char *module, uint32_t import_library_nid, uint32_t import_func_nid, const void *hook_func);
233 SceUID taiHookFunctionOffsetForKernel(SceUID pid, tai_hook_ref_t *p_hook, SceUID modid, int segidx, uint32_t offset, int thumb, const void *hook_func);
234 int taiGetModuleInfoForKernel(SceUID pid, const char *module, tai_module_info_t *info);
235 int taiHookReleaseForKernel(SceUID tai_uid, tai_hook_ref_t hook);
243 SceUID taiHookFunctionExportForUser(tai_hook_ref_t *p_hook, tai_hook_args_t *args);
244 SceUID taiHookFunctionImportForUser(tai_hook_ref_t *p_hook, tai_hook_args_t *args);
245 SceUID taiHookFunctionOffsetForUser(tai_hook_ref_t *p_hook, tai_offset_args_t *args);
246 int taiGetModuleInfo(const char *module, tai_module_info_t *info);
247 int taiHookRelease(SceUID tai_uid, tai_hook_ref_t hook);
248 
271 HELPER SceUID taiHookFunctionExport(tai_hook_ref_t *p_hook, const char *module, uint32_t library_nid, uint32_t func_nid, const void *hook_func) {
272  tai_hook_args_t args;
273  args.size = sizeof(args);
274  args.module = module;
275  args.library_nid = library_nid;
276  args.func_nid = func_nid;
277  args.hook_func = hook_func;
278  return taiHookFunctionExportForUser(p_hook, &args);
279 }
280 
301 HELPER SceUID taiHookFunctionImport(tai_hook_ref_t *p_hook, const char *module, uint32_t import_library_nid, uint32_t import_func_nid, const void *hook_func) {
302  tai_hook_args_t args;
303  args.size = sizeof(args);
304  args.module = module;
305  args.library_nid = import_library_nid;
306  args.func_nid = import_func_nid;
307  args.hook_func = hook_func;
308  return taiHookFunctionImportForUser(p_hook, &args);
309 }
310 
324 HELPER SceUID taiHookFunctionOffset(tai_hook_ref_t *p_hook, SceUID modid, int segidx, uint32_t offset, int thumb, const void *hook_func) {
325  tai_offset_args_t args;
326  args.size = sizeof(args);
327  args.modid = modid;
328  args.segidx = segidx;
329  args.offset = offset;
330  args.thumb = thumb;
331  args.source = hook_func;
332  return taiHookFunctionOffsetForUser(p_hook, &args);
333 }
336 #ifdef __GNUC__
337 
345 #define TAI_CONTINUE(type, hook, ...) ({ \
346  struct _tai_hook_user *cur, *next; \
347  cur = (struct _tai_hook_user *)(hook); \
348  next = (struct _tai_hook_user *)cur->next; \
349  (next == NULL) ? \
350  ((type(*)())cur->old)(__VA_ARGS__) \
351  : \
352  ((type(*)())next->func)(__VA_ARGS__) \
353  ; \
354 })
355 #else // __GNUC__
356 #error Non-GCC compatible compilers are currently unsupported
357 #endif // __GNUC__
358 
377 SceUID taiInjectAbsForKernel(SceUID pid, void *dest, const void *src, size_t size);
378 SceUID taiInjectDataForKernel(SceUID pid, SceUID modid, int segidx, uint32_t offset, const void *data, size_t size);
379 int taiInjectReleaseForKernel(SceUID tai_uid);
387 SceUID taiInjectAbs(void *dest, const void *src, size_t size);
389 int taiInjectRelease(SceUID tai_uid);
390 
402 HELPER SceUID taiInjectData(SceUID modid, int segidx, uint32_t offset, const void *data, size_t size) {
403  tai_offset_args_t args;
404  args.size = sizeof(args);
405  args.modid = modid;
406  args.segidx = segidx;
407  args.offset = offset;
408  args.source_size = size;
409  args.source = data;
410  return taiInjectDataForUser(&args);
411 }
421 int taiLoadPluginsForTitleForKernel(SceUID pid, const char *titleid, int flags);
430 SceUID taiLoadKernelModule(const char *path, int flags, void *opt);
431 int taiStartKernelModuleForUser(SceUID modid, tai_module_args_t *args, void *opt, int *res);
432 SceUID taiLoadStartKernelModuleForUser(const char *path, tai_module_args_t *args);
433 SceUID taiLoadStartModuleForPidForUser(const char *path, tai_module_args_t *args);
434 int taiStopKernelModuleForUser(SceUID modid, tai_module_args_t *args, void *opt, int *res);
435 int taiUnloadKernelModule(SceUID modid, int flags, void *opt);
436 int taiStopUnloadKernelModuleForUser(SceUID modid, tai_module_args_t *args, void *opt, int *res);
437 int taiStopModuleForPidForUser(SceUID modid, tai_module_args_t *args, void *opt, int *res);
438 int taiUnloadModuleForPid(SceUID pid, SceUID modid, int flags, void *opt);
439 int taiStopUnloadModuleForPidForUser(SceUID modid, tai_module_args_t *args, void *opt, int *res);
440 
453 HELPER int taiStartKernelModule(SceUID modid, int args, void *argp, int flags, void *opt, int *res) {
454  tai_module_args_t argg;
455  argg.size = sizeof(argg);
456  argg.args = args;
457  argg.argp = argp;
458  argg.flags = flags;
459  return taiStartKernelModuleForUser(modid, &argg, opt, res);
460 }
461 
472 HELPER SceUID taiLoadStartKernelModule(const char *path, int args, void *argp, int flags) {
473  tai_module_args_t argg;
474  argg.size = sizeof(argg);
475  argg.args = args;
476  argg.argp = argp;
477  argg.flags = flags;
478  return taiLoadStartKernelModuleForUser(path, &argg);
479 }
480 
492 HELPER SceUID taiLoadStartModuleForPid(SceUID pid, const char *path, int args, void *argp, int flags) {
493  tai_module_args_t argg;
494  argg.size = sizeof(argg);
495  argg.pid = pid;
496  argg.args = args;
497  argg.argp = argp;
498  argg.flags = flags;
499  return taiLoadStartModuleForPidForUser(path, &argg);
500 }
501 
514 HELPER int taiStopKernelModule(SceUID modid, int args, void *argp, int flags, void *opt, int *res) {
515  tai_module_args_t argg;
516  argg.size = sizeof(argg);
517  argg.args = args;
518  argg.argp = argp;
519  argg.flags = flags;
520  return taiStopKernelModuleForUser(modid, &argg, opt, res);
521 }
522 
535 HELPER int taiStopUnloadKernelModule(SceUID modid, int args, void *argp, int flags, void *opt, int *res) {
536  tai_module_args_t argg;
537  argg.size = sizeof(argg);
538  argg.args = args;
539  argg.argp = argp;
540  argg.flags = flags;
541  return taiStopUnloadKernelModuleForUser(modid, &argg, opt, res);
542 }
543 
557 HELPER int taiStopModuleForPid(SceUID pid, SceUID modid, int args, void *argp, int flags, void *opt, int *res) {
558  tai_module_args_t argg;
559  argg.size = sizeof(argg);
560  argg.pid = pid;
561  argg.args = args;
562  argg.argp = argp;
563  argg.flags = flags;
564  return taiStopModuleForPidForUser(modid, &argg, opt, res);
565 }
566 
580 HELPER int taiStopUnloadModuleForPid(SceUID pid, SceUID modid, int args, void *argp, int flags, void *opt, int *res) {
581  tai_module_args_t argg;
582  argg.size = sizeof(argg);
583  argg.pid = pid;
584  argg.args = args;
585  argg.argp = argp;
586  argg.flags = flags;
587  return taiStopUnloadModuleForPidForUser(modid, &argg, opt, res);
588 }
589 
598 int taiMemcpyUserToKernel(void *kernel_dst, const void *user_src, size_t len);
599 int taiMemcpyKernelToUser(void *user_dst, const void *kernel_src, size_t len);
600 
605 #ifdef __cplusplus
606 }
607 #endif
608 
609 #endif // TAI_HEADER
SceUID taiLoadStartModuleForPidForUser(const char *path, tai_module_args_t *args)
Loads and starts a user module for another process.
Definition: taihen-user.c:522
int taiMemcpyKernelToUser(void *user_dst, const void *kernel_src, size_t len)
Copies data from kernel to user.
Definition: taihen-user.c:916
SceUID taiHookFunctionExportForKernel(SceUID pid, tai_hook_ref_t *p_hook, const char *module, uint32_t library_nid, uint32_t func_nid, const void *hook_func)
Add a hook to a module function export.
Definition: taihen.c:72
SceUID taiHookFunctionAbs(SceUID pid, tai_hook_ref_t *p_hook, void *dest_func, const void *hook_func)
Add a hook given an absolute address.
Definition: taihen.c:41
HELPER int taiStopUnloadKernelModule(SceUID modid, int args, void *argp, int flags, void *opt, int *res)
Helper function for taiStopUnloadKernelModuleForUser.
Definition: taihen.h:535
char name[27]
Module name.
Definition: taihen.h:57
uintptr_t imports_start
Pointer to import table in process address space.
Definition: taihen.h:60
int taiHookReleaseForKernel(SceUID tai_uid, tai_hook_ref_t hook)
Release a hook.
Definition: taihen.c:204
Extended module information.
Definition: taihen.h:53
uintptr_t exports_end
Pointer to end of export table.
Definition: taihen.h:59
int taiMemcpyUserToKernel(void *kernel_dst, const void *user_src, size_t len)
Copies data from user to kernel.
Definition: taihen-user.c:884
HELPER int taiStopKernelModule(SceUID modid, int args, void *argp, int flags, void *opt, int *res)
Helper function for taiStopKernelModuleForUser.
Definition: taihen.h:514
struct _tai_module_info tai_module_info_t
Extended module information.
uintptr_t tai_hook_ref_t
Hook information.
Definition: taihen.h:215
SceUID taiHookFunctionImportForKernel(SceUID pid, tai_hook_ref_t *p_hook, const char *module, uint32_t import_library_nid, uint32_t import_func_nid, const void *hook_func)
Add a hook to a module function import.
Definition: taihen.c:115
struct _tai_offset_args tai_offset_args_t
Pass offset arguments to kernel.
SceUID taiHookFunctionExportForUser(tai_hook_ref_t *p_hook, tai_hook_args_t *args)
Add a hook to a module function export for the calling process.
Definition: taihen-user.c:44
int taiStopKernelModuleForUser(SceUID modid, tai_module_args_t *args, void *opt, int *res)
Stops a kernel module.
Definition: taihen-user.c:576
HELPER SceUID taiInjectData(SceUID modid, int segidx, uint32_t offset, const void *data, size_t size)
Helper function for taiInjectDataForUser.
Definition: taihen.h:402
SceUID taiHookFunctionOffsetForKernel(SceUID pid, tai_hook_ref_t *p_hook, SceUID modid, int segidx, uint32_t offset, int thumb, const void *hook_func)
Add a hook to a module manually with an offset.
Definition: taihen.c:159
#define HELPER
Definition: taihen.h:46
HELPER SceUID taiLoadStartModuleForPid(SceUID pid, const char *path, int args, void *argp, int flags)
Helper function for taiLoadStartModuleForPidForUser.
Definition: taihen.h:492
int taiLoadPluginsForTitleForKernel(SceUID pid, const char *titleid, int flags)
Parses the taiHEN config and loads all plugins for a titleid to a process.
Definition: taihen.c:270
int taiInjectReleaseForKernel(SceUID tai_uid)
Release an injection.
Definition: taihen.c:255
SceUID taiInjectDataForUser(tai_offset_args_t *args)
Inject data into the current process bypassing MMU flags given an offset.
Definition: taihen-user.c:304
uintptr_t imports_end
Pointer to end of import table.
Definition: taihen.h:61
SceUID taiHookFunctionImportForUser(tai_hook_ref_t *p_hook, tai_hook_args_t *args)
Add a hook to a module function import for the calling process.
Definition: taihen-user.c:105
int taiHookRelease(SceUID tai_uid, tai_hook_ref_t hook)
Release a hook for the calling process.
Definition: taihen-user.c:246
int taiGetModuleInfo(const char *module, tai_module_info_t *info)
Gets information on a currently loaded module.
Definition: taihen-user.c:209
uint32_t module_nid
Module NID.
Definition: taihen.h:56
int taiStartKernelModuleForUser(SceUID modid, tai_module_args_t *args, void *opt, int *res)
Starts a kernel module.
Definition: taihen-user.c:416
HELPER int taiStopUnloadModuleForPid(SceUID pid, SceUID modid, int args, void *argp, int flags, void *opt, int *res)
Helper function for taiStopUnloadModuleForPidForUser.
Definition: taihen.h:580
HELPER SceUID taiHookFunctionOffset(tai_hook_ref_t *p_hook, SceUID modid, int segidx, uint32_t offset, int thumb, const void *hook_func)
Helper function for taiHookFunctionOffsetForUser.
Definition: taihen.h:324
int taiUnloadModuleForPid(SceUID pid, SceUID modid, int flags, void *opt)
Unloads a user module for a process directly.
Definition: taihen-user.c:789
HELPER SceUID taiHookFunctionImport(tai_hook_ref_t *p_hook, const char *module, uint32_t import_library_nid, uint32_t import_func_nid, const void *hook_func)
Helper function for taiHookFunctionImportForUser.
Definition: taihen.h:301
uintptr_t exports_start
Pointer to export table in process address space.
Definition: taihen.h:58
int taiInjectRelease(SceUID tai_uid)
Release an injection for the calling process.
Definition: taihen-user.c:344
SceUID taiInjectAbsForKernel(SceUID pid, void *dest, const void *src, size_t size)
Injects data into a process bypassing MMU flags.
Definition: taihen.c:219
Pass offset arguments to kernel.
Definition: taihen.h:78
Pass module arguments to kernel.
Definition: taihen.h:91
SceUID taiLoadKernelModule(const char *path, int flags, void *opt)
Loads a kernel module.
Definition: taihen-user.c:373
SceUID taiInjectAbs(void *dest, const void *src, size_t size)
Injects data into the current process bypassing MMU flags.
Definition: taihen-user.c:276
SceUID taiInjectDataForKernel(SceUID pid, SceUID modid, int segidx, uint32_t offset, const void *data, size_t size)
Inject data into a process bypassing MMU flags given an offset.
Definition: taihen.c:236
HELPER SceUID taiLoadStartKernelModule(const char *path, int args, void *argp, int flags)
Helper function for taiLoadStartKernelModuleForUser.
Definition: taihen.h:472
Pass hook arguments to kernel.
Definition: taihen.h:67
HELPER SceUID taiHookFunctionExport(tai_hook_ref_t *p_hook, const char *module, uint32_t library_nid, uint32_t func_nid, const void *hook_func)
Helper function for taiHookFunctionExportForUser.
Definition: taihen.h:271
int taiUnloadKernelModule(SceUID modid, int flags, void *opt)
Unloads a kernel module directly.
Definition: taihen-user.c:633
Internal structure.
Definition: taihen.h:220
int taiStopModuleForPidForUser(SceUID modid, tai_module_args_t *args, void *opt, int *res)
Stops a user module for another process.
Definition: taihen-user.c:734
int taiGetModuleInfoForKernel(SceUID pid, const char *module, tai_module_info_t *info)
Gets information on a currently loaded module.
Definition: taihen.c:191
size_t size
Structure size, set to sizeof(tai_module_info_t)
Definition: taihen.h:54
SceUID taiLoadStartKernelModuleForUser(const char *path, tai_module_args_t *args)
Loads and starts a kernel module.
Definition: taihen-user.c:469
int taiStopUnloadModuleForPidForUser(SceUID modid, tai_module_args_t *args, void *opt, int *res)
Stops and unloads a user module for a process.
Definition: taihen-user.c:829
HELPER int taiStartKernelModule(SceUID modid, int args, void *argp, int flags, void *opt, int *res)
Helper function for taiStartKernelModuleForUser.
Definition: taihen.h:453
SceUID taiHookFunctionOffsetForUser(tai_hook_ref_t *p_hook, tai_offset_args_t *args)
Add a hook to a module manually with an offset for the calling process.
Definition: taihen-user.c:155
SceUID modid
Module UID.
Definition: taihen.h:55
struct _tai_hook_args tai_hook_args_t
Pass hook arguments to kernel.
int taiStopUnloadKernelModuleForUser(SceUID modid, tai_module_args_t *args, void *opt, int *res)
Stops and unloads a kernel module.
Definition: taihen-user.c:675
HELPER int taiStopModuleForPid(SceUID pid, SceUID modid, int args, void *argp, int flags, void *opt, int *res)
Helper function for taiStopModuleForPidForUser.
Definition: taihen.h:557
struct _tai_module_args tai_module_args_t
Pass module arguments to kernel.