-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpotifyVirus.cpp
More file actions
129 lines (102 loc) · 2.67 KB
/
Copy pathSpotifyVirus.cpp
File metadata and controls
129 lines (102 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>
#include <Windows.h>
#include <tlhelp32.h>
DWORD FindProcessId(const std::wstring& processName)
{
PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);
HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (processesSnapshot == INVALID_HANDLE_VALUE) {
return 0;
}
Process32First(processesSnapshot, &processInfo);
if (!processName.compare(processInfo.szExeFile))
{
CloseHandle(processesSnapshot);
return processInfo.th32ProcessID;
}
while (Process32Next(processesSnapshot, &processInfo))
{
if (!processName.compare(processInfo.szExeFile))
{
CloseHandle(processesSnapshot);
return processInfo.th32ProcessID;
}
}
CloseHandle(processesSnapshot);
return 0;
}
HWND GetWindowFromProcessID(DWORD targetProcID)
{
HWND hwnd = NULL;
do
{
hwnd = FindWindowEx(NULL, hwnd, NULL, NULL);
DWORD dwProcID = 0;
GetWindowThreadProcessId(hwnd, &dwProcID);
if (dwProcID == targetProcID)
return hwnd;
} while (hwnd != NULL);
return NULL;
}
HWND FindSpotify()
{
DWORD spotifyPID = FindProcessId(L"Spotify.exe");
if (!spotifyPID)
return NULL;
return GetWindowFromProcessID(spotifyPID);
}
void SendCommand(HWND spotify, int command)
{
SendMessage(spotify, WM_APPCOMMAND, 0, MAKELPARAM(0, command));
}
void HandleInput(HWND spotify)
{
static bool bPressed = 0; //Flag
if (GetKeyState(VK_RCONTROL) & 0x8000)
{
// Strg UP -> Play/Pause
if ((GetAsyncKeyState(VK_UP) & 0x8000) && !bPressed) {
bPressed = true;
SendCommand(spotify, APPCOMMAND_MEDIA_PLAY_PAUSE);
//std::cout << "Skipping song" << std::endl;
}
// Strg Right -> Next
if ((GetAsyncKeyState(VK_RIGHT) & 0x8000) && !bPressed) {
bPressed = true;
SendCommand(spotify, APPCOMMAND_MEDIA_NEXTTRACK);
//std::cout << "Next song" << std::endl;
}
// Strg Left -> Prev
if ((GetAsyncKeyState(VK_LEFT) & 0x8000) && !bPressed) {
bPressed = true;
SendCommand(spotify, APPCOMMAND_MEDIA_PREVIOUSTRACK);
//std::cout << "Prev song" << std::endl;
}
// shady stuff
if (GetKeyState(VK_UP) == 0 && !((GetAsyncKeyState(VK_LEFT) & 0x8000) || (GetAsyncKeyState(VK_RIGHT) & 0x8000))) {
bPressed = false;
}
if (GetKeyState(VK_RIGHT) == 0 && !((GetAsyncKeyState(VK_UP) & 0x8000) || (GetAsyncKeyState(VK_LEFT) & 0x8000))) {
bPressed = false;
}
if (GetKeyState(VK_LEFT) == 0 && !((GetAsyncKeyState(VK_RIGHT) & 0x8000) || (GetAsyncKeyState(VK_UP) & 0x8000))) {
bPressed = false;
}
}
if (GetKeyState(VK_RCONTROL) == 0)
{
bPressed = false;
}
}
int main()
{
ShowWindow(GetConsoleWindow(), SW_HIDE);
while (true) {
Sleep(20);
HWND spotify = FindSpotify();
if (!spotify)
continue;
HandleInput(spotify);
}
}