zoukankan      html  css  js  c++  java
  • Windows 获取windows密码

    #include <iostream>
    #define Main main
    #define COLOR_GREEN system("color 2");
    #include <vector>
    #include <list>
    #include <string>
    #include <WinSock2.h>
    #include <WS2tcpip.h>
    #include <memory>
    #include <VersionHelpers.h>
    #include <LM.h>
    #include <winnetwk.h>
    #include "BitMap.h"
    #include <wlanapi.h>
    #include "ATBAudioEngine/ATBAudioEngine.h"
    #include "Package.h"
    
    #pragma comment(lib,"Ws2_32.lib")
    #pragma comment(lib,"Mpr.lib")
    #pragma comment(lib,"netapi32.lib")
    #pragma comment(lib,"Wlanapi.lib")
    #include <Windows.h>
    
    class disorderly
    {
        int m_buf[10] = { 0 };
    public:
    
        void initBuf()
        {
            srand(GetTickCount());
            int len = sizeof(m_buf) / sizeof(int);
            for (int i = 0; i < len; i++)
            {
                m_buf[i] = rand() % 100;
                printf("%d, ", m_buf[i]);
            }
        }
    
        //范围
        void initBuf(int range)
        {
            srand(GetTickCount());
            int len = sizeof(m_buf) / sizeof(int);
            for (int i = 0; i < len; i++)
            {
                m_buf[i] = rand() % range;
                printf("%d, ", m_buf[i]);
            }
        }
    
        int *getBuf() { return m_buf; }
    
        int getLen() { return sizeof(m_buf) / sizeof(int); }
    
        void print()
        {
            printf("
    ");
            int len = sizeof(m_buf) / sizeof(int);
            for (int i = 0; i < len; i++)
            {
                printf("%d, ", m_buf[i]);
            }
            printf("
    ");
        }
    
        void C(int *Arr, int Len)
        {
            int TempData = 0;
            int i = 0;
            int j = 0;
            for (i = 1; i < Len; i++)
            {
                j = i;
                TempData = *(Arr + i);
                //如果当前的数据小于当前数据的上一个
                //那么进行赋值, j--, 然后再判断j--数据是否小于上一个数据
                while (j > 0 && TempData < Arr[j - 1])
                {
                    Arr[j] = Arr[j - 1];
                    j--;
                }
                Arr[j] = TempData;
            }
    
            //for (int i = 0; i < 5; i++)
            //{
            //    std::thread th(C, i);
            //    th.join();
            //    //th.detch();
            //}
        }
    
        void M(int *Arr, int Len)
        {
            for (int i = 0; i < Len - 1; i++)
            {
                for (int j = i + 1; j < Len; j++)
                {
                    if (Arr[i] > Arr[j])
                    {
                        int temp = Arr[i];
                        Arr[i] = Arr[j];
                        Arr[j] = temp;
                    }
                }
            }
        }
    
        void X(int *Arr, int Len)
        {
            int k = -1;
            for (int i = 0; i < Len - 1; i++)
            {
                k = i;
                for (int j = i + 1; j < Len; j++)
                {
                    //第一波出来的必定是最小的
                    if (Arr[k] > Arr[j])
                    {
                        k = j;
                    }
                }
                int temp = Arr[i];
                Arr[i] = Arr[k];
                Arr[k] = temp;
            }
        }
    
        void GetAllUserName(std::vector<std::wstring> & allUserName)
        {
            // See more: http://msdn.microsoft.com/en-us/library/windows/desktop/aa370652(v=vs.85).aspx
            LPUSER_INFO_1 pBuf = NULL;
            LPUSER_INFO_1 pTmpBuf;
            DWORD dwLevel = 1;
            DWORD dwEntriesRead = 0;
            DWORD dwTotalEntries = 0;
            DWORD dwResumeHandle = 0;
            DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
            NET_API_STATUS nStatus;
            LPTSTR pszServerName = NULL;
    
            do
            {
                nStatus = NetUserEnum((LPCWSTR)pszServerName,
                    dwLevel,
                    FILTER_NORMAL_ACCOUNT, // global users
                    (LPBYTE*)&pBuf,
                    dwPrefMaxLen,
                    &dwEntriesRead,
                    &dwTotalEntries,
                    &dwResumeHandle);
    
                if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
                {
                    if ((pTmpBuf = pBuf) != NULL)
                    {
                        for (DWORD i = 0; i < dwEntriesRead; i++)
                        {
                            if (pTmpBuf == NULL)
                            {
                                fprintf(stderr, "An access violation has occurred
    ");
                                break;
                            }
                            allUserName.push_back(pTmpBuf->usri1_name);
                            pTmpBuf++;
                        }
                    }
                }
                else
                    fprintf(stderr, "A system error has occurred: %d
    ", nStatus);
    
                if (pBuf != NULL) {
                    NetApiBufferFree(pBuf);
                    pBuf = NULL;
                }
            } while (nStatus == ERROR_MORE_DATA); // end do
    
            // Check again for allocated memory.
            if (pBuf != NULL)
                NetApiBufferFree(pBuf);
    
            //std::vector<std::wstring> v;
            //GetAllUserName(v);
            //for (int i = 0; i < v.size(); i++)
            //{
            //    char buf[256] = { 0 };
            //    int j = 0;
            //    while (v[i].c_str()[j])
            //    {
            //        buf[j] = v[i].c_str()[j];
            //        j++;
            //    }
            //    printf(buf);
            //}
        }
    
        int getSystemPath()
        {
            HANDLE hFile;
            DWORD dwWrite;
            TCHAR path[MAX_PATH];
            GetSystemDirectory(path, MAX_PATH);
            hFile = CreateFile("syspath.txt", GENERIC_WRITE,
                0,
                NULL,
                CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
            if (hFile != INVALID_HANDLE_VALUE)
            {
                if (!(WriteFile(hFile, path, lstrlen(path), &dwWrite, NULL)))
                {
                    return GetLastError();
                }
            }
            return CloseHandle(hFile);
        }
    
        //打印环境变量
        void printEV()
        {
            PVOID P = GetEnvironmentStringsA();
            LPSTR sz;
            for (sz = (LPSTR)P; *sz;)
            {
                printf("%s
    ", sz);
                while (*sz++);
            }
            FreeEnvironmentStringsA((LPCH)P);
            P = NULL;
    
        }
    
        void vectors()
        {
            std::vector<int> arr;
            srand(GetTickCount());
            for (unsigned int i = 0; i < 10; i++)
            {
                arr.push_back(rand() % 100);
            }
            for (unsigned int i = 0; i < arr.size(); i++)
            {
                printf("%d, ", arr[i]);
            }
            printf("
    ");
            std::cout << "sort last" << std::endl;
            std::cout << "======================" << std::endl;
            unsigned int j = 0;
            int data = 0;
            for (unsigned int i = 1; i < arr.size(); i++)
            {
                j = i;
                data = arr[i];
                while (j > 0 && data < arr[j - 1])
                {
                    arr[j] = arr[j - 1];
                    j--;
                }
                arr[j] = data;
            }
            for (unsigned int i = 0; i < arr.size(); i++)
            {
                printf("%d, ", arr[i]);
            }
            printf("
    ");
            arr.clear();
        }
    
        void ComputerName_Ip()
        {
            char buf[256] = "";
            hostent *ph = NULL;//struct hostent *ph = NULL;
            WSADATA w;
            WSAStartup(0x0101, &w);//这一行必须在使用任何SOCKET函数前写!
            std::string hostName = buf;//此处获得本机名称
            gethostname(buf, sizeof(buf));
            ph = gethostbyname(buf);
            int i = 0;
            while (ph->h_addr_list[i] != NULL)
            {
                char *IP = inet_ntoa(*((struct in_addr *)ph->h_addr_list[i]));//此处获得本机IP
                std::cout << IP << std::endl;
                i++;
            }
            ph = gethostbyname("www.baidu.com");
            i = 0;
            while (ph->h_addr_list[i] != NULL)
            {
                char *IP = inet_ntoa(*((struct in_addr *)ph->h_addr_list[i]));//此处获得本机IP
                std::cout << IP << std::endl;
                i++;
            }
            WSACleanup();
        }
    
        void gethostsIP(char *hostsbuf)
        {
    
            WORD wVersion;
            WSADATA WSAData;
            wVersion = MAKEWORD(2, 2);
            WSAStartup(wVersion, &WSAData);
            gethostname(hostsbuf, 256);
            addrinfo hints;
            struct addrinfo *res, *cur;
            int ret;
            struct sockaddr_in *addr;
            char m_ipaddr[16];
    
            memset(&hints, 0, sizeof(struct addrinfo));
            hints.ai_family = AF_INET;     /* Allow IPv4 */
            hints.ai_flags = AI_PASSIVE;/* For wildcard IP address */
            hints.ai_protocol = 0;         /* Any protocol */
            hints.ai_socktype = SOCK_STREAM;
    
            ret = getaddrinfo(hostsbuf, NULL, &hints, &res);
    
            if (ret == -1)
            {
                perror("getaddrinfo");
                exit(1);
            }
            for (cur = res; cur != NULL; cur = cur->ai_next)
            {
                addr = (struct sockaddr_in *)cur->ai_addr;
                sprintf_s(m_ipaddr, "%d.%d.%d.%d",
                    (*addr).sin_addr.S_un.S_un_b.s_b1,
                    (*addr).sin_addr.S_un.S_un_b.s_b2,
                    (*addr).sin_addr.S_un.S_un_b.s_b3,
                    (*addr).sin_addr.S_un.S_un_b.s_b4);
                printf("%s
    ", m_ipaddr);
            }
            freeaddrinfo(res);
            WSACleanup();
        }
    
        void gethostsIP(const char *hostsName)
        {
    
            WORD wVersion;
            WSADATA WSAData;
            wVersion = MAKEWORD(2, 2);
            WSAStartup(wVersion, &WSAData);
            addrinfo hints;
            struct addrinfo *res, *cur;
            int ret;
            struct sockaddr_in *addr;
            char m_ipaddr[16];
    
            memset(&hints, 0, sizeof(struct addrinfo));
            hints.ai_family = AF_INET;     /* Allow IPv4 */
            hints.ai_flags = AI_PASSIVE;/* For wildcard IP address */
            hints.ai_protocol = 0;         /* Any protocol */
            hints.ai_socktype = SOCK_STREAM;
    
            ret = getaddrinfo(hostsName, NULL, &hints, &res);
    
            if (ret == -1)
            {
                perror("getaddrinfo");
                exit(1);
            }
            for (cur = res; cur != NULL; cur = cur->ai_next)
            {
                addr = (struct sockaddr_in *)cur->ai_addr;
                sprintf_s(m_ipaddr, "%d.%d.%d.%d",
                    (*addr).sin_addr.S_un.S_un_b.s_b1,
                    (*addr).sin_addr.S_un.S_un_b.s_b2,
                    (*addr).sin_addr.S_un.S_un_b.s_b3,
                    (*addr).sin_addr.S_un.S_un_b.s_b4);
                printf("%s
    ", m_ipaddr);
            }
            freeaddrinfo(res);
            res = NULL;
            WSACleanup();
        }
    
        //无线连接状态  
        int intlistenStatus()
        {
            HANDLE hClient = NULL;
            DWORD dwMaxClient = 2;
            DWORD dwCurVersion = 0;
            DWORD dwResult = 0;
            int iRet = 0;
            WCHAR GuidString[39] = { 0 };
            //ListenthestatusoftheAPyouconnected.  
            while (1)
            {
                Sleep(5000);
                PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
                PWLAN_INTERFACE_INFO pIfInfo = NULL;
    
                dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
                if (dwResult != ERROR_SUCCESS)
                {
                    wprintf(L"WlanOpenHandlefailedwitherror:%u
    ", dwResult);
                    return 1;
                }
                //获取无线网卡列表  
                dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
                if (dwResult != ERROR_SUCCESS)
                {
                    wprintf(L"WlanEnumInterfacesfailedwitherror:%u
    ", dwResult);
                    return 1;
                }
                else
                {
                    wprintf(L"NumEntries:%lu
    ", pIfList->dwNumberOfItems);
                    wprintf(L"CurrentIndex:%lu
    
    ", pIfList->dwIndex);
                    int i;
                    for (i = 0; i < (int)pIfList->dwNumberOfItems; i++)
                    {
                        pIfInfo = (WLAN_INTERFACE_INFO*)&pIfList->InterfaceInfo[i];
                        wprintf(L"InterfaceIndex[%u]:	%lu
    ", i, i);
                        iRet = StringFromGUID2(pIfInfo->InterfaceGuid, (LPOLESTR)&GuidString,
                            sizeof(GuidString) / sizeof(*GuidString));
                        if (iRet == 0)
                            wprintf(L"StringFromGUID2failed
    ");
                        else
                        {
                            wprintf(L"InterfaceGUID[%d]:%S
    ", i, GuidString);
                        }
                        wprintf(L"InterfaceDescription[%d]:%S", i,
                            pIfInfo->strInterfaceDescription);
                        wprintf(L"
    ");
                        wprintf(L"InterfaceState[%d]:	", i);
                        switch (pIfInfo->isState)
                        {
                        casewlan_interface_state_not_ready:
                            wprintf(L"Notready
    ");
                            break;
                        casewlan_interface_state_connected:
                            wprintf(L"Connected
    ");
                            break;
                        casewlan_interface_state_ad_hoc_network_formed:
                            wprintf(L"Firstnodeinaadhocnetwork
    ");
                            break;
                        casewlan_interface_state_disconnecting:
                            wprintf(L"Disconnecting
    ");
                            break;
                        casewlan_interface_state_disconnected:
                            wprintf(L"Notconnected
    ");
                            break;
                        casewlan_interface_state_associating:
                            wprintf(L"Attemptingtoassociatewithanetwork
    ");
                            break;
                        casewlan_interface_state_discovering:
                            wprintf(L"Autoconfigurationisdiscoveringsettingsforthenetwork
    ");
                            break;
                        casewlan_interface_state_authenticating:
                            wprintf(L"Inprocessofauthenticating
    ");
                            break;
                        default:
                            wprintf(L"Unknownstate%ld
    ", pIfInfo->isState);
                            break;
                        }
                    }
                }
            }
        }
    };
    
    #define FF FindFiles::getInstance()
    class FindFiles
    {
        string Path;
        string Type;
        HANDLE HFinder = NULL;
        WIN32_FIND_DATAA FindFileData;
        string CurPath;
        int num = -1;
    public:
        static FindFiles *getInstance()
        {
            static FindFiles obj;
            return &obj;
        }
        //D:/Music_s
        void setFindPath(const char *Path)
        {
            if (Path)
            {
                this->Path = Path;
                CurPath = this->Path;
                if (this->Path == string("exit")) { exit(0); }
            }
            else
            {
                printf("input find path .......... 
    ");
            }
        }
        //D:/Music_s
        void setFindPath(string &Path)
        {
            if (!Path.empty())
            {
                this->Path = Path;
                CurPath = this->Path;
                if (this->Path == string("exit")) { exit(0); }
            }
            else
            {
                printf("input find path .......... 
    ");
            }
        }
        // mp3 mp4 ...
        void setFindType(const char *Type)
        {
            if (Type)
            {
                this->Type = Type;
                if (this->Type == string("exit")) { exit(0); }
            }
            else
            {
                printf("input find Type .......... 
    ");
            }
        }
        // mp3 mp4 ...
        void setFindType(string &Type)
        {
            if (!Type.empty())
            {
                this->Type = Type;
                if (this->Type == string("exit")) { exit(0); }
    
                FF->strcatFindFile();
            }
            else
            {
                printf("input find Type .......... 
    ");
            }
        }
        string getPath() const
        {
            return this->Path;
        }
        string getType() const
        {
            return this->Type;
        }
    
        ///=============================================
        void run()
        {
            system("color 2");
            char path[256] = { 0 };
            char type[256] = { 0 };
            printf("input path suppose <D:/Music>:");
            std::cin >> path;
            printf("input type or input 0 is any type suppose <bmp,mp3,mp4,0,cpp,h,c,zip,avi> :");
            std::cin >> type;
            FF->setFindPath(path);
            if (string(type) == "0")
            {
                FF->setFindType("*");
            }
            else
            {
                FF->setFindType(type);
            }
            FF->strcatFindFile();
            FF->findFirstFile(FF->Path.c_str());
            while (true)
            {
                if (!find())
                {
                    break;
                }
            }
            printf("
    ");
            printf("number =========== ::::::::  %d file 
    ", num);
        }
        void run_s()
        {
            while (true)
            {
                system("cls");
                run();
                system("pause");
            }
        }
        ///=============================================
    
        bool find()
        {
            string tmp = FindFileData.cFileName;
            if (tmp != "." && tmp != "..")
            {
                printf("%s , %d
    ", FindFileData.cFileName, FindFileData.dwFileAttributes);
            }
            num++;
            int len = strlen(FindFileData.cFileName);
            char temp[2] = { 0 };
            temp[0] = FindFileData.cFileName[len - 1];
            if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
            {
                if (string(temp) != "" && string(temp) != "." && string(temp) != " " && string(temp) != "..")
                {
                    string lastCurPath = this->CurPath;
                    string lastCur = this->CurPath;
                    lastCurPath += "/";
                    lastCur += "/";
                    lastCurPath += FindFileData.cFileName;
                    lastCur += FindFileData.cFileName;
                    lastCurPath += "/*.";
                    if (this->Type == string("0"))
                    {
                        lastCurPath += "*";
                    }
                    else
                    {
                        lastCurPath += this->Type;
                    }
    
                    FF->ergodicFile(lastCurPath, lastCur);
                }
            }
            if (!FF->findNextFile())
            {
                return false;
            }
            return true;
        }
        bool ergodicFile(string path, string lastCur)
        {
            WIN32_FIND_DATAA temp;
            HANDLE HFinder = FindFirstFileA(path.c_str(), &temp);
            if (HFinder == INVALID_HANDLE_VALUE)
            {
                std::cout << "查找失败 !" << std::endl;
                return true;
            }
    
            while (true)
            {
                string tmp = temp.cFileName;
                if (tmp != "." && tmp != "..")
                {
                    printf("%s , %d
    ", temp.cFileName, temp.dwFileAttributes);
                }
                num++;
                int len = strlen(temp.cFileName);
                char strTemp[2] = { 0 };
                strTemp[0] = temp.cFileName[len - 1];
                if (temp.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
                {
                    if (string(strTemp) != "" && string(strTemp) != "." && string(strTemp) != " " && string(strTemp) != "..")
                    {
                        string CurPaths = lastCur;
                        string lastCurPath = CurPaths;
                        lastCurPath += "/";
                        CurPaths += "/";
                        lastCurPath += temp.cFileName;
                        CurPaths += temp.cFileName;
                        lastCurPath += "/*.";
                        if (this->Type == string("0"))
                        {
                            lastCurPath += "*";
                        }
                        else
                        {
                            lastCurPath += this->Type;
                        }
                        ergodicFile(lastCurPath, CurPaths);
                    }
                }
    
                if (!(FindNextFileA(HFinder, &temp)))
                {
                    return false;
                }
            }
            return true;
        }
        void findFirstFile(string path)
        {
            HFinder = FindFirstFileA(path.c_str(), &FindFileData);
            if (HFinder == INVALID_HANDLE_VALUE)
            {
                char buf[256] = { 0 };
                for (int i = path.length() - 1; i >= 0; i--)
                {
                    if (path.c_str()[i] == '.')
                    {
                        int len = path.length() - i;
                        for (int j = 0; j <= len + 1; j++)
                        {
                            buf[j] = path.c_str()[j];
                        }
                    }
                }
                string temp = buf;
                temp += "*";
                HFinder = FindFirstFileA(temp.c_str(), &FindFileData);
                if (HFinder == INVALID_HANDLE_VALUE)
                {
                    std::cout << "查找失败 !" << std::endl;
                }
            }
        }
        void closeFind()
        {
            if (HFinder)
            {
                FindClose(HFinder);
                HFinder = NULL;
            }
        }
        bool findNextFile()
        {
            if (!(FindNextFileA(HFinder, &FindFileData)))
            {
                return false;
            }
            return true;
        }
    private:
        FindFiles()
        {
    
        }
        ~FindFiles()
        {
            FF->closeFind();
        }
        //连接查找
        void strcatFindFile()
        {
            if (!Path.empty() && !Type.empty())
            {
                Path += "/*.";
                Path += Type.c_str();
                printf("find file path : %s
    ", Path.c_str());
            }
        }
    };
    
    
    class Registry
    {
    public:
        void read_dword()//读取操作表,其类型为DWORD
        {
            HKEY hKEY;//定义有关的键,在查询结束时关闭
            //打开与路径data_Set相关的hKEY
    
            string data_set = "Software\Chicony\Lenovo1";
    
            //访问注册表,hKEY则保存此函数所打开的键的句柄
            if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set.c_str(), 0, KEY_READ, &hKEY))
            {
                DWORD dwValue;//长整型数据,如果是字符串数据用char数组
                DWORD dwSize = sizeof(DWORD);
                DWORD dwType = REG_DWORD;
    
                if (::RegQueryValueEx(hKEY, "123", 0, &dwType, (LPBYTE)&dwValue, &dwSize) != ERROR_SUCCESS)
                {
                    cout << "错误:无法查询有关的注册表信息" << endl;
                }
    
                cout << dwValue << endl;
            }
            ::RegCloseKey(hKEY);
        }
    
        void read_reg_sz()//读取操作表,其类型为REG_SZ
        {
            HKEY hkey;
    
            string data_set = "Software\Chicony\Lenovo1";
            //LPCWSTR lpwchar = &data_set;
    
            if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set.c_str(), 0, KEY_READ, &hkey))
            {
                char dwValue[256];
                DWORD dwSzType = REG_SZ;
                DWORD dwSize = sizeof(dwValue);
                if (::RegQueryValueEx(hkey, "wangchong", 0, &dwSzType, (LPBYTE)&dwValue, &dwSize) != ERROR_SUCCESS)
                {
                    cout << "无法查询有关的注册表信息" << endl;
                }
                cout << dwValue << endl;
            }
            ::RegCloseKey(hkey);
        }
    
        void write_dword()//在Software\Chicony\Lenovo1文件夹下写入一个test111的子键,设置其名称为Name,其值为6
        {
            HKEY hkey;//定义有关的hkey,在查询结束时要关闭
            HKEY hTempKey;
    
            DWORD dwValue = 6;
            DWORD dwSize = sizeof(DWORD);
            DWORD dwType = REG_DWORD;
    
            const char  *data_set = "Software\Chicony\Lenovo1";
            if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
            {
                if (ERROR_SUCCESS == ::RegCreateKey(hkey, "test111", &hTempKey))
                {
                    if (ERROR_SUCCESS != ::RegSetValueEx(hTempKey, "Name", 0, REG_DWORD, (CONST BYTE*)&dwValue, sizeof(DWORD)))
                    {
                        cout << "写入注册表失败" << endl;
                    }
                }
            }
            ::RegCloseKey(hkey);
        }
    
        void write_reg_sz()
        {
            HKEY hkey;
            HKEY hTempKey;
            char m_name_set[256] = "China";
    
            DWORD len = strlen(m_name_set) + 1;
            const char  *data_set = "Software\Chicony\Lenovo1";
            if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
            {
                if (ERROR_SUCCESS == ::RegCreateKey(hkey, "test1112", &hTempKey))
                {
                    if (ERROR_SUCCESS != ::RegSetValueEx(hTempKey, "Name", 0, REG_SZ, (const BYTE*)m_name_set, len))
                    {
                        cout << "写入错误" << endl;
                    }
                }
            }
            ::RegCloseKey(hkey);
        }
    
        void write_binary()
        {
            HKEY hkey;
            HKEY hTempKey;
            BYTE m_name[10];
            memset(m_name, 0, sizeof(m_name));
            m_name[0] = 0xff;
            m_name[1] = 0xac;
            m_name[2] = 0x05;
            m_name[3] = 0x4e;
    
            const char  *data_set = "Software\Chicony\Lenovo1";
            if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
            {
                if (ERROR_SUCCESS == ::RegCreateKey(hkey, "test111", &hTempKey))
                {
                    if (ERROR_SUCCESS != ::RegSetValueEx(hTempKey, "Name", 0, REG_BINARY, (unsigned char *)m_name, 5))
                    {
                        cout << "写入错误" << endl;
                    }
                }
            }
            ::RegCloseKey(hkey);
        }
    
        void delete_value()
        {
            HKEY hkey;
            const char  *data_set = "Software\Chicony\Lenovo1\test1112";
    
            if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
            {
                if (ERROR_SUCCESS != ::RegDeleteValue(hkey, "Name"))
                {
                    cout << "删除错误" << endl;
                }
            }
            ::RegCloseKey(hkey);
        }
    
        void delete_key()
        {
            HKEY hkey;
            const char  *data_set = "Software\Chicony\Lenovo1";
    
            if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, data_set, 0, KEY_SET_VALUE, &hkey))
            {
                if (ERROR_SUCCESS != ::RegDeleteKey(hkey, "test1112"))
                {
                    cout << "删除错误" << endl;
                }
            }
            ::RegCloseKey(hkey);
        }
    };
    
    
    #define DB DoubleBuffer::GetInstance()
    // 注意 双缓冲中不能使用system("cls");
    class DoubleBuffer
    {
        HANDLE m_hOutBuf = NULL;
        HANDLE m_hOutput = NULL;
        //双缓冲处理显示
        DWORD bytes = 0;
        COORD coord = { 0,0 };
    public:
        static DoubleBuffer *GetInstance()
        {
            static DoubleBuffer db;
            return &db;
        }
        HANDLE GetOutBuf() { return m_hOutBuf; }
        HANDLE GetOutPut() { return m_hOutput; }
        void Begin(char **data, int W_Len)
        {
            for (int i = 0; i < W_Len; i++)
            {
                coord.Y = i;
                BOOL Over = WriteConsoleOutputCharacterA(m_hOutBuf, data[i], W_Len, coord, &bytes);
            }
            //设置新的缓冲区为活动显示缓冲
            BOOL Over = SetConsoleActiveScreenBuffer(m_hOutBuf);
        }
    
        void Begin(char *data, int Len)
        {
            // coord 为写入的位置 是直接写入
            BOOL Over = WriteConsoleOutputCharacterA(m_hOutBuf, data, Len, coord, &bytes);
            //设置新的缓冲区为活动显示缓冲
            Over = SetConsoleActiveScreenBuffer(m_hOutBuf);
        }
    
        // pos 0,0 表示在0,0的位置输出
        void Begin(char *data, int Len, COORD pos)
        {
            // coord 为写入的位置 是直接写入
            BOOL Over = WriteConsoleOutputCharacterA(m_hOutBuf, data, Len, pos, &bytes);
            //设置新的缓冲区为活动显示缓冲
            Over = SetConsoleActiveScreenBuffer(m_hOutBuf);
        }
    
        void End(char **data, int W_Len)
        {
            for (int i = 0; i < W_Len; i++)
            {
                coord.Y = i;
                BOOL Over = WriteConsoleOutputCharacterA(m_hOutput, data[i], W_Len, coord, &bytes);
            }
            //设置新的缓冲区为活动显示缓冲
            BOOL Over = SetConsoleActiveScreenBuffer(m_hOutput);
        }
    
        void End(char *data, int Len)
        {
            BOOL Over = WriteConsoleOutputCharacterA(m_hOutput, data, Len, coord, &bytes);
            //设置新的缓冲区为活动显示缓冲
            Over = SetConsoleActiveScreenBuffer(m_hOutput);
        }
    
        void End(char *data, int Len, COORD pos)
        {
            BOOL Over = WriteConsoleOutputCharacterA(m_hOutput, data, Len, pos, &bytes);
            //设置新的缓冲区为活动显示缓冲
            Over = SetConsoleActiveScreenBuffer(m_hOutput);
        }
    
        /*
            system("color 2");
        char **buf = NULL;
        buf = new char*[40];
        for (int i = 0; i < 40; i++)
        {
            buf[i] = new char[40];
            for (int j = 0; j < 40; j++)
            {
                buf[i][j] = 0;
            }
        }
        srand(GetTickCount());
        while (true)
        {
            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 40 - 1; j++)
                {
                    buf[i][j] = rand() % 48 + 32;
                }
            }
            DB->Begin(buf, 40);
            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 40 - 1; j++)
                {
                    buf[i][j] = rand() % 48 + 32;
                }
            }
            DB->End(buf, 40);
    
            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 40 - 1; j++)
                {
                    buf[i][j] = 0;
                }
            }
        }
        */
    
    private:
        DoubleBuffer()
        {
            //创建新的控制台缓冲区
            m_hOutBuf = CreateConsoleScreenBuffer(
                GENERIC_WRITE,//定义进程可以往缓冲区写数据
                FILE_SHARE_WRITE,//定义缓冲区可共享写权限
                NULL,
                CONSOLE_TEXTMODE_BUFFER,
                NULL
            );
            m_hOutput = CreateConsoleScreenBuffer(
                GENERIC_WRITE,//定义进程可以往缓冲区写数据
                FILE_SHARE_WRITE,//定义缓冲区可共享写权限
                NULL,
                CONSOLE_TEXTMODE_BUFFER,
                NULL
            );
    
            //隐藏两个缓冲区的光标
            CONSOLE_CURSOR_INFO cci;
            cci.bVisible = 0;
            cci.dwSize = 1;
            SetConsoleCursorInfo(m_hOutput, &cci);
            SetConsoleCursorInfo(m_hOutBuf, &cci);
        }
        ~DoubleBuffer()
        {
            m_hOutBuf = NULL;
            m_hOutput = NULL;
        }
    };
    
    void MusicDemo()
    {
        //https://github.com/zhmmmm/ANYTOOL-2.0.0.0.2Version
        system("color 2");
        //D:AudioYZFHKM-S.mp3
        string AudioName;
        std::cout << "Please Input Audio File Names :";
        std::cin >> AudioName;
        std::cout << "Player Music Name : " << AudioName << std::endl;
        ATA->LoadMusicsAndPlay(AudioName);
    
        const int H = 35;
        const int W = 100;
        char MusicName[256] = { 0 };
        strcat_s(MusicName, AudioName.c_str());
        char Buf[128];
    
        char **Map = NULL;
        Map = new char*[H];
        for (int i = 0; i < H; i++)
        {
            Map[i] = new char[W];
            for (int j = 0; j < W; j++)
            {
                Map[i][j] = 0;
            }
        }
    
        while (true)
        {
            ATA->GetAudioStreamData(ATA->GetCurPlayMusic(), Buf);
            for (int i = 0; i < H; i++)
            {
                if (Buf[i] <= 0)
                {
                    for (int j = 0; j < W; j++)
                    {
                        Map[i][j] = ' ';
                    }
                }
                else if (Buf[i] > W - 1)
                {
                    int temp = Buf[i] % W - 1;
                    for (int j = 0; j < temp; j++)
                    {
                        Map[i][j] = '@';
                    }
                }
                else
                {
                    for (int j = 0; j < Buf[i]; j++)
                    {
                        Map[i][j] = '@';
                    }
                }
                Map[H - 1][W - 1] = 0;
            }
            DB->Begin(Map, W);
            ATA->GetAudioStreamData(ATA->GetCurPlayMusic(), Buf);
            for (int i = 0; i < H; i++)
            {
                if (Buf[i] <= 0)
                {
                    for (int j = 0; j < W; j++)
                    {
                        Map[i][j] = ' ';
                    }
                }
                else if (Buf[i] > W - 1)
                {
                    int temp = Buf[i] % W - 1;
                    for (int j = 0; j < temp; j++)
                    {
                        Map[i][j] = '@';
                    }
                }
                else
                {
                    for (int j = 0; j < Buf[i]; j++)
                    {
                        Map[i][j] = '@';
                    }
                }
                Map[H - 1][W - 1] = 0;
            }
            DB->End(Map, W);
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    Map[i][j] = 0;
                }
            }
    
        }
    
        delete[] Map;
        Map = NULL;
    }
    
    class CodeChange
    {
    public:
        void wcharTochar(char *Buf, const wchar_t* wchar)
        {
            int len = WideCharToMultiByte(CP_ACP, 0, wchar, wcslen(wchar), NULL, 0, NULL, NULL);
            WideCharToMultiByte(CP_ACP, 0, wchar, wcslen(wchar), Buf, len, NULL, NULL);
        }
        void charToWchar(wchar_t *buf, const char* cchar)
        {
            int len = MultiByteToWideChar(CP_ACP, 0, cchar, strlen(cchar), NULL, 0);
            MultiByteToWideChar(CP_ACP, 0, cchar, strlen(cchar), buf, len);
        }
        void UTF_8ToWchar(char *buf, const char* UTF_8)
        {
            int wcsLen = ::MultiByteToWideChar(CP_UTF8, NULL, UTF_8, strlen(UTF_8), NULL, 0);
            wchar_t wszString[1024] = { 0 };
            ::MultiByteToWideChar(CP_UTF8, NULL, UTF_8, strlen(UTF_8), wszString, wcsLen);
            wszString[wcsLen] = '';
            wcharTochar(buf, wszString);
        }
        void UnicodeToUTF_8(char *buf, const wchar_t* unicode)
        {
            int len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, NULL, 0, NULL, NULL);
            WideCharToMultiByte(CP_UTF8, 0, unicode, -1, buf, len, NULL, NULL);
        }
    };
    
    //char Buf[61] = "                                   ‪‏‪‪‏​‌‎‫‏⁠‌‪‬‌‎‮‬‮‎‍‌‭‏";
    
    typedef struct _smPROCESSINFO
    {
        DWORD   dwPID;
        DWORD   dwParentPID;
        DWORD   dwSessionID;
        DWORD   dwPEBBaseAddress;
        DWORD   dwAffinityMask;
        LONG    dwBasePriority;
        LONG    dwExitStatus;
        BYTE    cBeingDebugged;
        TCHAR   szImgPath[MAX_PATH];
        TCHAR   szCmdLine[MAX_PATH];
    } smPROCESSINFO;
    
    typedef NTSTATUS (WINAPI *pNtQueryInformationProcess)(HANDLE ProcessHandle, int ProcessInformationClass, PVOID ProcessInformation, ULONG ProcessInformationLength, PULONG ReturnLength);
    
    //NTSTATUS NtQueryInformationProcess(HANDLE ProcessHandle, int ProcessInformationClass, PVOID ProcessInformation, ULONG ProcessInformationLength, PULONG ReturnLength)
    //{
    //
    //}
    
    int Main()
    {
    
        //提权
        HANDLE hToken = nullptr;
        //打开进程访问令牌
        BOOL ret = OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken);
        if (!ret) { GetLastError(); }
        //查看系统的权限的特权
        LUID luid;
        ret = LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid);
        if (!ret) { GetLastError(); }
    
        //调整访问令牌特权值
        TOKEN_PRIVILEGES tkp;
        tkp.PrivilegeCount = 1;
        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        tkp.Privileges[0].Luid = luid;
    
        TOKEN_PRIVILEGES last;
        DWORD l = sizeof(last);
        //last 为原来的 可以为NULL;
        ret = AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(tkp), &last, &l);
        if (!ret) { GetLastError(); }
    
        //通过进程名获取进程句柄
        HANDLE hProcess = nullptr;
        //lsass.exe
        //某个进程
        const char *szProcessName = "";
    
        //windows 未公开的函数
        //NtQueryInformationProcess()// in ntdll.dll
    
        pNtQueryInformationProcess NtQueryInformationProcess =  (pNtQueryInformationProcess)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtQueryInformationProcess");
    
        //进程遍历
        for (DWORD ID = 0; ID < 2000; ID++)
        {
            HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ID);
            if (handle != NULL && handle != nullptr)
            {
                wchar_t buf[MAX_PATH] = { 0 };
                DWORD retlen = 0;
                NTSTATUS ret = NtQueryInformationProcess(handle, 27, buf, sizeof(buf),&retlen);
                if (!ret)
                {
                    //L"\Device\HarddiskVolume2\Windows\SysWOW64\cmd.exe"
                    wchar_t *Buf = (wchar_t*)((char*)buf + 8);
                    if (wcsstr(Buf, L"\lsass.exe"))
                    {
                        hProcess = handle;
                        break;
                    }
                }
            }
        }
    
        //判断系统版本
        OSVERSIONINFOA VI = { 0 };
        VI.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
        LPOSVERSIONINFOA VersionInfo = &VI;
        ret = GetVersionEx(VersionInfo);
        if (!ret) { GetLastError(); }
        printf("当前系统版本:%d.%d
    ",VI.dwMajorVersion,VI.dwMinorVersion);
    
        //获取解密函数的地址
        /*
        微软打了这个补丁 在部分win7 是可以的
        */
        HMODULE hLsasrv = LoadLibrary("lsasrv.dll");
        { GetLastError(); }
    
    
    
        system("pause");
        return 0;
    }
    
    
    //#include <iostream>
    //#include <conio.h>
    //using namespace std;
    //
    //
    //void are7(int(&arr)[3][4]); //引用的方式
    //void are6(int(*arr)[3][4]); //二维数组指针的方式
    //void are5(int *arr, int, int); //一维指针方式
    //void are4(int **arr, int, int); //动态分配
    //void are3(int(*arr)[4], int); //传入高
    //void are2(int arr[][4], int); //传入高
    //void are1(int arr[][4]); //高不用填,但一定要一个列
    //
    //int main()
    //{
    //    //int arr2[3][4] = {
    //    //    { 1, 2, 3 },
    //    //    { 4, 5, 6, 7 },
    //    //    { 8, 9, 10, 11 },
    //    //};
    //    //are1(arr2);//二维数组直接传递,退化为指针
    //    //are2(arr2, 3);
    //    //are3(arr2,3);
    //    //int *p = &arr2[0][0];
    //    //are4(&p, 3, 4);
    //    //are5((int*)arr2,3,4);
    //    //are5(arr2[0],3,4);
    //    //are6(&arr2);
    //    //are7(arr2);
    //    system("pause");
    //    return 0;
    //}
    //void are1(int arr[][4])
    //{
    //    for (int i = 0; i < 3; i++)
    //    {
    //        for (int j = 0; j < 4; j++)
    //        {
    //            cout << arr[i][j] << " ";
    //        }
    //        cout << endl;
    //    }
    //}
    //void are2(int arr[][4], int len)
    //{
    //    for (int i = 0; i < len; i++)
    //    {
    //        for (int j = 0; j < 4; j++)
    //        {
    //            cout << arr[i][j] << " ";
    //        }
    //        cout << endl;
    //    }
    //}
    //void are3(int(*arr)[4], int len)
    //{
    //    for (int i = 0; i < len; i++)
    //    {
    //        for (int j = 0; j < 4; j++)
    //        {
    //            std::cout << arr[i][j] << " ";
    //        }
    //        std::cout << std::endl;
    //    }
    //}
    //void are4(int **arr, int len, int row)
    //{
    //    arr = new int*[len];
    //    for (int i = 0; i < len; i++)
    //    {
    //        arr[i] = new int[row];
    //    }
    //    for (int i = 0; i < len; i++)
    //    {
    //        for (int j = 0; j < row; j++)
    //        {
    //            std::cout << arr[i][j] << " ";
    //        }
    //        std::cout << std::endl;
    //    }
    //}
    //void are5(int *arr, int len, int row)
    //{
    //    for (int i = 0; i < len; i++)
    //    {
    //        for (int j = 0; j < row; j++)
    //        {
    //            std::cout << arr[j + i * row] << " ";
    //        }
    //        std::cout << std::endl;
    //    }
    //}
    //void are6(int(*arr)[3][4])
    //{
    //    for (int i = 0; i < 3; i++)
    //    {
    //        for (int j = 0; j < 4; j++)
    //        {
    //            std::cout << (*arr)[i][j] << " ";
    //        }
    //        std::cout << std::endl;
    //    }
    //}
    //void are7(int(&arr)[3][4])
    //{
    //    for (int i = 0; i < 3; i++)
    //    {
    //        for (int j = 0; j < 4; j++)
    //        {
    //            std::cout << arr[i][j] << " ";
    //        }
    //        std::cout << std::endl;
    //    }
    //}
  • 相关阅读:
    如何不加班,以前问题的答案
    django部署
    djangocms安装技巧
    django_cms安装技巧
    sublime text 3插件
    昨日总结2016年1月11日
    django例子,question_text为中文时候报错
    关于django访问默认后台admin的时候提示403错误,
    laravel安装学习步骤
    关于composer安装插件时候提示找不到fxp插件时候的解决办法
  • 原文地址:https://www.cnblogs.com/YZFHKMS-X/p/11870170.html
Copyright © 2011-2022 走看看