常用代码库

xingyun86 6月前 212

常用代码库

#include <string>
#include <vector>
#include <thread>
#include <Commctrl.h>
#include <Shlwapi.h>
#include <TlHelp32.h>
#pragma comment(lib, "Shlwapi")
HMODULE GetProcessModuleHandle(DWORD dwProcessId, LPCWSTR lpcwModuleName)
{
    HMODULE hModule = NULL;
    HANDLE hSnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId);
    if (hSnapshot != NULL) 
    {
        MODULEENTRY32W me32w = { 0 };
        ::memset(&me32w, 0, sizeof(me32w));
        me32w.dwSize = sizeof(me32w);
        for (BOOL bRet = ::Module32FirstW(hSnapshot, &me32w); (bRet == TRUE); bRet = ::Module32NextW(hSnapshot, &me32w))
        {
            if (::wcsicmp(me32w.szModule, lpcwModuleName) == 0)
            { 
                hModule = me32w.hModule;
                break;
            }
        }
        ::CloseHandle(hSnapshot);
    }
    return(hModule);
}
__inline static
std::vector<PROCESSENTRY32W> GetProcessListByName(const std::wstring& wstrName)
{
    std::vector<PROCESSENTRY32W> vProcess = {};
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hSnapshot != INVALID_HANDLE_VALUE)
    {
        PROCESSENTRY32W pew = { sizeof(pew) };
        for (BOOL bRet = Process32FirstW(hSnapshot, &pew); bRet == TRUE; bRet = Process32NextW(hSnapshot, &pew))
        {
            if (StrStrIW(pew.szExeFile, wstrName.c_str()) != NULL)
            {
                vProcess.emplace_back(pew);
            }
        }
        CloseHandle(hSnapshot);
        hSnapshot = INVALID_HANDLE_VALUE;
    }
    return vProcess;
}
 auto procs = GetProcessListByName(L"SmartCUTPro.exe");
 if (procs.empty() == false)
 {
     auto& it = procs.at(0);
     HANDLE h = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, it.th32ProcessID);
     if (h != NULL)
     {
         CHAR czSrcText[13] = { 0 };
         SIZE_T czSrcTextLen = sizeof(czSrcText) / sizeof(*czSrcText);
         SIZE_T czSrcTextReadLen = 0;
         CHAR czDstText[] = "软件";
         SIZE_T czDstTextLen = sizeof(czDstText) / sizeof(*czDstText);
         SIZE_T czDstTextReadLen = 0;
         HMODULE hMod = GetProcessModuleHandle(it.th32ProcessID, L"SmartCUTPro.exe");
         ::ReadProcessMemory(h, (LPCVOID)((DWORD_PTR)hMod + 0x24D87C), (LPVOID)czSrcText, czSrcTextLen, &czSrcTextReadLen);
         ::WriteProcessMemory(h, (LPVOID)((DWORD_PTR)hMod + 0x24D87C), (LPCVOID)czDstText, czDstTextLen, &czDstTextReadLen);
         ::WriteProcessMemory(h, (LPVOID)((DWORD_PTR)hMod + 0x24DCEA), (LPCVOID)czDstText, czDstTextLen, &czDstTextReadLen);
         ::WriteProcessMemory(h, (LPVOID)((DWORD_PTR)hMod + 0x24DCF7), (LPCVOID)czDstText, czDstTextLen, &czDstTextReadLen);
         ::WriteProcessMemory(h, (LPVOID)((DWORD_PTR)hMod + 0x386853), (LPCVOID)czDstText, czDstTextLen, &czDstTextReadLen);
         ::CloseHandle(h);
     }
 }
 {
                    WCHAR wCaption[4096] = { 0 };
                    WCHAR wClassName[4096] = { 0 };
                    HWND hWHWnd = NULL;
                    HWND hDstWnd = NULL;
                    for (hDstWnd = ::FindWindowExW(hWHWnd, hDstWnd, L"TForm1", NULL);
                        hDstWnd != NULL;
                        hDstWnd = ::FindWindowExW(hWHWnd, hDstWnd, L"TForm1", NULL))
                    {
                        ::SendMessageW(hDstWnd, WM_GETTEXT, (WPARAM)(sizeof(wCaption) / sizeof(*wCaption)), (LPARAM)wCaption);
                        if (*wCaption != L'\0')
                        {
                            std::wstring wTitle = wCaption;
                            std::wstring wPrefix = L"Smart";
                            if (wTitle.find(wPrefix) == 0)
                            {
                                std::wstring wExtern = wTitle.substr(wPrefix.length());
                                wTitle = L"内部软件 " + wExtern;
                                ::SendMessageW(hDstWnd, WM_SETTEXT, NULL, (LPARAM)wTitle.c_str());
                                HMENU hMenu = ::GetMenu(hDstWnd);
                                if (hMenu)
                                {
                                    for (int i = 0; i < ::GetMenuItemCount(hMenu); i++)
                                    {
                                        HMENU hSubMenu = ::GetSubMenu(hMenu, i);
                                        if (hSubMenu != NULL)
                                        {
                                            WCHAR wSubMenuText[MAX_PATH] = { 0 };
                                            ::GetMenuStringW(hMenu, i, wSubMenuText, sizeof(wSubMenuText) / sizeof(*wSubMenuText), MF_BYPOSITION);
                                            if (wcsstr(wSubMenuText, L"帮助") != NULL)
                                            {
                                                ::DeleteMenu(hMenu, i, MF_BYPOSITION);
                                                break;
                                            }
                                        }
                                    }
                                }
                                ::EnumChildWindows(hDstWnd, [](HWND hWnd, LPARAM)->BOOL CALLBACK
                                    {
                                        WCHAR wCaption[4096] = { 0 };
                                        WCHAR wClassName[4096] = { 0 };
                                        ::GetWindowTextW(hWnd, wCaption, sizeof(wCaption) / sizeof(*wCaption));
                                        ::GetClassNameW(hWnd, wClassName, sizeof(wClassName) / sizeof(*wClassName));
                                        if (*wClassName != L'\0')
                                        {
                                            if (wcsicmp(wClassName, L"TToolBar") == 0)
                                            {
                                            }
                                        }
                                        return TRUE;
                                    }, NULL);
                                break;
                            }
                        }
                    }
}


上传的附件:
×
打赏作者
最新回复 (0)
只看楼主
全部楼主
返回