#include "stdafx.h" #include "common.h" #include "DebugSection.h" #include //デバッグ用 #include "../BasicCompiler_Common/debug.h" extern HANDLE hDebugProcess; extern DWORD processIdDebug; extern DebugSectionCollection debugSectionCollection; CDebugThreadInfo *pobj_dti; CDebugThreadInfo::CDebugThreadInfo(){ memset(this,0,sizeof(CDebugThreadInfo)); } CDebugThreadInfo::~CDebugThreadInfo(){ Free(); } BOOL CDebugThreadInfo::Reflesh(int ThreadNum){ Free(); ULONG_PTR lpData; ULONG_PTR lpAccBytes; DWORD dwRWSectionPos; dwRWSectionPos=debugSectionCollection.debugSections[0]->dwImageBase+ debugSectionCollection.debugSections[0]->dwRVA_RWSection; ReadProcessMemory(hDebugProcess, (void *)(dwRWSectionPos+sizeof(DWORD)*256+ThreadNum*sizeof(DWORD)), &iProcLevel, sizeof(DWORD),&lpAccBytes); lplpObp=(ULONG_PTR *)HeapAlloc(hHeap,0,(iProcLevel+1)*sizeof(ULONG_PTR)); lplpSpBase=(ULONG_PTR *)HeapAlloc(hHeap,0,(iProcLevel+1)*sizeof(ULONG_PTR)); lpdwCp=(DWORD *)HeapAlloc(hHeap,0,(iProcLevel+1)*sizeof(DWORD)); this->relationalObjectModuleIndexes.resize( iProcLevel + 1 ); //lplpObp ReadProcessMemory(hDebugProcess, (void *)(dwRWSectionPos+sizeof(DWORD)*256*2+ThreadNum*sizeof(DWORD)), &lpData, sizeof(ULONG_PTR),&lpAccBytes); ReadProcessMemory(hDebugProcess, (void *)lpData, lplpObp, (iProcLevel+1)*sizeof(ULONG_PTR),&lpAccBytes); //lplpSpBase ReadProcessMemory(hDebugProcess, (void *)(dwRWSectionPos+sizeof(DWORD)*256*2+sizeof(ULONG_PTR)*256+ThreadNum*sizeof(ULONG_PTR)), &lpData, sizeof(ULONG_PTR),&lpAccBytes); ReadProcessMemory(hDebugProcess, (void *)lpData, lplpSpBase, (iProcLevel+1)*sizeof(ULONG_PTR),&lpAccBytes); //現在の実行情報 CONTEXT Context; Context.ContextFlags=CONTEXT_CONTROL; GetThreadContext(array_hDebugThread[ThreadNum],&Context); //マッピングされているモジュールのイメージベースを取得 //HMODULE array_hModule[1024]; //DWORD cbReturned; //if(!EnumProcessModules( hDebugProcess, array_hModule, sizeof(HMODULE)*1024, &cbReturned )) return 0; auto modules = ActiveBasic::Common::GetModules(processIdDebug); HMODULE hTargetModule=0; for (std::size_t i = 0; i < modules.size(); ++i) { if ((LONG_PTR)modules[i]<=(LONG_PTR)EIP_RIP(Context)) { if (hTargetModuledwImageBase==hTargetModule){ debugSectionCollection.choice(i); break; } } } extern int MemPos_CodeSection; extern int FileSize_CodeSection; if(ImageBase+MemPos_CodeSection <= EIP_RIP(Context) && EIP_RIP(Context) < ImageBase+MemPos_CodeSection+FileSize_CodeSection){ lplpObp[iProcLevel]=EIP_RIP(Context); lplpSpBase[iProcLevel]=SP_BASE(Context); } //else API関数内などの場合は既存の lplpObp[iProcLevel] を利用する return 1; } void CDebugThreadInfo::Free(void){ if(lplpObp){ HeapDefaultFree(lplpObp); HeapDefaultFree(lplpSpBase); HeapDefaultFree(lpdwCp); relationalObjectModuleIndexes.clear(); } memset(this,0,sizeof(CDebugThreadInfo)); }