C语言实现HOOK窗口过程
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C语言实现HOOK窗口过程
#include
DWORD dwMyProcessId;
DWORD dwImageBase;
DWORD dwImageSize;
DWORD dwMsgThread;
wchar_t dbgBuffer[8192];
#define DBG_MSG(format,...) {\
wsprintfW(dbgBuffer, format, __VA_ARGS__); \
OutputDebugString(dbgBuffer); \
}
typedef struct
{
LPARAM lparam;
WNDPROC orgiProc;
}WndData;
BOOL EnableSpecificPrivilege(BOOL bEnable, LPCTSTR Name)
{
BOOL bResult = FALSE;
HANDLE hToken;
TOKEN_PRIVILEGES TokenPrivileges;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken) == 0)
{
return FALSE;
}
TokenPrivileges.PrivilegeCount = 1;
TokenPrivileges.Privileges[0].Attributes = bEnable ? SE_PRIVILEGE_ENABLED : 0;
bResult = LookupPrivilegeValue(NULL, Name, &TokenPrivileges.Privileges[0].Luid);
if (!bResult)
{
CloseHandle(hToken);
return FALSE;
}
bResult = AdjustTokenPrivileges(hToken, FALSE, &TokenPrivileges,
sizeof(TOKEN_PRIVILEGES), NULL, NULL);
if (GetLastError() != ERROR_SUCCESS || !bResult)
{
CloseHandle(hToken);
return FALSE;
}
CloseHandle(hToken);
return TRUE;
}
DWORD EnableAllPrivilege(BOOL bEnable)
{
DWORD count = 0;
///
count += EnableSpecificPrivilege(bEnable, SE_ASSIGNPRIMARYTOKEN_NAME);
count += EnableSpecificPrivilege(bEnable, SE_AUDIT_NAME);
count += EnableSpecificPrivilege(bEnable, SE_BACKUP_NAME);
count += EnableSpecificPrivilege(bEnable, SE_CHANGE_NOTIFY_NAME);
count += EnableSpecificPrivilege(bEnable, SE_CREATE_PAGEFILE_NAME);
count += EnableSpecificPrivilege(bEnable, SE_CREATE_PERMANENT_NAME);
count += EnableSpecificPrivilege(bEnable, SE_CREATE_TOKEN_NAME);
count += EnableSpecificPrivilege(bEnable, SE_DEBUG_NAME);
count += EnableSpecificPrivilege(bEnable, SE_INC_BASE_PRIORITY_NAME);
count += EnableSpecificPrivilege(bEnable, SE_INCREASE_QUOTA_NAME);
count += EnableSpecificPrivilege(bEnable, SE_LOAD_DRIVER_NAME);
count += EnableSpecificPrivilege(bEnable, SE_LOCK_MEMORY_NAME);
count += EnableSpecificPrivilege(bEnable, SE_PROF_SINGLE_PROCESS_NAME);
count += EnableSpecificPrivilege(bEnable, SE_REMOTE_SHUTDOWN_NAME);
count += EnableSpecificPrivilege(bEnable, SE_RESTORE_NAME);
count += EnableSpecificPrivilege(bEnable, SE_SECURITY_NAME);
count += EnableSpecificPrivilege(bEnable, SE_SHUTDOWN_NAME);
count += EnableSpecificPrivilege(bEnable, SE_SYSTEM_ENVIRONMENT_NAME);
count += EnableSpecificPrivilege(bEnable, SE_SYSTEM_PROFILE_NAME);
count += EnableSpecificPrivilege(bEnable, SE_SYSTEMTIME_NAME);
count += EnableSpecificPrivilege(bEnable, SE_TAKE_OWNERSHIP_NAME);
count += EnableSpecificPrivilege(bEnable, SE_TCB_NAME);
count += EnableSpecificPrivilege(bEnable, SE_UNSOLICITED_INPUT_NAME);
count += EnableSpecificPrivilege(bEnable, SE_MACHINE_ACCOUNT_NAME);
return count;
}
BOOL GetMouduleRanage(wchar_t* pModName, DWORD *pdwBase, DWORD *size)
{