⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xsemu.cpp

📁 Windows CE XScale "emulator" for StrongARM
💻 CPP
字号:
//
// XSEmu 0.1 (c) praxon
//

#include "stdafx.h"
#include "xsemu.h"
#include <commctrl.h>
#include <commdlg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <cstring>
#include <string.h>
#include <windows.h>
#include <winbase.h>

#define MAX_LOADSTRING 100


void EnterDebugLoop(const LPDEBUG_EVENT DebugEv)
{
   DWORD dwContinueStatus = DBG_CONTINUE;
   
   for(;;) 
   { 
   
      WaitForDebugEvent(DebugEv, INFINITE); 

      switch (DebugEv->dwDebugEventCode) 
      { 
		 case 0: // process pulled from under
			return;

         case EXCEPTION_DEBUG_EVENT: 
 
            switch(DebugEv->u.Exception.ExceptionRecord.ExceptionCode)
            { 
			case EXCEPTION_ILLEGAL_INSTRUCTION:

				_CONTEXT mtcx;
				mtcx.ContextFlags=CONTEXT_FULL;
			
				GetThreadContext((void *)DebugEv->dwThreadId,&mtcx);
				char strDbg[100];
				
				sprintf(strDbg,"(%d) PC:%d\nLR:%d\n",DebugEv->dwThreadId,mtcx.Pc,mtcx.Lr);
				FILE * pFile;
				pFile = fopen ("xslog.txt","wc");
				fputs(strDbg,pFile);
				
				unsigned long Instruction;
				unsigned long _num;
				
				ReadProcessMemory((void *)DebugEv->dwProcessId,LPCVOID(mtcx.Pc),(void *)&Instruction,4,&_num);

				// BX instructionset unsupported on StrongARM (add BXNE, BXE etc..)

				switch (Instruction) {
					case 0xe12fff10:			  // BX  Rx
						Instruction = 0xe1a0f000; // MOV PC,Rx
						break;
					case 0xe12fff11:
						Instruction = 0xe1a0f001;
						break;
					case 0xe12fff12:
						Instruction = 0xe1a0f002;
						break;
					case 0xe12fff13:
						Instruction = 0xe1a0f003;
						break;
					case 0xe12fff14:
						Instruction = 0xe1a0f004;
						break;
					case 0xe12fff15:
						Instruction = 0xe1a0f005;
						break;
					case 0xe12fff16:
						Instruction = 0xe1a0f006;
						break;
					case 0xe12fff17:
						Instruction = 0xe1a0f007;
						break;
					case 0xe12fff18:
						Instruction = 0xe1a0f008;
						break;
					case 0xe12fff19:
						Instruction = 0xe1a0f009;
						break;
					case 0xe12fff1a:
						Instruction = 0xe1a0f00a;
						break;
					case 0xe12fff1b:
						Instruction = 0xe1a0f00b;
						break;
					default:
						MessageBox(0,_T("Unhandled Illegal Instruction"),_T("Error"),0);
						return;
				}

				
				WriteProcessMemory((void *)DebugEv->dwProcessId,(void *)(mtcx.Pc),(void *)&Instruction,4,&_num);

				fclose(pFile);

				//mtcx.Pc +=4;
				//SetThreadContext((void *)DebugEv->dwThreadId,&mtcx); // skip

				break;

               case EXCEPTION_ACCESS_VIOLATION: 
                  break;
 
               case EXCEPTION_BREAKPOINT: 
                  break;
 
               case EXCEPTION_DATATYPE_MISALIGNMENT: 
                  break;
 
               case EXCEPTION_SINGLE_STEP: 
                  break;
 
               case DBG_CONTROL_C: 
                  break;
 
               default:
               // Handle other exceptions. 
                  break;
            } 
 
         case CREATE_THREAD_DEBUG_EVENT: 
         
         case CREATE_PROCESS_DEBUG_EVENT: 
         
         case EXIT_THREAD_DEBUG_EVENT: 
         
         case EXIT_PROCESS_DEBUG_EVENT: 

         case LOAD_DLL_DEBUG_EVENT: 
         
         case UNLOAD_DLL_DEBUG_EVENT: 
         
         case OUTPUT_DEBUG_STRING_EVENT: 
         
         case RIP_EVENT:
		
 
   ContinueDebugEvent(DebugEv->dwProcessId, 
                      DebugEv->dwThreadId, 
                      dwContinueStatus);
   }

   }
}


int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)
{
	
	wchar_t cmdl = *lpCmdLine;

	MessageBox(0,&cmdl,_T("XSEmu 0.1"),0);

	STARTUPINFO si = { sizeof(si) };

	PROCESS_INFORMATION pi = { NULL, NULL, 0, 0 };

	if( !CreateProcess( &cmdl, NULL, NULL, NULL, FALSE, 
		 DEBUG_ONLY_THIS_PROCESS, NULL, NULL, &si, &pi ) )
		
	{
		MessageBox(0,_T("Failed to start slave"),_T("Project XSEmu"),0);
		free(&si);
		free(&pi);
		return 0;
	}

	  wchar_t dbe[100];
	  swprintf(dbe,_T("Started %d(%d)"),pi.hProcess,pi.hThread);

		MessageBox(0,dbe,_T("Project XSEmu"),0);

		DEBUG_EVENT de;
		EnterDebugLoop(&de);
		MessageBox(0,_T("Debugger exiting"),_T("XSEmu 0.1"),0);
		free(&si);
		free(&pi);
		CloseHandle(pi.hThread);
		CloseHandle(pi.hProcess);
		return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -