2025年微信hook什么意思(微信hook原理)

微信hook什么意思(微信hook原理)p 一 注入自己的 dll br 一些教程视频中 易语言的注入就一句代码 etcp 的一个模块 我能力有限 手头也没有现成的代码 所以就像还是用键盘 hook 的方式注入 后期在考虑进程间通讯做群控 另外就是觉得在 dll 里面写窗口似乎简单一点 br 键盘 hook 注入的相关代码如下 function installKeyho Boolean p

大家好,我是讯享网,很高兴认识大家。



 <p>一、注入自己的dll。<br />一些教程视频中,易语言的注入就一句代码。etcp的一个模块。我能力有限,手头也没有现成的代码。所以就像还是用键盘hook的方式注入。后期在考虑进程间通讯做群控。另外就是觉得在dll里面写窗口似乎简单一点。<br />键盘hook注入的相关代码如下 

讯享网

function installKeyhook: Boolean; stdcall;var
&nbsp; h: hwnd;
&nbsp; GameTid: THandle;
begin
&nbsp; Result := False;
&nbsp; h := FindWindow(‘WeChatLoginWndForPC’, nil);
&nbsp; if h = 0 then
&nbsp; begin
&nbsp; &nbsp; h := FindWindow(‘WeChatMainWndForPC’, nil);
&nbsp; &nbsp; if h = 0 then
&nbsp; &nbsp; begin
&nbsp; &nbsp; &nbsp; MessageBox(0, ‘未找到微信窗口’, ‘提示’, 0);
&nbsp; &nbsp; &nbsp; exit;
&nbsp; &nbsp; end;
&nbsp; end;
&nbsp; GameTid := GetWindowThreadProcessId(h);
&nbsp; keyhhk := SetWindowsHookEx(WH_KEYBOARD, @keyhook, GetModuleHandle(‘WeHelp.dll’), GameTid);
&nbsp; if keyhhk &gt; 0 then
&nbsp; begin
&nbsp; &nbsp; Result := True;
&nbsp; end;
end;

function keyhook(icode, wp, lp: Integer): LRESULT; stdcall;
begin
&nbsp; if (icode = HC_ACTION) then
&nbsp; begin
&nbsp; &nbsp; if (wp = VK_HOME) and ((1 shl 31) and lp = 0) then
&nbsp; &nbsp; begin
&nbsp; &nbsp; &nbsp; if Form_main = nil then
&nbsp; &nbsp; &nbsp; begin
&nbsp; &nbsp; &nbsp; &nbsp; Form_Main := TForm_Main.Create(nil);
&nbsp; &nbsp; &nbsp; end;
&nbsp; &nbsp; &nbsp; Form_Main.Visible := not Form_Main.Visible;
&nbsp; &nbsp; end;
&nbsp; end;
&nbsp; Result := CallNextHookEx(keyhhk, icode, wp, lp);
end;

dll中加上以上代码,在注入exe中调用,就实现了键盘hook注入 。我是hook了home键。
二、微信消息的hook。这个网上有很多查找hook位置的教程。我纠结了很久的是易语言所谓的超级hook功能。

每次微信接受消息就会运行图示这段asm,网上传的inlinehook 就是在c3的位置jmp至自己的内存位置,然后运行自己的代码,自己代码运行完后运行 原来c3位置的mov ecx,0x7A2DFA20
然后再jmp会c8 继续微信的运行。也就是再微信每次接受消息的时候运行一段自己的代码,比如说把消息内容保存下来,这就是所谓的微信消息hook。
delphi写的时候没什么参考。jmp跳转实在写的有点乱。所以我直接修改c3位置的代码为call我的自设代码。运行完成后再retn回来。期间用全局变量把寄存器值都截取下来了。关键代码如下:

Fhookaddr := AHookAddr;
FByteLen := ByteLength;
FMyproc := Integer(DspProc);
FOldCode := GetMemory(SizeOf(Pointer) + FByteLen * sizeof(Byte)); &nbsp;//申请FOldCode空间
CopyMemory(FOldCode, Pointer(FHookAddr), FByteLen * sizeof(Byte));
FMyAsm2 := GetMemory(100 * SizeOf(Byte)); &nbsp; //申请FMyAsm空间
VirtualProtect(FMyAsm2, 100 * sizeof(Byte), PAGE_EXECUTE_READWRITE, @oldprotect); &nbsp; &nbsp; &nbsp;//调整FmyAsm内存空间可读写
FillMemory(FMyAsm2, 100 * SizeOf(Byte), \(90); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //初始化空间全部为nop<br />temp := Integer(Self); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //temp赋值为superhook自身指针<br />PByte(Integer(FMyAsm2))^ := \)60; &nbsp; &nbsp; &nbsp; //pushad
PByte(Integer(FMyAsm2) + 1)^ := \(C7; &nbsp; &nbsp; &nbsp;//mov<br />Pbyte(Integer(FMyAsm2) + 2)^ := \)C1; &nbsp; //ecx
PInteger(Integer(FMyAsm2) + 3)^ := temp; &nbsp; &nbsp; &nbsp;//self
CopyMemory(Pointer(Integer(FMyAsm2) + 7), @codearr, 73 * sizeof(Byte)); &nbsp; //codeArr写入,内容为将寄存器的值取出至对象字段
Pbyte(Integer(FMyAsm2) + 81)^ := \(E8; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //call<br />PInteger(Integer(FMyAsm2) + 82)^ := FMyProc - Integer(FMyAsm2) - 82 - 4; &nbsp;//FMyProc的地址<br />PByte(Integer(FMyAsm2) + 86)^ := \)61; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//popad
CopyMemory(Pointer(Integer(FMyAsm2) + 87), FOldCode, FByteLen * sizeof(Byte)); &nbsp;//运行截取过来的值
PByte(Pointer(Integer(FMyAsm2) + 88 + Fbytelen))^ := \(C2; &nbsp; &nbsp;// 在内存字段的最终写下(retn )<br />Pword(Pointer(Integer(FMyAsm2) + 89 + Fbytelen))^ := \)0000;
HookAddr;

三、通讯录的读取。
网络教程是类似消息截取一样再登陆的时候做了一个hook。但是像我这样只用一个账号,且用键盘hook的模式,就感觉不是很方面。总感觉有很多时候是开启微信以后再注入的。
所以我想总归有一个地方存储了通讯了的相关讯息。于是分以下几步描述下(截图实在他麻烦,有ce,od基础的我想应该能理解我说的):
1、ce搜索微信特定名称,比如讨厌的人1111
2、不停切换,最小化,最大化,再搜索讨厌的人1111,ce数据再50以内。
3、修改一半的数据为讨厌的人2222,通过是否改变通讯录名称来筛选数据。
4、重复3确认讨厌的人1111的内存地址。
5、od追溯内存地址偏移。发现通讯录存储为典型的二叉树结构如下:
接下来就是通过找到的二叉树根。对二叉树进行遍历。我只会递归的二叉遍历,代码如下:

procedure AddListTraver;
&nbsp;
&nbsp; procedure DoAddListTraver(ARoot: Integer);
&nbsp; begin
&nbsp;
&nbsp; &nbsp; if pbyte(ARoot + \(D)^ = 0 then<br />&nbsp; &nbsp; begin<br />&nbsp; &nbsp; &nbsp; //Form_Client.DspMsg(ARoot.ToHexString);<br />&nbsp; &nbsp; &nbsp; SetLength(arr_Addlist, Length(arr_Addlist) + 1);<br />&nbsp; &nbsp; &nbsp; arr_Addlist[High(arr_Addlist)] := ARoot;<br />&nbsp; &nbsp; &nbsp; DoAddListTraver(pinteger(ARoot + \)8)^);
&nbsp; &nbsp; &nbsp; DoAddListTraver(pinteger(ARoot)^);
&nbsp; &nbsp; end;
&nbsp; end;
&nbsp;
var
&nbsp; addr: LongInt;
&nbsp; base: LongInt;
&nbsp; header: DWORD;
begin
&nbsp; SetLength(arr_Addlist, 0);
&nbsp; SupermemScan(AddrListSig, GetModuleHandle(‘WeChatWin’) + \(1000, GetModuleHandle(&#39;WeChatWin&#39;) + \)1000 + \(, addr);<br />&nbsp; addr := addr - \)4;
&nbsp; base := Pdword(addr)^;
&nbsp; header := pdword(pdword(pdword(base)^ + \(28 + \)84)^ + \(4)^;<br />&nbsp; //二叉遍历<br />// &nbsp;DoAddListTraver(pdword(header)^);<br />// &nbsp;DoAddListTraver(pdword(header + \)8)^);
&nbsp; DoAddListTraver(header);
&nbsp;
end;


讯享网

四、消息发送call。delphi写的难点似乎就是构造以下消息及id的结构。实现代码如下:

procedure SendMsg(wx_ID, Amsg: string; aite: string = ‘’);
type
&nbsp; Tmsg = record
&nbsp; &nbsp; content: PChar;
&nbsp; &nbsp; len1: LongInt;
&nbsp; &nbsp; len2: LongInt;
&nbsp; end;
var
&nbsp; p_ID, Pamsg, paite: TMsg;
&nbsp; callAddr: LongInt;
&nbsp; buff: array[0..\(87c] of Byte;<br />&nbsp; p1, p2, p3: Pointer;<br />begin<br />&nbsp; SupermemScan(SendCallSig, GetModuleHandle(&#39;WeChatWin&#39;) + \)1000, GetModuleHandle(‘WeChatWin’) + \(1000 + \), callAddr);
&nbsp; callAddr := callAddr + \(F + pdword(callAddr + \)b)^;
&nbsp; p_ID.content := PChar(wx_ID);
&nbsp; p_ID.len1 := Length(wx_ID);
&nbsp; p_ID.len2 := Length(wx_ID) * 2;
&nbsp; Pamsg.content := PChar(Amsg);
&nbsp; Pamsg.len1 := Length(Amsg);
&nbsp; Pamsg.len2 := Length(Amsg) * 2;
&nbsp; if aite = ‘’ then
&nbsp; begin
&nbsp; &nbsp; paite.content := nil;
&nbsp; end
&nbsp; else
&nbsp; begin
&nbsp; &nbsp; paite.content := PChar(aite);
&nbsp; end;
&nbsp; paite.len1 := Length(aite);
&nbsp; paite.len2 := Length(aite) * 2;
&nbsp; p1 := @p_ID;
&nbsp; p2 := @Pamsg;
&nbsp; p3 := @paite;
&nbsp; asm
&nbsp; &nbsp; &nbsp; &nbsp; mov &nbsp; &nbsp; edx, p1;
&nbsp; &nbsp; &nbsp; &nbsp; mov &nbsp; &nbsp; eax, p3;
&nbsp; &nbsp; &nbsp; &nbsp; push &nbsp; &nbsp;1;
&nbsp; &nbsp; &nbsp; &nbsp; push &nbsp; &nbsp;eax;
&nbsp; &nbsp; &nbsp; &nbsp; mov &nbsp; &nbsp; ebx, p2;
&nbsp; &nbsp; &nbsp; &nbsp; push &nbsp; &nbsp;ebx;
&nbsp; &nbsp; &nbsp; &nbsp; lea &nbsp; &nbsp; ecx, buff;
&nbsp; &nbsp; &nbsp; &nbsp; call &nbsp; &nbsp;calladdr;
&nbsp; &nbsp; &nbsp; &nbsp; add &nbsp; &nbsp; esp, $C;
&nbsp; end;
&nbsp;
end;

这段代码我自己都觉得挺烂的 尤其 p1 p2 p3那段,欢迎介绍一些更好的写法。
我自己还有一些不清楚的地方:
1、做群控的话,涉及进程间通信,delphi没有易语言那种一句话代码,不知道用什么组件实现比较合适。
2、上面的这些代码 &nbsp;尤其是发信的这段 挺烂的 &nbsp;有没有大佬优化下。
3、注入的方式我自己熟悉的只有键盘hook ,还有远程线程注入。但以前捣鼓的时候 ,还有远程线程注入。就微信hook ,那种比较合适,为啥。

小讯
上一篇 2025-06-16 16:29
下一篇 2025-06-01 23:20

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/197295.html