zoukankan      html  css  js  c++  java
  • 伪句柄实验

    // 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;
    }
  • 相关阅读:
    Luogu 三国游戏
    牛客练习赛60E
    cf1321E
    cf988D
    cf1089F
    cf1055C
    cf997B
    cf1033D
    cf1062D
    cf1081E
  • 原文地址:https://www.cnblogs.com/Alyoyojie/p/5317280.html
Copyright © 2011-2022 走看看