code:
#pragma once
#include <Boot/Config.hpp>

#if MIRA_PLATFORM==MIRA_PLATFORM_ORBIS_BSD_650
/*
These are the required functions in order for the Oni Framework to operate properly
These are all offsets into the base of the kernel. They expect all standard FreeBSD 9 prototypes

The reason we do not hardcode offsets here, is due to the different platforms that are supported, and
for the platforms that do enable kernel ASLR (Address Space Layout Randomization?)
*/

#define kdlsym_addr__mtx_lock_flags                        0x00401CD0 //	FFFFFFFF82696190
#define kdlsym_addr__mtx_lock_sleep                        0x00401D70 //	FFFFFFFF82696230
#define kdlsym_addr__mtx_unlock_flags                      0x00401FA0 //	FFFFFFFF82696460
#define kdlsym_addr__mtx_unlock_sleep                      0x004020A0 //	FFFFFFFF82696560
#define kdlsym_addr__sceSblAuthMgrGetSelfInfo              0x0063CD40 //	FFFFFFFF8285CC70
#define kdlsym_addr__sx_slock                              0x000F5C30 //	FFFFFFFF822424E0
#define kdlsym_addr__sx_sunlock                            0x000F5F10 //	FFFFFFFF822427C0
#define kdlsym_addr__sx_xlock                              0x000F5E10 //	FFFFFFFF822426C0
#define kdlsym_addr__sx_xunlock                            0x000F5FD0 //	FFFFFFFF82242880
#define kdlsym_addr__vm_map_lock_read                      0x0019F140 //	FFFFFFFF8264C990
#define kdlsym_addr__vm_map_unlock_read                    0x0019F190 //	FFFFFFFF8264C9E0
#define kdlsym_addr_AesCbcCfb128Decrypt                    0x003A2E00 //	FFFFFFFF825C01A0
#define kdlsym_addr_AesCbcCfb128Encrypt                    0x003A2BD0 //	FFFFFFFF825BFF70
#define kdlsym_addr_allproc                                0x02382FF8 //	FFFFFFFF844BBE80
#define kdlsym_addr_allproc_lock                           0x02382F98 //	FFFFFFFF844BBE20
#define kdlsym_addr_copyin                                 0x001EA710
#define kdlsym_addr_copyinstr                              0x001EAB40 //	FFFFFFFF825C18A0
#define kdlsym_addr_critical_enter                         0x0028E7A0 //	FFFFFFFF824A9CF0
#define kdlsym_addr_critical_exit                          0x0028E7B0 //	FFFFFFFF824A9D00
#define kdlsym_addr_dmem_start_app_process                 0x002469F0 //	FFFFFFFF8227CC90
#define kdlsym_addr_eventhandler_register                  0x001EC400 //	FFFFFFFF82602AD0
#define kdlsym_addr_exec_new_vmspace                       0x0038AD10 //	FFFFFFFF8231AA80
#define kdlsym_addr_faultin                                0x00006DD0 //	FFFFFFFF825E0060
#define kdlsym_addr_fget_unlocked                          0x000C34B0 //	FFFFFFFF825E0060
#define kdlsym_addr_fpu_kern_ctx                           0x0274C040
#define kdlsym_addr_fpu_kern_enter                         0x001BFF90 //	FFFFFFFF8256B330
#define kdlsym_addr_fpu_kern_leave                         0x001C0090 //	FFFFFFFF8256B420
#define kdlsym_addr_free                                   0x0010E460 //	FFFFFFFF8220D9A0
#define kdlsym_addr_gpu_va_page_list                       0x0271E208 //	FFFFFFFF8486AC68
#define kdlsym_addr_icc_nvs_read                           0x00395830 //	FFFFFFFF826640A0
#define kdlsym_addr_kern_close                             0x000C0EC0 //	FFFFFFFF82449050
#define kdlsym_addr_kern_mkdirat                           0x00340BD0 //	FFFFFFFF826A3730
#define kdlsym_addr_kern_open                              0x0033B9B0 //	FFFFFFFF8269E5E0
#define kdlsym_addr_kern_openat                            0x0033BA10 //	FFFFFFFF8269E640
#define kdlsym_addr_kern_readv                             0x00153248
#define kdlsym_addr_kern_reboot                            0x0010D390 //	FFFFFFFF824069A0
#define kdlsym_addr_kern_sysents                           0x0107C610
#define kdlsym_addr_kernel_map                             0x01AC60E0
#define kdlsym_addr_kmem_alloc                             0x000FCC80 //	FFFFFFFF82450380
#define kdlsym_addr_kmem_free                              0x000FCE50 //	FFFFFFFF82450550
#define kdlsym_addr_kproc_create                           0x00137DF0 //	FFFFFFFF8228A0A0
#define kdlsym_addr_kthread_add                            0x00138360 //	FFFFFFFF8228A600
#define kdlsym_addr_kthread_exit                           0x00138640 //	FFFFFFFF8228A8F0
#define kdlsym_addr_M_MOUNT                                0x019BF300 //	FFFFFFFF83C90CA0
#define kdlsym_addr_M_TEMP                                 0x014B4110 //	FFFFFFFF83740EB0
#define kdlsym_addr_malloc                                 0x0010E250 //	FFFFFFFF8220D7A0
#define kdlsym_addr_memcmp                                 0x00050AC0 //	FFFFFFFF82407A90
#define kdlsym_addr_memcpy                                 0x001EA530 //	FFFFFFFF825C1200
#define kdlsym_addr_memset                                 0x003205C0
#define kdlsym_addr_mini_syscore_self_binary               0x014C9D48
#define kdlsym_addr_mtx_init                               0x00402780 //	FFFFFFFF82696C30
#define kdlsym_addr_mtx_lock_sleep                         0x00401D70 //	FFFFFFFF82696230
#define kdlsym_addr_mtx_unlock_sleep                       0x004020A0 //	FFFFFFFF82696560
#define kdlsym_addr_pfind                                  0x004034E0 //	FFFFFFFF8253D8E0
#define kdlsym_addr_pmap_activate                          0x002EAFD0 //	FFFFFFFF8225A280
#define kdlsym_addr_printf                                 0x00436040 //	FFFFFFFF82322ED0
#define kdlsym_addr_prison0                                0x010986A0 //	FFFFFFFF8333D4F8
#define kdlsym_addr_proc0                                  0x01AA4600 //	FFFFFFFF844BFA40
#define kdlsym_addr_proc_reparent                          0x00035330 //	FFFFFFFF82606340
#define kdlsym_addr_proc_rwmem                             0x0030D150 //	FFFFFFFF8230EA60
#define kdlsym_addr_realloc                                0x0010E590 //	FFFFFFFF8220DAD0
#define kdlsym_addr_rootvnode                              0x022C1A70 //	FFFFFFFF84500320
#define kdlsym_addr_RsaesPkcs1v15Dec2048CRT                0x001FD7D0 //	?? can't backtrace to it on 650
#define kdlsym_addr_sbl_eap_internal_partition_key         0x02790C90 //	FFFFFFFF848DCCD0
#define kdlsym_addr_sbl_pfs_sx                             0x0271E5D8 //	FFFFFFFF84879040
#define kdlsym_addr_sceSblAuthMgrIsLoadable2               0x0063C4F0 //	FFFFFFFF8285C400
#define kdlsym_addr_sceSblAuthMgrSmStart                   0x006418E0 //	FFFFFFFF8285D0F0
#define kdlsym_addr_sceSblAuthMgrSmVerifyHeader            0x00642B40 //	FFFFFFFF8285EC50
#define kdlsym_addr_sceSblAuthMgrVerifyHeader              0x0063C550 //	FFFFFFFF8285C460
#define kdlsym_addr_sceSblDriverSendMsg                    0x0061D7F0 //	FFFFFFFF82837720 sceSblDriverSendMsg
#define kdlsym_addr_sceSblGetEAPInternalPartitionKey       0x006256E0 //	FFFFFFFF8283F190
#define kdlsym_addr_sceSblKeymgrClearKey                   0x0062DB10 //	FFFFFFFF828497C0
#define kdlsym_addr_sceSblKeymgrSetKeyForPfs               0x0062D780 //	FFFFFFFF82849440
#define kdlsym_addr_sceSblKeymgrSmCallfunc                 0x0062E2A0 //	FFFFFFFF82849010
#define kdlsym_addr_sceSblPfsSetKeys                       0x0061EFA0 //	FFFFFFFF82841160
#define kdlsym_addr_sceSblServiceMailbox                   0x00632540 //	FFFFFFFF8284C860
#define kdlsym_addr_sceSblACMgrGetPathId                   0x0
#define kdlsym_addr_self_orbis_sysvec                      0x019BBCD0
#define kdlsym_addr_Sha256Hmac                             0x002D55B0 //	FFFFFFFF825357C0
#define kdlsym_addr_snprintf                               0x00436350 //	FFFFFFFF823231E0
#define kdlsym_addr_sscanf                                 0x00175900 //	FFFFFFFF82443460
#define kdlsym_addr_strcmp                                 0x001D0FD0 //	FFFFFFFF82541460
#define kdlsym_addr_strdup                                 0x001C1C30 //	FFFFFFFF82450110
#define kdlsym_addr_strlen                                 0x003B71A0 //	FFFFFFFF82443030
#define kdlsym_addr_strstr                                 0x0017DFB0 //	FFFFFFFF82681440
#define kdlsym_addr_sys_accept                             0x0031A170 //	FFFFFFFF823C6190
#define kdlsym_addr_sys_bind                               0x00319820 //	FFFFFFFF823C5820
#define kdlsym_addr_sys_close                              0x000C0EB0 //	FFFFFFFF82449040
#define kdlsym_addr_sys_dup2                               0x000BF050 //	FFFFFFFF82447220
#define kdlsym_addr_sys_fstat                              0x000C1430 //	FFFFFFFF824495E0
#define kdlsym_addr_sys_getdents                           0x00341390 //	FFFFFFFF826A3ED0
#define kdlsym_addr_sys_kill                               0x000D19D0 //	FFFFFFFF8222B5C0
#define kdlsym_addr_sys_listen                             0x00319A60 //	FFFFFFFF823C5A60
#define kdlsym_addr_sys_lseek                              0x0033D9F0 //	FFFFFFFF826A05A0
#define kdlsym_addr_sys_mkdir                              0x00340B50 //	FFFFFFFF826A36B0
#define kdlsym_addr_sys_mlock                              0x0013E250 //	FFFFFFFF822AC1E0
#define kdlsym_addr_sys_mlockall                           0x0013E300 //	FFFFFFFF822AC290
#define kdlsym_addr_sys_mmap                               0x0013D230 //	FFFFFFFF822AB1A0
#define kdlsym_addr_sys_munmap                             0x0013D9A0 //	FFFFFFFF822AB8F0
#define kdlsym_addr_sys_nmount                             0x001DE2E0 //	FFFFFFFF822AB8F0
#define kdlsym_addr_sys_open                               0x0033B990 //	FFFFFFFF8269E5C0
#define kdlsym_addr_sys_ptrace                             0x0030D5E0 //	FFFFFFFF8230F100
#define kdlsym_addr_sys_read                               0x00152AB0 //	FFFFFFFF8259B370
#define kdlsym_addr_sys_recvfrom                           0x0031B460 //	FFFFFFFF823C7430
#define kdlsym_addr_sys_rmdir                              0x00340ED0 //	FFFFFFFF826A3A30
#define kdlsym_addr_sys_sendto                             0x0031AD10 //	FFFFFFFF823C6D00
#define kdlsym_addr_sys_setuid                             0x00054950 //	FFFFFFFF8230BA00
#define kdlsym_addr_sys_shutdown                           0x0031B6A0 //	FFFFFFFF823C7680
#define kdlsym_addr_sys_socket                             0x00318EE0 //	FFFFFFFF823C4F00
#define kdlsym_addr_sys_stat                               0x0033DFE0 //	FFFFFFFF826A0B80
#define kdlsym_addr_sys_unlink                             0x0033D3D0 //	FFFFFFFF8269FF60
#define kdlsym_addr_sys_unmount                            0x001DFC70 //	FFFFFFFF82640F20
#define kdlsym_addr_sys_wait4                              0x00035470 //	FFFFFFFF82606480
#define kdlsym_addr_sys_write                              0x00152FC0 //	FFFFFFFF8259B860
#define kdlsym_addr_trap_fatal                             0x00171580 //	FFFFFFFF824ECF30	? code is diff in trap
#define kdlsym_addr_utilUSleep                             0x00658C30 //	FFFFFFFF82899BF0
#define kdlsym_addr_vm_map_lookup_entry                    0x0019F760 //	FFFFFFFF8264CF80
#define kdlsym_addr_vmspace_acquire_ref                    0x0019EF90 //	FFFFFFFF8264C7E0
#define kdlsym_addr_vmspace_alloc                          0x0019EB20 //	FFFFFFFF8264C360
#define kdlsym_addr_vmspace_free                           0x0019EDC0 //	FFFFFFFF8264C610
#define kdlsym_addr_vsnprintf                              0x004363F0 //	FFFFFFFF82323280
#define kdlsym_addr_Xfast_syscall                          0x000001C0 //	FFFFFFFF822001C0	lol
#define kdlsym_addr_wakeup                                 0x003FB940 //	FFFFFFFF82429CF0

// PS4GDB
#define kdlsym_addr_bzero                                  0xDEADC0DEDEADBEEF
#define kdlsym_addr_sys_getpid                             0xDEADC0DEDEADBEEF
#define kdlsym_addr_sys_sysctl                             0xDEADC0DEDEADBEEF

// FakeSelf hooks
#define kdlsym_addr_sceSblAuthMgrIsLoadable__sceSblACMgrGetPathId_hook        0x0
#define kdlsym_addr_sceSblAuthMgrIsLoadable2_hook                             0x0
#define kdlsym_addr_sceSblAuthMgrSmLoadSelfSegment__sceSblServiceMailbox_hook 0x0
#define kdlsym_addr_sceSblAuthMgrSmLoadSelfBlock__sceSblServiceMailbox_hook   0x0
#define kdlsym_addr_sceSblAuthMgrVerifyHeader_hookA                           0x0
#define kdlsym_addr_sceSblAuthMgrVerifyHeader_hookB                           0x0

// FakePkg hooks
#define kdlsym_addr_sceSblKeymgrSetKeyStorage__sceSblDriverSendMsg_hook       0x0
#define kdlsym_addr_sceSblKeymgrInvalidateKey__sx_xlock_hook                  0x0
#define kdlsym_addr_npdrm_decrypt_isolated_rif__sceSblKeymgrSmCallfunc_hook   0x0
#define kdlsym_addr_npdrm_decrypt_rif_new__sceSblKeymgrSmCallfunc_hook        0x0
#define kdlsym_addr_mountpfs__sceSblPfsSetKeys_hookA                          0x0
#define kdlsym_addr_mountpfs__sceSblPfsSetKeys_hookB                          0x0

// sceshellcore patches
// SceShellCore patches - call sceKernelIsGenuineCEX
#define ssc_sceKernelIsGenuineCEX_patchA                   0x0
#define ssc_sceKernelIsGenuineCEX_patchB                   0x0
#define ssc_sceKernelIsGenuineCEX_patchC                   0x0
#define ssc_sceKernelIsGenuineCEX_patchD                   0x0

// SceShellCore patches - call nidf_libSceDipsw
#define ssc_nidf_libSceDipsw_patchA                        0x0
#define ssc_nidf_libSceDipsw_patchB                        0x0
#define ssc_nidf_libSceDipsw_patchC                        0x0
#define ssc_nidf_libSceDipsw_patchD                        0x0

// SceShellCore patches - use free prefix instead fake
#define ssc_fake_to_free_patch                             0x0

// SceShellCore patches - enable remote pkg installer
#define ssc_enable_data_mount_patch                        0x0

#endif


code:
#pragma once
#include <Boot/Config.hpp>

#if MIRA_PLATFORM==MIRA_PLATFORM_ORBIS_BSD_672
/*
    These are the required functions in order for the Oni Framework to operate properly
    These are all offsets into the base of the kernel. They expect all standard FreeBSD 9 prototypes

    The reason we do not hardcode offsets here, is due to the different platforms that are supported, and
    for the platforms that do enable kernel ASLR (Address Space Layout Randomization?)
*/

#define kdlsym_addr__mtx_lock_flags                        0x00496540
#define kdlsym_addr__mtx_lock_sleep                        0x004965E0
#define kdlsym_addr__mtx_lock_spin_flags                   0x00496970
#define kdlsym_addr__mtx_unlock_flags                      0x00496810
#define kdlsym_addr__mtx_unlock_sleep                      0x00496910
#define kdlsym_addr__mtx_unlock_spin_flags                 0x00496B30
#define kdlsym_addr__sceSblAuthMgrGetSelfInfo              0x0065E010
#define kdlsym_addr__sceSblAuthMgrSmStart                  0x0065E490
#define kdlsym_addr__sx_init_flags                         0x00042450
#define kdlsym_addr__sx_slock                              0x000424E0
#define kdlsym_addr__sx_sunlock                            0x000427C0
#define kdlsym_addr__sx_xlock                              0x000426C0
#define kdlsym_addr__sx_xunlock                            0x00042880
#define kdlsym_addr__thread_lock_flags                     0x00496C90
#define kdlsym_addr__vm_map_lock_read                      0x0044CD40
#define kdlsym_addr__vm_map_unlock_read                    0x0044CD90
#define kdlsym_addr_AesCbcCfb128Decrypt                    0x003C0550
#define kdlsym_addr_AesCbcCfb128Encrypt                    0x003C0320
#define kdlsym_addr_allproc                                0x022BBE80
#define kdlsym_addr_allproc_lock                           0x022BBE20
#define kdlsym_addr_avcontrol_sleep                        0x00700E50
#define kdlsym_addr_cloneuio                               0x002D3060
#define kdlsym_addr_console_cdev                           0x022C0CD8
#define kdlsym_addr_console_write                          0x003F8710
#define kdlsym_addr_contigfree                             0x000B7510
#define kdlsym_addr_contigmalloc                           0x000B7150
#define kdlsym_addr_copyin                                 0x003C17A0
#define kdlsym_addr_copyinstr                              0x003C1C50
#define kdlsym_addr_copyout                                0x003C16B0
#define kdlsym_addr_critical_enter                         0x002AA0A0
#define kdlsym_addr_critical_exit                          0x002AA0B0
#define kdlsym_addr_deci_tty_write                         0x004A97E0
#define kdlsym_addr_destroy_dev                            0x003BDCB0
#define kdlsym_addr_dmem_start_app_process                 0x0007CC90
#define kdlsym_addr_dynlib_do_dlsym                        0x00417960
#define kdlsym_addr_dynlib_find_obj_by_handle              0x00418AC0
#define kdlsym_addr_eventhandler_deregister                0x00403220
#define kdlsym_addr_eventhandler_find_list                 0x00403420
#define kdlsym_addr_eventhandler_register                  0x00402E80
#define kdlsym_addr_exec_new_vmspace                       0x0011AE30
#define kdlsym_addr_faultin                                0x003E0410
#define kdlsym_addr_fget_unlocked                          0x0024BAA0
#define kdlsym_addr_fpu_kern_ctx                           0x02694080
#define kdlsym_addr_fpu_kern_enter                         0x0036B6E0
#define kdlsym_addr_fpu_kern_leave                         0x0036B7D0
#define kdlsym_addr_free                                   0x0000D9A0
#define kdlsym_addr_gdt                                    0x01BBCA10
#define kdlsym_addr_gpu_va_page_list                       0x0266AC68
#define kdlsym_addr_icc_nvs_read                           0x00464450
#define kdlsym_addr_kern_close                             0x00249400
#define kdlsym_addr_kern_ioctl                             0x0039C5C0
#define kdlsym_addr_kern_mkdirat                           0x004A3AE0
#define kdlsym_addr_kern_open                              0x0049E990
#define kdlsym_addr_kern_openat                            0x0049E9F0
#define kdlsym_addr_kern_readv                             0x0039B790
#define kdlsym_addr_kern_reboot                            0x00206D50
#define kdlsym_addr_kern_sysents                           0x0111E000
#define kdlsym_addr_kern_thr_create                        0x004A6FB0
#define kdlsym_addr_kernel_map                             0x0220DFC0
#define kdlsym_addr_kernel_mount                           0x00442F90
#define kdlsym_addr_killproc                               0x0002DC80
#define kdlsym_addr_kmem_alloc                             0x00250730
#define kdlsym_addr_kmem_free                              0x00250900
#define kdlsym_addr_kproc_create                           0x0008A0A0
#define kdlsym_addr_kproc_exit                             0x0008A310
#define kdlsym_addr_kthread_add                            0x0008A600
#define kdlsym_addr_kthread_exit                           0x0008A8F0
#define kdlsym_addr_M_IOV                                  0x01A87AD0
#define kdlsym_addr_M_LINKER                               0x01A8EDB0
#define kdlsym_addr_M_MOUNT                                0x01A90CA0
#define kdlsym_addr_M_TEMP                                 0x01540EB0
#define kdlsym_addr_make_dev_p                             0x003BD770
#define kdlsym_addr_malloc                                 0x0000D7A0
#define kdlsym_addr_memcmp                                 0x00207E40
#define kdlsym_addr_memcpy                                 0x003C15B0
#define kdlsym_addr_memmove                                0x003EBB00
#define kdlsym_addr_memset                                 0x001687D0
#define kdlsym_addr_mini_syscore_self_binary               0x0156A588
#define kdlsym_addr_mount_arg                              0x00442CF0
#define kdlsym_addr_mount_argb                             0x004412B0
#define kdlsym_addr_mount_argf                             0x00442DE0
#define kdlsym_addr_mtx_destroy                            0x00497050
#define kdlsym_addr_mtx_init                               0x00496FE0
#define kdlsym_addr_mtx_lock_sleep                         0x004965E0
#define kdlsym_addr_mtx_unlock_sleep                       0x00496910
#define kdlsym_addr_name_to_nids                           0x00417C40
#define kdlsym_addr_pause                                  0x0022A080
#define kdlsym_addr_pfind                                  0x0033DC90
#define kdlsym_addr_pmap_activate                          0x0005A280
#define kdlsym_addr_printf                                 0x00123280
#define kdlsym_addr_prison0                                0x0113E518
#define kdlsym_addr_proc0                                  0x022BFA40
#define kdlsym_addr_proc_reparent                          0x004066F0
#define kdlsym_addr_proc_rwmem                             0x0010EE10
#define kdlsym_addr_realloc                                0x0000DAD0
#define kdlsym_addr_rootvnode                              0x02300320
#define kdlsym_addr_RsaesPkcs1v15Dec2048CRT                0x001D6050
#define kdlsym_addr_sbl_eap_internal_partition_key         0x026DCCD0
#define kdlsym_addr_sbl_keymgr_buf_gva                     0x02698808
#define kdlsym_addr_sbl_keymgr_buf_va                      0x02698000
#define kdlsym_addr_sbl_keymgr_key_rbtree                  0x02694580
#define kdlsym_addr_sbl_keymgr_key_slots                   0x02694570
#define kdlsym_addr_sbl_pfs_sx                             0x02679040
#define kdlsym_addr_sbl_drv_msg_mtx                        0x0266AC70
#define kdlsym_addr_sceSblACMgrGetPathId                   0x00233C70
#define kdlsym_addr_sceSblAuthMgrIsLoadable2               0x0065D7A0
#define kdlsym_addr_sceSblAuthMgrSmVerifyHeader            0x00660260
#define kdlsym_addr_sceSblAuthMgrVerifyHeader              0x0065D800
#define kdlsym_addr_sceSblDriverSendMsg                    0x00637AE0
#define kdlsym_addr_sceSblGetEAPInternalPartitionKey       0x0063F550
#define kdlsym_addr_sceSblKeymgrClearKey                   0x00649B80
#define kdlsym_addr_sceSblKeymgrSetKeyForPfs               0x00649800
#define kdlsym_addr_sceSblKeymgrSetKeyStorage              0x00646E00
#define kdlsym_addr_sceSblKeymgrSmCallfunc                 0x006493D0
#define kdlsym_addr_sceSblPfsSetKeys                       0x00641520
#define kdlsym_addr_sceSblRngGetRandomNumber               0x00665230
#define kdlsym_addr_sceSblServiceMailbox                   0x0064CC20
#define kdlsym_addr_sched_prio                             0x004453C0
#define kdlsym_addr_self_orbis_sysvec                      0x01A8A398
#define kdlsym_addr_Sha256Hmac                             0x00335B70
#define kdlsym_addr_snprintf                               0x00123590
#define kdlsym_addr_spinlock_exit                          0x000A35F0
#define kdlsym_addr_sprintf                                0x001234C0
#define kdlsym_addr_sscanf                                 0x00243810
#define kdlsym_addr_strcmp                                 0x00341810
#define kdlsym_addr_strdup                                 0x002504C0
#define kdlsym_addr_strlen                                 0x002433E0
#define kdlsym_addr_strncmp                                0x0039B6E0
#define kdlsym_addr_strstr                                 0x004817F0
#define kdlsym_addr_sys_accept                             0x001C6540
#define kdlsym_addr_sys_bind                               0x001C5BD0
#define kdlsym_addr_sys_close                              0x002493F0
#define kdlsym_addr_sys_dup2                               0x002475D0
#define kdlsym_addr_sys_fstat                              0x00249990
#define kdlsym_addr_sys_getdents                           0x004A4280
#define kdlsym_addr_sys_kill                               0x0002B5C0
#define kdlsym_addr_sys_listen                             0x001C5E10
#define kdlsym_addr_sys_lseek                              0x004A0950
#define kdlsym_addr_sys_mkdir                              0x004A3A60
#define kdlsym_addr_sys_mlock                              0x000AC1E0
#define kdlsym_addr_sys_mlockall                           0x000AC290
#define kdlsym_addr_sys_mmap                               0x000AB1A0
#define kdlsym_addr_sys_munmap                             0x000AB8F0
#define kdlsym_addr_sys_nmount                             0x0043F9C0
#define kdlsym_addr_sys_open                               0x0049E970
#define kdlsym_addr_sys_ptrace                             0x0010F4B0
#define kdlsym_addr_sys_read                               0x0039B720
#define kdlsym_addr_sys_recvfrom                           0x001C77E0
#define kdlsym_addr_sys_rmdir                              0x004A3DE0
#define kdlsym_addr_sys_sendto                             0x001C70B0
#define kdlsym_addr_sys_setuid                             0x0010BDB0
#define kdlsym_addr_sys_shutdown                           0x001C7A30
#define kdlsym_addr_sys_socket                             0x001C52B0
#define kdlsym_addr_sys_stat                               0x004A0F30
#define kdlsym_addr_sys_unlink                             0x004A0310
#define kdlsym_addr_sys_unmount                            0x004412D0
#define kdlsym_addr_sys_wait4                              0x00406830
#define kdlsym_addr_sys_write                              0x0039BCF0
#define kdlsym_addr_trap_fatal                             0x002ED2E0
#define kdlsym_addr_utilUSleep                             0x0069B2A0
#define kdlsym_addr_vm_fault_disable_pagefaults            0x000C0BB0
#define kdlsym_addr_vm_fault_enable_pagefaults             0x000C0BE0
#define kdlsym_addr_vm_map_lookup_entry                    0x0044D330
#define kdlsym_addr_vmspace_acquire_ref                    0x0044CB90
#define kdlsym_addr_vmspace_alloc                          0x0044C710
#define kdlsym_addr_vmspace_free                           0x0044C9C0
#define kdlsym_addr_vn_fullpath                            0x002F0C40
#define kdlsym_addr_vsnprintf                              0x00123630
#define kdlsym_addr_wakeup                                 0x0022A0A0
#define kdlsym_addr_Xfast_syscall                          0x000001C0

// PS4GDB
#define kdlsym_addr_bzero                                  0x003C14F0
#define kdlsym_addr_sys_getpid                             0x10B500
#define kdlsym_addr_sys_sysctl                             0x2785C0

// Kernel Hooks
#define kdlsym_addr_printf_hook                            0x01A9FE98

// FakeSelf Hooks
#define kdlsym_addr_sceSblAuthMgrIsLoadable__sceSblACMgrGetPathId_hook        0x006591BC
#define kdlsym_addr_sceSblAuthMgrIsLoadable2_hook                             0x0065930F
#define kdlsym_addr_sceSblAuthMgrSmLoadSelfBlock__sceSblServiceMailbox_hook   0x00661571
#define kdlsym_addr_sceSblAuthMgrSmLoadSelfSegment__sceSblServiceMailbox_hook 0x0066092A
#define kdlsym_addr_sceSblAuthMgrVerifyHeader_hookA                           0x00659AC6
#define kdlsym_addr_sceSblAuthMgrVerifyHeader_hookB                           0x0065A758

// FakePkg Hooks
#define kdlsym_addr_sceSblKeymgrSetKeyStorage__sceSblDriverSendMsg_hook       0x00646EA5
#define kdlsym_addr_sceSblKeymgrInvalidateKey__sx_xlock_hook                  0x0064AA3D
#define kdlsym_addr_npdrm_decrypt_isolated_rif__sceSblKeymgrSmCallfunc_hook   0x00669500
#define kdlsym_addr_npdrm_decrypt_rif_new__sceSblKeymgrSmCallfunc_hook        0x0066A313
#define kdlsym_addr_mountpfs__sceSblPfsSetKeys_hookA                          0x006CDF15
#define kdlsym_addr_mountpfs__sceSblPfsSetKeys_hookB                          0x006CE141

// sceRegMgr
#define kdlsym_addr_sceRegMgrGetInt                        0x00508A60
#define kdlsym_addr_sceRegMgrSetInt                        0x005077D0
#define kdlsym_addr_sceRegMgrGetBin                        0x005093A0
#define kdlsym_addr_sceRegMgrSetBin                        0x005092F0
#define kdlsym_addr_sceRegMgrGetStr                        0x00509220
#define kdlsym_addr_sceRegMgrSetStr                        0x00509060

// SceShellCore patches - call sceKernelIsGenuineCEX
#define ssc_sceKernelIsGenuineCEX_patchA                   0x00189602
#define ssc_sceKernelIsGenuineCEX_patchB                   0x00835642
#define ssc_sceKernelIsGenuineCEX_patchC                   0x00880492
#define ssc_sceKernelIsGenuineCEX_patchD                   0x00A12B92

// SceShellCore patches - call nidf_libSceDipsw
#define ssc_nidf_libSceDipsw_patchA                        0x00189630
#define ssc_nidf_libSceDipsw_patchB                        0x00254107
#define ssc_nidf_libSceDipsw_patchC                        0x00835670
#define ssc_nidf_libSceDipsw_patchD                        0x00A12BC0

#define ssc_enable_fakepkg_patch                           0x003EFCF0

// SceShellCore patches - use free prefix instead fake
#define ssc_fake_to_free_patch                             0x00FD2BF1

// SceShellCore patches - enable remote pkg installer
#define ssc_enable_data_mount_patch                        0x0033943E

// SceShellCore patches - enable VR without spoof
#define ssc_enable_vr_patch                                0x00DDDD50

// SceShellCore patches - enable official external HDD support (Support added in 4.50
#define ssc_external_hdd_pkg_installer_patch               0x009FB311
#define ssc_external_hdd_version_patchA                    0x00606A0D
#define ssc_external_hdd_version_patchB                    0x00149BF0

// SceShellUI patches - debug patches
#define ssu_sceSblRcMgrIsAllowDebugMenuForSettings_patch   0x0001D670
#define ssu_sceSblRcMgrIsStoreMode_patch                   0x0001D9D0

// SceShellUI - remote play related patching
#define ssu_CreateUserForIDU_patch                         0x001A0900
#define ssu_remote_play_menu_patch                         0x00EC8291

// SceRemotePlay - enabler patches
#define srp_enabler_patchA                                 0x0010C6D4
#define srp_enabler_patchB                                 0x0010C6EF

#endif

repo_name: veiledmerc/mira

license: mit


code:
#pragma once
#include <Boot/Config.hpp>

#if MIRA_PLATFORM==MIRA_PLATFORM_ORBIS_BSD_900
/*
    These are the required functions in order for the Oni Framework to operate properly
    These are all offsets into the base of the kernel. They expect all standard FreeBSD 9 prototypes

    The reason we do not hardcode offsets here, is due to the different platforms that are supported, and
    for the platforms that do enable kernel ASLR (Address Space Layout Randomization?)
*/

#define kdlsym_addr__mtx_lock_flags                        0x002EEEB0
#define kdlsym_addr__mtx_lock_sleep                        0x002EEF50
#define kdlsym_addr__mtx_lock_spin_flags                   0x002EF2D0
#define kdlsym_addr__mtx_unlock_flags                      0x002EF170
#define kdlsym_addr__mtx_unlock_sleep                      0x002EF270
#define kdlsym_addr__mtx_unlock_spin_flags                 0x002EF4A0
#define kdlsym_addr__sceSblAuthMgrGetSelfInfo              0x006441E0
#define kdlsym_addr__sceSblAuthMgrSmStart                  0x0063FEE0
#define kdlsym_addr__sx_init_flags                         0x0043E390
#define kdlsym_addr__sx_slock                              0x0043E1A0
#define kdlsym_addr__sx_sunlock                            0x0043E710
#define kdlsym_addr__sx_xlock                              0x0043E610
#define kdlsym_addr__sx_xunlock                            0x0043E7D0
#define kdlsym_addr__thread_lock_flags                     0x002EF610
#define kdlsym_addr__vm_map_lock_read                      0x0007BB80
#define kdlsym_addr__vm_map_unlock_read                    0x0007BBD0
#define kdlsym_addr_AesCbcCfb128Decrypt                    0x001FF500
#define kdlsym_addr_AesCbcCfb128Encrypt                    0x001FF2D0
#define kdlsym_addr_allproc                                0x01B946E0
#define kdlsym_addr_allproc_lock                           0x01B94680
#define kdlsym_addr_avcontrol_sleep                        0x006EAE30
#define kdlsym_addr_cloneuio                               0x0044E7E0
#define kdlsym_addr_console_cdev                           0x021F1128
#define kdlsym_addr_console_write                          0x002D6EB0
#define kdlsym_addr_contigfree                             0x00270BB0
#define kdlsym_addr_contigmalloc                           0x00270810
#define kdlsym_addr_copyin                                 0x002716A0
#define kdlsym_addr_copyinstr                              0x00271B50
#define kdlsym_addr_copyout                                0x002715B0
#define kdlsym_addr_critical_enter                         0x002C1980
#define kdlsym_addr_critical_exit                          0x002C19A0
#define kdlsym_addr_deci_tty_write                         0x0048CDE0
#define kdlsym_addr_destroy_dev                            0x001EFAB0
#define kdlsym_addr_dmem_start_app_process                 0x00116B60
#define kdlsym_addr_dynlib_do_dlsym                        0x0021F1E0
#define kdlsym_addr_dynlib_find_obj_by_handle              0x00220360
#define kdlsym_addr_eventhandler_deregister                0x000F8700
#define kdlsym_addr_eventhandler_find_list                 0x000F88F0
#define kdlsym_addr_eventhandler_register                  0x000F8370
#define kdlsym_addr_exec_new_vmspace                       0x00050E60
#define kdlsym_addr_faultin                                0x001D4910
#define kdlsym_addr_fget_unlocked                          0x0045D170
#define kdlsym_addr_fpu_kern_ctx                           0x026541C0
#define kdlsym_addr_fpu_kern_enter                         0x002196D0
#define kdlsym_addr_fpu_kern_leave                         0x00219790
#define kdlsym_addr_free                                   0x00301CE0
#define kdlsym_addr_gdt                                    0x021FB280 // sus
#define kdlsym_addr_gpu_va_page_list                       0x02646CA8
#define kdlsym_addr_icc_nvs_read                           0x0010B310
#define kdlsym_addr_kern_close                             0x0045AAC0
#define kdlsym_addr_kern_ioctl                             0x0044FA80
#define kdlsym_addr_kern_mkdirat                           0x001DF080
#define kdlsym_addr_kern_open                              0x001D9EE0
#define kdlsym_addr_kern_openat                            0x001D9F40
#define kdlsym_addr_kern_readv                             0x0044F350
#define kdlsym_addr_kern_reboot                            0x0029A380
#define kdlsym_addr_kern_sysents                           0x01100310
#define kdlsym_addr_kern_thr_create                        0x001ED670
#define kdlsym_addr_kernel_map                             0x02268D48
#define kdlsym_addr_kernel_mount                           0x0004DF50
#define kdlsym_addr_killproc                               0x00029780
#define kdlsym_addr_kmem_alloc                             0x0037BE70
#define kdlsym_addr_kmem_free                              0x0037C040
#define kdlsym_addr_kproc_create                           0x000969E0
#define kdlsym_addr_kproc_exit                             0x00096C50
#define kdlsym_addr_kthread_add                            0x00096F40
#define kdlsym_addr_kthread_exit                           0x00097230
#define kdlsym_addr_M_IOV                                  0x01A792C0
#define kdlsym_addr_M_LINKER                               0x0155C2D0
#define kdlsym_addr_M_MOUNT                                0x015279F0
#define kdlsym_addr_M_TEMP                                 0x015621E0
#define kdlsym_addr_make_dev_p                             0x001EF590
#define kdlsym_addr_malloc                                 0x00301B20
#define kdlsym_addr_memcmp                                 0x00271E20
#define kdlsym_addr_memcpy                                 0x002714B0
#define kdlsym_addr_memmove                                0x000AF850
#define kdlsym_addr_memset                                 0x001496C0
#define kdlsym_addr_mini_syscore_self_binary               0x01579DF8
#define kdlsym_addr_mount_arg                              0x0004DCC0
#define kdlsym_addr_mount_argb                             0x0004D460
#define kdlsym_addr_mount_argf                             0x0004DDB0
#define kdlsym_addr_mtx_destroy                            0x002EF9D0
#define kdlsym_addr_mtx_init                               0x002EF960
#define kdlsym_addr_mtx_lock_sleep                         0x002EEF50
#define kdlsym_addr_mtx_unlock_sleep                       0x002EF270
#define kdlsym_addr_name_to_nids                           0x0021F4C0
#define kdlsym_addr_pause                                  0x00453EA0
#define kdlsym_addr_pfind                                  0x00178960
#define kdlsym_addr_pmap_activate                          0x00138940
#define kdlsym_addr_printf                                 0x000B7A30
#define kdlsym_addr_prison0                                0x0111F870 // sus
#define kdlsym_addr_proc0                                  0x01B90E00
#define kdlsym_addr_proc_reparent                          0x00173E90
#define kdlsym_addr_proc_rwmem                             0x0041EB00
#define kdlsym_addr_realloc                                0x00301DE0
#define kdlsym_addr_rootvnode                              0x021EFF20
#define kdlsym_addr_RsaesPkcs1v15Dec2048CRT                0x004628B0
#define kdlsym_addr_sbl_eap_internal_partition_key         0x026C4C90
#define kdlsym_addr_sbl_keymgr_buf_gva                     0x0264C808
#define kdlsym_addr_sbl_keymgr_buf_va                      0x0264C000
#define kdlsym_addr_sbl_keymgr_key_rbtree                  0x02648248
#define kdlsym_addr_sbl_keymgr_key_slots                   0x02648238
#define kdlsym_addr_sbl_pfs_sx                             0x0264DB40
#define kdlsym_addr_sbl_drv_msg_mtx                        0x02646CB0
#define kdlsym_addr_sceSblACMgrGetPathId                   0x0008BCD0
#define kdlsym_addr_sceSblAuthMgrIsLoadable2               0x006439A0
#define kdlsym_addr_sceSblAuthMgrSmVerifyHeader            0x00641C60
#define kdlsym_addr_sceSblAuthMgrVerifyHeader              0x00643A00
#define kdlsym_addr_sceSblDriverSendMsg                    0x0061CED0
#define kdlsym_addr_sceSblGetEAPInternalPartitionKey       0x0061DC10
#define kdlsym_addr_sceSblKeymgrClearKey                   0x0061F9D0
#define kdlsym_addr_sceSblKeymgrSetKeyForPfs               0x0061F690
#define kdlsym_addr_sceSblKeymgrSetKeyStorage              0x00624970
#define kdlsym_addr_sceSblKeymgrSmCallfunc                 0x0061F260
#define kdlsym_addr_sceSblPfsSetKeys                       0x006252D0
#define kdlsym_addr_sceSblRngGetRandomNumber               0x006496A0
#define kdlsym_addr_sceSblServiceMailbox                   0x00630C40
#define kdlsym_addr_sched_prio                             0x001CBB90
#define kdlsym_addr_self_orbis_sysvec                      0x01528E30
#define kdlsym_addr_Sha256Hmac                             0x00445060
#define kdlsym_addr_snprintf                               0x000B7D30
#define kdlsym_addr_spinlock_exit                          0x00314780
#define kdlsym_addr_sprintf                                0x000B7C70
#define kdlsym_addr_sscanf                                 0x0026C8D0
#define kdlsym_addr_strcmp                                 0x0040E700
#define kdlsym_addr_strdup                                 0x00278540
#define kdlsym_addr_strlen                                 0x0030F450
#define kdlsym_addr_strncmp                                0x00124750
#define kdlsym_addr_strstr                                 0x00487AB0
#define kdlsym_addr_sys_accept                             0x004488A0
#define kdlsym_addr_sys_bind                               0x00447F30
#define kdlsym_addr_sys_close                              0x0045AAB0
#define kdlsym_addr_sys_dup2                               0x00458CB0
#define kdlsym_addr_sys_fstat                              0x0045B030
#define kdlsym_addr_sys_getdents                           0x001DF840
#define kdlsym_addr_sys_kill                               0x00027050
#define kdlsym_addr_sys_listen                             0x00448170
#define kdlsym_addr_sys_lseek                              0x001DBF10
#define kdlsym_addr_sys_mkdir                              0x001DF000
#define kdlsym_addr_sys_mlock                              0x00166F30
#define kdlsym_addr_sys_mlockall                           0x00166FE0
#define kdlsym_addr_sys_mmap                               0x00165F50
#define kdlsym_addr_sys_munmap                             0x00166660
#define kdlsym_addr_sys_nmount                             0x0004A960
#define kdlsym_addr_sys_open                               0x001D9EC0
#define kdlsym_addr_sys_ptrace                             0x0041F1A0
#define kdlsym_addr_sys_read                               0x0044EBC0
#define kdlsym_addr_sys_recvfrom                           0x00449B40
#define kdlsym_addr_sys_rmdir                              0x001DF380
#define kdlsym_addr_sys_sendto                             0x00449420
#define kdlsym_addr_sys_setuid                             0x000018E0
#define kdlsym_addr_sys_shutdown                           0x00449D90
#define kdlsym_addr_sys_socket                             0x00447530
#define kdlsym_addr_sys_stat                               0x001DC4F0
#define kdlsym_addr_sys_unlink                             0x001DB8D0
#define kdlsym_addr_sys_unmount                            0x0004C290
#define kdlsym_addr_sys_wait4                              0x00173FD0
#define kdlsym_addr_sys_write                              0x0044F0D0
#define kdlsym_addr_trap_fatal                             0x002DF710
#define kdlsym_addr_utilUSleep                             0x0065B170
#define kdlsym_addr_vm_fault_disable_pagefaults            0x00156C70
#define kdlsym_addr_vm_fault_enable_pagefaults             0x00156CA0
#define kdlsym_addr_vm_map_lookup_entry                    0x0007C1C0
#define kdlsym_addr_vmspace_acquire_ref                    0x0007B9E0
#define kdlsym_addr_vmspace_alloc                          0x0007B550
#define kdlsym_addr_vmspace_free                           0x0007B810
#define kdlsym_addr_vn_fullpath                            0x002648C0
#define kdlsym_addr_vsnprintf                              0x000B7DD0
#define kdlsym_addr_wakeup                                 0x00453EC0
#define kdlsym_addr_Xfast_syscall                          0x000001C0

// PS4GDB
#define kdlsym_addr_bzero                                  0x002713F0
#define kdlsym_addr_sys_getpid                             0x271E50
#define kdlsym_addr_sys_sysctl                             0x2A2E90

// Kernel Hooks
#define kdlsym_addr_printf_hook                            0x01A7ED68

// FakeSelf Hooks
#define kdlsym_addr_sceSblAuthMgrIsLoadable__sceSblACMgrGetPathId_hook        0x0064473C
#define kdlsym_addr_sceSblAuthMgrIsLoadable2_hook                             0x0064488E
#define kdlsym_addr_sceSblAuthMgrSmLoadSelfBlock__sceSblServiceMailbox_hook   0x00642F68
#define kdlsym_addr_sceSblAuthMgrSmLoadSelfSegment__sceSblServiceMailbox_hook 0x0064232D
#define kdlsym_addr_sceSblAuthMgrVerifyHeader_hookA                           0x00645026
#define kdlsym_addr_sceSblAuthMgrVerifyHeader_hookB                           0x00645D09

// FakePkg Hooks
#define kdlsym_addr_sceSblKeymgrSetKeyStorage__sceSblDriverSendMsg_hook       0x00624A15
#define kdlsym_addr_sceSblKeymgrInvalidateKey__sx_xlock_hook                  0x0062084D
#define kdlsym_addr_npdrm_decrypt_isolated_rif__sceSblKeymgrSmCallfunc_hook   0x0064E070
#define kdlsym_addr_npdrm_decrypt_rif_new__sceSblKeymgrSmCallfunc_hook        0x0064EE3E
#define kdlsym_addr_mountpfs__sceSblPfsSetKeys_hookA                          0x006C3EF9
#define kdlsym_addr_mountpfs__sceSblPfsSetKeys_hookB                          0x006C412A

// sceRegMgr
#define kdlsym_addr_sceRegMgrGetInt                        0x004E9DD0
#define kdlsym_addr_sceRegMgrSetInt                        0x004E8B10
#define kdlsym_addr_sceRegMgrGetBin                        0x004EA770
#define kdlsym_addr_sceRegMgrSetBin                        0x004EA6C0
#define kdlsym_addr_sceRegMgrGetStr                        0x004EA5F0
#define kdlsym_addr_sceRegMgrSetStr                        0x004F65B5

// SceShellCore patches - call sceKernelIsGenuineCEX
#define ssc_sceKernelIsGenuineCEX_patchA                   0x0016EAA4
#define ssc_sceKernelIsGenuineCEX_patchB                   0x008621D4
#define ssc_sceKernelIsGenuineCEX_patchC                   0x008AFBC2
#define ssc_sceKernelIsGenuineCEX_patchD                   0x00A27BD4

// SceShellCore patches - call nidf_libSceDipsw
#define ssc_nidf_libSceDipsw_patchA                        0x0016EAD2
#define ssc_nidf_libSceDipsw_patchB                        0x00249F7B
#define ssc_nidf_libSceDipsw_patchC                        0x00862202
#define ssc_nidf_libSceDipsw_patchD                        0x00A27C02

#define ssc_enable_fakepkg_patch                           0x003D7AFF

// SceShellCore patches - use free prefix instead fake
#define ssc_fake_to_free_patch                             0x00FD3211

// SceShellCore patches - enable remote pkg installer
#define ssc_enable_data_mount_patch                        0x0032079B

// SceShellCore patches - enable VR without spoof
#define ssc_enable_vr_patch                                0x00DB0B80

// SceShellCore patches - enable official external HDD support (Support added in 4.50
// #define ssc_external_hdd_pkg_installer_patch               0x00A10A80
// #define ssc_external_hdd_version_patchA                    0x006180FD
// #define ssc_external_hdd_version_patchB                    0xDEADC0DE

// SceShellUI patches - debug patches
#define ssu_sceSblRcMgrIsAllowDebugMenuForSettings_patch   0x0001D1C0
#define ssu_sceSblRcMgrIsStoreMode_patch                   0x0001D520

// SceShellUI - remote play related patching
// #define ssu_CreateUserForIDU_patch                         0xDEADC0DE
// #define ssu_remote_play_menu_patch                         0xDEADC0DE

// SceRemotePlay - enabler patches
// #define srp_enabler_patchA                                 0xDEADC0DE
// #define srp_enabler_patchB                                 0xDEADC0DE

#endif


code:
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com

#include "Kernel.hpp"
#include <Mira.hpp>
#include <Utils/Logger.hpp>
#include <Utils/Types.hpp>
#include <Utils/Kdlsym.hpp>

extern "C"
{
    #include <sys/proc.h>
    #include <sys/uio.h>
    #include <sys/mount.h>
    #include <machine/stdarg.h>
}

int proc_rw_mem(struct proc* p, void* ptr, size_t size, void* data, size_t* n, int write)
{
	auto s_DebuggerThread = Mira::Framework::GetFramework()->GetSyscoreThread();
	if (s_DebuggerThread == nullptr)
	{
		WriteLog(LL_Error, "could not get debugger thread.");
		return -EIO;
	}

    auto proc_rwmem = (int(*)(struct proc* p, struct uio* uio))kdlsym(proc_rwmem);
    struct thread* td = s_DebuggerThread;
    struct iovec iov;
    struct uio uio;
    int ret;

    if (!p) {
        ret = EINVAL;
        goto error;
    }

    if (size == 0) {
        if (n)
            *n = 0;
        ret = 0;
        goto error;
    }

    memset(&iov, 0, sizeof(iov));
    iov.iov_base = (caddr_t)data;
    iov.iov_len = size;

    memset(&uio, 0, sizeof(uio));
    uio.uio_iov = &iov;
    uio.uio_iovcnt = 1;
    uio.uio_offset = (off_t)ptr;
    uio.uio_resid = (ssize_t)size;
    uio.uio_segflg = UIO_SYSSPACE;
    uio.uio_rw = write ? UIO_WRITE : UIO_READ;
    uio.uio_td = td;

    ret = proc_rwmem(p, &uio);
    if (n)
        *n = (size_t)((ssize_t)size - uio.uio_resid);

error:
   return ret;
}

int proc_rw_mem_pid(int pid, void* ptr, size_t size, void* data, size_t* n, int write)
{
    auto _mtx_unlock_flags = (void(*)(struct mtx *m, int opts, const char *file, int line))kdlsym(_mtx_unlock_flags);
    auto pfind = (struct proc* (*)(pid_t processId))kdlsym(pfind);
    struct proc* process = pfind(pid);
    if (process == nullptr)
        return -EPROCUNAVAIL;
    _mtx_unlock_flags(&process->p_mtx, 0, __FILE__, __LINE__);

    return proc_rw_mem(process, ptr, size, data, n, write);
}

struct proc *proc_find_by_name(const char *name)
{
    if (!name) {
        return NULL;
    }

    struct proclist* allproc = (struct proclist*)*(uint64_t*)kdlsym(allproc);
    WriteLog(LL_Info, "All Proc: %p", allproc);

    struct proc* p = NULL;
    FOREACH_PROC_IN_SYSTEM(p)
    {
        if (!memcmp(p->p_comm, name, strlen(name))) {
            return p;
        }
    }

    return NULL;
}

void build_iovec(struct iovec **iov, int *iovlen, const char *name, const char *val, size_t len)
{
    auto strdup = (char*(*)(const char *string, struct malloc_type* type))kdlsym(strdup);
    auto strlen = (size_t(*)(const char *str))kdlsym(strlen);
    auto realloc = (void*(*)(void *addr, unsigned long size, struct malloc_type *mtp, int flags))kdlsym(realloc);
    struct malloc_type* M_MOUNT = (struct malloc_type*)kdlsym(M_MOUNT);

    int i;

    if (*iovlen < 0)
        return;

    i = *iovlen;

    *iov = (struct iovec*)realloc(*iov, sizeof **iov * (i + 2), M_MOUNT, 0);

    if (*iov == NULL) {
        *iovlen = -1;
        return;
    }

    if (name) {
        (*iov)[i].iov_base = strdup(name, M_MOUNT);
        (*iov)[i].iov_len = strlen(name) + 1;
    } else {
        (*iov)[i].iov_base = NULL;
        (*iov)[i].iov_len = 0;
    }
    i++;

    if (val) {
        (*iov)[i].iov_base = strdup(val, M_MOUNT);

        if (len == (size_t)-1) {
                len = strlen(val) + 1;
        }

        (*iov)[i].iov_len = (int)len;
    } else {
        (*iov)[i].iov_base = NULL;
        (*iov)[i].iov_len = 0;
    }

    *iovlen = ++i;
}


code:
#pragma once
#include <Utils/Types.hpp>

#ifdef __cplusplus
extern "C"{
#endif

struct task_struct;
struct proc;
struct proc_vm_map_entry;
struct vnode;
struct iovec;

#define  VM_PROT_GPU_READ ((vm_prot_t)0x10)
#define  VM_PROT_GPU_WRITE ((vm_prot_t)0x20)

#define PROT_CPU_READ 0x1
#define PROT_CPU_WRITE 0x2
#define PROT_CPU_EXEC 0x4
#define PROT_GPU_READ 0x10
#define PROT_GPU_WRITE 0x20

typedef struct _ProcVmMapEntry
{
	char name[32];
	vm_offset_t start;
	vm_offset_t end;
	vm_offset_t offset;
	uint16_t prot;
}ProcVmMapEntry;

#ifdef __cplusplus
typedef enum SceAuthenticationId_t : uint64_t
{
	SceVdecProxy = 0x3800000000000003ULL,
	SceVencProxy = 0x3800000000000004ULL,
	Orbis_audiod = 0x3800000000000005ULL,
	Coredump = 0x3800000000000006ULL,
	SceSysCore = 0x3800000000000007ULL,
	Orbis_setip = 0x3800000000000008ULL,
	GnmCompositor = 0x3800000000000009ULL,
	SceShellUI = 0x380000000000000fULL, // NPXS20001
	SceShellCore = 0x3800000000000010ULL,
	NPXS20103 = 0x3800000000000011ULL,
	NPXS21000 = 0x3800000000000012ULL,
	// TODO: Fill in the rest
	Decid = 0x3800000000010003,
} SceAuthenticationId;

typedef enum SceCapabilities_t : uint64_t
{
	Max = 0xFFFFFFFFFFFFFFFFULL,
} SceCapabilites;
#endif

/*
	kernelRdmsr

	TODO: Description
*/
extern uint64_t kernelRdmsr(int Register);
extern int proc_rw_mem_pid(int pid, void* ptr, size_t size, void* data, size_t* n, int write);
extern int proc_rw_mem(struct proc* p, void* ptr, size_t size, void* data, size_t* n, int write);

extern struct proc* proc_find_by_name(const char* name);
extern int proc_get_vm_map(struct proc* p, struct proc_vm_map_entry** entries, size_t* num_entries);

extern void build_iovec(struct iovec **iov, int *iovlen, const char *name, const char *val, size_t len);
extern int kernel_vmount(int flags, ...);

extern void	*memcpy(void * __restrict, const void * __restrict, size_t);
extern void	*memmove(void *, const void *, size_t);
extern void	*memset(void *, int, size_t);
extern int	 memcmp(const void *, const void *, size_t);

extern size_t strlen(const char *str);
extern int strcmp(const char *str1, const char *str2);

extern void cpu_enable_wp();
extern void cpu_disable_wp();

extern int cpu_sidt(void *buff);
extern int cpu_sldt(void *buff);
extern int cpu_sgdt(void *buff);

//bool orbisThreadEscape(int32_t p_RealGroupId, int32_t p_SavedGroupId, int32_t p_EffectiveUserId, int32_t p_RealUserId, void* p_Prison, struct vnode* p_RootDir, struct vnode* p_JailRootDir, enum SceAuthenticationId_t p_AuthId, enum SceCapabilities_t p_SceCaps);

#ifdef __cplusplus
}
#endif


code:
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com

#include <Utils/Logger.hpp>
#include <Utils/Kdlsym.hpp>
#include <Utils/SysWrappers.hpp>
#include <Mira.hpp>

extern "C"
{
	#include <sys/fcntl.h>
};

using namespace Mira::Utils;

Logger* Logger::m_Instance = nullptr;
Logger* Logger::GetInstance()
{
	if (m_Instance == nullptr)
		m_Instance = new Logger();

	return m_Instance;
}

Logger::Logger() :
	m_LogLevel(LL_None),
	m_Buffer{0},
	m_FinalBuffer{0},
	m_Handle(-1)
{
#ifdef _DEBUG
	m_LogLevel = LL_Debug;
#else
	m_LogLevel = LL_Error;
#endif
	m_Handle = -1;

	memset(m_Buffer, 0, sizeof(m_Buffer));
	memset(m_FinalBuffer, 0, sizeof(m_FinalBuffer));

	// Initialize a mutex to prevent overlapping spam
	auto sx_init_flags = (void(*)(struct sx* sx, const char* description, int opts))kdlsym(_sx_init_flags);
	sx_init_flags(&m_Mutex, "logsx", 0);
}

Logger::~Logger()
{
	// auto mtx_destroy = (void(*)(struct mtx* mutex))kdlsym(mtx_destroy);
	// mtx_destroy(&m_Mutex);
}


code:
#pragma once
#include <Utils/New.hpp>
#include <Utils/Kernel.hpp>
#include <Utils/Kdlsym.hpp>

extern "C"
{
	#include <sys/param.h>
	#include <sys/lock.h>
	#include <sys/sx.h>
}

enum LogLevels
{
	LL_None,
	LL_Info,
	LL_Warn,
	LL_Error,
	LL_Debug,
	LL_All
};

#define KNRM  "\x1B[0m"
#define KRED  "\x1B[31m"
#define KGRN  "\x1B[32m"
#define KYEL  "\x1B[33m"
#define KBLU  "\x1B[34m"
#define KMAG  "\x1B[35m"
#define KCYN  "\x1B[36m"
#define KWHT  "\x1B[37m"
#define KGRY  "\x1b[90m"

#define Logger_MaxBuffer 0x500
#ifdef _DEBUG
#define WriteLog(logLevel, format, ...) Mira::Utils::Logger::GetInstance()->WriteLog_Internal2(logLevel, __FUNCTION__, __LINE__, format, ##__VA_ARGS__)
#else
#define WriteLog(x, y, ...)
#endif

namespace Mira
{
	namespace Utils
	{
		class Logger
		{
		private:
			static Mira::Utils::Logger* m_Instance;

			enum LogLevels m_LogLevel;
			char m_Buffer[Logger_MaxBuffer];
			char m_FinalBuffer[Logger_MaxBuffer];

			int32_t m_Handle;

			struct sx m_Mutex;

		protected:
			Logger();
			~Logger();

		public:
			static Mira::Utils::Logger* GetInstance();

			struct sx* GetMutex() { return &m_Mutex; }

			template<typename... Args>
			inline void WriteLog_Internal2(enum LogLevels p_LogLevel, const char* p_Function, int32_t p_Line, const char* p_Format, Args... p_Args)
			{
				// If the logger is set not to output anything, skip everything
				if (m_LogLevel <= LL_None)
					return;

				if (p_LogLevel > m_LogLevel)
					return;

				auto memset = (void* (*)(void *s, int c, size_t n))kdlsym(memset);
				auto snprintf = (int(*)(char *str, size_t size, const char *format, ...))kdlsym(snprintf);
				auto printf = (void(*)(char *format, ...))kdlsym(printf);
				auto __sx_xlock = (int (*)(struct sx *sx, int opts, const char* file, int line))kdlsym(_sx_xlock);
				auto __sx_xunlock = (int (*)(struct sx *sx, const char* file, int line))kdlsym(_sx_xunlock);

				// Zero out the buffer
				__sx_xlock(&m_Mutex, 0, __FILE__, __LINE__);
				{
					memset(m_Buffer, 0, sizeof(m_Buffer));
					memset(m_FinalBuffer, 0, sizeof(m_FinalBuffer));

					snprintf(m_Buffer, sizeof(m_Buffer), p_Format, p_Args...);

					const char* s_LevelString = "None";
					const char* s_LevelColor = KNRM;
					switch (p_LogLevel)
					{
					case LL_Info:
						s_LevelString = "Info";
						s_LevelColor = KGRN;
						break;
					case LL_Warn:
						s_LevelString = "Warn";
						s_LevelColor = KYEL;
						break;
					case LL_Error:
						s_LevelString = "Error";
						s_LevelColor = KRED;
						break;
					case LL_Debug:
						s_LevelString = "Debug";
						s_LevelColor = KGRY;
						break;
					case LL_None:
					default:
						s_LevelString = "None";
						s_LevelColor = KNRM;
						break;
					}

					snprintf(m_FinalBuffer, sizeof(m_FinalBuffer), "%s[%s] %s:%d : %s %s\n", s_LevelColor, s_LevelString, p_Function, p_Line, m_Buffer, KNRM);
					printf(m_FinalBuffer);
				}
				__sx_xunlock(&m_Mutex, __FILE__, __LINE__);
			}
		};
	}
}


code:
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com

#include "New.hpp"
#include <Utils/Kdlsym.hpp>
#include <Utils/Kernel.hpp>
#include <Utils/Logger.hpp>

extern "C"
{
	#include <vm/vm.h>
	#include <sys/malloc.h>

	#include <vm/uma.h>
};

void * operator new(unsigned long int p_Size)
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnew-returns-null"
	if (p_Size == 0)
		return nullptr;
#pragma clang diagnostic pop

	auto malloc = (void*(*)(unsigned long size, struct malloc_type* type, int flags))kdlsym(malloc);
	auto M_TEMP = (struct malloc_type*)kdlsym(M_TEMP);

	if (p_Size >= 0x10000000)
	{
		auto printf = (void(*)(const char *format, ...))kdlsym(printf);
		printf("op_new error: requested (%llx) data\n\n\n", p_Size);

		for (;;)
			__asm__("nop");
	}

	return malloc(p_Size, M_TEMP, M_ZERO | M_NOWAIT);
}

// placement new
void * operator new(unsigned long int p_Size, void * p_Pointer)
{
    return p_Pointer;
}

// operator new[]
void * operator new[] (unsigned long int p_Size)
{
	return ::operator new(p_Size);
}

// Delete
void operator delete(void* p_Pointer) noexcept
{
	if (p_Pointer == nullptr)
		return;

	auto free = (void(*)(void* addr, struct malloc_type* type))kdlsym(free);
	auto M_TEMP = (struct malloc_type*)kdlsym(M_TEMP);

	free(p_Pointer, M_TEMP);
}

void operator delete[](void* p_Pointer) noexcept
{
	::operator delete(p_Pointer);
}


code:
#pragma once

// new
void * operator new(unsigned long int cbSize);

// new[]
void* operator new[](unsigned long int cbSize);

// placement new
void * operator new(unsigned long int cbSize, void * pv);

// delete
void operator delete(void* p) noexcept;

// delete[]
void operator delete[] (void* p) noexcept;


code:
#pragma once

extern "C"
{
    #include <sys/param.h>
    #include <sys/lock.h>
    #include <sys/mutex.h>
};

namespace Utils
{
    template <typename T>
    class RingBuffer
    {
    private:
        struct mtx m_Mutex;
        T* m_Buffer;
        size_t m_Head;
        size_t m_Tail;
        const size_t m_MaxSize;
        bool m_Full;

    public:
        RingBuffer(size_t p_Size) :
            m_Buffer(new T[p_Size]),
            m_Head(0),
            m_Tail(0),
            m_MaxSize(p_Size),
            m_Full(false)
        {
            auto mtx_init = (void(*)(struct mtx *m, const char *name, const char *type, int opts))kdlsym(mtx_init);
            mtx_init(&m_Mutex, "", nullptr, 0);
        }

        ~RingBuffer()
        {
            auto mtx_destroy = (void(*)(struct mtx* mutex))kdlsym(mtx_destroy);

            if (m_Buffer)
                delete [] m_Buffer;

            m_Head = 0;
            m_Tail = 0;
            m_MaxSize = 0;
            m_Full = false;

            mtx_destroy(&m_Mutex);
        }

        void reset()
        {
            // TODO: lock
            m_Head = m_Tail;
            m_Full = false;
            // TODO: unlock
        }

        bool empty() const
        {
            return (!m_Full && (m_Head == m_Tail));
        }

        bool full() const
        {
            return m_Full;
        }

        size_t capacity() const
        {
            return m_MaxSize;
        }

        size_t size() const
        {
            size_t s_Size = m_MaxSize;
            if (!m_Full)
            {
                if (m_Head >= m_Tail)
                    s_Size = m_Head - m_Tail;
                else
                    s_Size = m_MaxSize + (m_Head - m_Tail);
            }

            return s_Size;
        }

        void put(T p_Item)
        {
            // TODO: lock
            m_Buffer[m_Head] = p_Item;

            if (m_Full)
                m_Tail = (m_Tail + 1) % m_MaxSize;

            m_Head = (m_Head + 1) % m_MaxSize;
            m_Full = m_Head == m_Tail;
            // TODO: unlock
        }

        T get()
        {
            // TODO: lock
            if (empty())
                return T();

            auto s_Value = m_Buffer[m_Tail];
            m_Full = false;
            m_Tail = (m_Tail + 1) % m_MaxSize;
            // TODO: unlock

            return s_Value;
        }

        const T* data()
        {
            return m_Buffer;
        }
    };
}


code:
#pragma once
#include "Types.hpp"

namespace Mira
{
    namespace Utils
    {
        typedef struct _SelfHeader
        {
            uint8_t Unknown00[0x18];
            uint16_t EntityCount;
        } SelfHeader;
    }
}


code:
#pragma once
#include <Utils/Types.hpp>
#include <Utils/Kernel.hpp>

// WARNING: Spans should never OWN the buffer
template<typename T>
class Span
{
protected:
    // Data pointer
    uint8_t* m_Data;

    // Data Length
    uint32_t m_DataLength;

    // Current offset within the span
    uint32_t m_Offset;

public:
    Span() :
        m_Data(nullptr),
        m_DataLength(0),
        m_Offset(0)
    {
        // DO Nothing
    }

    Span(uint8_t* p_Source, uint32_t p_SourceLength) :
        m_Data(p_Source),
        m_DataLength(p_SourceLength),
        m_Offset(0)
    {
    }

    ~Span()
    {
        // Zero out everything for this span
        m_Data = nullptr;
        m_DataLength = 0;
        m_Offset = 0;
    }

    // Copy constructor
    Span(const Span& p_Other) :
        m_Data(p_Other.m_Data),
        m_DataLength(p_Other.m_DataLength),
        m_Offset(p_Other.m_Offset)
    {

    }

    // Copy assignment
    Span& operator=(const Span& p_Other)
    {
        if (&p_Other == this)
            return *this;

        m_Data = p_Other.m_Data;
        m_DataLength = p_Other.m_DataLength;
        m_Offset = p_Other.m_Offset;

        return *this;
    }

    // Move constructor
    Span(Span&& p_Other) :
        m_Data(p_Other.m_Data),
        m_DataLength(p_Other.m_DataLength),
        m_Offset(p_Other.m_Offset)
    {
        p_Other.m_Data = nullptr;
        p_Other.m_DataLength = 0;
        p_Other.m_Offset = 0;
    }

    // Move assignment
    Span& operator=(Span&& p_Other)
    {
        if (&p_Other == this)
            return *this;

        m_Data = p_Other.m_Data;
        m_DataLength = p_Other.m_DataLength;
        m_Offset = p_Other.m_Offset;

        p_Other.m_Data = nullptr;
        p_Other.m_DataLength = 0;
        p_Other.m_Offset = 0;

        return *this;
    }

    T& operator*() const
    {
        if (sizeof(T) > m_DataLength)
            return T();

        return *reinterpret_cast<T*>(m_Data);
    }

    bool isNull() const { return m_Data == nullptr || m_DataLength == 0; }

    T* operator->() const { return m_Data; }

    Span subspan(uint32_t p_Length)
    {
        if (p_Length > getRemainingBytes())
            return Span();

        return Span(m_Data + m_Offset, p_Length, false);
    }

    Span subspan(uint32_t p_Offset, uint32_t p_Length)
    {
        if (p_Offset + p_Length >= m_DataLength)
            return Span();

        return Span(m_Data + p_Offset, p_Length, false);
    }

    // Get a structure, returns nullptr if invalid or out of bounds of span
    template<typename X>
    X* get_struct()
    {
        auto s_ObjectSize = sizeof(X);
        if (getRemainingBytes() < s_ObjectSize)
            return nullptr;

        auto s_ObjectPtr = reinterpret_cast<X*>(m_Data + m_Offset);
        m_Offset += s_ObjectSize;
        return s_ObjectPtr;
    }

    // Gets a structure at a specific offset
    template<typename X>
    X* get_struct(uint32_t p_Offset)
    {
        if (p_Offset >= m_DataLength)
            return nullptr;

        if (p_Offset + sizeof(X) >= m_DataLength)
            return nullptr;

        return reinterpret_cast<X*>(m_Data + p_Offset);
    }

    template<typename X>
    bool set_struct(uint32_t p_Offset, X* p_Object)
    {
        if (p_Offset >= m_DataLength)
            return false;

        if (p_Offset + sizeof(X) >= m_DataLength)
            return false;

        if (p_Object == nullptr)
            return false;

        memcpy(m_Data + p_Offset, p_Object, sizeof(*p_Object));
        return true;
    }

    bool set_buffer(uint32_t p_Offset, uint8_t* p_Source, uint32_t p_Length)
    {
        if (p_Offset >= m_DataLength)
            return false;

        if (p_Offset + p_Length > m_DataLength)
            return false;

        if (p_Source == nullptr)
            return false;

        memcpy(m_Data + p_Offset, p_Source, p_Length);
        return true;
    }

    // Set the current offset
    void setOffset(uint32_t p_Offset)
    {
        if (p_Offset >= m_DataLength)
            return;

        m_Offset = p_Offset;
    }

    // Get the current offset
    uint32_t getOffset() { return m_Offset; }

    // Get the remaining bytes left
    uint32_t getRemainingBytes() { return m_DataLength - m_Offset; }

    // Get the length of the entier span
    uint32_t getLength() { return m_DataLength; }

    // Not operator
    bool operator !()
    {
        if (m_Data == nullptr || m_DataLength == 0)
            return true;

        return false;
    }

    // Creates a copy of a buffer, and holds it as a span
    static Span make_span_from(uint8_t* p_Source, uint32_t p_SourceLength)
    {
        auto s_Span = Span(p_SourceLength);
        if (!s_Span)
            return Span();

        if (!s_Span.set_buffer(0, p_Source, p_SourceLength))
            return Span();

        return s_Span;
    }

    T* data() { return m_Data; }
    uint8_t* dataAtOffset()
    {
        if (m_Data != nullptr)
            return &m_Data[m_Offset];
        else
            return nullptr;
    }
    uint32_t size() { return m_DataLength; }

    void zero() { if (m_Data != nullptr && m_DataLength != 0) memset(m_Data, 0, m_DataLength); }
};