📄 shellinj.c
字号:
which is more useful. */
pGlobalCopy->rMinRect.left = p->MinRect.Left;
pGlobalCopy->rMinRect.top = p->MinRect.Top;
pGlobalCopy->rMinRect.right = p->MinRect.Right;
pGlobalCopy->rMinRect.bottom= p->MinRect.Bottom;
ReleaseSharedMemPtr();
for (loop = 0; loop < MyCopy.nClientWnds; loop++)
PostMessage(MyCopy.hClientWnds[loop],
MyCopy.wmClientMsgs[loop], wParam,
(LPARAM)p->hWin);
return BaseClassResult;
}
else
{
for (loop = 0; loop < MyCopy.nClientWnds; loop++)
PostMessage(MyCopy.hClientWnds[loop],
MyCopy.wmClientMsgs[loop], wParam, lParam);
}
}
else if (Msg == wm_DecCount) {
SharedMemory *pInfo = GetSharedMemPtr();
int nUsers = pInfo->nUsers;
ReleaseSharedMemPtr();
if (nUsers == 0)
UnsubclassShell();
return 0;
}
return CallWindowProc((WNDPROC)g_OrgShellWndProc,
hWnd, Msg, wParam, lParam);
}
BOOL SubclassShell( void )
{
HWND h;
if (!g_bShellSubclassed) {
g_bShellSubclassed = TRUE;
wm_ShellHook = RegisterWindowMessage("SHELLHOOK");
wm_DecCount = RegisterWindowMessage("SI_DEC");
h = GetShellWnd("Shell_TrayWnd;MSTaskSwWClass");
if (!h) //must be Win98 or Win95 with IE4
h = GetShellWnd(
"Shell_TrayWnd;ReBarWindow32;MSTaskSwWClass");
if (h) {
SharedMemory *pInfo;
SetupSharedMemMap();
pInfo = GetSharedMemPtr();
pInfo->hShellHookCatcher = h;
ReleaseSharedMemPtr();
g_OrgShellWndProc = GetWindowLong(h, GWL_WNDPROC);
SetWindowLong(h, GWL_WNDPROC, (LONG)ShellHookCatcher);
/* *** you can subclass other shell windows here */
return TRUE;
}
else
return FALSE;
}
else
return FALSE;
}
void UnsubclassShell( void )
{
if (g_bShellSubclassed) {
SharedMemory *p = GetSharedMemPtr();
HWND h = p->hShellHookCatcher;
ReleaseSharedMemPtr();
SetWindowLong(h, GWL_WNDPROC, g_OrgShellWndProc);
g_bShellSubclassed = FALSE;
/* *** un-subclass other shell windows here */
ShutdownSharedMemMap();
}
}
/****** COM Object / DllMain Functions ******/
/* These functions implement the four exported COM
functions, as well as DllMain(). With the exception of
DllUnregisterServer(), the COM functions are only called
from the shell's address space. */
/*utility functions*/
/* RegDeleteKey2 is like the RegDeleteKey API function,
except this version will also remove all of this key's
subkeys. (RegDeleteKey won't delete subkeys under NT.) */
LONG RegDeleteKey2(HKEY hKeyParent, LPCTSTR lpszKeyChild)
{
FILETIME time;
char buffer[256];
DWORD dwSize;
/* open the child key */
HKEY hKeyChild;
long result = RegOpenKeyEx(hKeyParent, lpszKeyChild, 0,
KEY_ALL_ACCESS, &hKeyChild);
if (result != ERROR_SUCCESS)
return result;
/* Enumerate all of the descendents of this child. */
dwSize = sizeof(buffer);
while (RegEnumKeyEx(hKeyChild, 0, buffer, &dwSize, NULL,
NULL, NULL, &time) == ERROR_SUCCESS) {
/* delete the descendents of this child */
result = RegDeleteKey2(hKeyChild, buffer);
if (result != ERROR_SUCCESS) {
/* cleanup before exiting */
RegCloseKey(hKeyChild);
return result;
}
dwSize = sizeof(buffer);
}
/* close this child key */
RegCloseKey(hKeyChild);
/* delete this child key */
return RegDeleteKey(hKeyParent, lpszKeyChild);
}
/* CLSIDstring converts a CLSID to a char string */
char* CLSIDstring(REFCLSID clsid, char* buf, int bufsize)
{
/* Get a Unicode version of the CLSID string */
LPOLESTR pWideCLSID = NULL;
HRESULT hresult = StringFromCLSID(clsid, &pWideCLSID);
assert(SUCCEEDED(hresult) && (pWideCLSID != NULL));
/* convert to non-Unicode characters */
assert(bufsize >= 39);
wcstombs(buf, pWideCLSID, bufsize);
/* free the Unicode version of the string */
CoTaskMemFree(pWideCLSID);
return buf;
}
/* SetKeyAndValue creates a key and/or sets its value. */
BOOL SetKeyAndValue(const char* szKey, const char* szSubkey,
const char* szValue, const char *szValueName)
{
HKEY hKey;
char KeyNameBuf[1024];
long result;
wsprintf(KeyNameBuf, "%s%s%s", szKey,
(szSubkey?"\\":""), (szSubkey?szSubkey:""));
result = RegCreateKeyEx(HKEY_CLASSES_ROOT,
KeyNameBuf, 0, NULL, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &hKey, NULL);
if (result == ERROR_SUCCESS) {
if (szValue != NULL)
RegSetValueEx(hKey, szValueName, 0, REG_SZ,
(BYTE*)szValue, lstrlen(szValue)+1);
RegCloseKey(hKey);
return TRUE;
}
else
return FALSE;
}
/* DllCanUnloadNow() Returns S_OK if the DLL can unload now */
STDAPI DllCanUnloadNow( void )
{
if (g_bShellSubclassed)
return S_FALSE;
else
{ /* NOTE! normal COM-server DLLs would NOT call
DllUnregisterServer() directly, AT ANY TIME. It
is normally only called by installation programs.
This is a "special" DLL, though, and having it
unregister itself is more convenient than having
to do it from another program. */
DllUnregisterServer();
return S_OK;
}
}
/* Traditionally, DllGetClassObject() gets a pointer to the
requested COM object. This version always returns an error.*/
#ifdef __BORLANDC__
# pragma argsused
#endif
STDAPI DllGetClassObject(REFCLSID clsid,
REFIID iid, void** ppv)
{
SubclassShell();
return CLASS_E_CLASSNOTAVAILABLE;
}
/* DllRegisterServer() stores the COM info in the registry */
STDAPI DllRegisterServer( void )
{
char szKey[512], szClassID[512], szModule[512];
/* Get the location of this DLL */
GetModuleFileName(g_hModule, szModule, sizeof(szModule));
/* create the registry-key name for this CLSID */
wsprintf(szKey, "CLSID\\%s", CLSIDstring(
REFERENCE(CLSID_ShellInjector), szClassID, sizeof(szClassID)) );
/* create the CLSID main registry key */
SetKeyAndValue(szKey, NULL, szFriendlyName, NULL);
/* add the filename under the main key */
SetKeyAndValue(szKey, "InprocServer32", szModule, NULL);
/* Add a threading-model indicator value. This isn't
documented as being necessary for SHLoadInProc, but is */
SetKeyAndValue(szKey, "InprocServer32", "Apartment",
"ThreadingModel");
return S_OK;
}
/* DllUnregisterServer() removes COM info from the registry */
STDAPI DllUnregisterServer()
{
/* create the registry-key name for this CLSID */
char szKey[512], szClassID[512];
wsprintf(szKey, "CLSID\\%s", CLSIDstring(
REFERENCE(CLSID_ShellInjector), szClassID, sizeof(szClassID)) );
/* remove the key and all subkeys */
RegDeleteKey2(HKEY_CLASSES_ROOT, szKey);
return S_OK;
}
/* DllMain - DLL entry point (called by both shell and user)*/
#ifdef __BORLANDC__
# pragma argsused
#endif
#ifdef __cplusplus
extern "C"
#endif
__declspec( dllexport ) BOOL APIENTRY DllMain(
HANDLE hModule, DWORD dwReason, void *Reserved)
{
// Reserved; /* avoid "parameter not used" warning */
if (dwReason == DLL_PROCESS_ATTACH)
g_hModule = (HINSTANCE)hModule;
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -