/******************************************************************************
Module: DIPSLib.cpp
Notices: Copyright (c) 2000 Jeffrey Richter
******************************************************************************/
#include "..\CmnHdr.h" /* See Appendix A. */
#include <WindowsX.h>
#include <CommCtrl.h>
#define DIPSLIBAPI __declspec(dllexport)
#include "DIPSLib.h"
#include "Resource.h"
///////////////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
// This function forces the debugger to be invoked
void ForceDebugBreak() {
__try { DebugBreak(); }
__except(UnhandledExceptionFilter(GetExceptionInformation())) { }
}
#else
#define ForceDebugBreak()
#endif
///////////////////////////////////////////////////////////////////////////////
// Forward references
LRESULT WINAPI GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam);
INT_PTR WINAPI Dlg_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
///////////////////////////////////////////////////////////////////////////////
// Instruct the compiler to put the g_hhook data variable in
// its own data section called Shared. We then instruct the
// linker that we want to share the data in this section
// with all instances of this application.
#pragma data_seg("Shared")
HHOOK g_hhook = NULL;
DWORD g_dwThreadIdDIPS = 0;
#pragma data_seg()
// Instruct the linker to make the Shared section
// readable, writable, and shared.
#pragma comment(linker, "/section:Shared,rws")
///////////////////////////////////////////////////////////////////////////////
// Nonshared variables
HINSTANCE g_hinstDll = NULL;
///////////////////////////////////////////////////////////////////////////////
BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, PVOID fImpLoad) {
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
// DLL is attaching to the address space of the current process.
g_hinstDll = hinstDll;
break;
case DLL_THREAD_ATTACH:
// A new thread is being created in the current process.
break;
case DLL_THREAD_DETACH:
// A thread is exiting cleanly.
break;
case DLL_PROCESS_DETACH:
// The calling process is detaching the DLL from its address space.
break;
}
return(TRUE);
}
///////////////////////////////////////////////////////////////////////////////
BOOL WINAPI SetDIPSHook(DWORD dwThreadId) {
BOOL fOk = FALSE;
if (dwThreadId != 0) {
// Make sure that the hook is not already installed.
chASSERT(g_hhook == NULL);
// Save our thread ID in a shared variable so that our GetMsgProc
// function can post a message back to to thread when the server
// window has been created.
g_dwThreadIdDIPS = GetCurrentThreadId();
// Install the hook on the specified thread
g_hhook = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, g_hinstDll,
dwThreadId);
fOk = (g_hhook != NULL);
if (fOk) {
// The hook was installed successfully; force a benign message to
// the thread's queue so that the hook function gets called.
fOk = PostThreadMessage(dwThreadId, WM_NULL, 0, 0);
}
} else {
// Make sure that a hook has been installed.
chASSERT(g_hhook != NULL);
fOk = UnhookWindowsHookEx(g_hhook);
g_hhook = NULL;
}
return(fOk);
}
///////////////////////////////////////////////////////////////////////////////
LRESULT WINAPI GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam) {
static BOOL fFirstTime = TRUE;
if (fFirstTime) {
// The DLL just got injected.
fFirstTime = FALSE;
// Uncomment the line below to invoke the debugger
// on the process that just got the injected DLL.
// ForceDebugBreak();
// Create the DTIS Server window to handle the client request.
CreateDialog(g_hinstDll, MAKEINTRESOURCE(IDD_DIPS), NULL, Dlg_Proc);
// Tell the DIPS application that the server is up
// and ready to handle requests.
PostThreadMessage(g_dwThreadIdDIPS, WM_NULL, 0, 0);
}
return(CallNextHookEx(g_hhook, nCode, wParam, lParam));
}
///////////////////////////////////////////////////////////////////////////////
void Dlg_OnClose(HWND hwnd) {
DestroyWindow(hwnd);
}
///////////////////////////////////////////////////////////////////////////////
static const TCHAR g_szRegSubKey[] =
TEXT("Software\\Richter\\Desktop Item Position Saver");
///////////////////////////////////////////////////////////////////////////////
void SaveListViewItemPositions(HWND hwndLV) {
int nMaxItems = ListView_GetItemCount(hwndLV);
// When saving new positions, delete the old position
// information that is currently in the registry.
LONG l = RegDeleteKey(HKEY_CURRENT_USER, g_szRegSubKey);
// Create the registry key to hold the info
HKEY hkey;
l = RegCreateKeyEx(HKEY_CURRENT_USER, g_szRegSubKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hkey, NULL);
chASSERT(l == ERROR_SUCCESS);
for (int nItem = 0; nItem < nMaxItems; nItem++) {
// Get the name and position of a ListView item.
TCHAR szName[MAX_PATH];
ListView_GetItemText(hwndLV, nItem, 0, szName, chDIMOF(szName));
POINT pt;
ListView_GetItemPosition(hwndLV, nItem, &pt);
// Save the name and position in the registry.
l = RegSetValueEx(hkey, szName, 0, REG_BINARY, (PBYTE) &pt, sizeof(pt));
chASSERT(l == ERROR_SUCCESS);
}
RegCloseKey(hkey);
}
///////////////////////////////////////////////////////////////////////////////
void RestoreListViewItemPositions(HWND hwndLV) {
HKEY hkey;
LONG l = RegOpenKeyEx(HKEY_CURRENT_USER, g_szRegSubKey,
0, KEY_QUERY_VALUE, &hkey);
if (l == ERROR_SUCCESS) {
// If the ListView has AutoArrange on, temporarily turn it off.
DWORD dwStyle = GetWindowStyle(hwndLV);
if (dwStyle & LVS_AUTOARRANGE)
SetWindowLong(hwndLV, GWL_STYLE, dwStyle & ~LVS_AUTOARRANGE);
l = NO_ERROR;
for (int nIndex = 0; l != ERROR_NO_MORE_ITEMS; nIndex++) {
TCHAR szName[MAX_PATH];
DWORD cbValueName = chDIMOF(szName);
POINT pt;
DWORD cbData = sizeof(pt), nItem;
// Read a value name and position from the registry.
DWORD dwType;
l = RegEnumValue(hkey, nIndex, szName, &cbValueName,
NULL, &dwType, (PBYTE) &pt, &cbData);
if (l == ERROR_NO_MORE_ITEMS)
continue;
if ((dwType == REG_BINARY) && (cbData == sizeof(pt))) {
// The value is something that we recognize; try to find
// an item in the ListView control that matches the name.
LV_FINDINFO lvfi;
lvfi.flags = LVFI_STRING;
lvfi.psz = szName;
nItem = ListView_FindItem(hwndLV, -1, &lvfi);
if (nItem != -1) {
// We found a match; change the item's position.
ListView_SetItemPosition(hwndLV, nItem, pt.x, pt.y);
}
}
}
// Turn AutoArrange back on if it was originally on.
SetWindowLong(hwndLV, GWL_STYLE, dwStyle);
RegCloseKey(hkey);
}
}
///////////////////////////////////////////////////////////////////////////////
INT_PTR WINAPI Dlg_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
chHANDLE_DLGMSG(hwnd, WM_CLOSE, Dlg_OnClose);
case WM_APP:
// Uncomment the line below to invoke the debugger
// on the process that just got the injected DLL.
// ForceDebugBreak();
if (lParam)
SaveListViewItemPo
没有合适的资源?快使用搜索试试~ 我知道了~
hook example
共47个文件
h:4个
idb:4个
pdb:4个
需积分: 9 52 下载量 56 浏览量
2008-02-14
23:42:16
上传
评论
收藏 3.58MB RAR 举报
温馨提示
example for hooking example for hooking example for hooking
资源推荐
资源详情
资源评论
收起资源包目录
22.rar (47个子文件)
22-DIPSLib
22 DIPSLib.dsp 7KB
DIPSLib.rc 2KB
22 DIPSLib.vcproj 9KB
DIPSLib.aps 17KB
22 DIPSLib.dsw 545B
DIPSLib.cpp 8KB
22 DIPSLib.opt 48KB
Debug
vc70.idb 115KB
vc60.pdb 100KB
DIPSLib.res 144B
vc60.idb 265KB
DIPSLib.obj 186KB
vc70.pdb 580KB
BuildLog.htm 3KB
DIPSLib.sbr 0B
22 DIPSLib.pch 6MB
22 DIPSLib.suo 10KB
22 DIPSLib.sln 1KB
DIPSLib.h 569B
22 DIPSLib.plg 2KB
Resource.h 456B
22 DIPSLib.ncb 27KB
22-DIPS
22 DIPS.dsp 7KB
22 DIPS.opt 48KB
22 DIPS.vcproj 8KB
22 DIPS.plg 1KB
DIPS.APS 19KB
22 DIPS.sln 1KB
DIPS.ICO 766B
DIPS.CPP 4KB
22 DIPSLib.lib 2KB
Debug
DIPS.sbr 0B
vc70.idb 115KB
vc60.pdb 100KB
Dips.obj 172KB
vc60.idb 185KB
vc70.pdb 556KB
BuildLog.htm 2KB
DIPS.res 2KB
22 DIPS.pch 5.69MB
22 DIPS.dsw 539B
22 DIPS.suo 11KB
DIPS.RC 3KB
Resource.h 587B
22 DIPSLib.dll 100KB
22 DIPS.ncb 27KB
CmnHdr.h 8KB
共 47 条
- 1
资源评论
ingor
- 粉丝: 7
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功