作者: xiao 時間: 2018-5-23 12:07 標題: windows win32/64 屏幕取詞
有大俠寫過或者有經驗可以分享嗎
C 或者 ASM 都可以
謝謝
作者: rkkc 時間: 2018-5-23 13:18
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
作者: xiao 時間: 2018-5-24 12:13
本帖最後由 xiao 於 2018-5-24 12:20 編輯
回覆 2# rkkc
GIHUB 找到一個C#寫的, 據作者說是win95-win10 都可以用, x86, x64 都有源碼, 確定是用hook 4個API
https://github.com/williammortl/Prochook64
叉回來實驗了一下, 可以攔截到win32的, 不過不會改, 達不到自己的目標, 請問可以指點一下嗎
謝謝
[attach]2060953[/attach]
作者: rkkc 時間: 2018-5-24 12:46
windows api hook 或上述 prochook64 截取 the original function call 連 call parameters (即 passing data),你可以在此時查看、修改、儲存該資料內容,例如 Prochook64/64BitHookDLL/64BitHookDLL.cpp (hook dll),留意 comment
- BOOL WINAPI ShadowTextOutW(HDC textdc, int x, int y, LPCWSTR lptext, int cb) // TextOutW 嘅 string buffer
- {
- char szText[MAXTEXTOUT] = NULLSTR;
- int iLenText = 0;
- BOOL bRet = FALSE;
- BOOL bUsed = FALSE;
- // write text buffer
- iLenText = WideCharToMultiByte(CP_THREAD_ACP, WC_NO_BEST_FIT_CHARS, [color=Blue]lptext[/color], cb, szText, MAXTEXTOUT, "*", &bUsed);
- WriteToTextBuffer((LPCSTR)szText, (UINT)iLenText);
- // pass on call to real function
- UnhookFunction((PHOOKREC)&_hrTextOutW);
- bRet = TextOutW(textdc, x, y, lptext, cb); // 不作修改,原封傳回 the original TextOutW
- HookFunction((PHOOKREC)&_hrTextOutW);
- return bRet;
- }
作者: xiao 時間: 2018-5-24 15:05
回覆 4# rkkc
這個大概看得明白. 他的示範說明可以用HOOK. 不過俺的目標是攔截某些文字, 自動時間間隔, 不要按鈕才動作, 然後查自己的LOOKUP TABLE, 完全就是金山字典的功能. 比如螢幕顯示 "XXX A12345 XXX", 只要EDITBOX 顯示 "A12345", 有了這個 A12345, 後面的事情就完備了. 現在卡在這個地方, 不知道怎樣自動時間間隔去按 "GET按鈕"
作者: rkkc 時間: 2018-5-24 15:52
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,不詳解
