Exemplo n.º 1
0
int control_module_threads(SceUID module_id, int pause) {
    // get an array of all threads
    int thread_count;
    if (sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread, NULL, 0, &thread_count) < 0)
        return 0;
    if (thread_count < 1)
        return 0;
    SceUID thread_id[thread_count];
    if (sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread, thread_id, thread_count, NULL) < 0)
        return 0;
    int i;
    SceModule* module;
    SceKernelThreadInfo thread_info;
    thread_info.size = sizeof(SceKernelThreadInfo);
    for (i = 0; i < thread_count; i++) {
        // determine if a thread is from the game
        if (sceKernelReferThreadStatus(thread_id[i], &thread_info))
            continue;
        module = sceKernelFindModuleByAddress((unsigned int) thread_info.entry);
        if (module && module->modid == module_id) {
            // pause or resume the thread
            if (pause)
                sceKernelSuspendThread(thread_id[i]);
            else
                sceKernelResumeThread(thread_id[i]);
        }
    }
    return 1;
}
Exemplo n.º 2
0
int nkThreadSuspend(SceUID thId){

	int i, j;
	SceUID myThread, *Thread_Now;

	if(bufNow.pThread != 0) return 1;

	bufNow.pThread = sceKernelAllocPartitionMemory(1, "th", 0, MAX_THREAD*sizeof(SceUID), NULL);
	if(bufNow.pThread < 0){
		bufNow.count = 0;
		bufNow.pThread = 0;
		return 1;
	}
	Thread_Now = (SceUID*)sceKernelGetBlockHeadAddr(bufNow.pThread);

	sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread, Thread_Now, MAX_THREAD, &(bufNow.count));
	myThread = sceKernelGetThreadId();

	for(i = 0; i < bufNow.count; i++){
		unsigned char match = 0;
		SceUID tmp_thid = Thread_Now[i];
		
		for(j = 0; j < count_Start; j++){
			if((tmp_thid == Thread_Start[j]) || (tmp_thid == thId) || (tmp_thid == myThread)){
				match = 1;
				j = count_Start;
			}
		}
		if(match == 0){
			sceKernelSuspendThread(tmp_thid);
		}
	}

	return 0;
}
Exemplo n.º 3
0
static int _pspSdkReferInternal(const char *name, enum SceKernelIdListType type, 
		struct _ThreadInfoSkel *pInfo, int size, ReferFunc pRefer)
{
	int uid_count = 0;

	/* First determine the number of threads we have. */
	int res = sceKernelGetThreadmanIdList(type, NULL, 0, &uid_count);
	if (res < 0) {
		return res;
	}
	if (uid_count == 0) {
		return -1;  /* XXX: Should we return a kernel errorcode here? */
	}

	/* Grab UIDs for all of the threads. */
	SceUID uid_buf[uid_count];
	res = sceKernelGetThreadmanIdList(type, uid_buf, uid_count, NULL);
	if (res < 0) {
		return res;
	}

	int i;
	for (i = 0; i < uid_count; i++) {
		memset(pInfo, 0, size);
		pInfo->size = size;

		res = pRefer(uid_buf[i], pInfo);
		if (res < 0) {
			/* If we got an error than we probably don't have enough privileges
			   to access the thread's info. */
			continue;
		}

		if (pInfo->name[0] != '\0' && strcmp(pInfo->name, name) == 0) {
			/* Found it. */
			return uid_buf[i];
		}
	}

	/* Unable to find the thread (or insufficient access to retrieve it's info). */
	return -1;  /* XXX: Should we return a kernel errorcode here? */
}
Exemplo n.º 4
0
int nkLoad(){

	count_Start = 0;

	sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread, Thread_Start, MAX_THREAD, &count_Start);

	bufNow.count = 0;
	bufNow.pThread = 0;

	return 0;
}
Exemplo n.º 5
0
int threadCtrlSuspend()
{
	if (threadCtrlState() == THREAD_CTRL_STATE_SUSPEND) {
		return 1;
	}
	
	int i, n;
	SceUID this_thid;
	SceKernelThreadInfo thinfo;
	
	this_thid = sceKernelGetThreadId();
	
	sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread, current_thid, MAX_THREAD, &current_count);
	
	for (i = 0;i < current_count;i++) {
		memset(&thinfo, 0, sizeof(SceKernelThreadInfo));
		thinfo.size = sizeof(SceKernelThreadInfo);
		sceKernelReferThreadStatus(current_thid[i], &thinfo);
		
		if (thinfo.status & PSP_THREAD_SUSPEND || current_thid[i] == this_thid) {
			current_thid[i] = -1;
			continue;
		}
		for (n = 0;n < first_count;n++) {
			if (current_thid[i] == first_thid[n]) {
				current_thid[i] = -1;
				break;
			}
		}
	}
	
	/* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
	/*      I got a hint from taba's JPCheat, thanks!        */
	/* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
	if (use_safely_suspend) {
		int count;
		for (count = 0;count < 1000;count++) {
			if ((IO_MEM_STICK_STATUS & 0x2000) == 0) {
				count = 0;
			}
			sceKernelDelayThread(1);
		}
	}
	/* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
	
	for (i = 0;i < current_count;i++) {
		if (current_thid[i] >= 0) {
			sceKernelSuspendThread(current_thid[i]);
		}
	}
	
	return 0;
}
Exemplo n.º 6
0
static int MainThread( SceSize args, void *argp )
{
	hookDisplay();

	sceKernelDcacheWritebackInvalidateAll();
	sceKernelIcacheInvalidateAll();

	//scePowerTick( 0 );
	
	unsigned int paddata_old = 0;
	char file[64], flag = 0, size = 0;
	int x, y, fd, count = 0, thread_count_start, thread_count_now;
	SceUID thread_buf_start[MAX_THREAD], thread_buf_now[MAX_THREAD], myThread = sceKernelGetThreadId();
	SceCtrlData paddata;
	
	sceKernelDelayThread(10000);

	sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread, thread_buf_start, MAX_THREAD, &thread_count_start);

	
	while(1)
	{
		sceCtrlPeekBufferPositive(&paddata, 1);
		
		if(paddata.Buttons != paddata_old)
		{
			//press "note" button and magick begin
			if(paddata.Buttons & PSP_CTRL_NOTE)
			{
		
				// IdList Now
				sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread, thread_buf_now, MAX_THREAD, &thread_count_now);

				//hold all threads for a moment
				for(x = 0; x < thread_count_now; x++)
				{
					// thread id match 0 or 1
					unsigned char match = 0;
					SceUID tmp_thid = thread_buf_now[x];
					for(y = 0; y < thread_count_start; y++)
					{
						if((tmp_thid == thread_buf_start[y]) || (tmp_thid == myThread))
						{
							match = 1;
							y = thread_count_start;
						}
					}
					if(thread_count_start == 0) match = 1;
					if(match == 0)
					{
						sceKernelSuspendThread(tmp_thid);
					}

				}
					
				
				//can parse command list
				can_parse = 1;
				
				//resume all threads
				for(x = 0; x < thread_count_now; x++)
				{
					// thread id match 0 or 1
					unsigned char match = 0;
					SceUID tmp_thid = thread_buf_now[x];
					for(y = 0; y < thread_count_start; y++)
					{
						if((tmp_thid == thread_buf_start[y]) || (tmp_thid == myThread))
						{
							match = 1;
							y = thread_count_start;
						}
					}
					if(thread_count_start == 0) match = 1;
					if(match == 0)
					{
						sceKernelResumeThread(tmp_thid);
					}
				}
			}
		}
		paddata_old = paddata.Buttons;
		sceKernelDelayThread(10000);
	}

	return( 0 );
}
Exemplo n.º 7
0
int threadCtrlInit()
{
	return sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread, first_thid, MAX_THREAD, &first_count);
}