• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

Windogs

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

简单调试器的实现(三)完善调试器

Dll加载:

case LOAD_DLL_DEBUG_EVENT:
// Read the debugging information included in the newly
// loaded DLL. Be sure to close the handle to the loaded DLL
// with CloseHandle.

//Dll加载时会进行这个事件

dwContinueStatus = OnLoadDllDebugEvent(DebugEvent);
break;

 

DWORD OnLoadDllDebugEvent(const LPDEBUG_EVENT DebugEvent)
{
//我们可以通过DebugEvent->u.LoadDll.hFile获得Dll的句柄

//但是,没有直接从HANDLE->Path的API,需要代码进行转化

//具体方法很容易查找到,这里就不介绍了。

  GetFileNameFromHandle(DebugEvent->u.LoadDll.hFile);

  return DBG_CONTINUE;
}

 

读取内存:

 

读取内存的API我们已经介绍过了ReadProcessMemory。

部分代码:

//Addr  读取的地址

//Size = sizeof(BYTE)

void *lpBuff;

lpBuff = malloc(Size);

SIZE_T bytesRead;

 

for (i = 0; i < 32; i++)
{
  if ((i % 8) == 0)      //输出4行 8列
    printf("\n%x ", Addr);
  if (FALSE == ReadProcessMemory(G_Process, Addr, lpBuff, Size, &bytesRead))
  {
    printf("?? ");      //读取失败就输出" ??"
  }
  else
  {
    printf("%.2x ", *(BYTE*)lpBuff);
  }
  Addr = Addr + Size;
}

free(lpBuff);

 效果:

 

这章就讲这么多了。。。下一章节将详细的讲解软断点。

posted on 2015-03-28 18:43  Windogs  阅读(242)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3