-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStuffs.h
74 lines (58 loc) · 1.86 KB
/
Stuffs.h
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
#pragma once
#include <Windows.h>
#include <WinINet.h>
#include <string>
#pragma comment(lib, "wininet")
using namespace std;
void get_file(const char* dllName, const char* fileName, char* buffer, int bfSize) {
GetModuleFileName(GetModuleHandle(dllName), buffer, bfSize);
if (strlen(fileName) + strlen(buffer) < MAX_PATH) {
char* pathEnd = strrchr(buffer, '\\');
strcpy(pathEnd + 1, fileName);
}
else {
*buffer = 0;
}
}
std::string replaceAll(std::string subject, const std::string& search,
const std::string& replace) {
size_t pos = 0;
while ((pos = subject.find(search, pos)) != std::string::npos) {
subject.replace(pos, search.length(), replace);
pos += replace.length();
}
return subject;
}
inline std::string DownloadURL(const std::string &url) {
HINTERNET interwebs = InternetOpenA("Mozilla/5.0", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, NULL);
std::string rtn;
if (interwebs) {
HINTERNET url_file = InternetOpenUrlA(interwebs, url.c_str(), NULL, NULL, NULL, NULL);
if (url_file) {
char buffer[2000];
DWORD bytes_read;
do {
InternetReadFile(url_file, buffer, 2000, &bytes_read);
rtn.append(buffer, bytes_read);
memset(buffer, 0, 2000);
} while (bytes_read);
InternetCloseHandle(interwebs);
InternetCloseHandle(url_file);
std::string p = replaceAll(rtn, "|n", "\r\n");
return p;
}
}
InternetCloseHandle(interwebs);
std::string p = replaceAll(rtn, "|n", "\r\n");
return p;
}
void erase_peheader() {
HMODULE hdll;
char cpath[MAX_PATH];
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, "csapi.dll", &hdll);
GetModuleFileName(hdll, cpath, MAX_PATH);
DWORD old;
VirtualProtect(hdll, 0x500, PAGE_READWRITE, &old);
memset(hdll, 0, 0x500);
VirtualProtect(hdll, 0x500, old, &old);
}