15,978
社区成员
发帖
与我相关
我的任务
分享
#include <afx.h>
#include <windows.h>
#include <fstream>
#include <stdio.h>
#include <commctrl.h>
#include <tchar.h>
#include <iostream>
#include <string>
#pragma data_seg("MySec")
HHOOK g_hMouse=NULL;
//HWND g_hWnd=NULL;
HANDLE g_HInst = NULL;
#pragma data_seg()
#pragma comment(linker,"/section:MySec,RWS")
using namespace std;
RECT IcoRectArray[50];
int IconRectCount=0;
bool RefreshDesk()
{
//提权
HANDLE hToken;
HANDLE hProcess = GetCurrentProcess();
if ( OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken) )
{
TOKEN_PRIVILEGES tkp;
if ( LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid) )
{
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
BOOL bREt = AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0) ;
}
CloseHandle(hToken);
}
//定义变量
CString IcoNamesArrary[10];
//打开配置文件,获取其中的内容
fstream file;
file.open("G:\\word.txt");
string str;
file >> str;
file.close();
//cout << str;
//cout << endl;
//删除分隔符,将每条信息存入数组中
for (int i=0,j=0;i!=str.size();i++)
{
if (str[i]!='|')
{
IcoNamesArrary[j] += str[i];
}
else
{
j++;
}
}
//获取桌面图标信息
HWND listview = FindWindow(_T("progman"), NULL);
listview = FindWindowEx(listview, 0, _T("shelldll_defview"), NULL);
listview = FindWindowEx(listview, 0, _T("syslistview32"), NULL);
//int count=(int)SendMessage(listview, LVM_GETITEMCOUNT, 0, 0);
int count = ListView_GetItemCount(listview);
LVITEM lvi, *_lvi;
memset(&lvi, 0, sizeof(LVITEM));
WCHAR item[512];
WCHAR *_item;
unsigned long pid;
HANDLE process;
GetWindowThreadProcessId(listview, &pid);
process=OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
_lvi=(LVITEM*)VirtualAllocEx(process, NULL, 100,
MEM_COMMIT, PAGE_READWRITE);
_item=(WCHAR *)VirtualAllocEx(process, NULL, 256, MEM_COMMIT,
PAGE_READWRITE);
RECT rc;
rc.left = LVIR_ICON; //这个一定要设定 可以去看MSDN关于LVM_GETITEMRECT的说明
RECT* _rc =(RECT*)VirtualAllocEx( process, NULL, sizeof(RECT), MEM_COMMIT, PAGE_READWRITE);
lvi.mask = LVIF_TEXT;
lvi.cchTextMax=200;
lvi.pszText=(LPWSTR)_item;
lvi.iSubItem=0;
for(int i=0; i<count; i++)
{
DWORD size = 0;
//bool writeres = WriteProcessMemory(process, _lvi, &lvi, sizeof(lvi), &size);
WriteProcessMemory(process, _lvi, &lvi, sizeof(lvi), &size);
int retlen =SendMessage(listview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
//bool readres = ReadProcessMemory(process, _item, item, 256, &size);
ReadProcessMemory(process, _item, item, 256, &size);
::WriteProcessMemory( process, _rc, &rc, sizeof(rc), NULL);
::SendMessage( listview, LVM_GETITEMRECT, (WPARAM)i, (LPARAM)_rc);
ReadProcessMemory(process, _rc, &rc, sizeof(rc), NULL);
WCHAR ItemText[1000]={0};
CString strItemText(ItemText);
strItemText.MakeLower();
for (int n = 0;n < 10; n++)
{
if(!IcoNamesArrary[n].IsEmpty() && strItemText==IcoNamesArrary[n])
{
IcoRectArray[IconRectCount].left = rc.left;
IcoRectArray[IconRectCount].top = rc.top;
IcoRectArray[IconRectCount].right = rc.right;
IcoRectArray[IconRectCount].bottom = rc.bottom;
IconRectCount++;
}
}
}
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);
VirtualFreeEx(process, _rc, 0, MEM_RELEASE);
CloseHandle( process );
return true;
}
//鼠标钩子
LRESULT CALLBACK MouseProc(
int nCode,
WPARAM wParam,
LPARAM lParam
)
{
//定义一个鼠标HOOK结构体
MSLLHOOKSTRUCT *m = (MSLLHOOKSTRUCT *)lParam;
POINT pt = m->pt;
for (IconRectCount;IconRectCount<10;IconRectCount++)
{
if (pt.x>=IcoRectArray[IconRectCount].left&&pt.x<=IcoRectArray[IconRectCount].right&&
pt.y>=IcoRectArray[IconRectCount].top&&pt.y<=IcoRectArray[IconRectCount].bottom)
{
return TRUE;
}
}
return CallNextHookEx(g_hMouse,nCode,wParam,lParam);
}
_declspec(dllexport) void SetHook()
{
RefreshDesk();
g_hMouse = SetWindowsHookEx(WH_MOUSE_LL,MouseProc,GetModuleHandle(_T("desk")),0);
//g_hWnd = hwnd;
}