[C++] 纯文本查看 复制代码 #include <iostream>
#include <windows.h>
#include <TlHelp32.h>
using namespace std;
DWORD GetModuleInfo(DWORD pid,const wchar_t*name)
{
MODULEENTRY32 module;
module.dwSize = sizeof(module);
HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
if (handle == INVALID_HANDLE_VALUE)
{
return 0;
}
BOOL ret = Module32First(handle, &module);
while (ret)
{
if (!wcscmp(name, module.szModule))
{
CloseHandle(handle);
return (DWORD)module.modBaseAddr;
}
ret = Module32Next(handle, &module);
}
CloseHandle(handle);
return 0;
}
DWORD 取QQ号(DWORD pid)
{
HANDLE hprocess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (!hprocess)
{
cout << "打开进程失败,错误码: " << GetLastError() << endl;
return 0;
}
DWORD addr = GetModuleInfo(pid, L"AudioVideo.dll") + 0x8015FC;//QQ号码
DWORD num = 0;
BOOL ret = ReadProcessMemory(hprocess, (LPCVOID)addr, &num, 4, NULL);
if (!ret)
{
cout << "读取内存失败,错误码: " << GetLastError() << endl;
CloseHandle(hprocess);
return 0;
}
else
{
DWORD addr1 = GetModuleInfo(pid, L"PreloginLogic.dll") + 0x1165B0;//该QQ在线为1,不在线为0
DWORD isonline = 666;
if (ReadProcessMemory(hprocess, (LPCVOID)addr1, &isonline, 4, NULL) && isonline == 1)
{
CloseHandle(hprocess);
return num;
}
}
CloseHandle(hprocess);
return 0;
}
BOOL 该QQ是否在线(DWORD Q号)
{
PROCESSENTRY32 pe;
pe.dwSize = sizeof(pe);
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
BOOL ret = Process32First(hSnapshot, &pe);
while (ret)
{
if (!wcscmp(L"QQ.exe", pe.szExeFile))
{
if (取QQ号(pe.th32ProcessID) == Q号)
{
CloseHandle(hSnapshot);
return TRUE;
}
}
ret = Process32Next(hSnapshot, &pe);
}
CloseHandle(hSnapshot);
return FALSE;
}
int main()//适用于当前最新版本:QQ 9.4.9(27849),其它版本未测试
{
DWORD QQnum = 0;
while (TRUE)
{
cout << "请输入要检测是否在线的QQ号:" << endl;
cin >> QQnum;
if (QQnum)
{
cout << "你输入的QQ号为: " << QQnum << endl;
break;
}
}
clock_t start = clock();
BOOL ret = 该QQ是否在线(QQnum);
clock_t end = clock();
cout <<"该QQ号:"<< QQnum << " 在线状态为: " << ret <<" 耗时: " <<end-start<<"ms" << endl;
system("pause");
return 0;
} |