伪句柄实验

// 02 伪句柄实验.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <windows.h>
DWORD WINAPI ChildThread(PVOID pParam) {
    HANDLE hThreadParent = (HANDLE)pParam;
    FILETIME stcCreationTime, stcExitTime;
    FILETIME stcKernelTime, stcUserTime;
    GetThreadTimes(hThreadParent, &stcCreationTime,
        &stcExitTime, &stcKernelTime, &stcUserTime);
    SYSTEMTIME time;
    FILETIME LocalTime;
    FileTimeToLocalFileTime(&stcCreationTime, &LocalTime);
    FileTimeToSystemTime(&LocalTime, &time);
    return 0;
}

DWORD WINAPI ShowParentTime() {
    //HANDLE hThreadParent = GetCurrentThread();
    HANDLE hThreadParent = NULL;
    //将伪句柄转换为真句柄(也就是在句柄表中添加一项)
    DuplicateHandle(
        GetCurrentProcess(), // 拥有源句柄的进程句柄
        GetCurrentThread(),  // 指定对象的现有句柄(伪句柄)
        GetCurrentProcess(), // 拥有新对象句柄的进程句柄
        &hThreadParent,      // 用于保存新句柄
        0,                   // 安全访问级别
        false,               // 是否可以被子进程继承
        DUPLICATE_SAME_ACCESS); // 转换选项
    CreateThread(NULL, 0, ChildThread,
        (PVOID)hThreadParent, 0, NULL);
    return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
    ShowParentTime();
    system("pause");
    return 0;
}

 

posted @ 2016-03-24 21:31  天还是那么蓝  阅读(175)  评论(0编辑  收藏  举报