高难问题请教,500分!(100分)

  • 主题发起人 主题发起人 cAkk
  • 开始时间 开始时间
那你就接管他的wm_settext消息,把内容copy到你的程序
 
&lt;b&gt;window style:&lt;/b&gt;<br>WS_CHILDWINDOW<br>WS_VISIBLE<br>WS_VSCROLL<br>WS_HSCROLL<br>WS_OVERLAPPED<br><br>&lt;b&gt;Extended Style&lt;/b&gt;<br>WS_EX_LEFT<br>WS_EX_LTRREADING<br>WS_EX_RIGHTSCROLLBAR<br><br>&lt;b&gt;Class Styles:&lt;/b&gt;<br>CS_DBLCLKS<br><br>附注:该edit是放在一个MDIChild里面的.<br><br>&gt;&gt;那你就接管他的wm_settext消息,把内容copy到你的程序<br>怎样copy? <br>
 
library hookdemo;<br><br>uses<br>&nbsp; SysUtils,<br>&nbsp; Classes,windows,messages;<br><br>{$R *.RES}<br>const<br>&nbsp;CopyMessage=wm_user+1001;<br>&nbsp;HookMemFileName='Hook.DAT';<br><br><br>type<br>&nbsp; THookrec=record<br>&nbsp; &nbsp; hookerhandle:THandle;//your app<br>&nbsp; &nbsp; hookedhandle:THandle;//be hooked app<br>&nbsp; &nbsp; copyhook:integer;<br>&nbsp; end;<br>&nbsp; PHookRec=^THOOKrec;<br>var<br>&nbsp; hookrec:PHOOKRec;<br>&nbsp; memfile:THandle;<br>{------------ Hook procedures ------------------}<br>// Callback of the Keyboard Hook<br>function CopyHookProc(Code:integer;// hook code<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wParam:WPARAM;// removal flag 没用<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lParam:lParam // address of structure with message<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ):LRESULT;stdcall;<br>var<br>&nbsp; Buffer:PChar;<br>&nbsp; buffersize:integer;<br>&nbsp; copyStruct:Tcopydatastruct;<br>begin<br>&nbsp; if code=HC_ACTION then<br>&nbsp; begin<br>&nbsp; &nbsp; if (pmsg(lParam)^.hwnd=hookrec^.hookedhandle) and (PMsg(lParam)^.message=wm_settext) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Buffersize:=strlen(PChar(pmsg(lParam)^.lParam))+1*SizeOf(char);<br>&nbsp; &nbsp; &nbsp; getmem(Buffer,buffersize);<br>&nbsp; &nbsp; &nbsp; strcopy(Buffer,PChar(pmsg(lParam)^.lParam));<br>&nbsp; &nbsp; &nbsp; with copystruct do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; dwdata:=wm_user+1001;<br>&nbsp; &nbsp; &nbsp; &nbsp; cbdata:=buffersize;<br>&nbsp; &nbsp; &nbsp; &nbsp; lpdata:=Buffer;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; SendMessage(Hookrec^.hookerhandle,wm_copydata,0,Longint(@copystruct));<br>&nbsp; &nbsp; &nbsp; freemem(Buffer,buffersize);<br>&nbsp; &nbsp; end<br>&nbsp; end;<br>&nbsp; //HC_NoREmove need not process<br>&nbsp; Result := CallNextHookEx(Hookrec^.copyHook, Code, wParam, lParam);<br>end;<br><br><br>{----------------Procedures called by TCXHook component----------------}<br>procedure InstallHook; stdcall;<br>begin<br>&nbsp; Hookrec^.copyHook:=SetWindowsHookEx(WH_GetMessage, @copyHookProc, HInstance , 0);<br>end;<br>//UnInstallHook<br>procedure UnHook; &nbsp;stdcall;<br>begin<br>&nbsp; UnhookWindowsHookEx(Hookrec^.copyHook);<br>end;<br><br>procedure Sethandle(a,b:Integer); stdcall;<br>begin<br>&nbsp; hookrec^.hookerhandle:=a;<br>&nbsp; Hookrec^.hookedhandle:=b;<br>end;<br><br>procedure IntoDll; stdcall;<br>begin<br>&nbsp; MemFile:=OpenFileMapping(FILE_MAP_WRITE,False,HookMemFileName);<br>&nbsp; if MemFile=0 then<br>&nbsp; &nbsp; MemFile:=CreateFileMapping($FFFFFFFF,nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PAGE_READWRITE,0,SizeOf(THookRec),HookMemFileName);<br>&nbsp; HookRec:=MapViewOfFile(MemFile,FILE_MAP_WRITE,0,0,0);<br>&nbsp; if MemFile=0 then<br>&nbsp; FillChar(HookRec^,SizeOf(THookRec),0);<br>end;<br><br>procedure ExitDll; stdcall;<br>begin<br>&nbsp; UnmapViewOfFile(HookRec);<br>&nbsp; CloseHandle(MemFile);<br>end;<br><br>procedure DLLEntryPoint(reason:integer);<br>begin<br>&nbsp;case reason of<br>&nbsp; &nbsp;0: {DLL_PROCESS_DETACH} ExitDll;<br>&nbsp; &nbsp;1: {DLL_PROCESS_ATTACH} IntoDll;<br>&nbsp;end;<br>end;<br><br><br>exports<br>&nbsp;InstallHook,<br>&nbsp;UnHook,<br>&nbsp;Sethandle ;<br><br>begin<br>&nbsp;Intodll;<br>&nbsp;DLLProc:=@DLLEntryPoint;<br>end.<br>//上面是钩子的dll<br>//下面是主程序<br>unit ccopyhook;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure wmcopy(var message:TMessage);message wm_copydata;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br>procedure InstallHook; external 'Hookdemo.dll' name 'InstallHook';<br>procedure unhook;external 'hookdemo.dll' Name 'unhook';<br>procedure sethandle;external 'hookdemo.dll' Name 'sethandle';<br><br>procedure TForm1.wmcopy(var message: TMessage);<br>begin<br>&nbsp; if pcopydatastruct(message.lParam)^.dwdata=wm_user+1001 then<br>&nbsp; &nbsp; memo1.SetTextBuf(PChar(pcopydatastruct(message.lParam)^.lpData));<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; a,b:integer;<br>begin<br>&nbsp; &nbsp;b:=findwindow(yourwanttohook);<br>&nbsp; &nbsp;a:=handle;<br>&nbsp; &nbsp;sethandle(a,b);<br>&nbsp; &nbsp;installhook;<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; unhook;<br>end;<br><br>end.<br>//你试一下吧,我没试可能有bug.
 
to cakk:<br>&nbsp; 我刚看了一篇文章发现钩子也可以挂在消息处理的最后,这说明我们没准能使你要<br>crack的edit,响应wm_paste,wm_copy消息呢。:-)
 
又想了一下,挂在后面也不行:-(
 
不明白:<br>你即使能接管那玩意的消息又如何?<br>人家程序根本不处理wm_copy, wm_paste怎么办(做到这个太简单了, 重写<br>wndproc, 遇到这两个消息不发往defaultwndproc就能做到了)? <br>你自己来处理?<br>既然你能代替别人处理wm_copy, wm_paste消息, 那说明你本来就可以<br>得到文本的内容, 那还要截取消息干吗?<br>
 
又想了想,也许可以。如果能使edit响应wm_copy,wm_paste,那么不就省事了吗。<br>少写不少东西
 
hubdog: 你的hook不行.<br>&nbsp; &nbsp; &nbsp; &nbsp; 再想想,拜托.<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp;
 
不知道金山能不能翻译edit里的文章
 
金山?什么意思? 翻译过来也没用了,我要的是原文.<br><br>我有一个想法,初步试验可行,如果没有人有更好的想法,那么帮助我完成这个<br>想法也可以得分,很简单的. 我的想法是:<br><br>这个程序没有屏蔽的功能里面有find字符串功能,和delphi一样,如果你在<br>edit里面先选中(高亮)一个字符串,然后打开find功能,在查找字符串的那个<br>文本框里会自动填上这个字符串. 而在这个文本框(find对话框的那个)里,<br>是可以拷贝的,所以我想:如果把所有文本全部选中,是不是也会自动全部<br>出现在find对话框的文本框里,然后让我拷贝了事呢?<br><br>事实证明没这么简单,因为find对话框里面的文本框只支持单行文本,就是说<br>每次顶多只能拷贝一行文本,于是我一个想法冒出来:<br><br>"把全部文本都变成单行",中间用一个特殊字符分割开,这样就可以全部一次<br>拷贝出来,以后再用程序把那个特殊字符replace成回车换行就可以了!<br><br>所以,我的想法的关键就是"把全部文本都变成单行". 我已经通过手动实现了,<br>但现在我想通过程序来实现:既然手动可以实现,那么程序也一定可以实现.<br><br>所以,现在的关键就是: 给edit发送按键消息,模拟人工的动作. <br>"把全部文本都变成单行"其实就是:<br><br>1.先把插字符放到文首(ctrl+home);<br>2.循环:<br>&nbsp; 按end键,把插字符调到本行最后,按del键,把下一行调到本行上来,<br>&nbsp; 中间要按一个特殊字符,以示行与行的间隔.<br>3.直到最后一行被调上来(如何判断?) ,然后选择全部文本(模拟按键或发鼠标消息),<br>&nbsp; 然后调出find对话框(模拟按键或发鼠标消息),这时该文本应该出现在对话框<br>&nbsp; 的文本框里,然后按ctrl+insert,拷贝到剪贴版,然后粘贴到自己的程序里面,<br>&nbsp; 然后把特殊字符题换成回车换行即可.<br><br>上面的关键就是模拟按键(或鼠标),帮我解决,就可以得分!<br>
 
他总的画文字吧,截获他的paint
 
如果金山能翻译edit里的文章:<br>可以使它的客户区失效,迫使它重绘,<br>hook它的paint事件(不知道金山是不是这样做的),取得text信息
 
不行,只能得到对象的图形格式
 
请继续, 各抒己见.<br><br>(能帮助我实现我刚才说的那个想法的也可以得分)
 
老兄,还不如用FPE呢,当它是游戏如何,一定查起来容易多了,再查出应用地址<br>不久得了。<br>
 
如果用fpe, 我查出地址又如何把文本保存下来呢?
 
使用窗口的子类化!<br>1.先用getwindowlong( ...) 得到edit的winproc 并保存起来。<br>2.然后用setwindowlong(...)把自己的一个winproc来代替该edit的winproc.<br>3.现在所有发往edit的消息都进了你的proc,在自己的proc里处理这些消息,如果<br>有不想处理的消息,就把它传给那个保存下来的winproc中<br>4.用以上的方法将winproc再换回来。<br><br>
 
粗人: 看上去有道理, 我会试一试的. 谢!
 
不可能,setwindowlong只能是同一个线程的winproc才能设定(help里写的很清<br>楚)
 
对对,是的.<br>前几天研究那个问题:"自己createwindow出来的edit,想用f1设置字体"<br>的时候,看到过help是这么说的.<br><br>我现在怎么人云亦云了,呵呵.:-)<br>
 
后退
顶部