用Python发送微信消息给好友(优化篇) | 您所在的位置:网站首页 › python定时发送微信消息 › 用Python发送微信消息给好友(优化篇) |
目录
前言第二次优化第三次优化
前言
之前说了怎么写机器码到内存,然后调用。现在说说怎么优化。 用Python发送微信消息给好友 第二次优化再看一遍c语言的代码 void SendText( wchar_t* wsTextMsg) { // 发送的好友,filehelper是文件传输助手 wchar_t wsWxId[0x10] = L"filehelper"; WxBaseStruct wxWxid(wsWxId); // 发送的消息内容 WxBaseStruct wxTextMsg(wsTextMsg); wchar_t** pWxmsg = &wxTextMsg.buffer; char buffer[0x3B0] = { 0 }; char wxNull[0x100] = { 0 }; DWORD dllBaseAddress = (DWORD)GetModuleHandleA("WeChatWin.dll"); // 发消息的函数call地址 DWORD callAddress = dllBaseAddress + 0x521D30; __asm { lea eax, wxNull; push 0x1; push eax; mov edi, pWxmsg; push edi; lea edx, wxWxid; lea ecx, buffer; call callAddress; add esp, 0xC; } }上面的代码真正发消息的是asm里面的代码,之前的c代码都是在组装内存数据。那我们是不是可以用Python组装数据,只讲下面的汇编转为机器码写入内存调用,这样就少了很多无用的机器码。 改完的SendText函数如下 wchar_t wsWxId[0x10] = L"filehelper"; wchar_t wsTextMsg[0x100] = L"test"; WxBaseStruct wxWxid(wsWxId); WxBaseStruct wxTextMsg(wsTextMsg); wchar_t** pWxmsg = &wxTextMsg.buffer; char buffer[0x3B0] = { 0 }; char wxNull[0x100] = { 0 }; DWORD dllBaseAddress = (DWORD)GetModuleHandleA("WeChatWin.dll");; DWORD callAddress = dllBaseAddress + 0x521D30; void SendText() { __asm { lea eax, wxNull; push 0x1; push eax; mov edi, pWxmsg; push edi; lea edx, wxWxid; lea ecx, buffer; call callAddress; add esp, 0xC; } }汇编代码: 完整代码如下: import os import pymem import ctypes import time def convert_addr(addr): if isinstance(addr, int): addr = hex(addr) if addr.startswith("0x") or addr.startswith("0X"): addr = addr[2:] if len(addr) |
CopyRight 2018-2019 实验室设备网 版权所有 |