Skip to content

Commit

Permalink
Added stub privilege checker part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Princess-of-Sleeping committed Dec 25, 2023
1 parent ba02af8 commit 32c4c60
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/vita-elf-create/sce-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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++) {
Expand Down
22 changes: 22 additions & 0 deletions src/vita-libs-gen-2/defs.h
Original file line number Diff line number Diff line change
@@ -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_ */
12 changes: 9 additions & 3 deletions src/vita-libs-gen-2/vita-libs-gen-2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <sys/stat.h>
#include "vita-nid-db-yml.h"
#include "vita-nid-db.h"
#include "defs.h"
#include "utils/fs_list.h"


Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 32c4c60

Please sign in to comment.