Redirect UVL logging it to our logging. Fixed UVL IO hooks

This commit is contained in:
TheFloW 2016-01-26 17:31:41 +01:00
parent c6599212e4
commit ea65c3aeea
5 changed files with 37 additions and 46 deletions

View File

@ -818,8 +818,9 @@ int sceIoReadPatchedUVL(SceUID fd, void *data, SceSize size) {
}
int sceIoWritePatchedUVL(SceUID fd, const void *data, SceSize size) {
debugPrintf("%s\n", __FUNCTION__);
return sceIoWrite(fd, data, size);
// Redirect to our debug logging and close the uvloader.log descriptor
debugPrintf((char *)data);
return sceIoClose(fd);
}
int sceIoClosePatchedUVL(SceUID fd) {
@ -835,9 +836,9 @@ PatchValue patches_uvl[] = {
{ 0, 0, (uint32_t)&sceKernelWaitThreadEnd, sceKernelWaitThreadEndPatchedUVL },
{ 0, 0, (uint32_t)&sceIoOpen, sceIoOpenPatchedUVL },
{ 0, 0, (uint32_t)&sceIoLseek, sceIoLseekPatchedUVL },
{ 0, 0, (uint32_t)&sceIoRead, sceIoReadPatchedUVL }, // COULD NOT BE FOUND
{ 0, 0, (uint32_t)&sceIoWrite, sceIoWritePatchedUVL }, // COULD NOT BE FOUND
{ 0, 0, (uint32_t)&sceIoClose, sceIoClosePatchedUVL }, // COULD NOT BE FOUND
{ 0, 0, (uint32_t)&sceIoRead, sceIoReadPatchedUVL },
{ 0, 0, (uint32_t)&sceIoWrite, sceIoWritePatchedUVL },
{ 0, 0, (uint32_t)&sceIoClose, sceIoClosePatchedUVL },
};
#define N_UVL_PATCHES (sizeof(patches_uvl) / sizeof(PatchValue))
@ -862,7 +863,11 @@ void initPatchValues(PatchValue *patches, int n_patches) {
int i;
for (i = 0; i < n_patches; i++) {
patches[i].value = extractStub(patches[i].stub);
// debugPrintf("%d: 0x%08X\n", i, patches[i].value);
// These stubs call imports instead of syscalls/exports
if (i >= 7 && i <= 9) {
patches[i].value = findModuleImportByValue("SceLibKernel", "SceIofilemgr", patches[i].value);
}
}
}
@ -916,6 +921,10 @@ int PatchUVL() {
makeFunctionStub(shared_memory->sceIoWriteAddr, sceIoWritePatchedUVL);
makeFunctionStub(shared_memory->sceIoCloseAddr, sceIoClosePatchedUVL);
// Disable UVL logging because this causes crash for xerpi derpi
makeThumbDummyFunction0(extractFunctionStub((uint32_t)&uvl_debug_log) & ~0x1);
makeThumbDummyFunction0(extractFunctionStub((uint32_t)&uvl_log_write) & ~0x1);
// Make uvl_alloc_code_mem return 0
makeThumbDummyFunction0(extractFunctionStub((uint32_t)&uvl_alloc_code_mem) & ~0x1);

1
main.c
View File

@ -18,7 +18,6 @@
/*
TODO:
- Patch UVL logging
- NEARLY DONE: Terminate thread / free stack of previous VitaShell when reloading
- Redirecting .data segment when reloading
- Nethost. Patch UVL to be able to launch from host0

View File

@ -160,7 +160,7 @@ void makeFunctionStub(uint32_t address, void *function) {
}
void makeStub(uint32_t address, void *function) {
if ((uint32_t)function < 0x1000) {
if ((uint32_t)function < MAX_SYSCALL_VALUE) {
makeSyscallStub(address, (uint16_t)function);
} else {
makeFunctionStub(address, function);
@ -210,7 +210,7 @@ void makeArmDummyFunction0(uint32_t address) {
uvl_lock_mem();
uvl_flush_icache((void *)address, 0x4);
uvl_flush_icache((void *)address, 0x10);
}
void makeThumbDummyFunction0(uint32_t address) {
@ -450,46 +450,30 @@ uint32_t findModuleImportByUID(SceUID mod, char *libname, uint32_t nid) {
return findModuleImportByInfo(findModuleInfo(modname, text_addr, text_size), text_addr, libname, nid);
}
int findSyscallInModuleImports(uint32_t syscall, char modulename[27], uint32_t *addr) {
SceUID mod_list[MAX_MODULES];
int mod_count = MAX_MODULES;
uint32_t findModuleImportByValue(char *modname, char *libname, uint32_t value) {
uint32_t text_addr = 0, text_size = 0;
if (findModuleByName(modname, &text_addr, &text_size) == 0)
return 0;
int res = sceKernelGetModuleList(0xFF, mod_list, &mod_count);
if (res < 0)
return res;
SceModuleInfo *mod_info = findModuleInfo(modname, text_addr, text_size);
if (!mod_info)
return 0;
int i;
for (i = mod_count - 1; i >= 0; i--) {
SceKernelModuleInfo info;
info.size = sizeof(SceKernelModuleInfo);
if (sceKernelGetModuleInfo(mod_list[i], &info) < 0)
continue;
char modname[27];
uint32_t text_addr = 0, text_size = 0;
if(!getModuleInfo(mod_list[i], modname, &text_addr, &text_size))
continue;
SceModuleInfo *mod_info = findModuleInfo(modname, text_addr, text_size);
if (!mod_info)
continue;
uint32_t i = mod_info->impTop;
while (i < mod_info->impBtm) {
SceImportsTable3xx import;
convertToImportsTable3xx((void *)text_addr + i, &import);
uint32_t i = mod_info->impTop;
while (i < mod_info->impBtm) {
SceImportsTable3xx import;
convertToImportsTable3xx((void *)text_addr + i, &import);
if (import.lib_name && strcmp(import.lib_name, libname) == 0) {
int j;
for (j = 0; j < import.num_functions; j++) {
if (extractSyscallStub((uint32_t)import.func_entry_table[j]) == syscall) {
strcpy(modulename, modname);
*addr = (uint32_t)import.func_entry_table[j] - text_addr;
return 1;
if (extractStub((uint32_t)import.func_entry_table[j]) == value) {
return (uint32_t)import.func_entry_table[j];
}
}
i += import.size;
}
i += import.size;
}
return 0;
@ -717,7 +701,7 @@ void addImportNids(SceModuleInfo *mod_info, uint32_t text_addr, uint32_t reload_
uint32_t value = extractStub((uint32_t)import.func_entry_table[j]);
uint32_t nid = *(uint32_t *)(reload_text_addr + (uint32_t)&import.func_nid_table[j] - text_addr);
if (only_syscalls && value >= 0x4000)
if (only_syscalls && value >= MAX_SYSCALL_VALUE)
continue;
addNidValue(nid, value);

View File

@ -44,6 +44,8 @@
#define MAX_MODULES 128
#define MAX_NIDS 0x10000
#define MAX_SYSCALL_VALUE 0x1000
typedef struct {
uint16_t size;
uint8_t lib_version[2];
@ -125,8 +127,7 @@ uint32_t findModuleExportByName(char *modname, char *libname, uint32_t nid);
uint32_t findModuleImportByInfo(SceModuleInfo *mod_info, uint32_t text_addr, char *libname, uint32_t nid);
uint32_t findModuleImportByUID(SceUID mod, char *libname, uint32_t nid);
int findSyscallInModuleImports(uint32_t syscall, char modulename[27], uint32_t *addr);
uint32_t findModuleImportByValue(char *modname, char *libname, uint32_t value);
void duplicateModule(char *name, uint32_t *text_addr, uint32_t *text_size);

View File

@ -50,8 +50,6 @@ int debugPrintf(char *text, ...) {
vsprintf(string, text, list);
va_end(list);
printf(string);
netdbg(string);
SceUID fd = sceIoOpen("cache0:vitashell_log.txt", SCE_O_WRONLY | SCE_O_CREAT | SCE_O_APPEND, 0777);