summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReiko Asakura2021-02-28 19:03:41 -0500
committerReiko Asakura2021-02-28 19:03:41 -0500
commite75a1c2ad660bac6d594589a4e74353629a5024b (patch)
tree7d89cf0a6fa149a6fe78c44e09009bddf7a6fc55
parentRefactor opcode decode functions (diff)
downloadmusicpremium-e75a1c2ad660bac6d594589a4e74353629a5024b.tar.gz
Refactor module NID lookup functions
-rw-r--r--CMakeLists.txt1
-rw-r--r--module.c31
-rw-r--r--module.h20
-rw-r--r--musicpremium.c15
4 files changed, 56 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7efbbd4..e770894 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,6 +41,7 @@ set(SELF "${PROJECT_NAME}.skprx")
add_library("${ELF}" MODULE
musicpremium.c
musicpremium.emd
+ module.c
opcode.c
)
diff --git a/module.c b/module.c
new file mode 100644
index 0000000..9d39b92
--- /dev/null
+++ b/module.c
@@ -0,0 +1,31 @@
+/*
+ Copyright (C) 2020-2021 Reiko Asakura. All Rights Reserved.
+
+ Music Premium
+*/
+
+#include <kernel/constant.h>
+#include <libdbg.h>
+
+#include "module.h"
+
+/* ARGSUSED */
+int get_export(const char *modname, uint32_t libnid, uint32_t funcnid, uintptr_t *func, const char *name) {
+ int ret = module_get_export_func(KERNEL_PID, modname, libnid, funcnid, func);
+ if (ret == 0) {
+ SCE_DBG_LOG_INFO("Found export %s %p", name, *func);
+ } else {
+ SCE_DBG_LOG_ERROR("Failed to find export %s 0x%08X", name, ret);
+ }
+ return ret;
+}
+
+int get_module(SceUID pid, const char *name, tai_module_info_t *info) {
+ int ret = module_get_by_name_nid(pid, name, TAI_IGNORE_MODULE_NID, info);
+ if (ret == 0) {
+ SCE_DBG_LOG_INFO("Found module %s uid 0x%08X fingerprint 0x%08X", name, info->modid, info->module_nid);
+ } else {
+ SCE_DBG_LOG_ERROR("Failed to find module %s 0x%08X", name, ret);
+ }
+ return ret;
+}
diff --git a/module.h b/module.h
new file mode 100644
index 0000000..6514346
--- /dev/null
+++ b/module.h
@@ -0,0 +1,20 @@
+/*
+ Copyright (C) 2020-2021 Reiko Asakura. All Rights Reserved.
+
+ Music Premium
+*/
+
+#ifndef MODULE_H_
+#define MODULE_H_
+
+#include <taihen.h>
+
+#define GET_EXPORT(modname, libnid, funcnid, func) get_export(modname, libnid, funcnid, func, #func)
+
+#define GET_MODULE(pid, name, info) get_module(pid, name, info)
+
+int get_export(const char *modname, uint32_t libnid, uint32_t funcnid, uintptr_t *func, const char *name);
+
+int get_module(SceUID pid, const char *name, tai_module_info_t *info);
+
+#endif
diff --git a/musicpremium.c b/musicpremium.c
index fe8a979..213c021 100644
--- a/musicpremium.c
+++ b/musicpremium.c
@@ -12,6 +12,7 @@
#include <sblacmgr.h>
#include <taihen.h>
+#include "module.h"
#include "opcode.h"
#define GLZ(x) do {\
@@ -28,14 +29,6 @@
#define STREQ(s1, s2) (strncmp(s1, s2, sizeof(s1)) == 0)
-extern int module_get_export_func(SceUID pid, const char *modname, uint32_t libnid, uint32_t funcnid, uintptr_t *func);
-#define GET_EXPORT(mod, lib, func, fptr)\
- module_get_export_func(KERNEL_PID, mod, lib, func, (uintptr_t*)fptr)
-
-extern int module_get_by_name_nid(SceUID pid, const char *name, uint32_t nid, tai_module_info_t *info);
-#define GET_MODULE(pid, name, info)\
- module_get_by_name_nid(pid, name, TAI_IGNORE_MODULE_NID, info)
-
#define INJECT_ABS(idx, dest, src, size)\
(inject_id[idx] = taiInjectAbsForKernel(\
KERNEL_PID, dest, src, size))
@@ -61,7 +54,7 @@ static int (*sceAppMgrReleaseBgmPort)(void);
static int get_addr(void **inject_addr, void **hook_addr) {
// get sceAppMgrAcquireBgmPort addr
void *sceAppMgrAcquireBgmPort;
- RLZ(GET_EXPORT("SceAppMgr", 0x8AF17416, 0xAFCEAB96, &sceAppMgrAcquireBgmPort));
+ RLZ(GET_EXPORT("SceAppMgr", 0x8AF17416, 0xAFCEAB96, (void *)&sceAppMgrAcquireBgmPort));
// clear Thumb bit
sceAppMgrAcquireBgmPort = (void*)((int)sceAppMgrAcquireBgmPort & ~0x1);
@@ -139,8 +132,8 @@ int module_start(SceSize argc, const void *argv) { (void)argc; (void)argv;
startup();
// get SceAppMgr exports
- GLZ(GET_EXPORT("SceAppMgr", 0x8AF17416, 0xAAED7419, &sceAppMgrAcquireBgmPortWithPriority));
- GLZ(GET_EXPORT("SceAppMgr", 0x8AF17416, 0xF3717E37, &sceAppMgrReleaseBgmPort));
+ GLZ(GET_EXPORT("SceAppMgr", 0x8AF17416, 0xAAED7419, (void *)&sceAppMgrAcquireBgmPortWithPriority));
+ GLZ(GET_EXPORT("SceAppMgr", 0x8AF17416, 0xF3717E37, (void *)&sceAppMgrReleaseBgmPort));
// firmware independent way of getting absolute address
void *inject_addr = 0, *hook_addr = 0;