Skip to content

Instantly share code, notes, and snippets.

@hackpascal
Created April 15, 2017 08:46
Show Gist options
  • Save hackpascal/0a24b1857baf6ede254784f475e786de to your computer and use it in GitHub Desktop.
Save hackpascal/0a24b1857baf6ede254784f475e786de to your computer and use it in GitHub Desktop.
UltraEdit 强制离线激活
#include <Windows.h>
#include <locale.h>
typedef void (WINAPI *PFNSWITCHTOTHISWINDOW) (HWND, BOOL);
int _tmain(int argc, _TCHAR* argv[])
{
HWND hWindow, hButton;
DWORD dwButtonId, dwStyle;
HMODULE hModule;
PFNSWITCHTOTHISWINDOW SwitchToThisWindow;
setlocale(LC_ALL, "");
_tprintf(_T("[*] 正在查找 UltraEdit 注册窗口。。。"));
hWindow = FindWindow(NULL, _T("互联网激活"));
if (!hWindow)
{
_tprintf(_T("失败\n"));
_tprintf(_T("退出。。。"));
return 1;
}
_tprintf(_T("成功,窗口句柄 = 0x%08lX\n"), hWindow);
_tprintf(_T("[*] 正在查找 \"脱机激活\" 按钮。。。"));
hButton = FindWindowEx(hWindow, NULL, NULL, _T("脱机激活(&O)"));
if (!hButton)
{
_tprintf(_T("失败\n"));
_tprintf(_T("退出。。。"));
return 1;
}
_tprintf(_T("成功,窗口句柄 = 0x%08lX\n"), hButton);
_tprintf(_T("[*] 正在尝试启用并显示 \"脱机激活\" 按钮。。。"));
dwStyle = GetWindowLong(hButton, GWL_STYLE);
dwStyle |= WS_VISIBLE;
dwStyle &= ~WS_DISABLED;
SetWindowLong(hButton, GWL_STYLE, dwStyle);
RedrawWindow(hWindow, NULL, NULL, RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);
_tprintf(_T("[*] 正在尝试模拟发送单击按钮消息。。。"));
dwButtonId = GetDlgCtrlID(hButton);
PostMessage(hWindow, WM_COMMAND, MAKELPARAM(dwButtonId, BN_CLICKED), NULL);
hModule = GetModuleHandle(_T("user32.dll"));
SwitchToThisWindow = (PFNSWITCHTOTHISWINDOW)GetProcAddress(hModule, "SwitchToThisWindow");
if (SwitchToThisWindow)
SwitchToThisWindow(hWindow, TRUE);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment