SceKernelModulemgr

SceKernelModulemgr is in charge of loading both user modules and kernel modules. SceKernelModulemgr calls SceSblAuthMgr functions for the SELF decryption process. SceKernelModulemgr loads the ELF programs into memory along with linking with NIDs and relocation of ELF in position independent executables.

Module
The SELF can be found in.

Functions of this module are also embedded in NSKBL.

Libraries
This module exports kernel and user libraries.

0x8002D01E
Attempted to load a module with a start entry as bootfs.

Attempted to load a module that has syscall exports to usermode.

module_start no resident/failed
If module_start returns SCE_KERNEL_START_NO_RESIDENT, the module will start successfully, but it will be unloaded after the module_start call.

However, if the module_start of the module where the syscall export exists is called after boot and returns SCE_KERNEL_START_NO_RESIDENT/SCE_KERNEL_START_FAILED, then a kernel panic is triggered.

How to get module info
modid and SceUIDModuleClass are required to get module information.

Simply call sceGUIDReferObjectForDriver(sceKernelGetObjectForUidForDriver) with these parameters.

Module decrypt threads
SceKernelModulemgr_func_8100910D

This thread keeps waiting at sceKernelWaitEventFlagForDriver until a module decrypt request comes.

bits of sceKernelWaitEventFlagForDriver is 3.

Common functions
Decrypt module to membase with current ctx.

Called whenever a module is loaded.

Reads the header from the passed fd and performs some checks.

Data segment layout
Offsets are for FW 3.60.

Data section size is 0x203C0.

Loading Sequence
When loading a module the sequence creates a SceModule structure to represent it.

SELF Decryption
The following code can decrypt a SELF located at.

Set  to 1 if decrypting a usermode module else 0 for kernel (2 for SM but maybe not allowed).

Set  to 0 if you're decrypting the SELF at the right location (for example decrypting   located in  ). If you have copied the SELF elsewhere, you need to set the  to the right value for where the real path was.

is for modules that are too large and won't fit in contiguous regular memory.

Module decryption and signature checks ("HENkaku patches" on FW 1.60)
See also SELF_Loading to see how these SceSblAuthMgr functions are used to decrypt SELFs.

The code below will patch signature checks and bypass module decryption and allow homebrews to run. The idea is to hook SceSblAuthMgr* calls that are imported to SceKernelModulemgr. The offsets are from FW 1.60, you will probably need to modify functions defines (set to addresses of functions) and INSTALL_HOOK second arguments (set to addresses of imports in SceKernelModulemgr). For old FWs like 1.60, as there is no kASLR, you can set hardcoded addresses, else take HENkaku code. As a bonus there is also patch_npdrm functions that patches SceNpDrm to bypass some DRM checks and allow unsigned packages to be installed, which you also need to modify addresses. See SceNpDrm.

sceKernelFinalizeKblForKernel
Unloads ScePsp2BootConfig.

sceKernelLoadPtLoadSegForFwloaderForKernel
Temp name was sceKernelDecryptSelfByPathForKernel

This is an easy way of decrypting SELFs but you are limited to the kinds of SELFs you can load in the current context (for example, you can't load user modules from kernel context). It is also susceptible to limitations of where the SELF can be loaded from. For example, you are not allowed to load SELFs found in  from   because Secure Kernel checks the Media Type.

On FW 3.60, statically compiled SELF gives an error.

sceKernelLoadPreloadingModulesForKernel
Temp name was sceKernelLoadProcessModulesForKernel, sceKernelLoadStartDefaultSharedModulesForPidForKernel.

Loads the preloading modules for a process. This includes, for instance,.

If dipsw 210 is set, it checks if the preloading module flag and 0x8 are set, OR the flag 0x20 of sceKernelLoadModule. If that is the case, the module is loaded into DevKit Additional Memory (DRAM).

sceKernelUnloadProcessModulesForKernel
Temp name was sceKernelStopUnloadPreloadingModulesForKernel.

sceKernelStartPreloadingModulesForKernel
Temp name was sceKernelStartProcessModulesForKernel.

sceKernelGetModuleCBForKernel
Temp name was sceKernelGetModuleInternalForKernel, sceKernelGetModuleCBForDebugger. Wrongfully called sceKernelGetProcessEntryPointForKernel.

This name is not 100% sure, but it is accurate. This function returns a pointer to the "ModuleCB" (module control block) for specified module UID.

0.990:

3.60:

sceKernelGetProcessLibraryIdListForKernel
Temp name was sceKernelGetModuleUidListForKernel, sceKernelGetModuleExportLibraryListForKernel.

sceKernelGetModuleExportListForKernel
Temp name was sceKernelGetModuleLibraryIdListForKernel.

sceKernelGetModuleListByImportForKernel
Temp name was sceKernelGetModuleUidForKernel.

SceModulemgrForKernel_FB251B7A
maybe sceKernelGetModuleLibImportListForKernel

sceKernelGetModulePathForKernel
Temp name was sceKernelGetProcessMainModulePathForKernel.

sceKernelGetModuleFingerprintForKernel
Temp name was sceKernelGetModuleNIDForKernel.

sceKernelGetProcessEntryPointByAddrForKernel
Temp name : sceKernelGetModuleInternalByAddrForKernel

Used by sceKernelPrintBacktraceForDriver.

SceModulemgrForKernel_B73BE671
maybe sceKernelGetModuleLibStubInfoForKernel

sceKernelRegisterDebugCBForKernel
used by SceDeci4pDtracep

sceKernelUnregisterDebugCBForKernel
Temp name was sceKernelRegisterDebugCBCheckForKernel.

SceModulemgrForKernel_29CB2771
Related to process switch?

SceModulemgrForKernel_4865C72C
Related to non-linked?

SceModulemgrForKernel_F3CD647F
Set two param. Maybe related to syscall.

Used by SceSysLibTrace.

sceKernelLoadcoreKfreeForKernel
Calls sceKernelFreeHeapMemoryForDriver.

sceKernelGetModuleInfoByAddrForDriver
note : kernel only.

sceKernelRegisterLibaryForDriver
note : kernel only.

sceKernelReleaseLibaryForDriver
note : kernel only.

sceKernelUnloadModuleForDriver
In 1.69 existed in SceModulemgrForKernel

sceKernelInhibitLoadingModule
Added somewhere between 3.30 an 3.60 to prevent loading Sysmodules from webbrowser (see Vitasploit 2.00-3.36 and h-encore 3.65-3.68 writeup).

sceKernelBacktraceInternalForDriver
not has devmode/qaf check.

allow kernel trace.

_sceKernelBacktrace
Calls sceKernelBacktraceForDriver.

_sceKernelPrintBacktrace
Calls sceKernelPrintBacktraceForDriver.