-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin_systemFunctions.cpp
159 lines (154 loc) · 5.92 KB
/
win_systemFunctions.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "resource.h"
void inputSender(std::string& input, HANDLE& g_hChildStd_IN_Wr)
{
DWORD dwWritten;
WriteFile(g_hChildStd_IN_Wr, input.c_str(), input.length(), &dwWritten, NULL);
CloseHandle(g_hChildStd_IN_Wr);
}
void memoryMonitor(std::mutex& mtx, HANDLE& process, SIZE_T& memoryusage, bool& exitflag)
{
PROCESS_MEMORY_COUNTERS_EX pmc;
while(!exitflag)
{
GetProcessMemoryInfo(process, (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc));
mtx.lock();
memoryusage=pmc.PeakPagefileUsage;
mtx.unlock();
Sleep(100);
}
}
DWORD uploadContent(std::string ftp_prefix,
std::string domain,
std::string directory,
std::string username,
std::string password,
std::string filename,
std::string content,
DWORD& errorcode,
DWORD& ierrorcode,
std::string& errormessage)
{
if(InternetAttemptConnect(0)==ERROR_SUCCESS)
{
HINTERNET hInternet=InternetOpen((ftp_prefix+domain).c_str(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if(hInternet!=NULL)
{
HINTERNET hConnect=InternetConnect(hInternet, domain.c_str(), INTERNET_DEFAULT_FTP_PORT, username.c_str(), password.c_str(), INTERNET_SERVICE_FTP, 0, 0);
if(hConnect!=NULL)
{
HINTERNET ftpfile=FtpOpenFile(hConnect, (directory+"/"+filename).c_str(), GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY, 0);
if(ftpfile!=NULL)
{
DWORD dwWritten=0;
if(!InternetWriteFile(ftpfile, content.c_str(), content.length(), &dwWritten))
{
char szBuffer[4097];
memset(szBuffer, 0, sizeof(szBuffer));
DWORD dwBufferLength=4096;
InternetGetLastResponseInfo(&ierrorcode, szBuffer, &dwBufferLength);
errormessage=szBuffer;
errorcode=GetLastError();
}
else
{
errorcode=0;
ierrorcode=0;
errormessage.clear();
}
InternetCloseHandle(ftpfile);
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
return dwWritten;
}
if(errormessage.empty())
errormessage="ftpfile is NULL";
InternetCloseHandle(ftpfile);
}
if(errormessage.empty())
errormessage="hConnect is NULL";
InternetCloseHandle(hConnect);
}
if(errormessage.empty())
errormessage="hInternet is NULL";
InternetCloseHandle(hInternet);
}
errorcode=GetLastError();
return 0;
}
bool uploadFile(std::string ftp_prefix,
std::string domain,
std::string username,
std::string password,
std::string localfilename,
std::string filename,
DWORD& errorcode,
DWORD& ierrorcode,
std::string& errormessage)
{
bool bSuccess=false;
if(InternetAttemptConnect(0)==ERROR_SUCCESS)
{
HINTERNET hInternet=InternetOpen((ftp_prefix+domain).c_str(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if(hInternet!=NULL)
{
HINTERNET hConnect=InternetConnect(hInternet, domain.c_str(), INTERNET_DEFAULT_FTP_PORT, username.c_str(), password.c_str(), INTERNET_SERVICE_FTP, 0, 0);
if(hConnect!=NULL)
{
if(!FtpPutFile(hConnect, localfilename.c_str(), filename.c_str(), FTP_TRANSFER_TYPE_BINARY, 0))
{
char szBuffer[4097];
memset(szBuffer, 0, sizeof(szBuffer));
DWORD dwBufferLength=4096;
InternetGetLastResponseInfo(&ierrorcode, szBuffer, &dwBufferLength);
errormessage=szBuffer;
errorcode=GetLastError();
}
else
{
errorcode=0;
ierrorcode=0;
errormessage.clear();
bSuccess=true;
}
}
InternetCloseHandle(hConnect);
}
InternetCloseHandle(hInternet);
}
return bSuccess;
}
bool request(std::string http_prefix,
std::string domain,
std::string filename,
std::string& out)
{
bool bSuccess=false;
LPCTSTR rgpszAcceptTypes[]= {TEXT("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), NULL};
if(InternetAttemptConnect(0)==ERROR_SUCCESS)
{
HINTERNET hInternet=InternetOpen((http_prefix+domain).c_str(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if(hInternet!=NULL)
{
HINTERNET hConnect=InternetConnect(hInternet, domain.c_str(), INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if(hConnect!=NULL)
{
HINTERNET hRequest=HttpOpenRequest(hConnect, TEXT("GET"), filename.c_str(), NULL, NULL, rgpszAcceptTypes, INTERNET_FLAG_RESYNCHRONIZE, 0);
if(hRequest!=NULL)
{
if(HttpSendRequest(hRequest, (TCHAR*)"Content-type:text/html", -1L, NULL, 0))
{
char ch;
DWORD dwBytes;
while(InternetReadFile(hRequest, &ch, 1, &dwBytes) && dwBytes==1)
out+=ch;
bSuccess=true;
}
}
InternetCloseHandle(hRequest);
}
InternetCloseHandle(hConnect);
}
InternetCloseHandle(hInternet);
}
return bSuccess;
}