现在微信电脑版运用比较普遍,平时很想向QQ那样抓取聊天内容,或者作一个自应答系统,在这里写出对微信好友昵称的抓取。希望对大家起到抛砖引玉的作用。
部分源码:
foreach (Process process in processes)
{
if (process.ProcessName == "WeChat")
{
WxProcess = process;
this.textBox1.AppendText("微信已找到!" + Environment.NewLine);
this.textBox1.AppendText("微信句柄:\t" + "0x" + ((int)(process.Handle)).ToString("X8") + Environment.NewLine);
foreach (ProcessModule processModule in process.Modules)
{
if (processModule.ModuleName == "WeChatWin.dll")
{
WeChatWinBaseAddress = processModule.BaseAddress;
this.textBox1.AppendText("微信基址:\t" + "0x" + ((int)(processModule.BaseAddress)).ToString("X8") + Environment.NewLine);
WeChatVersion = processModule.FileVersionInfo.FileVersion;
this.textBox1.AppendText("微信版本:\t" + processModule.FileVersionInfo.FileVersion + Environment.NewLine);
break;
}
}
break;
}
}
if (WxProcess == null)
{
this.textBox1.AppendText("微信没有找到!");
return;
}
//微信号
int WxNameAddress = (int)WeChatWinBaseAddress + 0x1131B90;
this.textBox1.AppendText("微信号地址:\t" + "0x" + ((int)(WxNameAddress)).ToString("X8") + Environment.NewLine);
string str1=GetString(WxProcess.Handle, (IntPtr)WxNameAddress);
byte[] buffer = Encoding.GetEncoding("GB2312").GetBytes(str1);
string newString = Encoding.UTF8.GetString(buffer);
this.textBox1.AppendText("微信号:\t" + newString + Environment.NewLine);
//微信昵称
int WxNickNameAddress = (int)WeChatWinBaseAddress + 0x1131C64;
this.textBox1.AppendText("微信昵称地址:\t" + "0x" + ((int)(WxNickNameAddress)).ToString("X8") + Environment.NewLine);
string str2 = GetString(WxProcess.Handle, (IntPtr)WxNickNameAddress);
byte[] buffer1 = Encoding.UTF8.GetBytes(str2);
string newString1 = Encoding.UTF8.GetString(buffer1);
this.textBox1.AppendText("微信昵称:\t" + newString1 + Environment.NewLine);
}
String GetString(IntPtr hProcess, IntPtr lpBaseAddress, int nSize = 100)
{
byte[] data = new byte[nSize];
if (ReadProcessMemory(hProcess, lpBaseAddress, data, nSize, 0) == 0)
{
//读取内存失败!
return "";
}
String result = "";
String TempString = Encoding.ASCII.GetString(data);
// \0
foreach (char item in TempString)
{
if (item == '\0')
{
break;
}
result += item.ToString();
}
return result;
}
源代码下载:下载地址