jliu
驱动牛犊
驱动牛犊
  • 注册日期2001-09-03
  • 最后登录2004-09-14
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:974回复:0

帮我解释一下

楼主#
更多 发布于:2001-11-05 08:41
http://www.internals.com上的winio工具中的DLL的port32.cpp提供了一个从3环进入0环的代码.但有两句不明白
请问下面几句是什么意识?

      // Prepare the far call parameters
      WORD CallgateAddr[3];
      CallgateAddr[0] = 0x0;
      CallgateAddr[1] = 0x0;
      CallgateAddr[2] = (wGDTIndex << 3) | 3;
wGDTIndex<<3好象形成选择子,为何或上3?

付整个源码

bool CallRing0(PVOID pvRing0FuncAddr, WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize)
{
  GDT_DESCRIPTOR *pGDTDescriptor;
  GDTR gdtr;
  _asm Sgdt [gdtr]
  // Skip the null descriptor
  pGDTDescriptor = (GDT_DESCRIPTOR *)(gdtr.dwGDTBase + 8);
  // Search for a free GDT descriptor
  for (WORD wGDTIndex = 1; wGDTIndex < (gdtr.wGDTLimit / 8); wGDTIndex++)
  {
    if (pGDTDescriptor->Type == 0     &&
        pGDTDescriptor->System == 0   &&
        pGDTDescriptor->DPL == 0      &&
        pGDTDescriptor->Present == 0)
    {
      CALLGATE_DESCRIPTOR *pCallgate;
      pCallgate = (CALLGATE_DESCRIPTOR *) pGDTDescriptor;
      pCallgate->Offset_0_15 = LOWORD(pvRing0FuncAddr);
      pCallgate->Selector = 0x28;
      pCallgate->ParamCount = 0;
      pCallgate->Unused = 0;
      pCallgate->Type = 0xc;
      pCallgate->System = 0;
      pCallgate->DPL = 3;
      pCallgate->Present = 1;
      pCallgate->Offset_16_31 = HIWORD(pvRing0FuncAddr);

      // Prepare the far call parameters
      WORD CallgateAddr[3];
      CallgateAddr[0] = 0x0;
      CallgateAddr[1] = 0x0;
      CallgateAddr[2] = (wGDTIndex << 3) | 3;

      // Please fasten your seat belts!
      // We're about to make a hyperspace jump into RING 0.

      _asm Mov DX, [wPortAddr]
      _asm Mov EBX, [pdwPortVal]
      _asm Mov CL, [bSize]
      _asm Call FWORD PTR [CallgateAddr]

      // We have made it !
      // Now free the GDT descriptor
      memset(pGDTDescriptor, 0, 8);
      // Our journey was successful. Seeya.
      return true;
    }
    // Advance to the next GDT descriptor
    pGDTDescriptor++;
  }
  // Whoops, the GDT is full
  return false;
}
jliu
游客

返回顶部