-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
111 lines (85 loc) · 1.9 KB
/
main.cpp
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
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <stdlib.h>
#include "detect.h"
#include "monitor.h"
#pragma comment(lib, "Ws2_32.lib")
static void _init_winsock()
{
WSADATA wsaData;
int iResult;
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0) {
printf("WSAStartup failed: %d\n", iResult);
exit(1);
}
}
static void _print_ip(DWORD addr, DWORD port)
{
printf("%d.%d.%d.%d:%u",
(addr ) & 0xFF,
(addr >> 8) & 0xFF,
(addr >> 16) & 0xFF,
(addr >> 24),
port
);
}
DWORD dwThreadIds[MAX_CONN];
HANDLE hThreads[MAX_CONN];
static void _report_conns()
{
printf("Found %d connections:\n", nConn);
for (int i = 0; i < nConn; ++i) {
printf("... %2d: ", i);
_print_ip(connList[i].localAddr, connList[i].localPort);
printf(" -> ");
_print_ip(connList[i].remoteAddr, connList[i].remotePort);
printf("\n");
}
}
static void _spawn_threads()
{
for (int i = 0; i < nConn; ++i) {
hThreads[i] = CreateThread(
NULL, // default security
0, // default stack size
(LPTHREAD_START_ROUTINE) start_monitor, // func
(LPVOID) (LONGLONG) i, // arg
0, // (flags)
&dwThreadIds[i]
);
if (hThreads[i] == NULL) {
printf("CreateThread() for conn. id %d has failed;\n\terror code 0x%08x",
i, GetLastError());
exit(1);
}
}
}
int main()
{
_init_winsock();
find_ffxiv_connection();
_report_conns();
_spawn_threads();
DWORD res;
res = WaitForMultipleObjects(nConn, hThreads, TRUE, INFINITE);
if (res == WAIT_FAILED) {
printf("WaitForMultipleObjects() failed with error code 0x%08x\n",
GetLastError());
}
printf("Wait done.(res %08x=%u.) Now reaping...\n", res, res);
for(int i=0; i<nConn; i++)
{
CloseHandle(hThreads[i]);
}
printf("Reaping done.\n");
WSACleanup();
return 0;
}