Exports.c
上传用户:chzmdj
上传日期:2007-01-22
资源大小:135k
文件大小:13k
源码类别:

源码/资料

开发平台:

C/C++

  1. #include <windows.h>
  2. #include "NHTW32.h"
  3. #include "import.h"
  4. #include "HookApi.h"
  5. #include "FindWord.h"
  6. #include "..pub3216.h"
  7. #include "dbgfunc.h"
  8. #pragma data_seg(".sdata")  //start of section
  9. BOOL bDebugBegin = TRUE;
  10. HANDLE hMutex = NULL;                // 信号量,用於互斥。
  11. HANDLE hWork = NULL;
  12. APIHOOKSTRUCT g_ExtTextOutWHook = {
  13. "Gdi32.dll", // The module name that the api in it.
  14. "ExtTextOutW", // The api name that it will be hooked.
  15. 10,
  16. NULL, // This api point.
  17. {0, 0, 0, 0, 0, 0, 0}, // Use to record five byte at begin of api.
  18. // these data is get from this program. 
  19. // the system may be already run the other 
  20. // program that these program change api too.
  21. NULL, // The module name that the hook api in it.
  22. "NhExtTextOutW", // The hook api name that it will replace the api.
  23. NULL, // This hook api point.
  24. {0, 0, 0, 0, 0, 0, 0}, // Use to record five byte at begin of api.
  25. // these data is get from this program. 
  26. // the system may be already run the other 
  27. // program that these program change api too.
  28. 0,
  29. // Use to record five byte at begin of api.
  30. // these data is get from WINICE. it is pure.
  31. // Used when the BLIEA restart when BLIEA abort,
  32. // Use to restore this api data.
  33. {0XFF, 0X15, 0XFA, 0X13, 0XF3, 0XBF, 0X33}
  34.   };
  35. // 当前词数据结构·( 当前词:为由输入缓冲区中切出的单词 )
  36. char g_szCurWord[WORDMAXLEN] = ""; // 当前词缓冲区·
  37. RECT g_CurWordRect; // 记录当前词区域·
  38. int  g_nCurCaretPlace; // 记录当前光标位置·
  39. // 当前词数据结构·
  40. BOOL  g_bAllowGetCurWord = FALSE; //
  41. HWND  g_hNotifyWnd = NULL; //
  42. POINT g_CurMousePos; // 记录当前光标位置·
  43. UINT         g_nTextAlign;
  44. POINT        g_dwDCOrg;
  45. int          g_nExtra;
  46. POINT        g_CurPos;
  47. TEXTMETRIC   g_tm;
  48. ///////////////////////////////////////////////////////////////////////////
  49. // Modify by Yan/Gang 1997/11/18
  50. // 用於修改在计算 TA_CENTER 情况的失误。
  51. BOOL bRecAllRect = TRUE;
  52. RECT g_rcTotalRect;
  53. // End Modify
  54. ///////////////////////////////////////////////////////////////////////////
  55. #ifdef _DICTING_
  56. /////////////////////////////////////////////////////////////////////////////////
  57. // Modify by Yan/Gang 1997/11/19
  58. // 主要解决通配符的问题。
  59. int g_nGetWordStyle;
  60. // End Add.
  61. /////////////////////////////////////////////////////////////////////////////////
  62. #endif
  63. extern BOOL g_bCanWrite;
  64. BOOL g_bHooked = FALSE;
  65. #pragma data_seg()
  66. //*********************************************************************
  67. //Added by XGL, Jan 7th, 1999
  68. //for get word in Acrobat Reader
  69. extern HANDLE g_heventGetWord ; //event handle
  70. extern HANDLE g_hMappedFile ; //handle of file-mapping object
  71. extern void *g_pMemFile ; //pointer to memfile
  72. BOOL g_bAcrobatReaderWord = FALSE ; //indicate that the word was got
  73. //from Acrobat Reader
  74. //end of addition
  75. //*********************************************************************
  76. typedef BOOL (WINAPI *EXTTEXTOUTW_PROC)(HDC, int, int, UINT, CONST RECT *,  LPCTSTR, UINT, CONST INT *);
  77. DLLEXPORT DWORD WINAPI BL_SetFlag32(UINT nFlag, HWND hNotifyWnd, int MouseX, int MouseY)
  78. {
  79. //Modified by XGL, Jan 7th, 1999
  80. //for Acrobat Reader
  81. POINT ptWindow ;
  82. HWND hWnd ;
  83. void *pTemp ;
  84. ptWindow.x = MouseX ;
  85. ptWindow.y = MouseY ;
  86. hWnd = WindowFromPoint(ptWindow) ;
  87. //Are we getting word from Acrobat Reader
  88. __try
  89. {
  90. if (NULL != g_pMemFile 
  91. && EXISTED == *((BYTE*)g_pMemFile + PLUGIN_FLAG_POS)
  92. && hWnd == *((HWND*)((BYTE*)g_pMemFile + WND_HANDLE_POS)))
  93. {
  94. if(GETPHRASE_ENABLE == nFlag ||
  95. GETWORD_TW_ENABLE == nFlag ||
  96. GETWORD_D_ENABLE == nFlag ||
  97. GETWORD_D_TYPING_ENABLE == nFlag)
  98. {
  99. //fill mouse pos buffer
  100. pTemp = (BYTE*)g_pMemFile + MOUSE_X_POS ;
  101. *((int*)pTemp) = MouseX ;
  102. pTemp = (BYTE*)g_pMemFile + MOUSE_Y_POS ;
  103. *((int*)pTemp) = MouseY ;
  104. pTemp = (BYTE*)g_pMemFile + WND_NOTIFIY_POS ;
  105. *((HWND*)pTemp) = hNotifyWnd ;
  106. *((BYTE*)g_pMemFile + WORD_POS) = 0x0 ;
  107. //set get word flag
  108. ResetEvent(g_heventGetWord) ;
  109. return BL_OK;
  110. }
  111. else
  112. {
  113. //GETWORD_DISABLE and so on
  114. return BL_OK ;
  115. }
  116. }
  117. }
  118. __except (1)
  119. {
  120. SetEvent(g_heventGetWord) ;
  121. }
  122. //end of modification, XGL, Jan 7th, 1999
  123. switch (nFlag)
  124. {
  125. #ifdef _DICTING_
  126. /////////////////////////////////////////////////////////////////////////////////
  127. // Modify by Yan/Gang 1997/11/19
  128. // 主要解决通配符的问题。
  129. // 打字/用字取词。
  130. case GETPHRASE_ENABLE:
  131. case GETWORD_TW_ENABLE:
  132. // 查字取词。
  133. case GETWORD_D_ENABLE:
  134. // 设置取词方式。
  135. WaitForSingleObject(hMutex, INFINITE);
  136. g_nGetWordStyle = nFlag;
  137. BL_SetGetWordStyle(GETPHRASE_ENABLE/*nFlag*/);
  138. BL_SetPara16((short)hNotifyWnd, (short)MouseX, (short)MouseY);
  139. g_bAllowGetCurWord = TRUE;
  140. g_hNotifyWnd = hNotifyWnd;
  141. g_CurMousePos.x = MouseX;
  142. g_CurMousePos.y = MouseY;
  143.         g_szCurWord[0] = 0x00;
  144.     g_nCurCaretPlace = -1;
  145. BL_HookWinApi16();
  146. if (!g_bHooked)
  147. {
  148. HookWin32Api(&g_ExtTextOutWHook, HOOK_CAN_WRITE);
  149. g_bHooked = TRUE;
  150. }
  151. g_bAllowGetCurWord = TRUE;
  152. ReleaseMutex(hMutex);
  153. break;
  154. // End Modify
  155. //Added by XGL, Nov 18th, 1998
  156. //for typing assistant specially, it don't need phrase
  157. case GETWORD_D_TYPING_ENABLE:
  158. // 设置取词方式。
  159. WaitForSingleObject(hMutex, INFINITE);
  160. g_nGetWordStyle = nFlag;
  161. BL_SetGetWordStyle(GETWORD_D_ENABLE);
  162. BL_SetPara16((short)hNotifyWnd, (short)MouseX, (short)MouseY);
  163. g_bAllowGetCurWord = TRUE;
  164. g_hNotifyWnd = hNotifyWnd;
  165. g_CurMousePos.x = MouseX;
  166. g_CurMousePos.y = MouseY;
  167.         g_szCurWord[0] = 0x00;
  168.     g_nCurCaretPlace = -1;
  169. BL_HookWinApi16();
  170. if (!g_bHooked)
  171. {
  172. HookWin32Api(&g_ExtTextOutWHook, HOOK_CAN_WRITE);
  173. g_bHooked = TRUE;
  174. }
  175. g_bAllowGetCurWord = TRUE;
  176. ReleaseMutex(hMutex);
  177. break;
  178. //Adding ends. XGL, Nov 18th, 1998
  179. ////////////////////////////////////////////////////////////////////////////////
  180. #else
  181. case GETWORD_ENABLE:
  182. WaitForSingleObject(hMutex, INFINITE);
  183. BL_SetPara16((short)hNotifyWnd, (short)MouseX, (short)MouseY);
  184. g_bAllowGetCurWord = TRUE;
  185. g_hNotifyWnd = hNotifyWnd;
  186. g_CurMousePos.x = MouseX;
  187. g_CurMousePos.y = MouseY;
  188.         g_szCurWord[0] = 0x00;
  189.     g_nCurCaretPlace = -1;
  190. BL_HookWinApi16();
  191. if (!g_bHooked)
  192. {
  193. HookWin32Api(&g_ExtTextOutWHook, HOOK_CAN_WRITE);
  194. g_bHooked = TRUE;
  195. }
  196. g_bAllowGetCurWord = TRUE;
  197. ReleaseMutex(hMutex);
  198. break;
  199. #endif
  200. case GETPHRASE_DISABLE:
  201. case GETWORD_DISABLE:
  202. case GETWORD_D_TYPING_DISABLE:
  203. WaitForSingleObject(hMutex, INFINITE);
  204. g_bAllowGetCurWord = FALSE;
  205. if (g_bHooked)
  206. {
  207. RestoreWin32Api(&g_ExtTextOutWHook, HOOK_ONLY_READ);
  208. g_bHooked = FALSE;
  209. }
  210. BL_UnHookWinApi16();
  211. ReleaseMutex(hMutex);
  212. break;
  213. }
  214. return BL_OK;
  215. }
  216. DLLEXPORT DWORD WINAPI BL_GetText32(LPSTR lpszCurWord, int nBufferSize, LPRECT lpWordRect)
  217. {
  218. WORDRECT wr;
  219. DWORD dwCaretPlace;
  220. //DbgPrintfToICE("Nhw32.dll   GetText: Begin.");
  221. //modified by XGL, Jan 7th, 1999
  222. //for Acrobat Reader
  223. void *pTemp ;
  224. int nStrLen ;
  225. LPSTR lpstrLetter;
  226. if (WAIT_TIMEOUT == WaitForSingleObject(g_heventGetWord, NH_WAIT_TIME))
  227. {
  228. SetEvent(g_heventGetWord) ;
  229. }
  230. __try
  231. {
  232. //check if we got word from Acrobat Reader
  233. if (NULL != g_pMemFile
  234. && *((BYTE*)g_pMemFile + WORD_POS) != 0x0)
  235. {
  236. pTemp = (BYTE*)g_pMemFile + WORD_POS ;
  237. nStrLen = strlen(pTemp) ;
  238. //get proper len for copy
  239. nStrLen = (nStrLen < nBufferSize) ? nStrLen : nBufferSize ;
  240. strncpy(lpszCurWord, (LPSTR)pTemp, nStrLen) ;
  241. lpszCurWord[nStrLen] = 0x0 ;
  242. //copy word rect
  243. pTemp = (BYTE*)g_pMemFile + RECT_POS ;
  244. lpWordRect->left   = *((LONG*)pTemp) ;   
  245. pTemp = (BYTE*)pTemp + sizeof(LONG) ;
  246. lpWordRect->top    = *((LONG*)pTemp) ;    
  247. pTemp = (BYTE*)pTemp + sizeof(LONG) ;
  248. lpWordRect->right  = *((LONG*)pTemp) ;  
  249. pTemp = (BYTE*)pTemp + sizeof(LONG) ;
  250. lpWordRect->bottom = *((LONG*)pTemp) ;
  251. //set buffer to empty
  252. *((BYTE*)g_pMemFile + WORD_POS) = 0x0 ;
  253. }
  254. else
  255. {
  256. dwCaretPlace = BL_GetBuffer16(lpszCurWord, (short)nBufferSize, &wr);
  257. lpWordRect->left   = wr.left;   
  258. lpWordRect->right  = wr.right;  
  259. lpWordRect->top    = wr.top;    
  260. lpWordRect->bottom = wr.bottom;
  261. }
  262. }
  263. __except (1)
  264. {
  265. }
  266. //end of modification
  267. return dwCaretPlace;
  268. }
  269. DLLEXPORT BOOL WINAPI NhExtTextOutW(HDC hdc, // handle to device context 
  270. int X, // x-coordinate of reference point 
  271. int Y, // y-coordinate of reference point 
  272. UINT fuOptions, // text-output options 
  273. CONST RECT *lprc, // optional clipping and/or opaquing rectangle 
  274. LPCTSTR lpString, // points to string 
  275. UINT cbCount, // number of characters in string 
  276. CONST INT *lpDx  // pointer to array of intercharacter spacing values  
  277.    )
  278. {
  279. EXTTEXTOUTW_PROC ExtTextOutWApi;
  280. EXTTEXTOUTW_PROC ExtTextOutAApi;
  281. char szTemp[256];
  282. int  nTempLen;
  283. BOOL bWOrA;
  284. HANDLE hOldMutex;
  285. //////////////////////////////////////////////////////////////////////////
  286. // Modify by Yan/Gang 1998.02.19
  287. // Reason: 
  288. //        Because the CX register in Chinese version Windows different from English version.
  289. WORD wCXRegister, wCXInWCode, wCXInACode;
  290. LPWORD temp;
  291. _asm
  292. {
  293. mov wCXRegister, cx;
  294. };
  295. hOldMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, MUTEXNAME);
  296. WaitForSingleObject(hOldMutex, INFINITE);
  297. ExtTextOutWApi = (EXTTEXTOUTW_PROC)((DWORD)g_ExtTextOutWHook.lpWinApiProc - 10);
  298. ExtTextOutAApi = (EXTTEXTOUTW_PROC)((DWORD)g_ExtTextOutWHook.lpWinApiProc - 4);
  299. temp = (LPWORD)ExtTextOutWApi;
  300. wCXInWCode = temp[1];
  301. temp = (LPWORD)ExtTextOutAApi;
  302. wCXInACode = temp[1];
  303. if (wCXRegister == wCXInACode)
  304. { // ExtTextOutA
  305. bWOrA = 1;
  306. }
  307. else
  308. { // ExtTextOutW
  309. bWOrA = 0;
  310. }
  311. // Modify end.
  312. //////////////////////////////////////////////////////////////////////////
  313. // _asm // 用於判断当前是否为UNICODE.
  314. // {
  315. // cmp cx, 20b3h;
  316. // je  exttextouta;
  317. // mov bWOrA, 0; // ExtTextOutW
  318. // jmp end;
  319. //exttextouta:
  320. // mov bWOrA, 1; // ExtTextOutA
  321. //end:
  322. // };
  323. // End modify
  324. //////////////////////////////////////////////////////////////////////////
  325. // restore the old textout.
  326. #ifdef _DEUBG
  327. DbgPrintfToICE("Nhw32.dll   ExtTextOutW: Restore Begin.");
  328. #endif
  329. RestoreWin32Api(&g_ExtTextOutWHook, HOOK_NEED_CHECK);
  330. #ifdef _DEUBG
  331. DbgPrintfToICE("Nhw32.dll   ExtTextOutW: Restore End.");
  332. #endif
  333. // call old textout.
  334. if (bWOrA == 0)
  335. {
  336. ExtTextOutWApi(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
  337. nTempLen = WideCharToMultiByte(CP_ACP, 0, (const unsigned short *)lpString, cbCount, szTemp, 256, NULL, NULL);
  338. szTemp[nTempLen] = 0x00;
  339. ///////////////////////////////////////////////////////////////////////////
  340. // Modify by Yan/Gang 1997/11/18
  341. // 用於修改在计算 TA_CENTER 情况的失误。
  342. bRecAllRect = FALSE;
  343. g_dwDCOrg.x = 0;
  344. g_dwDCOrg.y = 0;
  345. GetStringRect(hdc, (LPSTR)szTemp, nTempLen, X, Y, &g_rcTotalRect, (LPINT)lpDx);
  346. bRecAllRect = TRUE;
  347. // End Modify
  348. ///////////////////////////////////////////////////////////////////////////
  349. BL_ExtTextOutW(hdc, X, Y, fuOptions, (LPRECT)lprc, (LPSTR)szTemp, nTempLen, (LPINT)lpDx);
  350. }
  351. else
  352. {
  353. ExtTextOutAApi(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
  354. }
  355. if (g_bHooked)
  356. {
  357. HookWin32Api(&g_ExtTextOutWHook, HOOK_NEED_CHECK);
  358. }
  359. ReleaseMutex(hOldMutex);
  360. CloseHandle(hOldMutex);
  361. return (TRUE);
  362. }
  363. DWORD BL_ExtTextOutW(HDC hDC,
  364.  int X,
  365.  int Y,
  366.  UINT fuOptions,
  367.  LPRECT lprc,
  368.  LPSTR lpString,
  369.  UINT cbCount,
  370.  LPINT lpDx)
  371. {
  372. //Added by XGL, Nov 3rd, 1998
  373. //We cannot get corret word with Explorer as background window
  374. //in Windows98, so this situation must be dealt with.
  375. if ((g_bAllowGetCurWord) && (!IsBadReadPtr(lpString, cbCount)) && (cbCount > 0))
  376. {
  377. g_nTextAlign = GetTextAlign(hDC);
  378. g_nExtra     = GetTextCharacterExtra(hDC);
  379. GetCurrentPositionEx(hDC, &g_CurPos);
  380. GetTextMetrics(hDC, &g_tm);
  381. if (WindowFromDC(hDC) == NULL)
  382. {
  383. // 赋零,用於避免MEMDC对串位置的影响·
  384. g_dwDCOrg.x = 0;
  385. g_dwDCOrg.y = 0;
  386. AddToTextOutBuffer(hDC, (LPSTR)lpString, cbCount, X, Y, lpDx);
  387. }
  388. else
  389. {
  390. GetDCOrgEx(hDC, &g_dwDCOrg);
  391. GetCurMousePosWord(hDC, (LPSTR)lpString, cbCount, X, Y, lpDx);
  392. }
  393. }
  394. else
  395. {
  396. }
  397. return (TRUE);
  398. }