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.

sceKernelRegisterModulesAfterBootForKernel
Yemp name was sceKernelSetupForModulemgr.

sceKernelFinalizeKblForKernel
Unloads ScePsp2BootConfig.

sceKernelRegisterSyscallForKernel
This is a guessed name.

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.

sceKernelMountBootimageFSForKernel
Temp name was sceLoadcoreIoMountBootimageFS, sceKernelMountBootfsForKernel.

sceKernelUmountBootimageFSForKernel
Temp name was sceLoadcoreIoUmountBootimageFS, sceKernelUmountBootfsForKernel.

sceKernelLoadModuleForPidForKernel
This is a guessed name.

sceKernelStartModuleForPidForKernel
This is a guessed name.

sceKernelStopModuleForPidForKernel
This is a guessed name.

sceKernelUnloadModuleForPidForKernel
This is a guessed name.

sceKernelModuleUnloadMySelfForKernel
This is a guessed name.

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
This is a guessed name. Temp name was sceKernelGetModuleInternalForKernel, sceKernelGetModuleCBForDebuggerForKernel, sceKernelGetProcessEntryPointForKernel.

This function returns a pointer to the "ModuleCB" (module control block) for specified module UID.

0.990:

3.60:

sceKernelGetModuleIdByPidForKernel
Temp name was sceKernelGetProcessMainModule.

sceKernelGetStubListForKernel
Temp name was sceKernelGetProcessLibStubIdList.

sceKernelGetProcessLibraryIdListForKernel
This is a guessed name.

Temp name was sceKernelGetModuleUidListForKernel, sceKernelGetModuleExportLibraryListForKernel.

sceKernelGetImportedLibraryListInModuleForKernel
Temp name was sceKernelGetModuleImportList.

sceKernelGetExportedLibraryListInModuleForKernel
Temp name was sceKernelGetModuleExportList, sceKernelGetModuleLibraryIdListForKernel.

sceKernelGetModuleListForKernel
This is a guessed name.

sceKernelGetModuleInfoForDebuggerForKernel
Temp name was sceKernelGetModuleList2.

sceKernelGetLibraryClientListForKernel
Temp name was sceKernelGetModuleListByImport, sceKernelGetModuleUidForKernel.

sceKernelGetLibEntCBListForSyslibtraceForKernel
Temp name was sceKernelGetModuleKernelExportList.

sceKernelGetLibraryExportInfoForDebuggerForKernel
Temp name was sceKernelGetModuleLibExportList, sceKernelGetModuleLibraryInfo.

sceKernelGetProgramIdentificationInfoForKernel
Temp name was sceKernelGetModuleAppInfo.

sceKernelGetModuleIsSharedByAddrForKernel
This is a guessed name.

sceKernelGetModulePathForKernel
This is a guessed name.

Temp name was sceKernelGetProcessMainModulePathForKernel.

sceKernelGetModuleFingerprintForKernel
This is a guessed name.

Temp name was sceKernelGetModuleNIDForKernel.

sceKernelGetLibraryDBFlagsForKernel
Temp name was sceKernelGetModuleInhibitState.

sceKernelGetModuleCBByAddrForKernel
This is a guessed name.

Temp name was sceKernelGetModuleInternalByAddrForKernel, sceKernelGetProcessEntryPointByAddrForKernel.

Used by sceKernelPrintBacktraceForDriver.

sceKernelGetModuleIdByAddrForDebuggerForKernel
Temp name was sceKernelGetModuleIdByAddr.

sceKernelGetModuleEntryPointForKernel
This is a guessed name.

sceKernelGetMetaDataForDebuggerForKernel
Temp name was sceKernelGetModuleEntryPointForUser.

sceKernelGetModuleInfoForKernel
This is a guessed name.

sceKernelGetModuleInfoMinByAddrForKernel
This is a guessed name.

sceKernelGetLibraryInfoForDebuggerForKernel
Temp name was sceKernelGetModuleLibraryInfo.

sceKernelGetLostLibraryInfoForKernel
Temp name was sceKernelGetModuleImportNonlinkedInfoByNID.

sceKernelGetLostLibraryListInModuleForKernel
Temp name was sceKernelGetModuleNonlinkedList.

sceKernelGetLostLibraryListForKernel
Temp name was sceKernelGetModuleNonlinkedImportInfo.

sceKernelRegisterDebugCBForKernel
This is a guessed name.

used by SceDeci4pDtracep

sceKernelUnregisterDebugCBForKernel
This is a guessed name.

Temp name was sceKernelRegisterDebugCBCheckForKernel.

SceModulemgrForKernel_F3CD647F
Set two param. Maybe related to syscall.

Used by SceSysLibTrace.

sceKernelLoadcoreKfreeForKernel
Calls sceKernelFreeHeapMemoryForDriver.

sceKernelGetModuleInfoByAddrForDriver
note : kernel only.

sceKernelRegisterLibaryForDriver
note : kernel only.

sceKernelUnregisterLibraryForDriver
Temp name was sceKernelReleaseLibary.

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
It does not have devmode/QAF check. It allows kernel trace.

_sceKernelBacktrace
Calls sceKernelBacktraceForDriver.

_sceKernelPrintBacktrace
Calls sceKernelPrintBacktraceForDriver.