just tried injecting dll into target process
procedure TMainHookTestForm.Button3Click(Sender: TObject);var Process: dword; StartInfo: TStartupInfo; ProcInfo: TProcessInformation; pid:Cardinal;Begin
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
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
联系客服