static PVOID AllocProcessMemory (HANDLE hProcess, DWORD dwNumBytes) {
	CONTEXT Context;
	DWORD dwThreadId, dwNumBytesXferred;
	HANDLE hThread;
	HINSTANCE hinstKrnl = GetModuleHandle(__TEXT("Kernel32"));
	PVOID pvMem;
	MEMORY_BASIC_INFORMATION mbi;

	hThread = CreateRemoteThread(hProcess, NULL,	dwNumBytes + sizeof(HANDLE),
         		(LPTHREAD_START_ROUTINE)GetProcAddress(hinstKrnl, "ExitThread"), 
               0,	CREATE_SUSPENDED,	&dwThreadId);
	if (hThread == NULL)
		return NULL;

	Context.ContextFlags = CONTEXT_CONTROL;
	if (!GetThreadContext(hThread, &Context))
   {
      ResumeThread(hThread);  //let the thread run and vanish
      return NULL;
   }

	if (sizeof(mbi) != VirtualQueryEx(hProcess, (PDWORD)STACKPTR(Context) - 1, &mbi, sizeof(mbi)))
   {
      ResumeThread(hThread);  //let the thread run and vanish
      return NULL;
   }

	pvMem = (PVOID) mbi.BaseAddress;
	if (!WriteProcessMemory(hProcess, pvMem, &hThread, sizeof(hThread), &dwNumBytesXferred)) 
   {
      ResumeThread(hThread);  //let the thread run and vanish
      return NULL;
   }

   pvMem = (PVOID) ((PHANDLE) pvMem + 1);

   return pvMem;
}
示例#2
0
文件: em2.c 项目: barak/scheme2c
main()
{
	S2CINT  *sp;

#if MAC_CLASSIC
	STACKPTR( sp );
	SetApplLimit( (char*)sp-57000 );
	console_options.nrows = 30;
	console_options.title = "\pScheme->C";
#endif
	printf( "Embedded Scheme->C Test Bed\n0- " );
	scheme2c( "(begin (set-stack-size! 57000) (set-time-slice! 100000))",
		  &status, &result, &error );
	if  (status != 0)  {
	   printf( "Initialization failed!\n" );
	   exit( 1 );
	}
	while  (gets( line ) != NULL)  {
	   switch  (s)  {
	      case 0:
	         ev0();
		 break;
	      case 1:
		 ev1();
		 break;
	      case 2:
		 ev2();
		 break;
	      case 3:
		 ev3();
		 break;
	   }
	   s = (s + 1) & 3;
	   if  (*result != 0)  printf( "%s\n", result );
	   if  (*error != 0)	printf( "%s", error );
	   printf( "%d- ", status );
	   fflush( stdout );
	}
	printf( "\n" );
	exit( 0 );
}