看流星社区

 找回密码
 注册账号
查看: 3028|回复: 0

使用NtUserBuildHwndList遍历窗口_win7x64

[复制链接]

该用户从未签到

发表于 2017-6-1 12:16:02 | 显示全部楼层 |阅读模式


在我的上一篇文章中讲到
51604788



枚举窗口 使用EnumWinodws是调用内核中NtUserBuildHwndList 这个函数最后2个参数必须是R3的地址

不然会返回0xC0000008错误,并且如果使用控制台窗口测试,这时ETHREAD下的win32Thread是NULL 也会返回0xC0000008错误

去实现的时候,返回成功了,但只传回线程的窗口HWND

然后去看了看win32k.sys的这个函数

下面是我修改了好的IDA F5这个函数
  1. // typedef NTSTATUS (__fastcall *PFN_NTUSERBULIDHWNDLIST)(
  2. //                                                     __int64 hDesktop,
  3. //                                                     __int64 hWndParent,
  4. //                                                     BOOLEAN bChildren,
  5. //                                                     unsigned int dwThreadId,
  6. //                                                     unsigned int lParam,
  7. //                                                     OUT PVOID pWnd,
  8. //                                                     OUT PVOID pBufSize);
  9. /*参考链接:
  10. http://read.pudn.com/downloads3/sourcecode/windows/248345/win2k/private/ntos/w32/ntuser/kernel/enumwin.c__.htm (win2k\private\ntos\w32\ntuser\kernel\enumwin.c)
  11. http://svn.netlabs.org/repos/odin32/trunk/include/win/win.h
  12. https://www.reactos.org/wiki/Techwiki:Win32k/WND
  13. https://www.reactos.org/wiki/Techwiki:Win32k/THREADINFO
  14. http://bbs.pediy.com/showthread.php?t=100983
  15. http://www.mengwuji.net/thread-99-1-1.html
  16. http://bbs.pediy.com/showthread.php?t=131950
  17. */
  18. __int64 __fastcall NtUserBuildHwndList(__int64 hDesktop, __int64 hWndParent, BOOL bChildren, unsigned int dwThreadId, unsigned int MaxNum_user, PVOID pWnd_User, unsigned __int64 pBuffSize_User)
  19. {
  20.   int m_ThreadId; // ebx@1
  21.   BOOL m_bChildren; // er14@1
  22.   __int64 m_hWndParent; // rdi@1
  23.   __int64 m_hDesktop; // rsi@1
  24.   __int64 m_m_pBwl; // r12@1
  25.   UINT flags; // er13@1
  26.   __int64 v13; // rax@1
  27.   __int64 v14; // rdx@1
  28.   tagWND *m_tagWnd; // rax@4
  29.   NTSTATUS status; // ebx@5
  30.   tagTHREADINFO *m_pti; // rax@8
  31.   tagTHREADINFO *m_m_pti; // rdi@8
  32.   tagDESKTOP *m_rpdesk; // rax@9
  33.   tagDESKTOP *m_p_desk_top; // rsi@16
  34.   tagTHREADINFO *v21; // rax@16
  35.   tagWND *m_top_wnd; // rax@22
  36.   __int64 m_pBwl; // rax@27
  37.   unsigned int m_max_hwnd; // edi@29
  38.   __int64 m_max_num_user; // rbx@29
  39.   unsigned __int64 m_p_buff_size_user; // r13@31
  40.   unsigned __int64 m_m_p_buff_size_user; // rdx@31
  41.   int v29; // [sp+48h] [bp-40h]@16
  42.   tagTHREADINFO *v30; // [sp+50h] [bp-38h]@16
  43.   tagDESKTOP *v31; // [sp+58h] [bp-30h]@16
  44.   int v32; // [sp+60h] [bp-28h]@16
  45.   int v33; // [sp+64h] [bp-24h]@16
  46.   PVOID Object; // [sp+98h] [bp+10h]@14
  47.   m_ThreadId = dwThreadId;
  48.   m_bChildren = bChildren;
  49.   m_hWndParent = hWndParent;
  50.   m_hDesktop = hDesktop;
  51.   m_m_pBwl = 0i64;
  52.   flags = 2;
  53.   LODWORD(v13) = ExEnterPriorityRegionAndAcquireResourceExclusive(gpresUser);
  54.   gptiCurrent = v13;
  55.   gbValidateHandleForIL = 0;
  56.   if ( *(_BYTE *)gpsi & 4 )
  57.     flags = 10;
  58.   if ( m_hWndParent )
  59.   {
  60.     LODWORD(m_tagWnd) = ValidateHwnd(m_hWndParent);
  61.     if ( !m_tagWnd )
  62.     {
  63.       status = 0xC0000008;
  64.       goto LABEL_41;
  65.     }
  66.   }
  67.   else
  68.   {
  69.     m_tagWnd = 0i64;
  70.   }
  71.   if ( m_ThreadId )
  72.   {
  73.     m_pti = (tagTHREADINFO *)PtiFromThreadId(m_ThreadId);
  74.     m_m_pti = m_pti;
  75.     if ( !m_pti || (m_rpdesk = m_pti->rpdesk) == 0i64 )
  76.     {
  77.       status = 0xC0000008;
  78.       UserSetLastError(0x57);
  79.       goto LABEL_41;
  80.     }
  81.     m_tagWnd = m_rpdesk->pDeskInfo->spwnd->spwndChild;
  82.   }
  83.   else
  84.   {
  85.     m_m_pti = 0i64;
  86.   }
  87.   if ( !m_hDesktop )
  88.   {
  89.     m_p_desk_top = 0i64;
  90.     Object = 0i64;
  91.     goto LABEL_20;
  92.   }
  93.   LOBYTE(v14) = 1;
  94.   if ( (int)ValidateHdesk((void *)m_hDesktop, v14, 1i64, &Object) < 0 )
  95.   {
  96.     status = 0xC0000008;
  97.     goto LABEL_41;
  98.   }
  99.   v32 = 0;
  100.   v33 = 0;
  101.   m_p_desk_top = (tagDESKTOP *)Object;
  102.   v31 = (tagDESKTOP *)Object;
  103.   v29 = 1;
  104.   LODWORD(v21) = PsGetCurrentProcess();
  105.   v30 = v21;
  106.   status = MapDesktop(&v29);
  107.   if ( status >= 0 )
  108.   {
  109.     m_tagWnd = m_p_desk_top->pDeskInfo->spwnd->spwndChild;
  110. LABEL_20:
  111.     if ( m_tagWnd )
  112.     {
  113.       if ( m_bChildren )
  114.       {
  115.         flags |= 1u;
  116.         m_tagWnd = m_tagWnd->spwndChild;
  117.       }
  118.     }
  119.     else if ( !m_p_desk_top )
  120.     {
  121.       m_top_wnd = (tagWND *)GetThreadDesktopWindow((__int64)m_m_pti);// /*0x060*/     struct _tagWND* spwndChild;      
  122.       if ( !m_top_wnd )
  123.       {
  124.         status = 0xC0000008;
  125.         UserSetLastError(0x57);
  126.         goto LABEL_41;
  127.       }
  128.       m_tagWnd = m_top_wnd->spwndChild;         // /*0x060*/     struct _tagWND* spwndChild;      
  129.     }
  130.     m_pBwl = BuildHwndList(m_tagWnd, flags, m_m_pti);
  131.     m_m_pBwl = m_pBwl;                          // _BWL 这个结构符号里找不到
  132.      /*
  133.                 ROS 中2k xp中定义如下:
  134.                 typedef struct _BWL
  135.                 {
  136.                    struct _BWL *pbwlNext;
  137.                    HWND        *phwndNext;
  138.                    HWND        *phwndMax;
  139.                    PTHREADINFO  ptiOwner;
  140.                    HWND         rghwnd[1];
  141.                 } BWL, *PBWL;
  142.       */
  143.     if ( m_pBwl )
  144.     {
  145.       m_max_hwnd = (unsigned __int64)((*(_QWORD *)(m_pBwl + 8) - m_pBwl - 0x20) >> 3) + 1;
  146.       m_max_num_user = MaxNum_user;
  147.       if ( MaxNum_user > 0x1FFFFFFF )
  148.         ExRaiseAccessViolation();
  149.       ProbeForWrite(pWnd_User, 8 * m_max_num_user, 4u);
  150.       m_p_buff_size_user = pBuffSize_User;
  151.       m_m_p_buff_size_user = pBuffSize_User;
  152.       if ( pBuffSize_User >= (unsigned __int64)W32UserProbeAddress )
  153.         m_m_p_buff_size_user = (unsigned __int64)W32UserProbeAddress;
  154.       *(_DWORD *)m_m_p_buff_size_user = *(_DWORD *)m_m_p_buff_size_user;
  155.       if ( m_max_hwnd > (unsigned int)m_max_num_user )
  156.       {
  157.         status = 0xC0000023;
  158.       }
  159.       else
  160.       {
  161.         memmove(pWnd_User, (const void *)(m_m_pBwl + 0x20), 8i64 * m_max_hwnd);
  162.         status = 0;
  163.       }
  164.       *(_DWORD *)m_p_buff_size_user = m_max_hwnd;
  165.     }
  166.     else
  167.     {
  168.       status = 0xC0000008;
  169.       UserSetLastError(8);
  170.     }
  171.     goto LABEL_37;
  172.   }
  173.   UserSetLastError(6);
  174. LABEL_37:
  175.   if ( m_m_pBwl )
  176.     FreeHwndList(m_m_pBwl);
  177.   if ( m_p_desk_top )
  178.     ObfDereferenceObject(m_p_desk_top);
  179. LABEL_41:
  180.   UserSessionSwitchLeaveCrit();
  181.   return (unsigned int)status;
  182. }
复制代码
可以看到 最后两个参数必须是R3的地址

否则返回0xC0000008错误,还有一点是如果这个线程的win32Thread是NULL的话也会返回0xC0000008错误(在控制台程序中出现)

修改后的代码,很明显可以知道如果dwThreadId是NULL的话就是枚举所有HWND




以下代码在win7 x64下测试通过

代码没有查询窗口的进程是谁

要查询的话只要调用

NtUserQueryWindow 即可得到

例如NtUserQueryWindow(hWnd,0);

R0:
  1. #include <ntddk.h>
  2. #define DEVICE_NAME L"\\device\\DjWow"
  3. #define LINK_NAME L"\\dosdevices\\DjWow" //\\??\\xxxx
  4. #define IOCTRL_BASE 0x800
  5.    
  6. #define IOCTL_CODE(i) \
  7.                 CTL_CODE(FILE_DEVICE_UNKNOWN, IOCTRL_BASE+i, METHOD_BUFFERED,FILE_ANY_ACCESS)  
  8.    
  9. #define CTL_HELLO                IOCTL_CODE(0)
  10. #define CTL_ULONG                IOCTL_CODE(1)
  11. #define CTL_WCHAR                IOCTL_CODE(2)
  12. #define CTL_CALLLIST        IOCTL_CODE(3)
  13. VOID testGetWndList(unsigned int ThreadId,PVOID OutputBuffer,ULONG BufferSize,PVOID Outbuflenbuf);
  14. typedef NTSTATUS (__fastcall *PFN_NTUSERBULIDHWNDLIST)(
  15.                                                                                                         __int64 hDesktop,
  16.                                                                                                         __int64 hWndParent,
  17.                                                                                                         BOOLEAN bChildren,
  18.                                                                                                         unsigned int dwThreadId,
  19.                                                                                                         unsigned int lParam,
  20.                                                                                                         OUT PVOID pWnd,
  21.                                                                                                         OUT PVOID pBufSize);
  22. //硬编码了
  23. PFN_NTUSERBULIDHWNDLIST g_NtUserBuildHwndList = (PFN_NTUSERBULIDHWNDLIST)0xfffff96000084630;
  24. NTSTATUS DispatchCommon(PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
  25. {
  26.         pIrp->IoStatus.Status = STATUS_SUCCESS;
  27.         pIrp->IoStatus.Information = 0;
  28.         UNREFERENCED_PARAMETER(pDeviceObject);
  29.         IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  30.         return STATUS_SUCCESS;
  31. }
  32. NTSTATUS DispatchCreate(PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
  33. {
  34.         pIrp->IoStatus.Status = STATUS_SUCCESS;
  35.         pIrp->IoStatus.Information = 0;
  36.         UNREFERENCED_PARAMETER(pDeviceObject);
  37.         IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  38.         return STATUS_SUCCESS;
  39. }
  40. NTSTATUS DispatchClose(PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
  41. {
  42.         pIrp->IoStatus.Status = STATUS_SUCCESS;
  43.         pIrp->IoStatus.Information = 0;
  44.         UNREFERENCED_PARAMETER(pDeviceObject);
  45.         IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  46.         return STATUS_SUCCESS;
  47. }
  48. NTSTATUS DispatchClear(PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
  49. {
  50.         pIrp->IoStatus.Status = STATUS_SUCCESS;
  51.         pIrp->IoStatus.Information = 0;
  52.         UNREFERENCED_PARAMETER(pDeviceObject);
  53.         IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  54.         return STATUS_SUCCESS;
  55. }
  56. NTSTATUS DispatchRead(PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
  57. {
  58.         PVOID pBuff = 0;
  59.         ULONG pBuffLen = 0;
  60.         ULONG pStackLen = 0;
  61.         PIO_STACK_LOCATION pStack = 0;
  62.         ULONG uMin = 0;
  63.         UNREFERENCED_PARAMETER(pDeviceObject);
  64.         pBuff = pIrp->AssociatedIrp.SystemBuffer;
  65.         pStack = IoGetCurrentIrpStackLocation(pIrp);
  66.         pStackLen = pStack->Parameters.Read.Length;
  67.         pBuffLen = (wcslen(L"hello world") + 1) * sizeof(WCHAR);
  68.         uMin = pBuffLen < pStackLen ? pBuffLen:pStackLen;
  69.         RtlCopyMemory(pBuff, L"hello wolrd", uMin);
  70.         pIrp->IoStatus.Status = STATUS_SUCCESS;
  71.         pIrp->IoStatus.Information = uMin;
  72.         IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  73.         return STATUS_SUCCESS;
  74. }
  75. NTSTATUS DispatchWrite(PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
  76. {
  77.         PVOID pWriteBuff = 0;
  78.         PVOID pBuff = 0;
  79.         ULONG uWriteBuffLen = 0;
  80.         PIO_STACK_LOCATION pStack = 0;
  81.         UNREFERENCED_PARAMETER(pDeviceObject);
  82.         pWriteBuff = pIrp->AssociatedIrp.SystemBuffer;
  83.         pStack = IoGetCurrentIrpStackLocation(pIrp);
  84.         uWriteBuffLen = pStack->Parameters.Write.Length;
  85.         pBuff = ExAllocatePoolWithTag(PagedPool, uWriteBuffLen,'TSET');
  86.         if(pBuff == NULL)
  87.         {
  88.                 pIrp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
  89.                 pIrp->IoStatus.Information = 0;
  90.                 return STATUS_INSUFFICIENT_RESOURCES;
  91.         }
  92.         RtlZeroMemory(pBuff, uWriteBuffLen);
  93.         RtlCopyMemory(pBuff,pWriteBuff, uWriteBuffLen);
  94.         ExFreePool(pBuff);
  95.         pBuff = 0;
  96.         IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  97.         pIrp->IoStatus.Status = STATUS_SUCCESS;
  98.         pIrp->IoStatus.Information = uWriteBuffLen;
  99.         return STATUS_SUCCESS;
  100. }
  101. NTSTATUS DispatchIoctrl(PDEVICE_OBJECT pDeviceObject, PIRP pIrp)
  102. {
  103.         PIO_STACK_LOCATION pStack = 0;
  104.         PVOID pBuff = 0;
  105.         ULONG uOutLen = 0;
  106.         ULONG uInLen = 0;
  107.         ULONG uCtlCode = 0;
  108.         ULONG_PTR *Context;
  109.         PVOID64 outbuflenbuf;
  110.         PVOID64 OutBuf;
  111.         unsigned int ThreadId;
  112.         UNREFERENCED_PARAMETER(pDeviceObject);
  113.         pStack = IoGetCurrentIrpStackLocation(pIrp);
  114.         uOutLen = pStack->Parameters.DeviceIoControl.OutputBufferLength;
  115.         uInLen = pStack->Parameters.DeviceIoControl.InputBufferLength;
  116.         pBuff = pIrp->AssociatedIrp.SystemBuffer;
  117.         uCtlCode = pStack->Parameters.DeviceIoControl.IoControlCode;
  118.         switch (uCtlCode)
  119.         {
  120.         case CTL_HELLO:
  121.                 DbgPrint("hello!\n");
  122.                 break;
  123.         case CTL_ULONG:
  124.                 {
  125.                         DbgPrint("pid:%d\n",*(ULONG*)pBuff);
  126.                         RtlCopyMemory(pBuff,L"ok",uOutLen);
  127.                         break;
  128.                 }
  129.         case CTL_WCHAR:
  130.                         DbgPrint("%ws",pBuff);
  131.                         break;
  132.         case CTL_CALLLIST:
  133.                 {
  134.                         Context = (ULONG_PTR*)pBuff;
  135.                         ThreadId = (unsigned int)Context[0];
  136.                         OutBuf = (PVOID)Context[1];
  137.                         uOutLen = Context[2];
  138.                         outbuflenbuf = (PVOID)Context[3];
  139.                         DbgPrint("[Drv]Thread Id is %d  OutpubBuffer=0x%08LLX  BufLen=0x%X outbuflenbuf = 0x%08LLX\n",ThreadId,OutBuf,uOutLen,outbuflenbuf);
  140.                         testGetWndList(ThreadId,OutBuf,uOutLen,outbuflenbuf);
  141.                         break;
  142.                 }
  143.         default:
  144.                 DbgPrint("UNKNUW CTLCODE!\n");
  145.                 break;
  146.         }
  147.         pIrp->IoStatus.Status = STATUS_SUCCESS;
  148.         pIrp->IoStatus.Information = uOutLen;
  149.         IoCompleteRequest(pIrp, IO_NO_INCREMENT);
  150.         return STATUS_SUCCESS;
  151. }
  152. /*
  153. 参考:
  154. http://bbs.pediy.com/showthread.php?t=100983
  155. http://www.mengwuji.net/thread-99-1-1.html
  156. http://bbs.pediy.com/showthread.php?t=131950
  157. I:\IDA分析\win7 x64\win32k.sys / win32k.i64
  158. */
  159. VOID testGetWndList(unsigned int ThreadId,PVOID64 OutputBuffer,ULONG BufferSize,PVOID64 Outbuflenbuf)
  160. {
  161.         //ULONG_PTR      *HwnBuf=NULL;
  162.         ULONG     BufSize=0;
  163.         ULONG     MaxNum = 0x1000;
  164.         NTSTATUS status;
  165.         int i = 0;
  166.         __int64 hwnd = 0;
  167.         __int64 *hwndtable = NULL;
  168.        
  169.         BufSize = BufferSize;
  170.         MaxNum = BufferSize/sizeof(ULONG_PTR);
  171.         //HwnBuf = (ULONG_PTR*)OutputBuffer;
  172.         DbgPrint("MAXNUM:0x%x",MaxNum);
  173.         DbgPrint("准备调用NtUserBuildHwndList...\n");
  174.        
  175.        
  176.         status = g_NtUserBuildHwndList(0,
  177.                                                                 0,
  178.                                                                 FALSE,
  179.                                                                 NULL,//ThreadId,
  180.                                                                 MaxNum,//MaxNum
  181.                                                                 OutputBuffer,
  182.                                                                 Outbuflenbuf);
  183.        
  184.         hwndtable = (__int64*)OutputBuffer;
  185.         DbgPrint("%d\n",*(ULONG_PTR*)Outbuflenbuf);
  186.         /*
  187.          0 d fffff960`00084862 e 1 0001 (0001) win32k!NtUserBuildHwndList+0x232
  188.          1 e fffff960`000847fb e 1 0001 (0001) win32k!NtUserBuildHwndList+0x1cb
  189.          3 e fffff960`00084804 e 1 0001 (0001) win32k!NtUserBuildHwndList+0x1d4
  190.         */
  191.         for (i = 0; i < *(ULONG_PTR*)Outbuflenbuf; i++)
  192.         {
  193.                 __try
  194.                 {
  195.                         hwnd = hwndtable[i];
  196.                         DbgPrint("0x%llx\n",hwnd);
  197.                 }
  198.                 __except(1)
  199.                 {
  200.                         DbgPrint("except!\n");
  201.                 }
  202.         }
  203.         DbgPrint("count:%d\n",i);
  204.         DbgPrint("NtUserBuildHwndList Returned status = 0x%08X \n",status);       
  205. }
  206. VOID DriverUnload(PDRIVER_OBJECT pDriverObject)
  207. {
  208.         UNICODE_STRING strLinkName ={0};
  209.         RtlInitUnicodeString(&strLinkName,LINK_NAME);
  210.         IoDeleteSymbolicLink(&strLinkName);
  211.         if(pDriverObject->DeviceObject)
  212.         {
  213.                 IoDeleteDevice(pDriverObject->DeviceObject);
  214.         }
  215.        
  216.         DbgPrint("DriverUnload");
  217.         return;
  218. }
  219. NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegPath)
  220. {
  221.         UNICODE_STRING strDeviceName = {0};
  222.         UNICODE_STRING strLinkName = {0};
  223.         NTSTATUS status = 0;
  224.         PDEVICE_OBJECT pDeviceObject = 0;
  225.         ULONG i = 0;
  226.         DbgPrint("[DJWOW]DriverEntry!\n");
  227.         UNREFERENCED_PARAMETER(pRegPath);
  228.         RtlInitUnicodeString(&strDeviceName, DEVICE_NAME);
  229.         RtlInitUnicodeString(&strLinkName, LINK_NAME);
  230.         status = IoCreateDevice(pDriverObject, 0, &strDeviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDeviceObject);
  231.         if(!NT_SUCCESS(status))
  232.         {
  233.                 DbgPrint("CretaDevice Faild:0x%x\n",status);
  234.                 return status;
  235.         }
  236.         pDeviceObject->Flags |= DO_BUFFERED_IO;
  237.         status = IoCreateSymbolicLink(&strLinkName,&strDeviceName);
  238.         if(!NT_SUCCESS(status))
  239.         {
  240.                 IoDeleteDevice(pDeviceObject);
  241.                 DbgPrint("IoCreateSymbolicdLink Faild:0x%x\n",status);
  242.                 return status;
  243.         }
  244.         for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION + 1; i++)
  245.         {
  246.                 pDriverObject->MajorFunction[i] = DispatchCommon;
  247.         }
  248.         pDriverObject->MajorFunction[IRP_MJ_CREATE] = DispatchCreate;
  249.         pDriverObject->MajorFunction[IRP_MJ_READ] = DispatchRead;
  250.         pDriverObject->MajorFunction[IRP_MJ_WRITE] = DispatchWrite;
  251.         pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchIoctrl;
  252.         pDriverObject->MajorFunction[IRP_MJ_CLOSE] = DispatchClose;
  253.         pDriverObject->MajorFunction[IRP_MJ_CLEANUP] = DispatchClear;
  254.         pDriverObject->DriverUnload = DriverUnload;
  255.         return STATUS_SUCCESS;
  256. }
复制代码


R3(也需要是x64):
  1. int CMFC_EXEDlg::SendDeviceIoControl(void)
  2. {
  3.         DWORD byteRetned=0;
  4.         DWORD retValue;
  5.         char buffer[300] = {0};
  6.         char wndbuffer[0x1000] = {0};
  7.         HWND* tmp = 0;
  8.        
  9.         ULONG_PTR IoContext[4]={0};//ThreadId,Outputbuffer,outbuflen
  10.         DWORD dwThreadId = GetCurrentThreadId();
  11.         CString str;
  12.         /*sprintf(buffer,"[Client]Current TheadId = %d\n",dwThreadId);
  13.         OutputDebugStringA(buffer);*/
  14.         //printf("[Client]Current TheadId = %d\n",dwThreadId);
  15.         str.Format(L"%d",dwThreadId);
  16.         m_edit_string = str;
  17.         UpdateData(FALSE);
  18.         /*sprintf(buffer,"[Client]WndList Buffer = 0x%08X\n",wndbuffer);
  19.         OutputDebugStringA(buffer);*/
  20.         //printf("[Client]WndList Buffer = 0x%08X\n",wndbuffer);
  21.         str.Format(L"0x%08x\r\n",wndbuffer);
  22.         m_edit_string += str;
  23.         HANDLE hDevice = CreateFileA( "\\\\.\\DjWow",
  24.                 GENERIC_READ | GENERIC_WRITE,
  25.                 0,
  26.                 NULL,
  27.                 OPEN_EXISTING,
  28.                 FILE_ATTRIBUTE_NORMAL,
  29.                 NULL
  30.                 );
  31.         if ( hDevice == ((HANDLE)0xFFFFFFFF) )
  32.     {
  33.                 OutputDebugStringA("[Client]Open SymbolLink Failed!\n");
  34.                 return 0;
  35.         }
  36.         //填充buffer
  37.         IoContext[0] = dwThreadId;
  38.         IoContext[1] = (ULONG_PTR)wndbuffer;
  39.         IoContext[2] = 0x1000;
  40.         IoContext[3] = (ULONG_PTR)&IoContext[2];
  41.         retValue=DeviceIoControl(hDevice,
  42.                 CTL_CALLLIST,
  43.                 IoContext,
  44.                 sizeof(ULONG_PTR)*4,
  45.                 wndbuffer,
  46.                 0x1000,
  47.                 &byteRetned,
  48.                 NULL);
  49.         CloseHandle(hDevice);
  50.         /*sprintf(buffer,"[Client]return value=%d\n",retValue);
  51.         OutputDebugStringA(buffer);*/
  52.         //printf("[Client]return value=%d\n",retValue);
  53.         m_edit_string += "\r\nok!";
  54.         //str.Format(L"%s",wndbuffer);
  55.         //m_edit_string += L"\r\n" + str;
  56.         tmp = (HWND*)wndbuffer;
  57.         int i = 0;
  58.         while (i < 100)
  59.         {
  60.                 GetWindowTextA(tmp[i],buffer,MAX_PATH-1);
  61.                 str.Format(L"%s",buffer);
  62.                 m_edit_string += L"\r\n" + str;
  63.                 UpdateData(FALSE);
  64.                 i++;
  65.         }
  66.         UpdateData(FALSE);
  67.         return 1;
  68. }
复制代码
为什么不用EnumWindows呢?

我就闲着无聊.....




   





点击按钮快速添加回复内容: 支持 高兴 激动 给力 加油 苦寻 生气 回帖 路过 感恩
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

小黑屋|手机版|Archiver|看流星社区 |网站地图

GMT+8, 2024-3-28 23:53

Powered by Kanliuxing X3.4

© 2010-2019 kanliuxing.com

快速回复 返回顶部 返回列表