0%

My Dlls

下面是写程序时自己写的一些函数,可以直接拿来用

项目地址:Github

DLL下载:dllCompilation

属性页配置

没有安装OpenSSL先下载安装 OpenSSL-Win32 OpenSSL-Win64 pswd:1234

链接库:

1
2
3
4
配置属性 => C/C++ => 常规 => 附加包含目录 D:\OpenSSL\OpenSSL-Win32\include
配置属性 => 链接器 => 常规 => 附加库目录 D:\OpenSSL\OpenSSL-Win32\lib\
配置属性 => 链接器 => 输入 => libssl.lib
libcrypto.lib

功能(pch.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
#ifndef PCH_H

#define PCH_H
#define BUFFER_SIZE 10000

#include "framework.h"
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <Windows.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <d3d9.h>
#include <openssl/md5.h>
#include <iphlpapi.h>
#include <time.h>
#include <tlhelp32.h>
#include <Psapi.h>
#include <d3d9.h>
#include <ctype.h>

#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "psapi.lib")
#pragma comment(lib, "d3d9.lib")

// 检测程序是否运行在虚拟机中 非虚拟机:0 虚拟机:1 Direct3D初始化失败:2 获取适配器信息失败:3
extern "C" _declspec(dllexport) DWORD WINAPI GPUProcDetect(LPVOID lpParameter);

// 传入进程名和类名,关闭所有在任务栏中打开的这些程序,但是不结束这个程序本身的进程
extern "C" _declspec(dllexport) int killtasks(const char* targetTitles[], size_t targetTitlesSize, const char* targetClassNames[], size_t targetClassNamesSize);

// 获取UUID的md5值,返回md5值字符串,可以作为识别计算机唯一标识
extern "C" _declspec(dllexport) char* getUUIDmd5();

// 通过个人Gitee仓库中获取IP和Port,一般用于程序需要内网穿透并需要客户端自动获取服务端IP和Port的场景(因为内网穿透的IP和Port经常变化)
// 使用方法:在个人仓库中创建一个.txt文件,内容格式为:127.0.0.1 8080,前面为IP后面为Port,中间使用空格分隔
// 第一个参数:点击该.txt文件,直接复制url,如:https://gitee.com/zzzzzyg/socket/blob/master/configuration.txt
// 第二个参数:点击.txt文件后,点击右边的原始数据,仅复制路径,如:/zzzzzyg/socket/raw/master/configuration.txt
extern "C" _declspec(dllexport) char* getIPaPORT(const char* url, const char* path);

// 检查文件是否不存在,不存在返回1,存在返回0
extern "C" _declspec(dllexport) int file_notexists(const char* filename);

// 使用curl下载文件到指定路径,url须为文件直链链接,文件路径使用/分隔符,不要使用\分隔符
extern "C" _declspec(dllexport) void curlDownload(const char* path, const char* url);

// 自定义打印
// 第一个参数:要打印的字符串
// 第二个参数:打印样式。0重置所有的样式 1粗体 2暗色(浅色) 3斜体 4下划线 5慢速闪烁 6快速闪烁 7反色 8隐藏 9删除线
// 第三个参数:前景色。0黑色 1红色 2绿色 3黄色 4蓝色 5洋红色 6青色 7白色
// 第四个参数:背景色。0黑色 1红色 2绿色 3黄色 4蓝色 5洋红色 6青色 7白色
extern "C" _declspec(dllexport) void printc(const char* str, char* style, int ForegroundColor, int BackgroundColor);

#endif //PCH_H

代码(2024.7.20)

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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319

#include "pch.h"

int containsSubstring(const char* str, const char* substr) {
char lowerStr[128];
char lowerSubstr[128];
int i;
for (i = 0; str[i] && i < 127; i++) {
lowerStr[i] = tolower((unsigned char)str[i]);
}
lowerStr[i] = '\0';

for (i = 0; substr[i] && i < 127; i++) {
lowerSubstr[i] = tolower((unsigned char)substr[i]);
}
lowerSubstr[i] = '\0';

return strstr(lowerStr, lowerSubstr) != NULL;
}


DWORD WINAPI GPUProcDetect(LPVOID lpParameter)
{
IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if (pD3D == NULL) {
return 2;
}
D3DADAPTER_IDENTIFIER9 adapterIdentifier;
HRESULT hr = pD3D->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &adapterIdentifier);
if (FAILED(hr)) {
pD3D->Release();
return 3;
}
if (containsSubstring(adapterIdentifier.Description, "vmware") || containsSubstring(adapterIdentifier.Description, "virtualbox")) {
pD3D->Release();
return 1;
}
pD3D->Release();
return 0;
}

BOOL IsInArray(const char* str, const char** array, size_t arraySize) {
for (size_t i = 0; i < arraySize; i++) {
if (strstr(str, array[i]) != NULL) {
return TRUE;
}
}
return FALSE;
}

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
struct EnumWindowsData {
const char** targetTitles;
size_t targetTitlesSize;
const char** targetClassNames;
size_t targetClassNamesSize;
} *data = (struct EnumWindowsData*)lParam;

char windowTitle[256];
char className[256];

if (GetWindowTextA(hwnd, windowTitle, sizeof(windowTitle))) {
if (IsInArray(windowTitle, data->targetTitles, data->targetTitlesSize)) {
ShowWindow(hwnd, SW_HIDE);
}
}

if (GetClassNameA(hwnd, className, sizeof(className))) {
if (IsInArray(className, data->targetClassNames, data->targetClassNamesSize)) {
ShowWindow(hwnd, SW_HIDE);
}
}

return TRUE;
}

DWORD WINAPI WindowProcDetect(LPVOID lpParameter)
{
struct EnumWindowsData {
const char** targetTitles;
size_t targetTitlesSize;
const char** targetClassNames;
size_t targetClassNamesSize;
} *data = (struct EnumWindowsData*)lpParameter;

while (1)
{
EnumWindows(EnumWindowsProc, (LPARAM)data);
Sleep(333);
}
return 0;
}

struct EnumWindowsData {
const char** targetTitles;
size_t targetTitlesSize;
const char** targetClassNames;
size_t targetClassNamesSize;
};


int killtasks(const char* targetTitles[], size_t targetTitlesSize, const char* targetClassNames[], size_t targetClassNamesSize)
{
struct EnumWindowsData data = {
targetTitles,
targetTitlesSize,
targetClassNames,
targetClassNamesSize
};

HANDLE hThread = CreateThread(NULL, 0, WindowProcDetect, &data, 0, NULL);
if (hThread == NULL) {
return 0;
}
else {
CloseHandle(hThread);
return 1;
}
}
void compute_md5(const char* str, unsigned char* digest) {
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx, str, strlen(str));
MD5_Final(digest, &ctx);
}
void sprint_md5(char* out, const unsigned char* digest) {
for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
sprintf_s(out + i * 2, MD5_DIGEST_LENGTH * 2 + 1 - i * 2, "%02x", digest[i]);
}
}

char* getUUIDmd5()
{
char UUIDMD5[MD5_DIGEST_LENGTH * 2 + 1];
FILE* fp;
char uuid[255] = { 0 };
unsigned char digest[MD5_DIGEST_LENGTH];
char md5string[MD5_DIGEST_LENGTH * 2 + 1];

if ((fp = _popen("wmic csproduct get UUID", "r")) == NULL) {
return NULL;
}

fgets(uuid, sizeof(uuid), fp);
fgets(uuid, sizeof(uuid), fp);
uuid[strcspn(uuid, "\n")] = 0;

if (_pclose(fp) != 0) {
return NULL;
}
compute_md5(uuid, digest);
sprint_md5(md5string, digest);
strcpy_s(UUIDMD5, sizeof(UUIDMD5), md5string);
}

void handle_errors() {
ERR_print_errors_fp(stderr);
}


char* getIPaPORT(const char* url, const char* path)
{
char IPANDPORT[0x100] = { 0 };
char host[256], service[32];
struct addrinfo hints, * res, * p;
int sockfd, n;
char buffer[BUFFER_SIZE];
SSL_CTX* ctx;
SSL* ssl;

WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
fprintf(stderr, "WSAStartup failed\n");
return NULL;
}
SSL_library_init();
OpenSSL_add_all_algorithms();
SSL_load_error_strings();
if (sscanf_s(url, "https://%[^/]/", host, (unsigned)_countof(host)) != 1) {
fprintf(stderr, "Invalid URL\n");
return NULL;
}
strcpy_s(service, sizeof(service), "https");
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
int status = getaddrinfo(host, service, &hints, &res);
if (status != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
return NULL;
}
for (p = res; p != NULL; p = p->ai_next) {
sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
if (sockfd == -1)
continue;

if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
closesocket(sockfd);
continue;
}

break;
}

if (p == NULL) {
fprintf(stderr, "Failed to connect\n");
return NULL;
}
ctx = SSL_CTX_new(TLS_client_method());
if (ctx == NULL) {
handle_errors();
return NULL;
}

ssl = SSL_new(ctx);
if (ssl == NULL) {
handle_errors();
return NULL;
}
SSL_set_fd(ssl, sockfd);
if (SSL_connect(ssl) <= 0) {
handle_errors();
return NULL;
}
char request[512];
snprintf(request, sizeof(request), "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", path, host);
SSL_write(ssl, request, strlen(request));
memset(buffer, 0, BUFFER_SIZE);
while ((n = SSL_read(ssl, buffer, BUFFER_SIZE - 1)) > 0) {
strcpy_s(IPANDPORT, sizeof(IPANDPORT), strstr(buffer, "\r\n\r\n") + 4);
memset(buffer, 0, BUFFER_SIZE);
goto A;
}
A:
if (n <= 0) {
handle_errors();
return NULL;
}
SSL_free(ssl);
SSL_CTX_free(ctx);
freeaddrinfo(res);
closesocket(sockfd);
EVP_cleanup();
WSACleanup();

return _strdup(IPANDPORT);
}
int file_notexists(const char* filename) {
FILE* file = NULL;
if (fopen_s(&file, filename, "r") != 0 || file == NULL) {
return 1;
}
else {
fclose(file);
return 0;
}
}


void curlDownload(const char* path, const char* url)
{
char curlcmd[0x300];
sprintf_s(curlcmd, sizeof(curlcmd), "curl -o %s %s", path, url);
system(curlcmd);
}


void printc(const char* str, char* style, int ForegroundColor, int BackgroundColor)
{
char styleStr[50] = "\033[";
int len = 0;
bool addedStyles[10] = { false };
if (style != NULL) {
for (int i = 0; style[i] != '\0'; i++) {
int styleCode = style[i] - '0';
if (!addedStyles[styleCode]) {
len += sprintf_s(styleStr + len, sizeof(styleStr) - len, "%dm;", styleCode);
addedStyles[styleCode] = true;
}
}
}
if (ForegroundColor <= 7 && ForegroundColor >= 0) {
len += sprintf_s(styleStr + len, sizeof(styleStr) - len, "3%dm;", ForegroundColor);
}
else
{
len += sprintf_s(styleStr + len, sizeof(styleStr) - len, "%37m;", ForegroundColor);
}
if (BackgroundColor <= 7 && BackgroundColor >= 0) {
len += sprintf_s(styleStr + len, sizeof(styleStr) - len, "4%dm;", BackgroundColor);
}
else
{
len += sprintf_s(styleStr + len, sizeof(styleStr) - len, "%40m;", BackgroundColor);
}
if (len > 0) {
styleStr[len - 1] = '\0';
}
printf("%s%s\033[0m\033[1m", styleStr, str);
}

BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}