Example #1
0
    void Sprite::setTextureRect(const fzRect& rect, const fzSize& untrimmedSize, bool rotated)
    {    
        m_textureRect = rect;
        m_rectRotated = rotated;
        
        setContentSize(untrimmedSize);
        updateTextureCoords(rect);

        
        // Calculate final offset
        fzPoint relativeOffset(m_unflippedOffset);
        if( m_flipX )
            relativeOffset.x *= -1;
        
        if( m_flipY )
            relativeOffset.y *= -1;

        m_offset = relativeOffset + (m_contentSize - m_textureRect.size)/2;
        
        
        // Generate untransformed vertices
        fzPoint xy2 = m_offset + m_textureRect.size;        

        m_vertices[0] = m_offset;
        m_vertices[1] = fzVec2(xy2.x, m_offset.y);
        m_vertices[2] = fzVec2(m_offset.x, xy2.y);
        m_vertices[3] = xy2;

        makeDirty(kFZDirty_transform_absolute);
    }
point2_t ModifyOffsetsDialog::calculateOffsets(int xoff, int yoff, int width, int height)
{
	int type = getAlignType();
	point2_t offset = getOffset();
	int x = xoff;
	int y = yoff;

	if (type >= 0)
	{
		// Monster
		if (type == 0)
		{
			x = width * 0.5;
			y = height - 4;
		}

		// Monster (GL-friendly)
		else if (type == 1)
		{
			x = width * 0.5;
			y = height;
		}

		// Projectile
		else if (type == 2)
		{
			x = width * 0.5;
			y = height * 0.5;
		}

		// Weapon (Fullscreen)
		else if (type == 3)
		{
			x = -160 + (width * 0.5);
			y = -200 + height;
		}

		// Weapon (Doom status bar)
		else if (type == 4)
		{
			x = -160 + (width * 0.5);
			y = -200 + 32 + height;
		}

		// Weapon (Heretic status bar)
		else if (type == 5)
		{
			x = -160 + (width * 0.5);
			y = -200 + 42 + height;
		}

		// Weapon (Hexen status bar)
		else if (type == 6)
		{
			x = -160 + (width * 0.5);
			y = -200 + 38 + height;
		}
	}
	else
	{
		// Relative offset
		if (relativeOffset())
		{
			if (xOffChange()) x = xoff + offset.x;
			if (yOffChange()) y = yoff + offset.y;
		}
		
		// Set offset
		else
		{
			if (xOffChange()) x = offset.x;
			if (yOffChange()) y = offset.y;
		}
	}

	return point2_t(x, y);
}
_declspec(dllexport) void __cdecl ODBG_Pluginaction(int origin,int action,void *item) 
{
  if(origin==PM_MAIN) 
  {
	  if(action==0) 
	  {
		  if(os_supported==false || ver==0)
		  {
			  MessageBox(mainWnd,"OS not supported.\r\n Only Windows 7 SP0/SP1 and XP SP2/SP3","HookSysCalls",0);
			  return;
		  }
		  else
		  {
			  FUNC Get_Status=(FUNC)GetProcAddress(GetModuleHandle(0),"_Getstatus");
		      if(Get_Status()!=STAT_STOPPED)
			  {
			        MessageBox(mainWnd,"Debuggee must be in paused mode.","HookSysCalls",0);
			        return;
			  }

			  if(done)        //we have successfully patched the target process
			  {
				  MessageBox(mainWnd,"Already hooked","HookSysCalls",0);
				  return;
			  }

			  if(ver==1) /*XP*/
			  {				   				
                          unsigned long kiFast=(unsigned long)GetProcAddress(GetModuleHandle("ntdll.dll"),"KiFastSystemCall");
					      unsigned long kiInt2e=(unsigned long)GetProcAddress(GetModuleHandle("ntdll.dll"),"KiIntSystemCall");
					      unsigned long readd_;
					      unsigned long SystemCall=0;  //_KUSER_SHARED_DATA::SystemCall At offset 0x300
					      ReadProcessMemory(hProcess,(void*)0x7ffe0300,&SystemCall,0x4,&readd_);
					      if(SystemCall==kiInt2e)  //Perhaps, it uses KiIntSystemCall instead.
						  {
						         INT2E=true;
						  }
					      else if(SystemCall==kiFast)
						  {
						         INT2E=false;
						  }
					      else
						  {
						         MessageBox(mainWnd,"Architecture not supported!","InjectHookLib",0);
						         return;
						  }
					      bool properAddr_found=false;
					      unsigned long rel=0;
					      unsigned char* po=0;
					      if(INT2E==true)
						  {
						       po=(unsigned char*)VirtualAllocEx(hProcess,0,0x1000,MEM_RESERVE|MEM_COMMIT,PAGE_EXECUTE_READWRITE);
							   if(po==0)
							   {
								     MessageBox(mainWnd,"Can't allocate memory into target process","InjectHookLib",0);
								     return;
							   }
							   else 
							   {
								     rel=relativeOffset(kiInt2e,(unsigned long)po);
								     properAddr_found=true;
							   }
						  }
					      else
						  {
						       unsigned long least=0x20000;
							   unsigned long max=0x80000000;
							   for(unsigned long i=least;i<max;i+=0x1000)   //Try to find the proper address
							   {
		                                  rel=relativeOffset(kiFast,i);
			                              if(  (rel>>0x18) == 0xC3)  //This is a must
										  {
				                                po=(unsigned char*)VirtualAllocEx(hProcess,(void*)i,0x1000,MEM_RESERVE|MEM_COMMIT,PAGE_EXECUTE_READWRITE);
								                if(po) /*Okay, lets copy shellcode_xp*/
												{
									                  if((unsigned long)po!=i)
													  {
										                       Addtolist(0,0,"Retrying...");
										                       VirtualFreeEx(hProcess,po,0x1000,MEM_DECOMMIT|MEM_RELEASE);
										                       continue;
													  }
													  else
													  {
														  properAddr_found=true;
														  break;
													  }
												}
										  }
							   }
						  }
						  
						  if(properAddr_found)
						  {			 
							         if(INT2E)//Slight modification to shellcode
									 {
										 memcpy(&shellcode_xp[0x84],INT_2E,7);
									 }
									 //--------------
							         unsigned long read;
									 WriteProcessMemory(hProcess,po,shellcode_xp,sizeof(shellcode_xp)-1,&read);
									 
									 unsigned char jump=0xE9;
									 unsigned long old;
									 
									 unsigned long Ki_=0;
									 if(INT2E==false) Ki_=kiFast;
									 else Ki_=kiInt2e;

									 
									 VirtualProtectEx(hProcess,(void*)Ki_,0x5,PAGE_EXECUTE_READWRITE,&old);
									 WriteProcessMemory(hProcess,(void*)Ki_,&jump,0x1,&read);
									 WriteProcessMemory(hProcess,(void*)(Ki_+1),&rel,0x4,&read);
									 VirtualProtectEx(hProcess,(void*)Ki_,0x5,old,&old);
									 Addtolist((unsigned long)po,0,"Hook code inserted.");
									 done=true;
						  }
				          if(!done)
						  {
					                  MessageBox(mainWnd,"Sorry, proper memory address could not be found","HookSysCalls",0);
					                  return;
						  }
			  }
			  else if(ver==2) /*windows 7*/
			  {
				          if(TEB)
						  {
					                 pShellcode=(unsigned char*)VirtualAllocEx(hProcess,0,0x1000,MEM_RESERVE|MEM_COMMIT,PAGE_EXECUTE_READWRITE);
						             if(!pShellcode)
									 {
							                  MessageBox(mainWnd,"Can't allocate memory in debuggee","InjectHookLib",0);
							                  return;
									 }
									 
									 unsigned long read_written;
						             if(ReadProcessMemory(hProcess,(void*)(TEB+0xC0),&gate_key,0x4,&read_written))
									 {
							                  if(ReadProcessMemory(GetCurrentProcess(),(void*)gate_key,&gate_code[0],0x7,&read_written)) //read from self
											  {
							                         unsigned long oldxx;
						                             if(!VirtualProtectEx(hProcess,(void*)gate_key,0x6,PAGE_EXECUTE_READWRITE,&oldxx))
													 {
							                              MessageBox(mainWnd,"Can't set proper memory protection.","InjectHookLib",0);
							                              return;
													 }
													 WriteProcessMemory(hProcess,(void*)gate_key,"\x68" /*push*/,0x1,&read_written);
													 WriteProcessMemory(hProcess,(void*)(gate_key+1),&pShellcode,0x4,&read_written);
													 WriteProcessMemory(hProcess,(void*)(gate_key+5),"\xC3",0x1,&read_written);
													 //-------------formulate shellcode
													 WriteProcessMemory(hProcess,pShellcode,shellcode_7,sizeof(shellcode_7)-1,&read_written);  //write shellcode
									                 WriteProcessMemory(hProcess,pShellcode+(sizeof(shellcode_7)-1),&gate_code[0],0x7,&read_written);  //write gate_code

													 //--------------------------------
													 Addtolist((unsigned long)pShellcode,0,"Hook code inserted.");
									                 done=true;
											  }
									 }
						  }
			  }
		   }
	   }