UVLoader
Userland Vita Loader
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Data Structures | Macros | Typedefs
Executable Resolver

Finds and resolves NIDs. More...

Data Structures

struct  resolve_entry
 Resolve table entry. More...
 
union  resolve_entry::value
 Value of the entry. More...
 
struct  module_info
 SCE module information section. More...
 
struct  module_exports
 SCE module export table. More...
 
struct  module_imports
 SCE module import table. More...
 
union  module_ports
 Either an SCE module import table or export table. More...
 
struct  segment_info
 A segment of the module in memory. More...
 
struct  loaded_module_info
 Loaded module information. More...
 

Macros

#define STUB_FUNC_MAX_LEN   16
 Max size for a stub function in bytes.
 
#define MAX_LOADED_MODS   128
 Maximum number of loaded modules.
 
#define MAX_RESOLVE_ENTRIES   0x10000
 Maximum number of resolves.
 
#define STUB_FUNC_SIZE   0x10
 Size of stub functions.
 
#define UVL_LIBKERN_BASE   0xE0000000
 sceLibKernel is where we import API calls from
 
#define UVL_LIBKERN_MAX_SIZE   0xE000
 Maximum size of sceLibKernel (for resolving loader)
 

Typedefs

typedef struct resolve_entry resolve_entry_t
 Resolve table entry.
 
typedef struct module_info module_info_t
 SCE module information section.
 
typedef struct module_exports module_exports_t
 SCE module export table.
 
typedef struct module_imports module_imports_t
 SCE module import table.
 
typedef union module_ports module_ports_t
 Either an SCE module import table or export table.
 
typedef struct segment_info segment_info_t
 A segment of the module in memory.
 
typedef struct loaded_module_info loaded_module_info_t
 Loaded module information.
 

Type of entry

#define RESOLVE_TYPE_UNKNOWN   0
 Unknown type.
 
#define RESOLVE_TYPE_FUNCTION   1
 Function call.
 
#define RESOLVE_TYPE_SYSCALL   2
 Syscall.
 
#define RESOLVE_TYPE_VARIABLE   3
 Imported variable.
 

Supported ARM instruction types

#define INSTRUCTION_UNKNOWN   0
 Unknown/unsupported instruction.
 
#define INSTRUCTION_MOVW   1
 MOVW Rd, #imm instruction.
 
#define INSTRUCTION_MOVT   2
 MOVT Rd, #imm instruction.
 
#define INSTRUCTION_SYSCALL   3
 SVC #imm instruction.
 
#define INSTRUCTION_BRANCH   4
 BX Rn instruction.
 

Search flags for importing loaded modules

See Also
uvl_resolve_all_loaded_modules
#define RESOLVE_MOD_IMPS   0x1
 Add entry from import function stubs.
 
#define RESOLVE_MOD_EXPS   0x2
 Add entry from exported information.
 
#define RESOLVE_IMPS_SVC_ONLY   0x4
 Used with RESOLVE_MOD_IMPS but only add syscalls for import entries.
 

Module infomation check

#define MOD_INFO_VALID_ATTR   0x0000
 
#define MOD_INFO_VALID_VER   0x0101
 

Interacting with the resolve table

int uvl_resolve_table_initialize ()
 Allocates memory for resolve table.
 
int uvl_resolve_table_destroy ()
 Frees memory for resolve table.
 
int uvl_resolve_table_add (resolve_entry_t *entry)
 Adds a resolve entry.
 
resolve_entry_tuvl_resolve_table_get (u32_t nid)
 Gets a resolve entry.
 

Estimating syscalls

resolve_entry_tuvl_estimate_syscall (u32_t nid)
 Estimates an unknown syscall.
 

Capturing and resolving stubs

int uvl_resolve_import_stub_to_entry (void *stub, u32_t nid, resolve_entry_t *entry)
 Creates resolve entry from stub function imported by a module.
 
int uvl_resolve_entry_to_import_stub (resolve_entry_t *entry, void *stub)
 Fills a stub with resolve entry.
 

ARM instruction functions

u32_t uvl_decode_arm_inst (u32_t cur_inst, u8_t *type)
 Get an instruction's type and immediate value.
 
u32_t uvl_encode_arm_inst (u8_t type, u16_t immed, u16_t reg)
 Creates an ARMv7 instruction.
 

Bulk add to resolve table

int uvl_resolve_add_imports (module_imports_t *imp_table, int syscalls_only)
 Add a module's import table's entries to the resolve table.
 
int uvl_resolve_add_exports (module_exports_t *exp_table)
 Add a module's export entries to the resolve table.
 

Resolving entries

int uvl_resolve_add_all_modules (int type)
 Adds entries from all loaded modules to resolve table.
 
int uvl_resolve_add_module (PsvUID modid, int type)
 Adds entries from a loaded module to resolve table.
 
int uvl_resolve_imports (module_imports_t *import)
 Resolves an import table.
 
int uvl_resolve_loader (u32_t nid, void *libkernel_base, void *stub)
 Resolves UVLoader imported function.
 

Detailed Description

Finds and resolves NIDs.

Typedef Documentation

Loaded module information.

Returned by sceKernelGetModuleInfo

SCE module export table.

Can be found in an ELF file or loaded in memory.

SCE module import table.

Can be found in an ELF file or loaded in memory.

typedef struct module_info module_info_t

SCE module information section.

Can be found in an ELF file or loaded in memory.

Either an SCE module import table or export table.

See Also
module_imports
module_exports

Resolve table entry.

This can represent either an unresolved entry from a homebrew or a resolved entry copied from a loaded module.

Function Documentation

u32_t uvl_decode_arm_inst ( u32_t  cur_inst,
u8_t type 
)

Get an instruction's type and immediate value.

Currently only supports ARMv7 encoding of MOV Rd, #imm, MOVT Rd, #imm, BX Rn, and SVC #imm. You should use the return value of this function to check for error but instead the value of type where INSTRUCTION_UNKNOWN is a failure.

Returns
Immediate value of instruction on success, indeterminate on error
Parameters
cur_instARMv7 instruction
typeSee defined "Supported ARM instruction types"
u32_t uvl_encode_arm_inst ( u8_t  type,
u16_t  immed,
u16_t  reg 
)

Creates an ARMv7 instruction.

Currently only supports ARMv7 encoding of MOV Rd, #imm, MOVT Rd, #imm, BX Rn, and SVC #imm. Depending on the type, not all parameters may be used.

Returns
ARMv7 instruction on success or 0 on failure.
Parameters
typeSee defined "Supported ARM instruction types"
immedImmediate value to encode
regRegister used in instruction
resolve_entry_t* uvl_estimate_syscall ( u32_t  nid)

Estimates an unknown syscall.

Estimates a syscall for a given NID based on information of existing syscalls in the resolve table.

Returns
Entry on success, NULL on error
Parameters
nidNID to resolve
int uvl_resolve_add_all_modules ( int  type)

Adds entries from all loaded modules to resolve table.

Returns
Zero on success, otherwise error
Parameters
typeAn OR combination of flags (see defined "Search flags for importing loaded modules") directing the search
int uvl_resolve_add_exports ( module_exports_t exp_table)

Add a module's export entries to the resolve table.

Returns
Zero on success, otherwise error
Parameters
exp_tableModule's export table
int uvl_resolve_add_imports ( module_imports_t imp_table,
int  syscalls_only 
)

Add a module's import table's entries to the resolve table.

A loaded module has it's stubs already resolved by the kernel. This will copy those resolved entries for our own use.

Returns
Zero on success, otherwise error
Parameters
imp_tableModule's import table to read from
syscalls_onlyIf set, will only add resolved syscalls and nothing else
int uvl_resolve_add_module ( PsvUID  modid,
int  type 
)

Adds entries from a loaded module to resolve table.

This functions takes a loaded module and attempts to read its import and/or export table and add entries to our resolve table.

Returns
Zero on success, otherwise error
Parameters
modidUID of the module
typeAn OR combination of flags (see defined "Search flags for importing loaded modules") directing the search
int uvl_resolve_entry_to_import_stub ( resolve_entry_t entry,
void *  stub 
)

Fills a stub with resolve entry.

Returns
Zero on success, otherwise error
Parameters
entryEntry to read from
stubStub function to fill
int uvl_resolve_import_stub_to_entry ( void *  stub,
u32_t  nid,
resolve_entry_t entry 
)

Creates resolve entry from stub function imported by a module.

Given the stub function of a loaded module that has already been resolved, extract the resolved information and write it to a resolve_entry_t.

Returns
Zero on success, otherwise error
Parameters
stubStub function to read
nidNID resolved by stub
entryEntry to write to
int uvl_resolve_imports ( module_imports_t import)

Resolves an import table.

Returns
Zero on success, otherwise error
Parameters
importImport table
int uvl_resolve_loader ( u32_t  nid,
void *  libkernel_base,
void *  stub 
)

Resolves UVLoader imported function.

UVLoader only depends on functions exported and imported by sceLibKernel. This function is a simplified version of the main resolver and does not use and external functions.

Returns
Zero on success, otherwise error
int uvl_resolve_table_add ( resolve_entry_t entry)

Adds a resolve entry.

This function does not check for duplicates.

Returns
Zero on success, otherwise error
Parameters
entryEntry to add
int uvl_resolve_table_destroy ( )

Frees memory for resolve table.

Returns
Zero on success, otherwise error
resolve_entry_t* uvl_resolve_table_get ( u32_t  nid)

Gets a resolve entry.

This function returns the last entry in the table that has the given NID.

Returns
Entry on success, NULL on error
Parameters
nidNID to resolve
int uvl_resolve_table_initialize ( )

Allocates memory for resolve table.

Returns
Zero on success, otherwise error