-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomImagesSpider-GUI.cpp
More file actions
164 lines (152 loc) · 5.22 KB
/
RandomImagesSpider-GUI.cpp
File metadata and controls
164 lines (152 loc) · 5.22 KB
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
#include <windows.h>
#include <string.h>
#include <string>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <fstream>
#include <io.h>
#include <graphics.h>
const std::string URL_TABLE[] = {
"https://api.ixiaowai.cn/mcapi/mcapi.php",
"http://api.mtyqx.cn/tapi/random.php",
"http://www.dmoe.cc/random.php",
"https://img.paulzzh.tech/touhou/random"
};
const int WRITE_WIDTH = 750;
const int WRITE_HEIGHT = 415;
const int GRAPH_WIDTH = 800;
const int GRAPH_HEIGHT = 600;
const int URLTABLE_SIZE = 4;
void URLImageDownloadToFileWithCertutil(std::string url, int identity) {
std::string command;
command += "certutil -urlcache -split -f ";
command += url;
command += " \"";
command += std::to_string(identity);
command += ".png\"";
std::cout << command << std::endl;
system(command.c_str());
}
void URLImageDownloadToFileWithVBS(std::string url, int identity) {
std::string command;
command += "cscript download.vbs ";
command += url;
command += " \"";
command += std::to_string(identity);
command += ".png\"";
std::cout << command << std::endl;
system(command.c_str());
}
void URLImageDownloadToFileWithPowerShellExec(std::string url, int identity) {
std::string command;
command += "powershell -exec bypass -c (new-object System.Net.WebClient).DownloadFile('";
command += url;
command += "','";
command += std::to_string(identity);
command += ".png')";
std::cout << command << std::endl;
system(command.c_str());
}
void URLImageDownloadToFileWithPowerShellWGet(std::string url, int identity) {
std::string command;
command += "powershell Invoke-WebRequest -Uri \"";
command += url;
command += "\" -OutFile \"";
command += std::to_string(identity);
command += ".png\"";
std::cout << command << std::endl;
system(command.c_str());
}
int GetImageFileSizeToCheckDelete(std::string filename) {
FILE *fp = fopen(filename.c_str(), "r");
if (!fp) return -1;
fseek(fp, 0L, SEEK_END);
int filesize = ftell(fp);
fclose(fp);
return filesize / 1024;
}
void SetImageSize(PIMAGE& image, int WIDTH, int HEIGHT, int x, int y) {
PIMAGE current = gettarget();
settarget(image);
int width, height;
width = getwidth();
height = getheight();
settarget(current);
PIMAGE tempImage = newimage(WIDTH, HEIGHT);
putimage(tempImage, 0, 0, WIDTH, HEIGHT, image, 0, 0, width, height);
getimage(image, tempImage, 0, 0, WIDTH, HEIGHT);
delimage(tempImage);
}
void ShowImageAtXY(int imageID, int x, int y) {
std::string filename = std::to_string(imageID) + ".png";
PIMAGE image = newimage();
getimage(image, filename.c_str(), 0, 0);
SetImageSize(image, WRITE_WIDTH, WRITE_HEIGHT, x, y);
putimage(x, y, WRITE_WIDTH, WRITE_HEIGHT, image, 0, 0);
delimage(image);
}
int main() {
srand(time(0));
HWND hwnd = FindWindow("ConsoleWindowClass", NULL);
if (hwnd) ShowWindow(hwnd, SW_HIDE);
initgraph(GRAPH_WIDTH, GRAPH_HEIGHT, 0);
setcaption("Random images spider by BoringHacker ");
int beginID = 0, imagesNumber = 0, chooseDownloader = 0, chooseModel = 0;
char inputInformation[100];
memset(inputInformation, 0, sizeof inputInformation);
inputbox_getline("Information!",
"Input beginID and imagesNumber(0<imagesNumber,separated by spaces):",
inputInformation, sizeof(inputInformation) / sizeof(*inputInformation));
int size = strlen(inputInformation), isCatchedSpace;
for (int i = 0; i < size; ++i) {
if (inputInformation[i] == ' ') isCatchedSpace = 1;
else {
if (isCatchedSpace == 0) beginID = beginID * 10 + (inputInformation[i] - '0');
else imagesNumber = imagesNumber * 10 + (inputInformation[i] - '0');
}
}
memset(inputInformation, 0, sizeof inputInformation);
inputbox_getline("Information!",
"Choose downloader:\n1.Windows Command Certutil\n2.Windows Command with \"download.vbs\"\n3.Windows Power Shell 1\n4.Windwos Power Shell 2",
inputInformation, sizeof(inputInformation) / sizeof(*inputInformation));
chooseDownloader = (*inputInformation) - '0';
memset(inputInformation, 0, sizeof inputInformation);
inputbox_getline("Information!",
"Choose model:\n1.Browse Model\n2.Batch Download Model",
inputInformation, sizeof(inputInformation) / sizeof(*inputInformation));
chooseModel = (*inputInformation) - '0';
for (int i = beginID; i < beginID + imagesNumber; ++i) {
switch (chooseDownloader) {
case 1:
URLImageDownloadToFileWithCertutil(URL_TABLE[rand() % URLTABLE_SIZE], i);
break;
case 2:
URLImageDownloadToFileWithVBS(URL_TABLE[rand() % URLTABLE_SIZE], i);
break;
case 3:
URLImageDownloadToFileWithPowerShellExec(URL_TABLE[rand() % URLTABLE_SIZE], i);
break;
case 4:
URLImageDownloadToFileWithPowerShellWGet(URL_TABLE[rand() % URLTABLE_SIZE], i);
break;
default: break;
}
std::string filename = std::to_string(i);
filename += ".png";
if (GetImageFileSizeToCheckDelete(filename) <= 50) {
std::string command = "del ";
command += filename;
system(command.c_str());
--i;
puts("log:Download failed,retried");
}
else {
ShowImageAtXY(i, (GRAPH_WIDTH - WRITE_WIDTH) / 2, (GRAPH_HEIGHT - WRITE_HEIGHT) / 2);
if (chooseModel == 1) getch();
cleardevice();
}
}
getch();
closegraph();
}