提交 e350df9f 编写于 作者: L ljc545w

优化部分逻辑

上级 38abfe37
......@@ -38,6 +38,8 @@ bool Injert(DWORD dwPid,wchar_t* workPath) {
string name = _com_util::ConvertBSTRToString((BSTR)workPath);
if (!isFileExists_stat(name)) {
MessageBox(NULL, dllpath, L"文件不存在", MB_ICONWARNING);
delete[] dllpath;
dllpath = NULL;
return 1;
}
bool status = InjectDll(dwPid, dllpath);
......
......@@ -44,7 +44,7 @@ wstring SelfInfoString = L"";
HANDLE hProcess = NULL;
bool isFileExists_stat(string& name) {
BOOL isFileExists_stat(string& name) {
struct stat buffer;
return (stat(name.c_str(), &buffer) == 0);
}
......@@ -226,4 +226,63 @@ wstring GetComWorkPath() {
int pos = wpath.find_last_of(L"\\");
wpath = wpath.substr(0,pos);
return wpath;
}
static BOOL GetWeChatInstallInfo(TCHAR* lpValueName, VOID* Value, DWORD lpcbData) {
HKEY hKey = NULL;
ZeroMemory(Value, lpcbData);
LSTATUS lRet = RegOpenKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\Tencent\\WeChat"), 0, KEY_QUERY_VALUE, &hKey);
if (lRet != 0) {
return false;
}
lRet = RegQueryValueEx(hKey, lpValueName, NULL, NULL, (LPBYTE)Value, &lpcbData);
RegCloseKey(hKey);
if (lRet != 0) {
return false;
}
return true;
}
tstring GetWeChatInstallDir() {
TCHAR* szProductType = new TCHAR[MAX_PATH];
GetWeChatInstallInfo((TCHAR*)TEXT("InstallPath"), (void*)szProductType, MAX_PATH);
tstring wxdir(szProductType);
delete[] szProductType;
szProductType = NULL;
return wxdir.length() == 0 ? TEXT("") : wxdir;
}
DWORD GetWeChatVerInt() {
DWORD version = 0x0;
GetWeChatInstallInfo((TCHAR*)TEXT("Version"), (void*)&version, sizeof(DWORD));
return version;
}
tstring GetWeChatVerStr() {
BYTE pversion[4] = { 0 };
GetWeChatInstallInfo((TCHAR*)TEXT("Version"), (void*)pversion, sizeof(DWORD));
TCHAR* temp = new TCHAR[20];
_stprintf_s(temp, 20, _T("%d.%d.%d.%d\0"), (int)(pversion[3] - 0x60), (int)pversion[2], (int)pversion[1], (int)pversion[0]);
tstring verStr(temp);
delete[] temp;
temp = NULL;
return verStr;
}
VOID StartWeChat()
{
tstring szAppName = GetWeChatInstallDir();
if (szAppName.length() == 0)
return;
szAppName += TEXT("\\WeChat.exe");
STARTUPINFO StartInfo;
ZeroMemory(&StartInfo, sizeof(StartInfo));
PROCESS_INFORMATION procStruct;
ZeroMemory(&procStruct, sizeof(procStruct));
StartInfo.cb = sizeof(STARTUPINFO);
if (CreateProcess((LPCTSTR)szAppName.c_str(), NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &StartInfo, &procStruct))
{
CloseHandle(procStruct.hProcess);
CloseHandle(procStruct.hThread);
}
}
\ No newline at end of file
......@@ -29,15 +29,22 @@
#include "robotdata.h"
using namespace std;
struct testStruct {
DWORD type;
wchar_t* desc;
};
bool isFileExists_stat(string& name);
#ifdef _UNICODE
#define tstring std::wstring
#else
#define tstring std::string
#endif
BOOL isFileExists_stat(string& name);
DWORD GetWeChatRobotBase();
DWORD GetWeChatPid();
DWORD StartRobotService();
DWORD StopRobotService();
BOOL CreateConsole();
wstring GetComWorkPath();
\ No newline at end of file
wstring GetComWorkPath();
tstring GetWeChatInstallDir();
DWORD GetWeChatVerInt();
tstring GetWeChatVerStr();
VOID StartWeChat();
\ No newline at end of file
......@@ -11,7 +11,9 @@ BOOL APIENTRY DllMain( HMODULE hModule,
case DLL_PROCESS_ATTACH:
{
#ifdef _DEBUG
PrintProcAddr();
if (ProcessIsWeChat()) {
PrintProcAddr();
}
#endif
break;
}
......
......@@ -155,6 +155,7 @@ wchar_t* GetTimeW() {
void PrintProcAddr() {
CreateConsole();
printf("WeChatVersion %s\n", GetWeChatVerStr().c_str());
printf("SendImage 0x%08X\n", (DWORD)SendImage);
printf("SendText 0x%08X\n", (DWORD)SendText);
printf("SendFile 0x%08X\n", (DWORD)SendFile);
......@@ -170,4 +171,71 @@ void PrintProcAddr() {
printf("VerifyFriendApply 0x%08X\n", (DWORD)VerifyFriendApply);
printf("AddFriendByV3 0x%08X\n", (DWORD)AddFriendByV3);
printf("AddFriendByWxid 0x%08X\n", (DWORD)AddFriendByWxid);
}
BOOL ProcessIsWeChat()
{
char szFileFullPath[MAX_PATH] = { 0 }, szProcessName[MAX_PATH] = { 0 };
GetModuleFileNameA(NULL, szFileFullPath, MAX_PATH);
int length = ::strlen(szFileFullPath);
for (int i = length - 1; i >= 0; i--)
{
if (szFileFullPath[i] == '\\')
{
i++;
for (int j = 0; i <= length; j++)
{
szProcessName[j] = szFileFullPath[i++];
}
break;
}
}
if (::strcmp(szProcessName, "WeChat.exe") != 0)
{
return FALSE;
}
else
{
return TRUE;
}
}
DWORD GetWeChatVerInt()
{
WCHAR VersionFilePath[MAX_PATH];
BYTE WeChatVersion[4] = { 0 };
if (GetModuleFileName((HMODULE)GetWeChatWinBase(), VersionFilePath, MAX_PATH) == 0)
{
return 0;
}
VS_FIXEDFILEINFO* pVsInfo;
unsigned int iFileInfoSize = sizeof(VS_FIXEDFILEINFO);
int iVerInfoSize = GetFileVersionInfoSize(VersionFilePath, NULL);
if (iVerInfoSize != 0) {
char* pBuf = new char[iVerInfoSize];
if (GetFileVersionInfo(VersionFilePath, 0, iVerInfoSize, pBuf)) {
if (VerQueryValue(pBuf, TEXT("\\"), (void**)&pVsInfo, &iFileInfoSize)) {
WeChatVersion[3] = (BYTE)(0x60 + (pVsInfo->dwFileVersionMS >> 16) & 0x0000FFFF);
WeChatVersion[2] = (BYTE)(pVsInfo->dwFileVersionMS & 0x0000FFFF);
WeChatVersion[1] = (BYTE)((pVsInfo->dwFileVersionLS >> 16) & 0x0000FFFF);
WeChatVersion[0] = (BYTE)(pVsInfo->dwFileVersionLS & 0x0000FFFF);
}
}
delete[] pBuf;
}
return *(DWORD*)WeChatVersion;
}
string GetWeChatVerStr() {
DWORD WeChatVersion = GetWeChatVerInt();
if (WeChatVersion == 0)
return "null";
string wxver = "";
BYTE* pWxVer = (BYTE*)&WeChatVersion;
strstream wxVer;
wxVer << (int)pWxVer[3] - 0x60 << "." << (int)pWxVer[2] << "." << (int)pWxVer[1] << "." << (int)pWxVer[0];
wxVer >> wxver;
return wxver;
}
\ No newline at end of file
......@@ -30,9 +30,11 @@
#include "VerifyFriendApply.h"
#include "AddFriend.h"
#include <vector>
#include <strstream>
#endif //PCH_H
using namespace std;
#pragma comment(lib,"version.lib")
// 对于导出函数,需要使用此宏修饰
#define DLLEXPORT extern "C" __declspec(dllexport)
......@@ -84,3 +86,6 @@ DLLEXPORT void UnHookAll();
wstring wreplace(wstring source, wchar_t replaced, wstring replaceto);
void PrintProcAddr();
wchar_t* GetTimeW();
BOOL ProcessIsWeChat();
DWORD GetWeChatVerInt();
string GetWeChatVerStr();
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册