dllmain.c
上传用户:yinuo83
上传日期:2007-01-08
资源大小:36k
文件大小:16k
源码类别:

钩子与API截获

开发平台:

C/C++

  1. #include <windows.h>
  2. #include <STDIO.H>
  3. HHOOK hMouseHook;
  4. LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam);
  5. static char fname[64],modulename[64],trash[640];
  6. static BOOL  BeenHooked=FALSE;
  7. BOOL flag=FALSE;
  8. DWORD SysFunc1,SysFunc2,SysFunc3,SysFunc4;
  9. DWORD MyFunc1,MyFunc2,MyFunc3,MyFunc4;
  10. BOOL ChangeFuncEntry(HANDLE,int);
  11. BOOL IsSysDll(char *name);
  12. void SendText(HDC hdc,LPCSTR lpszString,UINT cbString);
  13. //list all modules
  14. char modules[100][16];
  15. static int index=0;
  16. static RECT  rect;
  17. BOOL APIENTRY DllMain(HANDLE hModule,DWORD reason,LPVOID lpReserved)
  18. {
  19. switch( reason )
  20. {
  21. case DLL_PROCESS_ATTACH:
  22. GetModuleFileName(GetModuleHandle(NULL),modulename,64);
  23. CharLower(modulename);
  24. //MessageBox(NULL,modulename,"inject into process",MB_OK);
  25. //wsprintf(trash,"%ld %ldn%ld %ldn%ld %ldn%ld %ld",SysFunc1,MyFunc1,SysFunc2,MyFunc2,SysFunc3,MyFunc3,SysFunc4,MyFunc4);
  26. //MessageBox(NULL,"",trash,MB_OK);
  27. /*if(strcmp(modulename,"notepad.exe"))
  28. flag=TRUE;
  29. MessageBox(NULL,modulename,"inject into process",MB_OK);*/
  30. break;
  31. case DLL_PROCESS_DETACH:
  32. break;
  33. }
  34.     return TRUE;
  35. }
  36. BOOL InstallMouseHook() 
  37. {
  38. hMouseHook =SetWindowsHookEx(WH_MOUSE,(HOOKPROC)MouseProc,GetModuleHandle("hookdll.dll"),0);//GetCurrentThreadId());
  39. if ( hMouseHook == NULL)
  40. return FALSE;
  41.     return TRUE ;
  42. }
  43. BOOL UninstallMouseHook()
  44. {
  45. UnhookWindowsHookEx(hMouseHook);
  46. return TRUE;
  47. }
  48. LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
  49. {
  50. LPMOUSEHOOKSTRUCT lpMouseHookStruct;
  51. HWND hwnd;
  52. POINT MousePoint;
  53. static POINT old;
  54. int i;
  55. char modulelist[1600];
  56. DWORD base;
  57. MEMORY_BASIC_INFORMATION    mbi;
  58. //"E:Program FilesDevStudioSharedIDEbinMsdev.exe"
  59. //"c:\temp\testhook\debug\testhook.exe"
  60. if (nCode < 0)  // do not process the message 
  61. return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
  62. //if(strcmp(modulename,"c:\notepad.exe"))
  63. // return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
  64. base=0;
  65. while(VirtualQuery (base, &mbi, sizeof (mbi))>0)
  66. {
  67. if(mbi.Type==MEM_IMAGE)
  68. ChangeFuncEntry((DWORD)mbi.BaseAddress,1);
  69. base=(DWORD)mbi.BaseAddress+mbi.RegionSize;
  70. }
  71. //if(!BeenHooked)
  72. {
  73. /*BeenHooked=TRUE;
  74. ChangeFuncEntry(GetModuleHandle(NULL),1);
  75. ChangeFuncEntry(GetModuleHandle("imm32.dll"),1);
  76. ChangeFuncEntry(GetModuleHandle("comctl32.dll"),1);
  77. ChangeFuncEntry(GetModuleHandle("shell32.dll"),1);
  78. ChangeFuncEntry(GetModuleHandle("comdlg32.dll"),1);
  79. ChangeFuncEntry(GetModuleHandle("advapi32.dll"),1);
  80. ChangeFuncEntry(GetModuleHandle("rpcrt4.dll"),1);
  81. ChangeFuncEntry(GetModuleHandle("user32.dll"),1);
  82. ChangeFuncEntry(GetModuleHandle("kernel32.dll"),1);
  83. ChangeFuncEntry(GetModuleHandle("ntdll.dll"),1);
  84. ChangeFuncEntry(GetModuleHandle("msvcrt.dll"),1);
  85. //for msdev
  86. ChangeFuncEntry(GetModuleHandle("devshl.dll"),1);
  87. ChangeFuncEntry(GetModuleHandle("mfc42.dll"),1);
  88. ChangeFuncEntry(GetModuleHandle("oleaut32.dll"),1);
  89. ChangeFuncEntry(GetModuleHandle("lz32.dll"),1);
  90. ChangeFuncEntry(GetModuleHandle("version.dll"),1);
  91. ChangeFuncEntry(GetModuleHandle("ole32.dll"),1);
  92. */
  93. /*UnChangeFuncEntry(GetModuleHandle(NULL));
  94. UnChangeFuncEntry(GetModuleHandle("imm32.dll"));
  95. UnChangeFuncEntry(GetModuleHandle("comctl32.dll"));
  96. UnChangeFuncEntry(GetModuleHandle("shell32.dll"));
  97. UnChangeFuncEntry(GetModuleHandle("comdlg32.dll"));
  98. UnChangeFuncEntry(GetModuleHandle("advapi32.dll"));
  99. UnChangeFuncEntry(GetModuleHandle("rpcrt4.dll"));
  100. UnChangeFuncEntry(GetModuleHandle("user32.dll"));
  101. UnChangeFuncEntry(GetModuleHandle("kernel32.dll"));
  102. UnChangeFuncEntry(GetModuleHandle("ntdll.dll"));
  103. UnChangeFuncEntry(GetModuleHandle("msvcrt.dll"));
  104. //for msdev
  105. UnChangeFuncEntry(GetModuleHandle("devshl.dll"));
  106. UnChangeFuncEntry(GetModuleHandle("mfc42.dll"));
  107. UnChangeFuncEntry(GetModuleHandle("oleaut32.dll"));
  108. UnChangeFuncEntry(GetModuleHandle("lz32.dll"));
  109. UnChangeFuncEntry(GetModuleHandle("version.dll"));
  110. UnChangeFuncEntry(GetModuleHandle("ole32.dll"));
  111. */
  112. }
  113.  
  114.    if ( wParam == WM_MOUSEMOVE ) {
  115.  lpMouseHookStruct = (LPMOUSEHOOKSTRUCT)lParam;
  116.  MousePoint=lpMouseHookStruct->pt;
  117.  //if(old.x==MousePoint.x&&old.y==MousePoint.y)
  118.  //  return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
  119.  old.x=MousePoint.x;
  120.  old.y=MousePoint.y;
  121.  hwnd=WindowFromPoint(MousePoint);
  122.  ScreenToClient(hwnd,&MousePoint);
  123.  rect.left=MousePoint.x-100;
  124.  rect.top=MousePoint.y-3;
  125.  rect.right=MousePoint.x+100;
  126.  rect.bottom=MousePoint.y+3;
  127.  InvalidateRect(hwnd,&rect,FALSE);
  128.  //InvalidateRect(hwnd,NULL,FALSE);
  129.  }
  130.  return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
  131. }
  132. BOOL ChangeFuncEntry(HMODULE hmodule,int level)
  133. {
  134.     PIMAGE_DOS_HEADER pDOSHeader;
  135.     PIMAGE_NT_HEADERS pNTHeader;
  136.     PIMAGE_IMPORT_DESCRIPTOR pImportDesc;
  137. BOOL bSuccess = FALSE;
  138. char buffer[1024],buffer1[1024];
  139.     static int times=0;
  140. //int i,j;
  141.     BOOL you=FALSE;
  142. DWORD MyFunc1; 
  143.     DWORD dwProtect,temp;
  144. /*if(!strcmp(modulename,"c:\notepad.exe"))
  145. {
  146. GetModuleFileName(hmodule,fname,64);
  147. wsprintf(buffer,"module is %s.level=%d",fname,level);
  148. MessageBox(NULL,buffer,"",MB_OK);
  149. }*/
  150. /*get system functions and my functions' entry*/
  151. SysFunc1=(DWORD)GetProcAddress(GetModuleHandle("gdi32.dll"),"TextOutA");
  152. MyFunc1= (DWORD)GetProcAddress(GetModuleHandle("hookdll.dll"),"MyTextOutA");
  153. SysFunc2=(DWORD)GetProcAddress(GetModuleHandle("gdi32.dll"),"TextOutW");
  154. MyFunc2= (DWORD)GetProcAddress(GetModuleHandle("hookdll.dll"),"MyTextOutW");
  155. SysFunc3=(DWORD)GetProcAddress(GetModuleHandle("gdi32.dll"),"ExtTextOutA");
  156. MyFunc3= (DWORD)GetProcAddress(GetModuleHandle("hookdll.dll"),"MyExtTextOutA");
  157. SysFunc4=(DWORD)GetProcAddress(GetModuleHandle("gdi32.dll"),"ExtTextOutW");
  158. MyFunc4= (DWORD)GetProcAddress(GetModuleHandle("hookdll.dll"),"MyExtTextOutW");
  159. pDOSHeader=(PIMAGE_DOS_HEADER)hmodule;
  160. wsprintf(buffer,"textoua are %ld %ldn%ld %ldn%ld %ldn%ld %ldn",SysFunc1,MyFunc1,SysFunc2,MyFunc2,SysFunc3,MyFunc3,SysFunc4,MyFunc4);
  161. //MessageBox(NULL,buffer,"",MB_OK);
  162.     if (IsBadReadPtr(hmodule, sizeof(PIMAGE_NT_HEADERS)))
  163.         return FALSE;
  164.     
  165.     if (pDOSHeader->e_magic != IMAGE_DOS_SIGNATURE)
  166.         return FALSE;
  167.     
  168.     pNTHeader=(PIMAGE_NT_HEADERS)((DWORD)pDOSHeader+(DWORD)pDOSHeader->e_lfanew);
  169.     if (pNTHeader->Signature != IMAGE_NT_SIGNATURE)
  170.         return FALSE;
  171.     
  172.     pImportDesc = (PIMAGE_IMPORT_DESCRIPTOR)((DWORD)hmodule+(DWORD)pNTHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
  173.     
  174.     if (pImportDesc == (PIMAGE_IMPORT_DESCRIPTOR)pNTHeader) 
  175. return FALSE;
  176.     
  177. while (pImportDesc->Name) 
  178. {
  179. PIMAGE_THUNK_DATA pThunk;
  180. strcpy(buffer,(char*)((DWORD)hmodule+(DWORD)pImportDesc->Name));
  181. CharLower(buffer);
  182. /*if(!strcmp(buffer,"kernel32.dll")||
  183. //!strcmp(buffer,"user32.dll")||
  184. !strcmp(buffer,"imm32.dll")||
  185. //!strcmp(buffer,"comctl32.dll")||
  186. //!strcmp(buffer,"comdlg32.dll")||
  187. !strcmp(buffer,"ntdll.dll")||
  188. !strcmp(buffer,"advapi32.dll")||
  189. !strcmp(buffer,"hookdll.dll"))
  190. //MessageBox(NULL,buffer,"system dll",MB_OK);
  191. //return 0;*/
  192. if(strcmp(buffer,"gdi32.dll"))
  193. {
  194. pImportDesc++;
  195. continue;
  196. }
  197. else //if(!strcmp(buffer,"gdi32.dll"))
  198. {
  199. //GetModuleFileName(hmodule,fname,64);
  200. //wsprintf(buffer,"find gdi32 in %s",fname);
  201. //wsprintf(buffer1,"level is %d",level);
  202. //MessageBox(NULL,buffer,buffer1,MB_OK);
  203. pThunk=(PIMAGE_THUNK_DATA)((DWORD)hmodule+(DWORD)pImportDesc->FirstThunk);
  204. while (pThunk->u1.Function) 
  205. {
  206. if ((pThunk->u1.Function) == SysFunc1) 
  207. {
  208. //MessageBox(NULL,fname,"textoua textoua textoua textoua textoua",MB_OK);
  209. if(!IsBadWritePtr((LPVOID)(&pThunk->u1.Function), sizeof(DWORD)))
  210. (pThunk->u1.Function)=MyFunc1;
  211. else
  212. {
  213. if(VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),PAGE_EXECUTE_READWRITE, &dwProtect))
  214. {
  215. (pThunk->u1.Function)=MyFunc1;
  216. VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),dwProtect,&temp);
  217. }
  218. else
  219. MessageBox(NULL,fname,"textoua UNABLE UNABLE UNABLE UNABLE ",MB_OK);
  220. }
  221. }
  222. else if((pThunk->u1.Function) == SysFunc2)
  223. {
  224. //MessageBox(NULL,fname,"textouw textouw textouw textouw textouw",MB_OK);
  225. if(!IsBadWritePtr((LPVOID)(&pThunk->u1.Function), sizeof(DWORD)))
  226. (pThunk->u1.Function)=MyFunc2;
  227. else
  228. {
  229. if(VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),PAGE_EXECUTE_READWRITE, &dwProtect))
  230. {
  231. (pThunk->u1.Function)=MyFunc2;
  232. VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),dwProtect,&temp);
  233. }
  234. else
  235. MessageBox(NULL,fname,"textou2 UNABLE UNABLE UNABLE UNABLE ",MB_OK);
  236. }
  237. }
  238. else if((pThunk->u1.Function) == SysFunc3)
  239. {
  240. //MessageBox(NULL,fname,"exttextoua exttextoua exttextoua exttextoua",MB_OK);
  241. if(!IsBadWritePtr((LPVOID)(&pThunk->u1.Function), sizeof(DWORD)))
  242. (pThunk->u1.Function)=MyFunc3;
  243. else
  244. {
  245. if(VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),PAGE_EXECUTE_READWRITE, &dwProtect))
  246. {
  247. (pThunk->u1.Function)=MyFunc3;
  248. VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),dwProtect,&temp);
  249. }
  250. else
  251. MessageBox(NULL,fname,"exttextoua UNABLE UNABLE UNABLE UNABLE ",MB_OK);
  252. }
  253. }
  254. else if((pThunk->u1.Function) == SysFunc4)
  255. {
  256. //MessageBox(NULL,fname,"exttextouw exttextouw exttextouw exttextouw",MB_OK);
  257. if(!IsBadWritePtr((LPVOID)(&pThunk->u1.Function), sizeof(DWORD)))
  258. {
  259. (pThunk->u1.Function)=MyFunc4;
  260. VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),dwProtect,&temp);
  261. }
  262. else
  263. {
  264. if(VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),PAGE_EXECUTE_READWRITE, &dwProtect))
  265. (pThunk->u1.Function)=MyFunc4;
  266. else
  267. MessageBox(NULL,fname,"exttextouw UNABLE UNABLE UNABLE UNABLE ",MB_OK);
  268. }
  269. }
  270. pThunk++;
  271. }
  272. return 1;//already found gdi32
  273. }
  274. //else if(!strcmp(buffer,"imm32.dll")||!strcmp(buffer,"comctl32.dll")||!strcmp(buffer,"user32.dll"))
  275. // ChangeFuncEntry(GetModuleHandle(buffer),0);
  276. /*else
  277. {
  278. //if(recursive)
  279. ChangeFuncEntry(GetModuleHandle(buffer),level+1);
  280. }*/
  281. pImportDesc++;
  282.     return bSuccess;
  283. }
  284. BOOL UnChangeFuncEntry(HMODULE hmodule)
  285. {
  286.     PIMAGE_DOS_HEADER pDOSHeader;
  287.     PIMAGE_NT_HEADERS pNTHeader;
  288.     PIMAGE_IMPORT_DESCRIPTOR pImportDesc;
  289. BOOL bSuccess = FALSE;
  290. char buffer[1024],buffer1[1024];
  291.     static int times=0;
  292.     BOOL you=FALSE;
  293. DWORD MyFunc1; 
  294.     DWORD dwProtect,temp;
  295. /*get system functions and my functions' entry*/
  296. SysFunc1=(DWORD)GetProcAddress(GetModuleHandle("gdi32.dll"),"TextOutA");
  297. MyFunc1= (DWORD)GetProcAddress(GetModuleHandle("hookdll.dll"),"MyTextOutA");
  298. SysFunc2=(DWORD)GetProcAddress(GetModuleHandle("gdi32.dll"),"TextOutW");
  299. MyFunc2= (DWORD)GetProcAddress(GetModuleHandle("hookdll.dll"),"MyTextOutW");
  300. SysFunc3=(DWORD)GetProcAddress(GetModuleHandle("gdi32.dll"),"ExtTextOutA");
  301. MyFunc3= (DWORD)GetProcAddress(GetModuleHandle("hookdll.dll"),"MyExtTextOutA");
  302. SysFunc4=(DWORD)GetProcAddress(GetModuleHandle("gdi32.dll"),"ExtTextOutW");
  303. MyFunc4= (DWORD)GetProcAddress(GetModuleHandle("hookdll.dll"),"MyExtTextOutW");
  304. pDOSHeader=(PIMAGE_DOS_HEADER)hmodule;
  305.     if (IsBadReadPtr(hmodule, sizeof(PIMAGE_NT_HEADERS)))
  306.         return FALSE;
  307.     
  308.     if (pDOSHeader->e_magic != IMAGE_DOS_SIGNATURE)
  309.         return FALSE;
  310.     
  311.     pNTHeader=(PIMAGE_NT_HEADERS)((DWORD)pDOSHeader+(DWORD)pDOSHeader->e_lfanew);
  312.     if (pNTHeader->Signature != IMAGE_NT_SIGNATURE)
  313.         return FALSE;
  314.     
  315.     pImportDesc = (PIMAGE_IMPORT_DESCRIPTOR)((DWORD)hmodule+(DWORD)pNTHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
  316.     
  317.     if (pImportDesc == (PIMAGE_IMPORT_DESCRIPTOR)pNTHeader) 
  318. return FALSE;
  319.     
  320. while (pImportDesc->Name) 
  321. {
  322. PIMAGE_THUNK_DATA pThunk;
  323. strcpy(buffer,(char*)((DWORD)hmodule+(DWORD)pImportDesc->Name));
  324. CharLower(buffer);
  325. if(strcmp(buffer,"gdi32.dll"))
  326. {
  327. pImportDesc++;
  328. continue;
  329. }
  330. else 
  331. {
  332. pThunk=(PIMAGE_THUNK_DATA)((DWORD)hmodule+(DWORD)pImportDesc->FirstThunk);
  333. while (pThunk->u1.Function) 
  334. {
  335. if ((pThunk->u1.Function) == MyFunc1) 
  336. {
  337. if(!IsBadWritePtr((LPVOID)(&pThunk->u1.Function), sizeof(DWORD)))
  338. (pThunk->u1.Function)=SysFunc1;
  339. else
  340. {
  341. if(VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),PAGE_EXECUTE_READWRITE, &dwProtect))
  342. {
  343. (pThunk->u1.Function)=SysFunc1;
  344. VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),dwProtect,&temp);
  345. }
  346. else
  347. MessageBox(NULL,fname,"textoua UNABLE UNABLE UNABLE UNABLE ",MB_OK);
  348. }
  349. }
  350. else if((pThunk->u1.Function) == MyFunc2)
  351. {
  352. if(!IsBadWritePtr((LPVOID)(&pThunk->u1.Function), sizeof(DWORD)))
  353. (pThunk->u1.Function)=SysFunc2;
  354. else
  355. {
  356. if(VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),PAGE_EXECUTE_READWRITE, &dwProtect))
  357. {
  358. (pThunk->u1.Function)=SysFunc2;
  359. VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),dwProtect,&temp);
  360. }
  361. else
  362. MessageBox(NULL,fname,"textou2 UNABLE UNABLE UNABLE UNABLE ",MB_OK);
  363. }
  364. }
  365. else if((pThunk->u1.Function) == MyFunc3)
  366. {
  367. if(!IsBadWritePtr((LPVOID)(&pThunk->u1.Function), sizeof(DWORD)))
  368. (pThunk->u1.Function)=SysFunc3;
  369. else
  370. {
  371. if(VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),PAGE_EXECUTE_READWRITE, &dwProtect))
  372. {
  373. (pThunk->u1.Function)=SysFunc3;
  374. VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),dwProtect,&temp);
  375. }
  376. else
  377. MessageBox(NULL,fname,"exttextoua UNABLE UNABLE UNABLE UNABLE ",MB_OK);
  378. }
  379. }
  380. else if((pThunk->u1.Function) == MyFunc4)
  381. {
  382. if(!IsBadWritePtr((LPVOID)(&pThunk->u1.Function), sizeof(DWORD)))
  383. {
  384. (pThunk->u1.Function)=SysFunc4;
  385. VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),dwProtect,&temp);
  386. }
  387. else
  388. {
  389. if(VirtualProtect((LPVOID)(&pThunk->u1.Function), sizeof(DWORD),PAGE_EXECUTE_READWRITE, &dwProtect))
  390. (pThunk->u1.Function)=SysFunc4;
  391. else
  392. MessageBox(NULL,fname,"exttextouw UNABLE UNABLE UNABLE UNABLE ",MB_OK);
  393. }
  394. }
  395. pThunk++;
  396. }
  397. return 1;
  398. }
  399. pImportDesc++;
  400.     return bSuccess;
  401. }
  402. BOOL WINAPI MyTextOutA(HDC hdc, int nXStart, int nYStart, LPCSTR lpszString,int cbString)
  403. {
  404. if(cbString<128&&cbString>0&&nYStart>=rect.top&&nYStart<=rect.bottom)
  405. SendText(hdc,lpszString,cbString,0);
  406. return ((FARPROC)SysFunc1)(hdc,nXStart,nYStart,lpszString,cbString);
  407. }
  408. BOOL WINAPI MyTextOutW(HDC hdc, int nXStart, int nYStart, LPCSTR lpszString,int cbString)
  409. {
  410. if(cbString<128&&cbString>0&&nYStart>=rect.top&&nYStart<=rect.bottom)
  411. SendText(hdc,lpszString,cbString,1);
  412. return ((FARPROC)SysFunc2)(hdc, nXStart, nYStart, lpszString, cbString);
  413. }
  414. BOOL WINAPI MyExtTextOutA(HDC hdc, int nXStart, int nYStart, UINT fuOptions,const RECT FAR *lprc, LPCSTR lpszString,UINT cbString,int FAR *lpDx)
  415. {
  416. if(cbString<128&&cbString>0&&nYStart>=rect.top&&nYStart<=rect.bottom)
  417. SendText(hdc,lpszString,cbString,0);
  418. return ((FARPROC)SysFunc3)(hdc,nXStart,nYStart,fuOptions,lprc,lpszString,cbString,lpDx);
  419. }
  420. BOOL WINAPI MyExtTextOutW(HDC hdc, int nXStart, int nYStart, UINT fuOptions,const RECT FAR *lprc, LPCSTR lpszString,UINT cbString,int FAR *lpDx)
  421. {
  422. if(cbString<128&&cbString>0&&nYStart>=rect.top&&nYStart<=rect.bottom)
  423. SendText(hdc,lpszString,cbString,1);
  424. return ((FARPROC)SysFunc4)(hdc,nXStart,nYStart,fuOptions,lprc,lpszString,cbString,lpDx);
  425. }
  426. void SendText(HDC hdc,LPCSTR lpszString,UINT cbString,int IsW)
  427. {
  428. HANDLE hmap;
  429. HWND hdlg,hwnd;
  430. char *text;
  431. //find window and send text
  432. hdlg=FindWindow("#32770","myciba");
  433. hwnd=WindowFromDC(hdc);
  434. if(hwnd!=hdlg)
  435. {
  436. //get shared memory
  437. hmap= OpenFileMapping(FILE_MAP_ALL_ACCESS,FALSE,"textbuf");
  438. if(!hmap)
  439. return;
  440. text= (char *)MapViewOfFile( hmap,FILE_MAP_ALL_ACCESS,0,0,128); 
  441. if(text==NULL)
  442. return;
  443. if(IsW)
  444. WideCharToMultiByte(CP_ACP,0,lpszString,cbString,text,cbString,NULL,NULL);
  445. else
  446. strcpy(text,lpszString);
  447. text[cbString]='';
  448. PostMessage(hdlg,65000,0,0);
  449. }
  450. return;
  451. }