From 8cd3b1509e9632455bb4e9f5d4b35aa1dc34754e Mon Sep 17 00:00:00 2001 From: joel16 Date: Sun, 26 Mar 2023 11:30:43 -0400 Subject: [PATCH] kernel: Get model via kernel plugin instead of using kubridge for one function --- .gitignore | 2 +- Makefile | 2 +- libs/include/kubridge.h | 182 ------------------ libs/include/vlf.h | 13 +- libs/lib/libpspkubridge.a | Bin 17186 -> 0 bytes plugin/{everest_kernel => kernel}/Makefile | 8 +- plugin/{everest_kernel => kernel}/exports.exp | 3 +- plugin/{everest_kernel => kernel}/imports.S | 4 + .../everest_kernel.c => kernel/kernel.c} | 120 +++--------- 9 files changed, 45 insertions(+), 289 deletions(-) delete mode 100644 libs/include/kubridge.h delete mode 100644 libs/lib/libpspkubridge.a rename plugin/{everest_kernel => kernel}/Makefile (70%) rename plugin/{everest_kernel => kernel}/exports.exp (93%) rename plugin/{everest_kernel => kernel}/imports.S (57%) rename plugin/{everest_kernel/everest_kernel.c => kernel/kernel.c} (65%) diff --git a/.gitignore b/.gitignore index c994bdd..5acbb14 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,7 @@ *.PBP app/*.prx app/*.SFO -app/data/everest_kernel.prx +app/data/kernel.prx app/data/kumdman.prx # Debug files diff --git a/Makefile b/Makefile index f87d641..a6d6f17 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SUBDIRS = plugin/everest_kernel plugin/kumdman app +SUBDIRS = plugin/kernel plugin/kumdman app all: @for dir in $(SUBDIRS); do $(MAKE) -C $$dir; done diff --git a/libs/include/kubridge.h b/libs/include/kubridge.h deleted file mode 100644 index a44a1ba..0000000 --- a/libs/include/kubridge.h +++ /dev/null @@ -1,182 +0,0 @@ -#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/include/vlf.h b/libs/include/vlf.h index 38d8e00..cfd73b3 100644 --- a/libs/include/vlf.h +++ b/libs/include/vlf.h @@ -1,6 +1,10 @@ #ifndef __VLF_H__ #define __VLF_H__ +#if defined (__cplusplus) +extern "C" { +#endif + typedef struct _VlfText *VlfText; typedef struct _VlfPicture *VlfPicture; typedef struct _VlfShadowedPicture *VlfShadowedPicture; @@ -773,7 +777,7 @@ VlfPicture vlfGuiAddPictureFile(char *file, int x, int y); * * @returns - a new VlfPivture on success, NULL on error */ -VlfPicture vlfGuiAddPictureResource(char *rco, char *name, int x, int y); +VlfPicture vlfGuiAddPictureResource(const char *rco, const char *name, int x, int y); /** * Removes a picture @@ -1795,7 +1799,7 @@ void vlfGuiCancelBottomDialog(); * * @returns - < 0 on error */ -int vlfGuiCentralMenu(int noptions, char **items, int defaultsel, int (* handler)(int sel), int dispx, int dispy); +int vlfGuiCentralMenu(int noptions, const char **items, int defaultsel, int (* handler)(int sel), int dispx, int dispy); /** * Cancels (remove) the central menu @@ -2029,7 +2033,8 @@ int vlfGuiSetEventDelayEx(int (* func)(void *), void * param, u32 delay); */ int vlfGuiDelayAllEvents(u32 delay); - - +#if defined (__cplusplus) +} #endif +#endif diff --git a/libs/lib/libpspkubridge.a b/libs/lib/libpspkubridge.a deleted file mode 100644 index 89d64d09107abaa4b118b757cbcada677902158d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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 diff --git a/plugin/everest_kernel/Makefile b/plugin/kernel/Makefile similarity index 70% rename from plugin/everest_kernel/Makefile rename to plugin/kernel/Makefile index 7d47e70..ea0e914 100644 --- a/plugin/everest_kernel/Makefile +++ b/plugin/kernel/Makefile @@ -1,5 +1,5 @@ -TARGET = everest_kernel -OBJS = everest_kernel.o imports.o exports.o +TARGET = kernel +OBJS = kernel.o imports.o exports.o PRX_EXPORTS = exports.exp @@ -21,5 +21,5 @@ include $(PSPSDK)/lib/build_prx.mak all: psp-build-exports -s $(PRX_EXPORTS) - mkdir "../../app/data/"; mv everest_kernel.prx "../../app/data/" - mkdir "../../app/drivers/"; mv everest_kernel.S "../../app/drivers/" + mkdir "../../app/data/"; mv kernel.prx "../../app/data/" + mkdir "../../app/drivers/"; mv kernel.S "../../app/drivers/" diff --git a/plugin/everest_kernel/exports.exp b/plugin/kernel/exports.exp similarity index 93% rename from plugin/everest_kernel/exports.exp rename to plugin/kernel/exports.exp index 1735fa9..07fd5f3 100644 --- a/plugin/everest_kernel/exports.exp +++ b/plugin/kernel/exports.exp @@ -4,7 +4,7 @@ PSP_BEGIN_EXPORTS PSP_EXPORT_VAR_HASH(module_info) PSP_EXPORT_END - PSP_EXPORT_START(everest_kernel, 0, 0x4001) + PSP_EXPORT_START(kernel, 0, 0x4001) PSP_EXPORT_FUNC_HASH(pspGetBaryonVersion) PSP_EXPORT_FUNC_HASH(pspGetPommelVersion) PSP_EXPORT_FUNC_HASH(pspGetTachyonVersion) @@ -25,5 +25,6 @@ PSP_BEGIN_EXPORTS PSP_EXPORT_FUNC_HASH(pspChkregGetPsCode) PSP_EXPORT_FUNC_HASH(pspSysconBatteryGetElec) PSP_EXPORT_FUNC_HASH(pspSysconBatteryGetTotalElec) + PSP_EXPORT_FUNC_HASH(pspGetModel) PSP_EXPORT_END PSP_END_EXPORTS diff --git a/plugin/everest_kernel/imports.S b/plugin/kernel/imports.S similarity index 57% rename from plugin/everest_kernel/imports.S rename to plugin/kernel/imports.S index 02b28d9..5a950ce 100644 --- a/plugin/everest_kernel/imports.S +++ b/plugin/kernel/imports.S @@ -5,3 +5,7 @@ STUB_START "SystemCtrlForKernel",0x00090000,0x00010005 STUB_FUNC 0x159AF5CC,sctrlHENFindFunction STUB_END + + STUB_START "sceChkreg_driver",0x00090000,0x00010005 + STUB_FUNC 0x59F8491D,sceChkreg_driver_59F8491D + STUB_END diff --git a/plugin/everest_kernel/everest_kernel.c b/plugin/kernel/kernel.c similarity index 65% rename from plugin/everest_kernel/everest_kernel.c rename to plugin/kernel/kernel.c index 967c676..f70ed75 100644 --- a/plugin/everest_kernel/everest_kernel.c +++ b/plugin/kernel/kernel.c @@ -9,63 +9,13 @@ #include #include "systemctrl.h" -#include "everest_kernel.h" +#include "kernel.h" -PSP_MODULE_INFO("everest_kernel", 0x1006, 7, 4); +PSP_MODULE_INFO("kernel", 0x1006, 1, 1); PSP_MAIN_THREAD_ATTR(0); #define MAKE_CALL(f) (0x0C000000 | (((u32)(f) >> 2) & 0x03ffffff)) -/** - * This structure represents a unique per-console identifier. It contains console specific information and can be used, - * for example, for DRM purposes and simple PSP hardware model checks. - * - * @remark On the PSP, Sony uses the term "PSID" (not to mixup with the term "OpenPSID" which represents a different set of - * unique identifier bits). On later consoles, like the PS Vita and PS4, Sony uses the term "ConsoleId" for this set of - * identifier bits. To be consistent within the PS family, we are going with the term "ConsoleId" here, even though APIs like - * sceOpenPSIDGetPSID() (which returns the ConsoleId) will remain as originally named by Sony. - */ -typedef struct { - /* Unknown. On retail set to 0. */ - u16 unk0; // 0 - /* Company code. Set to 1. */ - u16 companyCode; // 2 - /* Product code. */ - u16 productCode; // 4 - /* Product sub code. */ - u16 productSubCode; // 6 - /* Upper two bit of PsFlags. */ - u8 psFlagsMajor : 2; // 8 - /* Factory code. */ - u8 factoryCode : 6; // 8 - u8 uniqueIdMajor : 2; // 9 - /* Lower six bit of the PsFlags. Contain the QA flag, if set. */ - u8 psFlagsMinor : 6; // 9 - u8 uniqueIdMinor[6]; // 10 -} SceConsoleId; // size = 16 - -/* - * This structure contains the ConsoleId (termed "PSID" on the PSP) and an ECDSA signature used to verify the correctness of the - * ConsoleId. - * The ConsoleId is used, for example, in PSN DRM, DNAS and system configuration (with its derived PSCode). - */ -typedef struct { - /* Unique per-console identifier. */ - SceConsoleId consoleId; // 0 - /* Contains the public key of the certificate. No padding. */ - u8 plantextPublicKey[0x28]; // 16 - /* The 'r' part of the ECDSA signature pair (r, s). */ - u8 r[0x14]; // 56 - /* The 's' part of the ECDSA signature pair (r, s). */ - u8 s[0x14]; // 76 - /* The ECDSA public key (can be used to verify ECDSA signature rs). */ - u8 publicKey[0x28]; // 96 - /* Contains the encrypted private key of the certificate (with padding). */ - u8 encPrivateKey[0x20]; // 136 - /* Hash of previous data. */ - u8 hash[0x10]; // 168 -} SceIdStorageConsoleIdCertificate; // size = 184 - s32 sceSysconGetBaryonVersion(s32 *baryon); s32 sceSysconGetPommelVersion(s32 *pommel); s32 sceSyscon_driver_FB148FB6(s32 *polestar); // sceSysconGetPolestarVersion @@ -77,8 +27,7 @@ u32 sceSysconCmdExec(void *param, int unk); int sceSysconBatteryGetElec(int *elec); int sceSyscon_driver_4C539345(int *elec); // sceSysconBatteryGetTotalElec static int (*sceUtilsBufferCopyWithRange)(u8 *outbuff, int outsize, u8 *inbuff, int insize, int cmd); - -static SceIdStorageConsoleIdCertificate g_ConsoleIdCertificate; +s32 sceChkreg_driver_59F8491D(ScePsCode *pPsCode); static int _sceUtilsBufferCopyWithRange(u8 *outbuff, int outsize, u8 *inbuff, int insize, int cmd) { return (*sceUtilsBufferCopyWithRange)(outbuff, outsize, inbuff, insize, cmd); @@ -310,21 +259,23 @@ static u32 pspReadEEPROM(u8 addr) { return (param[0x21] << 8) | param[0x20]; } +static int pspErrCheck(u32 chdata) { + if ((chdata & 0x80250000) == 0x80250000) { + return -1; + } + else if (chdata & 0xFFFF0000) { + return(chdata & 0xFFFF0000) >> 16; + } + + return 0; +} + int pspReadSerial(u16 *pdata) { int err = 0; u32 data; u32 k1 = pspSdkSetK1(0); - int pspErrCheck(u32 chdata) { - if ((chdata & 0x80250000) == 0x80250000) - return -1; - else if (chdata & 0xFFFF0000) - return(chdata & 0xFFFF0000) >> 16; - - return 0; - } - data = pspReadEEPROM(0x07); err = pspErrCheck(data); @@ -344,40 +295,10 @@ int pspReadSerial(u16 *pdata) { return err; } -// Re-implementation of Subroutine sub_000001C4 - Address 0x000001C4 (openpsid.prx) -static int sceOpenPSIDLookupAndVerifyConsoleIdCertificate(void) { - int ret = 0; - const int KIRK_CERT_LEN = 0xB8; - - /* Obtain a ConsoleId certificate. TODO: Use include/idstorage.h for these values once chkreg gets merged */ - ret = pspIdStorageLookup(0x100, 0x38, &g_ConsoleIdCertificate, KIRK_CERT_LEN); - if (ret < 0) { - ret = pspIdStorageLookup(0x120, 0x38, &g_ConsoleIdCertificate, KIRK_CERT_LEN); - if (ret < 0) - return 0xC0520002; - } - - int k1 = pspSdkSetK1(0); - ret = _sceUtilsBufferCopyWithRange(NULL, 0, (u8 *)&g_ConsoleIdCertificate, KIRK_CERT_LEN, 0x12); - pspSdkSetK1(k1); - - if (ret != 0) - return 0xC0520001; - - return 0; -} - -// Reimplementation of Subroutine sceChkreg_driver_59F8491D (without sema) - Address 0x00000438 int pspChkregGetPsCode(ScePsCode *pPsCode) { - int ret = 0; - - if (((ret = sceOpenPSIDLookupAndVerifyConsoleIdCertificate()) == 0)) { - pPsCode->companyCode = g_ConsoleIdCertificate.consoleId.companyCode >> 0x8; - pPsCode->productCode = g_ConsoleIdCertificate.consoleId.productCode >> 0x8; - pPsCode->productSubCode = g_ConsoleIdCertificate.consoleId.productSubCode >> 0x8; - pPsCode->factoryCode = g_ConsoleIdCertificate.consoleId.factoryCode; - } - + int k1 = pspSdkSetK1(0); + int ret = sceChkreg_driver_59F8491D(pPsCode); + pspSdkSetK1(k1); return ret; } @@ -395,6 +316,13 @@ int pspSysconBatteryGetTotalElec(int *elec) { return ret; } +int pspGetModel(void) { + int k1 = pspSdkSetK1(0); + int ret = sceKernelGetModel(); + pspSdkSetK1(k1); + return ret; +} + int module_start(SceSize args __attribute__((unused)), void *argp __attribute__((unused))) { pspPatchMemlmd(sceKernelFindModuleByName("sceMesgLed")); pspSyncCache();