From 389c5780069a6eae21dd3effafb51ccfbd4ae0b1 Mon Sep 17 00:00:00 2001 From: Joel16 Date: Tue, 26 Jul 2022 22:11:10 -0400 Subject: [PATCH] leda: Initial commit --- .gitignore | 52 ++++ Makefile | 7 + README.md | 15 ++ libpspsystemctrl_kernel/Makefile | 14 ++ libpspsystemctrl_kernel/SystemCtrlForKernel.S | 133 ++++++++++ libs/include/kubridge.h | 182 ++++++++++++++ libs/lib/libpspkubridge.a | Bin 0 -> 17186 bytes plugin/Makefile | 24 ++ plugin/exports.exp | 12 + plugin/leda.c | 234 ++++++++++++++++++ plugin/stubs/InterruptManagerForKernel.S | 5 + plugin/stubs/ModuleMgrForUser.S | 6 + plugin/stubs/sceLoaderCore.S | 7 + 13 files changed, 691 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 libpspsystemctrl_kernel/Makefile create mode 100644 libpspsystemctrl_kernel/SystemCtrlForKernel.S create mode 100644 libs/include/kubridge.h create mode 100644 libs/lib/libpspkubridge.a create mode 100644 plugin/Makefile create mode 100644 plugin/exports.exp create mode 100644 plugin/leda.c create mode 100644 plugin/stubs/InterruptManagerForKernel.S create mode 100644 plugin/stubs/ModuleMgrForUser.S create mode 100644 plugin/stubs/sceLoaderCore.S diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c640929 --- /dev/null +++ b/.gitignore @@ -0,0 +1,52 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.la +*.lo +libs/lib/libpspsystemctrl_kernel.a + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex +*.prx + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..358398f --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +SUBDIRS = libpspsystemctrl_kernel plugin + +all: + @for dir in $(SUBDIRS); do $(MAKE) -C $$dir; done + +clean: + @for dir in $(SUBDIRS); do $(MAKE) clean -C $$dir; done diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc1cb69 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# LEDA Reverse Engineering Project + +This is a reverse engineered version of LEDA - Legacy Software Loader, version 0.1, by Dark_AleX. + + +# How you can help: +1. Get a copy of leda.prx from the [latest ME version 2.3](http://www.mediafire.com/download/6cz8ofj44a42wme/release_661me2.3+%28OFW+Version%29.zip) +2. Extract leda.prx and load it into your favourite hex editor. +3. Find the gzip magic (0x1F 0x8B 08 00 ...) and copy everything from the magic to the end of the file and save it as a new PRX file (leda_dec.prx). +4. Disassemble the new prx with prxtool ``prxtool -w leda_dec.prx -o leda_dec.txt`` +5. Start Reversing :P + + +# Credits: +- Valantin/leda: https://github.com/Valantin/leda/blob/master/leda.c diff --git a/libpspsystemctrl_kernel/Makefile b/libpspsystemctrl_kernel/Makefile new file mode 100644 index 0000000..2722406 --- /dev/null +++ b/libpspsystemctrl_kernel/Makefile @@ -0,0 +1,14 @@ +PSPSDK=$(shell psp-config --pspsdk-path) +OBJS = SystemCtrlForKernel_0000.o SystemCtrlForKernel_0001.o SystemCtrlForKernel_0002.o SystemCtrlForKernel_0003.o SystemCtrlForKernel_0004.o SystemCtrlForKernel_0005.o SystemCtrlForKernel_0006.o SystemCtrlForKernel_0007.o SystemCtrlForKernel_0008.o SystemCtrlForKernel_0009.o SystemCtrlForKernel_0010.o SystemCtrlForKernel_0011.o SystemCtrlForKernel_0012.o SystemCtrlForKernel_0013.o SystemCtrlForKernel_0014.o SystemCtrlForKernel_0015.o SystemCtrlForKernel_0016.o SystemCtrlForKernel_0017.o SystemCtrlForKernel_0018.o SystemCtrlForKernel_0019.o SystemCtrlForKernel_0020.o SystemCtrlForKernel_0021.o SystemCtrlForKernel_0022.o SystemCtrlForKernel_0023.o SystemCtrlForKernel_0024.o SystemCtrlForKernel_0025.o SystemCtrlForKernel_0026.o SystemCtrlForKernel_0027.o SystemCtrlForKernel_0028.o SystemCtrlForKernel_0029.o SystemCtrlForKernel_0030.o SystemCtrlForKernel_0031.o SystemCtrlForKernel_0032.o SystemCtrlForKernel_0033.o SystemCtrlForKernel_0034.o SystemCtrlForKernel_0035.o SystemCtrlForKernel_0036.o SystemCtrlForKernel_0037.o SystemCtrlForKernel_0038.o SystemCtrlForKernel_0039.o SystemCtrlForKernel_0040.o SystemCtrlForKernel_0041.o + +%.o: SystemCtrlForKernel.S + psp-gcc -g -O2 -G0 -Wall -I${PSPSDK}/include -DF_$* $< -c -o $@ + +all: $(OBJS) + psp-ar cru libpspsystemctrl_kernel.a $(OBJS) + psp-ranlib libpspsystemctrl_kernel.a + mv libpspsystemctrl_kernel.a "../libs/lib/" + +clean: + rm -f *.o + rm -f *.a diff --git a/libpspsystemctrl_kernel/SystemCtrlForKernel.S b/libpspsystemctrl_kernel/SystemCtrlForKernel.S new file mode 100644 index 0000000..bee4745 --- /dev/null +++ b/libpspsystemctrl_kernel/SystemCtrlForKernel.S @@ -0,0 +1,133 @@ + .set noreorder + +#include "pspimport.s" + +// Build files +// SystemCtrlForKernel_0000.o SystemCtrlForKernel_0001.o SystemCtrlForKernel_0002.o SystemCtrlForKernel_0003.o SystemCtrlForKernel_0004.o SystemCtrlForKernel_0005.o SystemCtrlForKernel_0006.o SystemCtrlForKernel_0007.o SystemCtrlForKernel_0008.o SystemCtrlForKernel_0009.o SystemCtrlForKernel_0010.o SystemCtrlForKernel_0011.o SystemCtrlForKernel_0012.o SystemCtrlForKernel_0013.o SystemCtrlForKernel_0014.o SystemCtrlForKernel_0015.o SystemCtrlForKernel_0016.o SystemCtrlForKernel_0017.o SystemCtrlForKernel_0018.o SystemCtrlForKernel_0019.o SystemCtrlForKernel_0020.o SystemCtrlForKernel_0021.o SystemCtrlForKernel_0022.o SystemCtrlForKernel_0023.o SystemCtrlForKernel_0024.o SystemCtrlForKernel_0025.o SystemCtrlForKernel_0026.o SystemCtrlForKernel_0027.o SystemCtrlForKernel_0028.o SystemCtrlForKernel_0029.o SystemCtrlForKernel_0030.o SystemCtrlForKernel_0031.o SystemCtrlForKernel_0032.o SystemCtrlForKernel_0033.o SystemCtrlForKernel_0034.o SystemCtrlForKernel_0035.o SystemCtrlForKernel_0036.o SystemCtrlForKernel_0037.o SystemCtrlForKernel_0038.o SystemCtrlForKernel_0039.o SystemCtrlForKernel_0040.o SystemCtrlForKernel_0041.o + +#ifdef F_SystemCtrlForKernel_0000 + IMPORT_START "SystemCtrlForKernel",0x00090000 +#endif +#ifdef F_SystemCtrlForKernel_0001 + IMPORT_FUNC "SystemCtrlForKernel",0xEB74FE45,sctrlKernelSetUserLevel +#endif +#ifdef F_SystemCtrlForKernel_0002 + IMPORT_FUNC "SystemCtrlForKernel",0xD339E2E9,sctrlHENIsSE +#endif +#ifdef F_SystemCtrlForKernel_0003 + IMPORT_FUNC "SystemCtrlForKernel",0x2E2935EF,sctrlHENIsDevhook +#endif +#ifdef F_SystemCtrlForKernel_0004 + IMPORT_FUNC "SystemCtrlForKernel",0x1090A2E1,sctrlHENGetVersion +#endif +#ifdef F_SystemCtrlForKernel_0005 + IMPORT_FUNC "SystemCtrlForKernel",0x78E46415,sctrlHENFindDriver +#endif +#ifdef F_SystemCtrlForKernel_0006 + IMPORT_FUNC "SystemCtrlForKernel",0x159AF5CC,sctrlHENFindFunction +#endif +#ifdef F_SystemCtrlForKernel_0007 + IMPORT_FUNC "SystemCtrlForKernel",0xB47C9D77,sctrlSEGetVersion +#endif +#ifdef F_SystemCtrlForKernel_0008 + IMPORT_FUNC "SystemCtrlForKernel",0x2794CCF4,sctrlKernelExitVSH +#endif +#ifdef F_SystemCtrlForKernel_0009 + IMPORT_FUNC "SystemCtrlForKernel",0x577AF198,sctrlKernelLoadExecVSHDisc +#endif +#ifdef F_SystemCtrlForKernel_0010 + IMPORT_FUNC "SystemCtrlForKernel",0x94FE5E4B,sctrlKernelLoadExecVSHDiscUpdater +#endif +#ifdef F_SystemCtrlForKernel_0011 + IMPORT_FUNC "SystemCtrlForKernel",0x75643FCA,sctrlKernelLoadExecVSHMs1 +#endif +#ifdef F_SystemCtrlForKernel_0012 + IMPORT_FUNC "SystemCtrlForKernel",0xABA7F1B0,sctrlKernelLoadExecVSHMs2 +#endif +#ifdef F_SystemCtrlForKernel_0013 + IMPORT_FUNC "SystemCtrlForKernel",0x7B369596,sctrlKernelLoadExecVSHMs3 +#endif +#ifdef F_SystemCtrlForKernel_0014 + IMPORT_FUNC "SystemCtrlForKernel",0xD690750F,sctrlKernelLoadExecVSHMs4 +#endif +#ifdef F_SystemCtrlForKernel_0015 + IMPORT_FUNC "SystemCtrlForKernel",0x2D10FB28,sctrlKernelLoadExecVSHWithApitype +#endif +#ifdef F_SystemCtrlForKernel_0016 + IMPORT_FUNC "SystemCtrlForKernel",0x1DDDAD0C,sctrlSESetConfig +#endif +#ifdef F_SystemCtrlForKernel_0017 + IMPORT_FUNC "SystemCtrlForKernel",0x16C3B7EE,sctrlSEGetConfig +#endif +#ifdef F_SystemCtrlForKernel_0018 + IMPORT_FUNC "SystemCtrlForKernel",0xAD4D5EA5,sctrlSESetConfigEx +#endif +#ifdef F_SystemCtrlForKernel_0019 + IMPORT_FUNC "SystemCtrlForKernel",0x8E426F09,sctrlSEGetConfigEx +#endif +#ifdef F_SystemCtrlForKernel_0020 + IMPORT_FUNC "SystemCtrlForKernel",0x85B520C6,sctrlSEMountUmdFromFile +#endif +#ifdef F_SystemCtrlForKernel_0021 + IMPORT_FUNC "SystemCtrlForKernel",0x1C90BECB,sctrlHENSetStartModuleHandler +#endif +#ifdef F_SystemCtrlForKernel_0022 + IMPORT_FUNC "SystemCtrlForKernel",0x745286D1,sctrlHENSetMemory +#endif +#ifdef F_SystemCtrlForKernel_0023 + IMPORT_FUNC "SystemCtrlForKernel",0xAC56B90B,GetUmdFile +#endif +#ifdef F_SystemCtrlForKernel_0024 + IMPORT_FUNC "SystemCtrlForKernel",0xB64186D0,SetUmdFile +#endif +#ifdef F_SystemCtrlForKernel_0025 + IMPORT_FUNC "SystemCtrlForKernel",0x5CB025F0,sctrlSESetBootConfFileIndex +#endif +#ifdef F_SystemCtrlForKernel_0026 + IMPORT_FUNC "SystemCtrlForKernel",0xCE0A654E,sctrlHENLoadModuleOnReboot +#endif +#ifdef F_SystemCtrlForKernel_0027 + IMPORT_FUNC "SystemCtrlForKernel",0xF9584CAD,oe_malloc +#endif +#ifdef F_SystemCtrlForKernel_0028 + IMPORT_FUNC "SystemCtrlForKernel",0xA65E8BC4,oe_free +#endif +#ifdef F_SystemCtrlForKernel_0029 + IMPORT_FUNC "SystemCtrlForKernel",0xF988C1DC,sctrlHENPatchSyscall +#endif +#ifdef F_SystemCtrlForKernel_0030 + IMPORT_FUNC "SystemCtrlForKernel",0x826668E9,sctrlHENPatchSyscall +#endif +#ifdef F_SystemCtrlForKernel_0031 + IMPORT_FUNC "SystemCtrlForKernel",0x02BFCB5F,sctrlHENPatchSyscall +#endif +#ifdef F_SystemCtrlForKernel_0032 + IMPORT_FUNC "SystemCtrlForKernel",0x98012538,SetSpeed +#endif +#ifdef F_SystemCtrlForKernel_0033 + IMPORT_FUNC "SystemCtrlForKernel",0x2F157BAF,SetConfig +#endif +#ifdef F_SystemCtrlForKernel_0034 + IMPORT_FUNC "SystemCtrlForKernel",0x56CEAF00,sctrlKernelQuerySystemCall +#endif +#ifdef F_SystemCtrlForKernel_0035 + IMPORT_FUNC "SystemCtrlForKernel",0x07232EA5,sctrlHENRegisterHomebrewLoader +#endif +#ifdef F_SystemCtrlForKernel_0036 + IMPORT_FUNC "SystemCtrlForKernel",0xB86E36D1,ApplyMemory +#endif +#ifdef F_SystemCtrlForKernel_0037 + IMPORT_FUNC "SystemCtrlForKernel",0x05D8E209,sctrlGetUsbState +#endif +#ifdef F_SystemCtrlForKernel_0038 + IMPORT_FUNC "SystemCtrlForKernel",0x80C0ED7B,sctrlStartUsb +#endif +#ifdef F_SystemCtrlForKernel_0039 + IMPORT_FUNC "SystemCtrlForKernel",0x5FC12767,sctrlStopUsb +#endif +#ifdef F_SystemCtrlForKernel_0040 + IMPORT_FUNC "SystemCtrlForKernel",0x053172F8,sctrlRebootDevice +#endif +#ifdef F_SystemCtrlForKernel_0041 + IMPORT_FUNC "SystemCtrlForKernel",0x7021205F,sctrlGetTitleid +#endif diff --git a/libs/include/kubridge.h b/libs/include/kubridge.h new file mode 100644 index 0000000..a44a1ba --- /dev/null +++ b/libs/include/kubridge.h @@ -0,0 +1,182 @@ +#ifndef __KULIBRARY__ +#define __KULIBRARY__ + +#if defined (__cplusplus) +extern "C" { +#endif + +#include +#include +#include +#include + +/** + * Functions to let user mode access certain functions only available in + * kernel mode +*/ + +/** + * Load a module using ModuleMgrForKernel. + * + * @param path - The path to the module to load. + * @param flags - Unused, always 0 . + * @param option - Pointer to a mod_param_t structure. Can be NULL. + * + * @returns The UID of the loaded module on success, otherwise one of ::PspKernelErrorCodes. + */ +SceUID kuKernelLoadModule(const char *path, int flags, SceKernelLMOption *option); + + +/** + * Load a module with a specific apitype + * + * @param ap�type - The apitype + * @param path - The path to the module to load. + * @param flags - Unused, always 0 . + * @param option - Pointer to a mod_param_t structure. Can be NULL. + * + * @returns The UID of the loaded module on success, otherwise one of ::PspKernelErrorCodes. + */ +SceUID kuKernelLoadModuleWithApitype2(int apitype, const char *path, int flags, SceKernelLMOption *option); + +/** + * Gets the api type + * + * @returns the api type in which the system has booted +*/ +int kuKernelInitApitype(); + +/** + * Gets the filename of the executable to be launched after all modules of the api. + * + * @param initfilename - String where copy the initfilename + * @returns 0 on success +*/ +int kuKernelInitFileName(char *initfilename); + +/** + * + * Gets the device in which the application was launched. + * + * @returns the device code, one of PSPBootFrom values. +*/ +int kuKernelBootFrom(); + +/** + * Get the key configuration in which the system has booted. + * + * @returns the key configuration code, one of PSPKeyConfig values +*/ +int kuKernelInitKeyConfig(); + +/** + * Get the user level of the current thread + * + * @return The user level, < 0 on error + */ +int kuKernelGetUserLevel(void); + +/** + * Set the protection of a block of ddr memory + * + * @param addr - Address to set protection on + * @param size - Size of block + * @param prot - Protection bitmask + * + * @return < 0 on error + */ +int kuKernelSetDdrMemoryProtection(void *addr, int size, int prot); + +/** + * Gets the model of the PSP from user mode. + * This function is available since 3.60 M33. + * In previous version, use the kernel function sceKernelGetModel + * + * @return one of PspModel values +*/ +int kuKernelGetModel(void); + +/** + * Find module by name + * + * @param modname - Name of Module + * @param mod - module structure for output (actually treated as SceModule2) + * + * @return < 0 on error + */ +int kuKernelFindModuleByName(char *modname, SceModule *mod); + +/** + * Invalidate the entire instruction cache + */ +void kuKernelIcacheInvalidateAll(void); + +/** + * Read 4 bytes from memory (with kernel memory access) + * + * @param addr - Address to read, must have 4 bytes alignment + */ +u32 kuKernelPeekw(void *addr); + +/** + * Write 4 bytes to memory (with kernel memory access) + * + * @param addr - Address to write, must have 4 bytes alignment + */ +void kuKernelPokew(void *addr, u32 value); + +/** + * memcpy (with kernel memory access) + * + * @param dest - Destination address + * @param src - Source address + * @param num - copy bytes count + * + * @return Destination address + */ +void *kuKernelMemcpy(void *dest, const void *src, size_t num); + +struct KernelCallArg { + u32 arg1; + u32 arg2; + u32 arg3; + u32 arg4; + u32 arg5; + u32 arg6; + u32 arg7; + u32 arg8; + u32 arg9; + u32 arg10; + u32 arg11; + u32 arg12; + u32 ret1; + u32 ret2; +}; + +/** + * Call a kernel function with kernel privilege + * + * @param func_addr - kernel function address + * @param args - kernel arguments and return values + * + * return < 0 on error + */ +int kuKernelCall(void *func_addr, struct KernelCallArg *args); + +/** + * Call a kernel function with kernel privilege and extended stack + * + * @param func_addr - kernel function address + * @param args - kernel arguments and return values + * + * return < 0 on error + */ +int kuKernelCallExtendStack(void *func_addr, struct KernelCallArg *args, int stack_size); + +void kuKernelGetUmdFile(char *umdfile, int size); + +#if defined (__cplusplus) +} +#endif + +#endif diff --git a/libs/lib/libpspkubridge.a b/libs/lib/libpspkubridge.a new file mode 100644 index 0000000000000000000000000000000000000000..89d64d09107abaa4b118b757cbcada677902158d GIT binary patch literal 17186 zcmeI4O>7%Q6o6miq$Po(B&yU(m0*LQAOwz`*p8#})1+-s6eqPvt5hY_UfYvo@y|x< zO^K0E5l0TF;(!oRL{%=8Dgg(C5J$wJCsdU)H%=T7Ck~u=Z+B-syRl=ZTGMWJr+qu~ z-i&8wrt{70&dzlFHCZcezA-!@IbA%Nn2yJiGx3-t;a_y(Rgw}(QOqw6A^%5Jy|$XMprIfHQvqy!lBk zSJ$@-xvE;)uCUzVM(YiiYzYLPY0skL=w!?wP~^viXoW!QCAv5hNCKVQ<8SXI>;Sxwbh zQCHNO9gV-iLJR2^igIz2E!3{d6{RHWY_`(OE6Z5(rt5$c^ zfM{LUOn;Mybhe{I6kAk=XrW$*sKz#w+PaDXm8{Wvk-g38N{Q7loyIEBic-LQwhQ77 z_79)JXsRD}VZ)jAvJ~{pG6Rfbn9@b8D0e#EMlWJKwMeIQuV5Oy=a!WnP<|)5fE$?p4>&Sw#T@F zegyyE&}F*_48mz!qxd5bbLaywgF0^;9Pwa9h#$rD?+Lom?$N!yvPEaKJEGlZ9YZ1Z z@aAafh!M?fhZVPx2^>1>x~%EEDE(OAr%>s~Mx`>5&p9LJ<6SVHPBlmTPR!rIdmMy$ z?avo7B*=7Iwp&t-1S8Tb2(Z=4P0p8<60d$o{|uEEr4!SfecmtIF+GlXb;C6EHN58* zdWLJq^c2R5`-S1>M1 z2`oo>kQ4JFJ&zgRM86Z$e`C4={lIcOKdy6Mv_A~f63+hy74;>3F3uYwl)rsvAaoICrj|z4|Fh$f&oB`eE)Y3NQwYQSrUr zXazTyiAT(3?)=;dl90>baVfre1dvO6ZH>TmbD0#mObaVZ<|>o1zLZYlB9q}duP+_+ znf9CSf6tSITzbo8)(6kDd1Iz9F9GAyUf!nKyO~UN!(=MaGbWcm{_#7KkV$Wuyy62U zS#X)8XV~T!CaWFXY)*H@X7AQ!fBWI?ZIX~pZ`t(2`(=QiV;$dlTg{p2Zn*5>+U(u2 zZ+{^Px%8IHaBY^pkqm+)%*&6_HGB@A1VbZbh=MgY@V|B4i5;7S)Ch@q8?L_u$BL+nKA!5=x0%O+HJx@CJ{Ip}T zhu<+bMkg0ZLMFXs(huJ;HwE}a_5|}`Wpd9sG^(?kO~<~Uc5EKtT-ibQ{p|jezey6Z z=`EWXAFTV(**5M1#-?!;lJ9gjVnD}Q>uvPKf}=q-9N6>|UP7eCO)@`y?To-m>Y3JwE|Hk170*2<8AqT>c095e5YS literal 0 HcmV?d00001 diff --git a/plugin/Makefile b/plugin/Makefile new file mode 100644 index 0000000..b0b1771 --- /dev/null +++ b/plugin/Makefile @@ -0,0 +1,24 @@ +TARGET = leda +OBJS = leda.o exports.o stubs/InterruptManagerForKernel.o stubs/ModuleMgrForUser.o stubs/sceLoaderCore.o + +PRX_EXPORTS = exports.exp + +PSP_FW_VERSION = 660 + +# Use the kernel's small inbuilt libc +USE_KERNEL_LIBC = 1 +# Use only kernel libraries +USE_KERNEL_LIBS = 1 + +INCDIR = ../libs/include +CFLAGS = -Os -G0 -Wall -fno-builtin-printf +CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti +ASFLAGS = $(CFLAGS) + +LIBDIR = ../libs/lib + +LDFLAGS = -nostartfiles +LIBS = -lpspkubridge -lpspsystemctrl_kernel + +PSPSDK=$(shell psp-config --pspsdk-path) +include $(PSPSDK)/lib/build_prx.mak diff --git a/plugin/exports.exp b/plugin/exports.exp new file mode 100644 index 0000000..884cb1a --- /dev/null +++ b/plugin/exports.exp @@ -0,0 +1,12 @@ +# Define the exports for the prx +PSP_BEGIN_EXPORTS + +# These four lines are mandatory (although you can add other functions like module_stop) +# syslib is a psynonym for the single mandatory export. +PSP_EXPORT_START(syslib, 0, 0x8000) + PSP_EXPORT_FUNC(module_start) + PSP_EXPORT_FUNC(module_stop) + PSP_EXPORT_VAR(module_info) +PSP_EXPORT_END + +PSP_END_EXPORTS diff --git a/plugin/leda.c b/plugin/leda.c new file mode 100644 index 0000000..34ae6be --- /dev/null +++ b/plugin/leda.c @@ -0,0 +1,234 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "kubridge.h" + +PSP_MODULE_INFO("Legacy_Software_Loader", 0x1006, 1, 0); + +// Structs and Macros (Mostly from uOFW) + +/** Current number category size for libraries. */ +#define LIBRARY_VERSION_NUMBER_CATEGORY_SIZE (2) + +/** + * This structure represents a function stub belonging to same privilege-level linked libraries, + * i.e. a kernel resident library linked with a kernel stub library. + */ +typedef struct { + /** The call to the imported function via a MIPS ASM Jump instruction. */ + u32 call; + /** The delay slot belonging to the call, typically a NOP instruction. */ + u32 delaySlot; +} DirectCall; + +/** + * This structure represents a function stub belonging to different privilege-level linked libraries, + * i.e. a kernel resident library linked with a user stub library. + */ +typedef struct { + /** The return instruction from the stub. Typically a JR $ra command. */ + u32 returnAddr; + /** The system call exception used to call the imported function. */ + u32 syscall; +} Syscall; + +/** + * This structure represents an imported function stub. + */ +typedef union { + /** User/User or Kernel/Kernel function stub. */ + DirectCall dc; + /** Kernel/User function stub. */ + Syscall sc; +} SceStub; + +/** + * This structure represents an imported variable stub. + */ +typedef struct { + u32 *addr; + /** The NID identifying the imported variable. */ + u32 nid; +} SceVariableStub; + +/** + * This structure represents the imports, provided by a resident library, that a given module is using. + * A module can have multiple stub libraries. + */ +typedef struct { + /** The name of the library. */ + const char *libName; //0 + /** + * The version of the library. It consists of a 'major' and 'minor' field. The version of a stub + * library shouldn't be higher than the version(s) of the corresponding resident library/libraries. + * Linking won't be performed in such a case. + */ + u8 version[LIBRARY_VERSION_NUMBER_CATEGORY_SIZE]; //4 + /** The library's attributes. Can be set to either SCE_LIB_NO_SPECIAL_ATTR or SCE_LIB_WEAK_IMPORT. */ + u16 attribute; //6 + /** + * The length of this entry table in 32-Bit words. Set this to either "STUB_LIBRARY_ENTRY_TABLE_OLD_LEN" + * or "STUB_LIBRARY_ENTRY_TABLE_NEW_LEN". Use this member when you want to iterate through a + * list of entry tables (size = len * 4). + */ + u8 len; //8 + /** The number of imported variables by the stub library. */ + u8 vStubCount; //9 + /** The number of imported functions by the stub library. */ + u16 stubCount; //10 + /** Pointer to an array of NIDs containing the NIDs of the imported functions and variables. */ + u32 *nidTable; //12 + /** Pointer to an array of imported function stubs. */ + SceStub *stubTable; //16 + /** Pointer to an array of imported variable stubs. */ + SceVariableStub *vStubTable; // 20 + /** Unknown. */ + u16 unk24; //24 +} SceStubLibraryEntryTable; + +// Globals +SceOff g_pos = 0; // 0x00003DD0 +SceOff g_pos2 = 0; // 0x00003DCC +s32 g_module_id = 0; // 0x00003DE4 +void *g_address = NULL; // 0x00003E10 +u32 g_address_size = 0; // 0x00003DE8 + +// Function prototypes +s32 sctrlHENRegisterHomebrewLoader(s32 (* handler)(const char *path, s32 flags, SceKernelLMOption *option)); +s32 sceKernelLinkLibraryEntriesWithModule(SceModule *mod, SceStubLibraryEntryTable *libStubTable, u32 size); +u32 sctrlHENFindFunction(char *modname, char *libname, u32 nid); +extern u32 sceKernelQuerySystemCall(void *func); + +s32 sub_000000F0(s32 *arg) { + s32 ret = 1; + + if (*arg == 0x3E00008) { + ret = 0; + + if (arg[1] != 0) { + return arg[1] != 0x3CC; + } + } + + return ret; +} + +void loc_00000164(void) { + kuKernelLoadModule(NULL, 0, NULL); + kuKernelLoadModuleWithApitype2(0, NULL, 0, NULL); + kuKernelInitApitype(); + kuKernelInitFileName(NULL); + kuKernelBootFrom(); + kuKernelInitKeyConfig(); + kuKernelGetUserLevel(); + kuKernelSetDdrMemoryProtection(NULL, 0, 0); + kuKernelGetModel(); + return; +} + +SceOff sub_000001FC(SceUID fd, SceOff offset, s32 whence) { + g_pos = sceIoLseek(fd, offset, whence); + + if (g_pos2 != 0) { + if (offset != 0 && whence == PSP_SEEK_END) { + return g_pos2; + } + } + + return g_pos; +} + +s32 sub_00000968(SceCtrlData *pad_data, s32 count) { + s32 k1 = pspSdkSetK1(0); + s32 ret = sceCtrlPeekBufferPositive(pad_data, count); + pspSdkSetK1(k1); + return ret; +} + +void sub_000009C4(void) { + s32 k1 = pspSdkSetK1(0); + sceKernelIcacheInvalidateAll(); + pspSdkSetK1(k1); +} + +void sub_000009FC(s32 level, s32 unk) { + s32 k1 = pspSdkSetK1(0); + sceDisplaySetBrightness(level, unk); + pspSdkSetK1(k1); +} + +s32 sub_00000A54(s32 SceLED, s32 state) { + s32 k1 = pspSdkSetK1 (0); + s32 ret = sceSysconCtrlLED(SceLED, state); + pspSdkSetK1(k1); + return ret; +} + +s32 sub_00000AB8(char *modname, char *libname, u32 nid) { + s32 ret = 0; + + u32 *func = (void *)sctrlHENFindFunction(modname, libname, nid); + + if (func != 0) { + ret = sceKernelQuerySystemCall(func); + + if (ret < 0) { + ret = 0; + } + } + + return ret; +} + +/** + * Subroutine at address 0x00000CCC + */ +void sub_00000CCC(void) { + sceKernelDcacheWritebackAll(); + sceKernelIcacheClearAll(); +} + +s32 sub_00002ACC(s32 arg, void *address, u32 size) { + // LoadCoreForKernel_C0913394 was used without any args in the original leda plugin + s32 ret = sceKernelLinkLibraryEntriesWithModule(NULL, NULL, 0); + + if (g_address == NULL && ret < 0) { + g_module_id = sceKernelGetModuleIdByAddress(address); + g_address = address; + g_address_size = size; + } + + // sub_000022D4(); + return ret; +} + +// TODO +s32 sub_00003304(const char *path, s32 flags, SceKernelLMOption *option) { + return 0; +} + +s32 loc_00000AB0(struct SceKernelLoadExecVSHParam *param) { + return sceKernelExitVSHKernel(NULL); +} + + +s32 module_start(SceSize args, void *argp) { + s32 api_type = sceKernelInitApitype(); + + if (api_type != PSP_INIT_APITYPE_MS2) { + return 1; + } + + Kprintf("LEDA - Legacy Software Loader, version 0.1, by Dark_AleX\n"); + sctrlHENRegisterHomebrewLoader(sub_00003304); + return 0; +} + +s32 module_stop(void) { + return 0; +} diff --git a/plugin/stubs/InterruptManagerForKernel.S b/plugin/stubs/InterruptManagerForKernel.S new file mode 100644 index 0000000..78fe706 --- /dev/null +++ b/plugin/stubs/InterruptManagerForKernel.S @@ -0,0 +1,5 @@ + .set noreorder + +#include "pspimport.s" + IMPORT_START "InterruptManagerForKernel",0x00010000 + IMPORT_FUNC "InterruptManagerForKernel",0xF153B371,sceKernelQuerySystemCall diff --git a/plugin/stubs/ModuleMgrForUser.S b/plugin/stubs/ModuleMgrForUser.S new file mode 100644 index 0000000..6d765a0 --- /dev/null +++ b/plugin/stubs/ModuleMgrForUser.S @@ -0,0 +1,6 @@ + .set noreorder + +#include "pspimport.s" + + IMPORT_START "ModuleMgrForUser",0x40010011 + IMPORT_FUNC "ModuleMgrForUser",0xD8B73127, sceKernelGetModuleIdByAddress diff --git a/plugin/stubs/sceLoaderCore.S b/plugin/stubs/sceLoaderCore.S new file mode 100644 index 0000000..10f5ab4 --- /dev/null +++ b/plugin/stubs/sceLoaderCore.S @@ -0,0 +1,7 @@ + .set noreorder + +#include "pspimport.s" + + IMPORT_START "LoadCoreForKernel",0x00010011 + IMPORT_FUNC "LoadCoreForKernel",0xA481E30E,sceKernelLinkLibraryEntriesWithModule + IMPORT_FUNC "LoadCoreForKernel",0xD8779AC6,sceKernelIcacheClearAll