我的使用createremotethread控制excel右鍵的源程式 (轉)
利用CreateRemoteThread將dll寫進.exe.利用SetWindowLong()改變excel中右鍵訊息。dll源:#include <.h>
BOOL __stdcall DllMain(HANDLE,D,LPVOID)
{
return TRUE;
}
/*
#pragma data_seg("shared")
#pragma data_seg()
#pragma comment(linker,"/SECTION:shared,rws")
*/
WNDPROC g_lpfnOldWndProc;
HWND g_hMsgWnd;
LRESULT ENTRY HookExcelWndProc(HWND hWnd, UINT wMessage , WPARAM wParam, LPARAM lParam)
{
try
{
switch (wMessage)
{
case WM_RBUTTONDOWN:
MessageBox(g_hMsgWnd,"u click the r button","",MB_OK);
return 1;
break;
case WM_CLOSE:
::ExitProcess (0);
break;
default:
if (NULL == g_lpfnOldWndProc)
return DefWindowProc(hWnd,wMessage,wParam,lParam);
else
return CallWindowProc(g_lpfnOldWndProc,hWnd,wMessage,wParam,lParam);
}
}
catch(...)
{
}
return 0;
}
LRESULT __stdcall HookExcelRightMenu(HWND hwnd)
{
g_hMsgWnd = hwnd;
g_lpfnOldWndProc=(WNDPROC)::SetWindowLong(hwnd,GWL_WNDPROC,(LONG)HookExcelWndProc);
MSG msg;
while( ::GetMessage( &msg, NULL, 0, 0 ))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return TRUE;
}
注入程式源程式:#include
#include
const int MAXINJECTSIZE = 10240;
typedef HMODULE (__stdcall * LPLOADLIBRARY)(LPCTSTR);
typedef FROC (__stdcall * LPGETPROCADDRESS)(HMODULE,LPCTSTR);
typedef BOOL (__stdcall * LPFREELIBRARY)(HMODULE);
typedef LRESULT (__stdcall * LPHookExcelRightMenu)(HWND);
typedef struct
{
LPLOADLIBRARY prcLoadLib;
LPGETPROCADDRESS prcGetProcAddr;
LPFREELIBRARY prcFreeLib;
TCHAR sPath[MAX_PATH+1];
HWND hInjectWnd;
}INJECT_DLL,*LPINJECT_DLL;
DWORD GetProcessIdFromName(LPCTSTR name)
{
PROCESSENTRY32 pe;
DWORD id = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
pe.dwSize = sizeof(PROCESSENTRY32);
if( !Process32First(hSnapshot,&pe) )
return 0;
do
{
pe.dwSize = sizeof(PROCESSENTRY32);
if( Process32Next(hSnapshot,&pe)==FALSE )
break;
if(stricmp(pe.szExeFile,name) == 0)
{
id = pe.th32ProcessID;
break;
}
} while(1);
CloseHandle(hSnapshot);
return id;
}
void EnableDePriv( void )
{
HANDLE hToken;
LUID sedebugnameValue;
TOKEN_PRIVILEGES tkp;
if ( ! OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) )
return;
if ( ! LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue ) )
{
CloseHandle( hToken );
return;
}
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Luid = sedebugnameValue;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if ( ! AdjustTokenPrivileges( hToken, FALSE, &tkp, sizeof tkp, NULL, NULL ) )
CloseHandle( hToken );
}
#pragma check_stack(off)
static DWORD __stdcall ControlExcelThread(LPVOID lpVoid)
{
try
{
LPINJECT_DLL lpInject = (LPINJECT_DLL)lpVoid;
if (NULL == lpInject)
return -1;
HMODULE hMod = lpInject->prcLoadLib(lpInject->szLibPath);
if (NULL == hMod)
return -2;
LPHookExcelRightMenu lpHookExcelRightMenu;
lpHookExcelRightMenu = (LPHookExcelRightMenu)lpInject ->prcGetProcAddr (hMod,MAKEINTRE(1));
if ( !lpHookExcelRightMenu)
{
lpInject ->prcFreeLib (hMod);
return -3;
}
lpHookExcelRightMenu(lpInject->hInjectWnd);
lpInject ->prcFreeLib (hMod);
}
catch(...)
{
return -1;
}
return 0;
}
#pragma check_stack(on)
LRESULT InJectDllIntoProcess(LPCSTR pstrProcessName,HWND hwnd)
{
DWORD dwProcessID = 0;
// dwProcessID=GetProcessIdFromName(pstrProcessName);
GetWindowThreadProcessId(hwnd,&dwProcessID);
if ( dwProcessID < 1)
return -1;
EnableDebugPriv();
HANDLE hInjectTarget = OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessID);
if (!hInjectTarget)
return -2;
INJECT_DLL pstInjectDll ;
memset(&pstInjectDll,0x0,sizeof(INJECT_DLL));
HMODULE hModule = ::LoadLibrary (TEXT("kernel32"));
if (!hModule)
return -3;
pstInjectDll.prcLoadLib = (LPLOADLIBRARY)::GetProcAddress(hModule,TEXT("LoadLibraryA"));
pstInjectDll.prcFreeLib = (LPFREELIBRARY)::GetProcAddress(hModule,TEXT("FreeLibrary"));
pstInjectDll.prcGetProcAddr = (LPGETPROCADDRESS)::GetProcAddress (hModule,TEXT("GetProcAddress"));
pstInjectDll.hInjectWnd = hwnd;
lstrcpy(pstInjectDll.szLibPath ,TEXT("E:KDCPackupdllinjectdlldebuginjectdll.dll"));
LPBYTE lpExcelAddr = (LPBYTE)::VirtualAllocEx (hInjectTarget,NULL,MAXINJECTSIZE,MEM_COMMIT, PAGE_EXECUTE_READWRITE);
LPINJECT_DLL param = (LPINJECT_DLL) VirtualAllocEx( hInjectTarget, 0, sizeof(INJECT_DLL), MEM_COMMIT, PAGE_READWRITE );
WriteProcessMemory(hInjectTarget,lpExcelAddr,&ControlExcelThread,MAXINJECTSIZE,0);
WriteProcessMemory(hInjectTarget,param,&pstInjectDll,sizeof(INJECT_DLL),0);
DWORD dwThreadId = 0;
HANDLE hInjectThread;
try
{
hInjectThread= ::CreateRemoteThread (hInjectTarget,NULL,0,(LPTHREAD_START_ROUTINE)lpExcelAddr,param,0,&dwThreadId);
}
catch(...)
{
}
if (!hInjectThread)
dwThreadId = ::GetLastError ();
else
CloseHandle(hInjectThread);
CloseHandle(hInjectTarget);
::VirtualFreeEx (hInjectTarget,lpExcelAddr,0,MEM_RELEASE);
::VirtualFreeEx (hInjectTarget,param,0,MEM_RELEASE);
return 0;
}
void main()
{
HWND hwnd;
hwnd = FindWindowEx(NULL,NULL,"XLMAIN",NULL);
if (hwnd)
{
hwnd = FindWindowEx(hwnd,NULL,"XLDESK",NULL);
if (hwnd)
{
hwnd = FindWindowEx(hwnd,NULL,"EXCEL7",NULL);
InJectDllIntoProcess("excel.exe",hwnd);
}
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-963042/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 將自已的程式加到滑鼠右鍵選單裡(轉)
- 右鍵新建裡面沒有word和excel 右鍵新建word不見了Excel
- 關聯自己的應用程式到右鍵選單中 (轉)
- 使用 zTree 右鍵選單功能的總結
- 利用熱鍵控制滑鼠移動的一個程式 (轉)
- jQuery實現的禁用右鍵選單程式碼jQuery
- jquery禁止在頁面使用滑鼠右鍵程式碼示例jQuery
- 如何使用jQuery禁用滑鼠右鍵jQuery
- 禁止網頁使用滑鼠右鍵網頁
- 解決Excel中右鍵選單中部分功能不可用的方法Excel
- 使用tcom控制ExcelExcel
- win10右鍵開啟方式找不到excel如何解決_win10系統右鍵開啟方式沒有excel解決方法Win10Excel
- C#將自己的程式新增到右鍵選單C#
- Excel 的VB程式設計 (轉)Excel程式設計
- 電腦點選右鍵控制皮膚沒反應怎麼回事_滑鼠右鍵控制皮膚沒反應如何解決
- 工程專案成本控制的關鍵(轉)
- 禁用滑鼠右鍵例項程式碼
- 我的程式觀 (轉)
- windows右鍵選單擴充套件容器[開源]Windows套件
- jQuery實現的禁用右鍵選單程式碼例項jQuery
- BCB:TEdit控制元件右對齊的簡單實現 (轉)控制元件
- 右鍵選單中的文字文件新增快捷鍵
- Dynamics 365 控制右側欄的介面
- Mac使用技巧:Excel中使用頻率較高的快捷鍵MacExcel
- jQuery禁用滑鼠右鍵程式碼例項jQuery
- javascript自定義右鍵選單程式碼JavaScript
- 自定義 IE 滑鼠右鍵彈出式 (轉)
- 使用mousedown事件使用右鍵觸發無反應事件
- Dos下鍵盤的完全控制 ------- 一系列的BIOS級別的鍵盤控制函式! (轉)iOS函式
- win10為什麼桌面右鍵假死 win10桌面右鍵假死的方法Win10
- 我把這個賊好用的Excel匯出工具開源了!!Excel
- 禁用TwebBrowser右鍵Web
- Win7 CreateRemoteThread 另類使用方法Win7REMthread
- 如何透過報表單元格右鍵控制報表跳轉到不同連結地址
- 控制元件treeview的使用 (轉)控制元件View
- win10桌面點右鍵一直轉圈怎麼辦_win10點選滑鼠右鍵一直轉圈的解決方法Win10
- HACCP原理——關鍵控制點的監控(轉載)
- 遮蔽滑鼠右鍵選單例項程式碼單例