From 32c4c6094d262cb5032064bb2bfe7a8785a36508 Mon Sep 17 00:00:00 2001 From: Princess-of-Sleeping <29831892+Princess-of-Sleeping@users.noreply.github.com> Date: Mon, 25 Dec 2023 18:04:17 +0900 Subject: [PATCH] Added stub privilege checker part 1 --- src/vita-elf-create/sce-elf.c | 10 +++++++--- src/vita-libs-gen-2/defs.h | 22 ++++++++++++++++++++++ src/vita-libs-gen-2/vita-libs-gen-2.cpp | 12 +++++++++--- 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 src/vita-libs-gen-2/defs.h diff --git a/src/vita-elf-create/sce-elf.c b/src/vita-elf-create/sce-elf.c index 18a4600..d1189a1 100644 --- a/src/vita-elf-create/sce-elf.c +++ b/src/vita-elf-create/sce-elf.c @@ -13,6 +13,7 @@ #include "utils/fail-utils.h" #include "utils/varray.h" #include "utils/endian-utils.h" +#include "../vita-libs-gen-2/defs.h" const uint32_t sce_elf_stub_func[3] = { 0xe3e00000, /* mvn r0, #0 */ @@ -318,12 +319,15 @@ static void set_module_import(vita_elf_t *ve, sce_module_imports_t *import, cons import->num_syms_funcs = library->functions_va.count; import->num_syms_vars = library->variables_va.count; import->library_nid = library->nid; - import->flags = library->library->flags & 0xFFFF; - if (library->library) { - import->library_name = library->library->name; + if ((library->library->flags & VITA_STUB_GEN_2_FLAG_WEAK) != 0) { + import->flags = 0x8; + } else { + import->flags = 0x0; } + import->library_name = library->library->name; + import->func_nid_table = calloc(library->functions_va.count, sizeof(uint32_t)); import->func_entry_table = calloc(library->functions_va.count, sizeof(void *)); for (i = 0; i < library->functions_va.count; i++) { diff --git a/src/vita-libs-gen-2/defs.h b/src/vita-libs-gen-2/defs.h new file mode 100644 index 0000000..7554a9f --- /dev/null +++ b/src/vita-libs-gen-2/defs.h @@ -0,0 +1,22 @@ + +#ifndef _VITA_STUB_GEN_2_DEFS_H_ +#define _VITA_STUB_GEN_2_DEFS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + +/* + * weak is set to 8 for compatibility with previous vita-libs-gen. + * When this value is changed due to optimization, it is when that compatibility is broken. + */ +#define VITA_STUB_GEN_2_FLAG_WEAK (0x8) +#define VITA_STUB_GEN_2_FLAG_IS_KERNEL (0x10) + + +#ifdef __cplusplus +} +#endif + +#endif /* _VITA_STUB_GEN_2_DEFS_H_ */ diff --git a/src/vita-libs-gen-2/vita-libs-gen-2.cpp b/src/vita-libs-gen-2/vita-libs-gen-2.cpp index 1b74de3..f19e115 100644 --- a/src/vita-libs-gen-2/vita-libs-gen-2.cpp +++ b/src/vita-libs-gen-2/vita-libs-gen-2.cpp @@ -6,6 +6,7 @@ #include #include "vita-nid-db-yml.h" #include "vita-nid-db.h" +#include "defs.h" #include "utils/fs_list.h" @@ -246,7 +247,6 @@ const char *find_item(int argc, char *argv[], const char *name){ return NULL; } - void vita_nid_db_gen_asm(NidStub *stub, DBEntry *entry, int is_function){ char path[0x400]; @@ -277,11 +277,17 @@ void vita_nid_db_gen_asm(NidStub *stub, DBEntry *entry, int is_function){ fprintf(fp, ".type %s, %%object\n", entry->name); } + int flag = 0; + + if(entry->library->privilege == LIBRARY_LOCATE_KERNEL){ + flag |= VITA_STUB_GEN_2_FLAG_IS_KERNEL; + } + fprintf(fp, "%s:\n", entry->name); fprintf(fp, ".if GEN_WEAK_EXPORTS\n"); - fprintf(fp, "\t.word 0x%04X0008\n", entry->library->version); + fprintf(fp, "\t.word 0x%04X%04X\n", entry->library->version & 0xFFFF, (flag | VITA_STUB_GEN_2_FLAG_WEAK) & 0xFFFF); fprintf(fp, ".else\n"); - fprintf(fp, "\t.word 0x%04X0000\n", entry->library->version); + fprintf(fp, "\t.word 0x%04X%04X\n", entry->library->version & 0xFFFF, flag & 0xFFFF); fprintf(fp, ".endif //GEN_WEAK_EXPORTS\n"); fprintf(fp, "\t.word 0x%08X\n", entry->library->nid); fprintf(fp, "\t.word 0x%08X\n", entry->nid);