[技術討論] windows win32/64 屏幕取詞

有大俠寫過或者有經驗可以分享嗎
C 或者 ASM 都可以
謝謝

windows 用 TextOut() 或 DrawTextA()/DrawTextW() 印字出 screen 或 printer
要截取 (hook) 某 api,用 detours api 註冊想 hook 嘅 function(s)
例子 https://stackoverflow.com/questi ... ing-text-in-notepad

* win95/98 寫過類似金山詞霸嘅 program,95/98 冇 detours api 煩好多
* 上述只是原理,實際 program 要自行參閱各 api reference doc. 及 examples

TOP

本帖最後由 xiao 於 2018-5-24 12:20 編輯

回覆 2# rkkc


    GIHUB 找到一個C#寫的, 據作者說是win95-win10 都可以用, x86, x64 都有源碼, 確定是用hook 4個API
https://github.com/williammortl/Prochook64
叉回來實驗了一下, 可以攔截到win32的, 不過不會改, 達不到自己的目標, 請問可以指點一下嗎
謝謝
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

TOP

windows api hook 或上述 prochook64 截取 the original function call 連 call parameters (即 passing data),你可以在此時查看、修改、儲存該資料內容,例如 Prochook64/64BitHookDLL/64BitHookDLL.cpp (hook dll),留意 comment
  1. BOOL WINAPI ShadowTextOutW(HDC textdc, int x, int y, LPCWSTR lptext, int cb) // TextOutW 嘅 string buffer
  2. {
  3.         char szText[MAXTEXTOUT] = NULLSTR;
  4.         int iLenText = 0;
  5.         BOOL bRet = FALSE;
  6.         BOOL bUsed = FALSE;

  7.         // write text buffer
  8.         iLenText = WideCharToMultiByte(CP_THREAD_ACP, WC_NO_BEST_FIT_CHARS, [color=Blue]lptext[/color], cb, szText, MAXTEXTOUT, "*", &bUsed);
  9.         WriteToTextBuffer((LPCSTR)szText, (UINT)iLenText);

  10.         // pass on call to real function
  11.         UnhookFunction((PHOOKREC)&_hrTextOutW);
  12.         bRet = TextOutW(textdc, x, y, lptext, cb); // 不作修改,原封傳回 the original TextOutW
  13.         HookFunction((PHOOKREC)&_hrTextOutW);

  14.         return bRet;
  15. }
複製代碼

TOP

回覆 4# rkkc


    這個大概看得明白. 他的示範說明可以用HOOK. 不過俺的目標是攔截某些文字, 自動時間間隔, 不要按鈕才動作, 然後查自己的LOOKUP TABLE, 完全就是金山字典的功能. 比如螢幕顯示 "XXX A12345 XXX", 只要EDITBOX 顯示 "A12345", 有了這個 A12345, 後面的事情就完備了. 現在卡在這個地方, 不知道怎樣自動時間間隔去按 "GET按鈕"

TOP

api hook 是其中一個重要部份,知道其他 applications 用甚麼 function 出字後

1. 建立 hook function,Applications 每次 call TextOut/ExtTextOut 時,會先 trigger hook function

2. hook function 內用 WindowFromDC( textdc ) 得到 window handle /* HDC textdc */,連同 x, y, lptext 一同儲存在你的 program 嘅 gobal structure/lookuptable 以 window handle 作 lookup id

3. 你的 program 要 handle mouse event,查當前 cursor 下面 window handle,用該 handle 去 lookup 那個 window x,y 有甚麼 text,popup 一個 text label window 顯示你的取詞翻譯

第 2 點是最重要,你要管理該 lookup table 內容,第 3 點是一般 windows programming,不詳解

TOP