Esempio n. 1
0
int main(int argc, char **argv) {
	sceKernelIcacheInvalidateRange(test_dyna, sizeof(test_dyna));
	memcpy(test_dyna, test1, test1_end - test1); ((void(*)(void))test_dyna)();

	sceKernelIcacheInvalidateRange(test_dyna, sizeof(test_dyna));
	memcpy(test_dyna, test2, test2_end - test2); ((void(*)(void))test_dyna)();
	
	return 0;
}
Esempio n. 2
0
File: utils.c Progetto: Kaegell/uofw
int sceKernelIcacheInvalidateRangeForUser(const void *p, u32 size)
{
    int ret;
    int oldK1 = pspShiftK1();
    if (!pspK1DynBufOk(p, size))
        ret = 0x800200D3;
    else
        ret = sceKernelIcacheInvalidateRange(p, size);
    pspSetK1(oldK1);
    return ret;
}
Esempio n. 3
0
/**
 * Remember you have to export the hooker function if using syscall hook
 */
int hook_import_bynid(SceModule *pMod, char *library, unsigned int nid, void *func, int syscall)
{
    PspModuleImport *pImp;
    void *stubTab;
    int stubLen;
    int i = 0;

    if(pMod == NULL)
        return -1;

    stubTab = pMod->stub_top;
    stubLen = pMod->stub_size;

    while(i<stubLen) {
        pImp = (PspModuleImport*)(stubTab+i);

        if((pImp->name) && (strcmp(pImp->name, library) == 0)) {
            int j;

            for(j=0; j<pImp->funcCount; j++) {
                if(pImp->fnids[j] == nid) {
                    void *addr = (void*)(&pImp->funcs[j*2]);

                    if(syscall) {
                        u32 syscall_num;

                        syscall_num = sctrlKernelQuerySystemCall(func);

                        if(syscall_num == (u32)-1) {
                            printk("%s: cannot find syscall in %s_%08X\n", __func__, library, nid);

                            return -1;
                        }

                        _sw(0x03E00008, (u32)addr);
                        _sw(MAKE_SYSCALL(syscall_num), (u32)(addr + 4));
                    } else {
                        _sw(MAKE_JUMP(func), (u32)addr);
                        _sw(NOP, (u32)(addr + 4));
                    }

                    sceKernelDcacheWritebackInvalidateRange(addr, 8);
                    sceKernelIcacheInvalidateRange(addr, 8);
                }
            }
        }

        i += (pImp->entLen * 4);
    }

    return 0;
}
Esempio n. 4
0
void api_hook_import_syscall(unsigned int address, void * function) {
    //valid address
    if (address) {
        //asm jr $ra
        *(unsigned int *) (address) = 0x03E00008;

        //asm syscall #
        *(unsigned int *) (address + 4) = (((sceKernelQuerySystemCall(function)) << 6) | 12);

        //flush cache
        sceKernelDcacheWritebackInvalidateRange((const void *) address, 8);
        sceKernelIcacheInvalidateRange((const void *) address, 8);
    }
}
Esempio n. 5
0
void api_hook_import(unsigned int address, void * function) {
    //valid address
    if (address) {
        //asm jmp
        *(unsigned int *) (address) = 0x08000000 | ((unsigned int) function & 0x0FFFFFFF) >> 2;

        //asm nop
        *(unsigned int *) (address + 4) = 0;

        //flush cache
        sceKernelDcacheWritebackInvalidateRange((const void *) address, 8);
        sceKernelIcacheInvalidateRange((const void *) address, 8);
    }
}
Esempio n. 6
0
/**
 * Remember you have to export the hooker function if using syscall hook
 */
int hook_import_bynid(SceModule *pMod, char *library, unsigned int nid, void *func)
{
	PspModuleImport *pImp;
	void *stubTab;
	int stubLen;
	int i = 0;

	if(pMod == NULL)
		return -1;

	stubTab = pMod->stub_top;
	stubLen = pMod->stub_size;

	while(i<stubLen) {
		pImp = (PspModuleImport*)(stubTab+i);

		if((pImp->name) && (strcmp(pImp->name, library) == 0)) {
			int j;

			for(j=0; j<pImp->funcCount; j++) {
				if(pImp->fnids[j] == nid) {
					void *addr = (void*)(&pImp->funcs[j*2]);
					if(func == NULL) {
						_sw(0x03E00008, (u32)addr);
						_sw(NOP, (u32)(addr + 4));
					} else {
						// Partition Check
						SceModule2 * mod = (SceModule2 *)pMod;
						if(((mod->text_addr & 0x80000000) && (((uint32_t)func) & 0x80000000)) || ((mod->text_addr & 0x80000000) == 0 && (((uint32_t)func) & 0x80000000) == 0))
						{
							REDIRECT_FUNCTION(func, addr);
						} else {
							_sw(0x03E00008, (u32)addr);
							_sw(MAKE_SYSCALL(sctrlKernelQuerySystemCall(func)), (u32)(addr + 4));
						}
					}

					sceKernelDcacheWritebackInvalidateRange(addr, 8);
					sceKernelIcacheInvalidateRange(addr, 8);
				}
			}
		}

		i += (pImp->entLen * 4);
	}

	return 0;
}
Esempio n. 7
0
/* Patch out the exception handler setup call for apps which come after us ;P */
int psplinkPatchException(void)
{
	unsigned int *addr;
	int intc;

	intc = pspSdkDisableInterrupts();
	addr = libsFindExportAddrByNid(refer_module_by_name("sceExceptionManager", NULL), "ExceptionManagerForKernel", 0x565C0B0E);
	if(addr)
	{
		*addr = (unsigned int) RegisterExceptionDummy;
		sceKernelDcacheWritebackInvalidateRange(addr, 4);
		sceKernelIcacheInvalidateRange(addr, 4);
	}
	pspSdkEnableInterrupts(intc);

	return 0;
}
Esempio n. 8
0
static int commitSelectedChar(HexEditor* prHex) {
    AsciiColumn* prCol = NULL;
    SceChar8 value = (SceChar8)0;
    SceChar8* pcDest = NULL;
    SceUInt32 offset = 0;

    if (prHex == NULL) {
        return HEXEDITOR_MEMORY;
    }
    prCol = &(prHex->rEditRow.rAscii);
    value = asciicolumn_commit(prCol);
    offset = getSelectedByteOffset(prHex);
    pcDest = (SceChar8*)offset;
    *pcDest = value;
    sceKernelDcacheWritebackInvalidateRange(pcDest, 1);
    sceKernelIcacheInvalidateRange(pcDest, 1);
    prHex->editing = 0;
    prHex->dirty = 1;
    return HEXEDITOR_SUCCESS;
}
Esempio n. 9
0
int libsPatchFunction(SceUID uid, const char *library, unsigned int nid, u16 retval)
{
	unsigned int* addr;
	int intc;
	int ret = 0;

	intc = pspSdkDisableInterrupts();
	addr = (unsigned int *) libsFindExportByNid(uid, library, nid);
	if(addr)
	{
		addr[0] = 0x03E00008;
		addr[1] = 0x24020000 | (unsigned int) retval;
		sceKernelDcacheWritebackInvalidateRange(addr, 8);
		sceKernelIcacheInvalidateRange(addr, 8);
		ret = 1;
	}
	pspSdkEnableInterrupts(intc);

	return ret;
}
Esempio n. 10
0
	virtual void flushDataCache(void *ptr, uint32 len) const {
		sceKernelDcacheWritebackRange(ptr, len);
		sceKernelIcacheInvalidateRange(ptr, len);
	}