GetThreadSelectorEntry为x64应用程序抛出ERROR_NOT_SUPPORTED

时间:2019-03-01 22:29:41

标签: debugging winapi

我试图编写一个非常简单的应用程序来调试Win32 64位应用程序。我的最终目标是获取远程线程的TIB和PEB,但是由于某种原因,我在32位应用程序上执行此操作的方式不适用于64位应用程序(除了查看Esp,Rsp并检查SegF和SegG之外) )。我要使用的代码在这里:

#include <windows.h>
#include <stdio.h>
#include <tlhelp32.h>

int main(int argc, char *argv[]){
  LDT_ENTRY             entry;
  DWORD                pid;
  HANDLE               hThread;
  HANDLE               hSnapshot;
  CONTEXT               context;
  context.ContextFlags = CONTEXT_CONTROL;

  if(argc < 2){
    printf("Usage: %s PID\n", argv[0]);
    exit(1);
  }

  pid = atoi(argv[1]);

  THREADENTRY32 te32;
  te32.dwSize = sizeof(te32);
  hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);
  while(Thread32Next(hSnapshot, &te32)){
    if(pid == te32.th32OwnerProcessID){
      hThread = OpenThread(THREAD_ALL_ACCESS, 0, te32.th32ThreadID);
      if(!hThread)
        exit(1);

      if(SuspendThread(hThread) == (DWORD) -1)
        exit(1);

      if(!GetThreadContext(hThread, &context))
        exit(1);

      printf("Rsp = 0x%x\n", context.Rsp);

      if(!GetThreadSelectorEntry(hThread, context.SegGs, &entry)){
        LPSTR buff = NULL;
        FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, 
          GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&buff, 0, NULL);
        printf("Error: %s\n", buff); //ERROR_NOT_SUPPORTED 50 0x32 The request is not supported.
        LocalFree(buff);
        exit(1);
      }
    }
  }
  CloseHandle(hSnapshot);
  return 0;
}

,但是它总是在“ GetThreadSelectorEntry”处引发错误。引发的错误代码是ERROR_NOT_SUPPORTED:不支持该请求。

我不明白为什么不支持它。有人知道为什么吗?

[编辑]

好吧,GetThreadSelectorEntry不适用于x86_64进程,有人知道我如何获得远程进程的TIB / PEB地址吗?

0 个答案:

没有答案