打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Article 4500 Subject Re: Hook Api (Textout, ExTextOut, DrawText) to get text from any window: How ?

Hook Api (Textout, ExTextOut, DrawText) to get text from any window: How ?

just tried injecting dll into target process
procedure TMainHookTestForm.Button3Click(Sender: TObject);var   Process: dword;   StartInfo: TStartupInfo;   ProcInfo: TProcessInformation;   pid:Cardinal;Begin
pid:=GetTargetProcessId; // by using CreateToolhelp32Snapshot,Process32Next, etc.. dont know easy way
     Process := OpenProcess(PROCESS_ALL_ACCESS,False,pid);
     InjectLibrary(Process, 'D:\TextHook.dll'); // downloaded utils afxCodeHook
end;



and it seems textout hook is working fineits getting all text from target application and listview (which is the purpose)however its getting all textout text which is cumbersome to process
need help to figure out how do i exactly get text from specified point from specified window (HDC)
i mean how do i implement it in dll

ThanksKamlesh

> {quote:title=Kamlesh Chauhan wrote:}{quote}> Dear Friends> > (with ref. to prev ques.)> i m trying to get text from this window and it seems> only option i have now is> hooking textout, drawtext, etc.. api> > both following (Non OCR) is able to capture-extract-grab, text from this window> http://www.hook-api.com/> http://www.renovation-software.com/en/text-grab-sdk/textgrab-sdk.html> > looking for some link, sample code, etc.. to get started from> > > > Thanks> Kamlesh> > Edit: > --------------> i downloaded one hook code-util and > was trying following code and it seems to work fine> only problem is it captures text only from my application form> > > ??> > > ====================================================> library TextHook;> > uses>     SysUtils,>     Windows,>     Messages,>     Math,>     DHDisasm,>     DHDisasmEx,>     DHHook,>     DHKernel,>     DHProcess,>     DHProtect,>     DHUtil;> > Type>     PHookInfo = ^KHookInfo;>     KHookInfo = Packed Record>               Hook:HHook;>               Text1:array[0..255] of Char;>               Text2:array[0..255] of Char;>               x,y:Integer;>     End;> > Var>   FMapping: THandle = 0;>   FHookInfo: PHookInfo = nil;>   vFile:TextFile;> >   oldTextOutA, nextTextOutA: function(DC: HDC; X, Y: Integer; Str: PAnsiChar; Count: Integer): BOOL; stdcall;>   oldTextOutW, nextTextOutW: function(DC: HDC; X, Y: Integer; Str: PWideChar; Count: Integer): BOOL; stdcall;> >   oldExtTextOutA, nextExtTextOutA: function(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: PAnsiChar; Count: Longint; Dx: PInteger): BOOL; stdcall;>   oldExtTextOutW, nextExtTextOutW: function(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: PWideChar; Count: Longint; Dx: PInteger): BOOL; stdcall;> > procedure textW(w:PWideChar; c: integer);> Var>    vStr:String;> begin>      Try>         vStr := WideCharToString(w);>         Append(vFile);>         WriteLn(vFile,vStr);>      Except>            MessageBeep(MB_ICONASTERISK);>      End;> end;> > procedure textA(s:PAnsiChar; c: integer);> Var>    vStr:String;> begin>      Try>         vStr:=StrPAs(S);>         Append(vFile);>         Write(vFile,vStr);>      Except>            MessageBeep(MB_ICONASTERISK);>      End;> end;> > function myTextOutA(DC: HDC; X, Y: Integer; Str: PAnsiChar; Count: Integer): BOOL; stdcall;> begin>     textA(Str,count);>     result := nextTextOutA(DC,X,Y,Str,Count);> end;> > function myTextOutW(DC: HDC; X, Y: Integer; Str: PWideChar; Count: Integer): BOOL; stdcall;> begin>      textW(Str,count);>      result := nextTextOutW(DC,X,Y,Str,Count);> end;> > function myExtTextOutA(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: PAnsiChar; Count: Longint; Dx: PInteger): BOOL; stdcall;> begin>     textA(Str,count);>     result := nextExtTextOutA(DC,X,Y,Options,rect,Str,Count,dx);> end;> > function myExtTextOutW(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: PWideChar; Count: Longint; Dx: PInteger): BOOL; stdcall;> begin>     textW(Str,count);>     result := nextExtTextOutW(DC,X,Y,Options,rect,Str,Count,dx);> end;> > Procedure InjectMain;> Var>    h: integer;> Begin>   h :=  GetModuleHandle('gdi32.dll');>   if h > 0 then>   begin>     @oldTextOutA := GetProcAddress(h,'TextOutA');>     if @oldTextOutA <> nil then>       DHHook.HookCode(@oldTextOutA,@myTextOutA,@nextTextOutA);> >     @oldTextOutW := GetProcAddress(h,'TextOutW');>     if @oldTextOutW <> nil then>       DHHook.HookCode(@oldTextOutW,@myTextOutW,@nextTextOutW);> >     @oldExtTextOutA := GetProcAddress(h,'ExtTextOutA');>     if @oldExtTextOutA <> nil then>       DHHook.HookCode(@oldExtTextOutA,@myExtTextOutA,@nextExtTextOutA);> >     @oldExtTextOutW := GetProcAddress(h,'ExtTextOutW');>     if @oldExtTextOutW <> nil then>       DHHook.HookCode(@oldExtTextOutW,@myExtTextOutW,@nextExtTextOutW);>   end;> end;> > procedure uninjectmain;> begin>   DHHook.UnhookCode(@nextTextOutA);>   DHHook.UnhookCode(@nextTextOutW);>   DHHook.UnhookCode(@nextExtTextOutA);>   DHHook.UnhookCode(@nextExtTextOutW);> end;> > Procedure DllMain(Reason: Integer);> Begin>      Case Reason of>           DLL_PROCESS_ATTACH:>           Begin>                FMapping := CreateFileMapping(INVALID_HANDLE_VALUE, nil, PAGE_READWRITE, 0, SizeOf(KHookInfo), 'KC_HookInfo');>                If FMapping = 0 then Exit;>                FHookInfo := PHookInfo( MapViewOfFile( FMapping, FILE_MAP_WRITE, 0, 0, SizeOf(KHookInfo) ) );>                If FHookInfo = Nil Then Exit;>                Assignfile(vFile,'D:\a2.txt');>                If FileExists('D:\a2.txt') Then Reset(vFile) Else Rewrite(vFile);>                InjectMain;>           End;>           DLL_PROCESS_DETACH:>           Begin>                UnInjectMain;>                closefile(vFile);>                If FHookInfo <> Nil then UnmapViewOfFile(FHookInfo);>                If FMapping <> 0 then CloseHandle(FMapping);>           End;>      End;> End;> > Begin>      DllProc := @DllMain;>      DllMain(DLL_PROCESS_ATTACH);> end.> ===========================================================> > Edited by: Kamlesh Chauhan on Dec 15, 2010 1:03 AM
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
GDI(图形设备接口)
VS2010/MFC编程入门之四十八(字体和文本输出:文本输出)
向窗口输出文字TextOut和DrawText函数
DC
如何用 GDI 绘制阴影文字
浅谈api hook技术
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服