-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
236 lines (200 loc) · 9.51 KB
/
Copy pathmain.c
File metadata and controls
236 lines (200 loc) · 9.51 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
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <windows.h>
#include <wininet.h>
#include <conio.h>
#pragma comment(lib, "wininet.lib")
#define MAX_INPUT_SIZE 512
#define LINES_PER_SCREEN 22
#define STREAM_BUFFER_SIZE 8192
#define COLOR_NAVY_CYAN 11
#define COLOR_LEAF_GREEN 10
#define COLOR_ALERT_YELLOW 14
#define COLOR_ERROR_RED 12
#define COLOR_TEXT_WHITE 15
#define COLOR_MARKDOWN_PURPLE 13
#define COLOR_SYSTEM_GRAY 8
void update_console_style(int text_color, int background_color) {
HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(stdout_handle, text_color + (background_color * 16));
}
void render_spruce_emblem() {
printf(" "); update_console_style(10, 0); printf("/\\\n");
printf(" "); update_console_style(10, 0); printf("/ \\\n");
printf(" "); update_console_style(2, 0); printf("/"); update_console_style(10, 0); printf(":::\\\n");
printf(" "); update_console_style(2, 0); printf("/ :::::\\\n");
printf(" "); update_console_style(2, 0); printf("/::::::::\\\n");
update_console_style(2, 0); printf("/__________\\\n");
update_console_style(6, 0); printf(" ||||\n");
update_console_style(8, 0); printf(" ======== \n");
update_console_style(COLOR_NAVY_CYAN, 0);
printf("\n S P R U C E [ beta v0.5 ]\n");
printf("===================================================\n");
}
void generate_safe_search_query(char *output, const char *raw_query) {
while (*raw_query) {
if (*raw_query == ' ') {
*output = '+';
} else if (isalnum((unsigned char)*raw_query)) {
*output = *raw_query;
} else {
output--;
}
raw_query++;
output++;
}
*output = '\0';
}
int handle_terminal_paging(int *printed_lines) {
(*printed_lines)++;
if (*printed_lines >= LINES_PER_SCREEN) {
update_console_style(0, 14);
printf("\n [ SPACE = Next Page | Q = Return to Search ] ");
update_console_style(COLOR_TEXT_WHITE, 0);
while (1) {
char user_press = _getch();
if (user_press == ' ' || user_press == '\r') {
system("cls");
render_spruce_emblem();
*printed_lines = 0;
return 1;
}
if (user_press == 'q' || user_press == 'Q') {
return 0;
}
}
}
return 1;
}
void process_network_html_stream(HINTERNET url_stream) {
char download_buffer[STREAM_BUFFER_SIZE];
DWORD content_bytes_read = 0;
int inside_tag = 0, inside_style = 0, inside_script = 0, inside_heading = 0;
int blank_space_counter = 0, lines_rendered = 0;
update_console_style(COLOR_TEXT_WHITE, 0);
while (InternetReadFile(url_stream, download_buffer, sizeof(download_buffer) - 1, &content_bytes_read) && content_bytes_read > 0) {
download_buffer[content_bytes_read] = '\0';
for (DWORD cursor = 0; cursor < content_bytes_read; cursor++) {
char current = download_buffer[cursor];
if (current == '<') {
inside_tag = 1;
if (_strnicmp(&download_buffer[cursor], "<style", 6) == 0) { inside_style = 1; }
if (_strnicmp(&download_buffer[cursor], "</style", 7) == 0) { inside_style = 0; }
if (_strnicmp(&download_buffer[cursor], "<script", 7) == 0) { inside_script = 1; }
if (_strnicmp(&download_buffer[cursor], "</script", 8) == 0) { inside_script = 0; }
if (_strnicmp(&download_buffer[cursor], "<a ", 3) == 0) {
update_console_style(COLOR_NAVY_CYAN, 0);
printf(" [");
}
if (_strnicmp(&download_buffer[cursor], "</a>", 4) == 0) {
printf("] ");
update_console_style(COLOR_TEXT_WHITE, 0);
}
if (download_buffer[cursor + 1] == 'h' && isdigit((unsigned char)download_buffer[cursor + 2])) {
inside_heading = 1;
update_console_style(COLOR_MARKDOWN_PURPLE, 0);
printf("\n\n>>> ");
}
if (download_buffer[cursor + 1] == '/' && download_buffer[cursor + 2] == 'h') {
inside_heading = 0;
update_console_style(COLOR_TEXT_WHITE, 0);
printf("\n");
if (!handle_terminal_paging(&lines_rendered)) return;
}
continue;
}
if (current == '>') {
inside_tag = 0;
if (cursor >= 2 && _strnicmp(&download_buffer[cursor - 2], "br", 2) == 0) {
printf("\n");
blank_space_counter = 0;
if (!handle_terminal_paging(&lines_rendered)) return;
}
if (cursor >= 1 && download_buffer[cursor - 1] == 'p') {
printf("\n\n");
blank_space_counter = 0;
if (!handle_terminal_paging(&lines_rendered)) return;
}
continue;
}
if (!inside_tag && !inside_style && !inside_script) {
if (strncmp(&download_buffer[cursor], "&", 5) == 0) { cursor += 4; printf("&"); continue; }
if (strncmp(&download_buffer[cursor], """, 6) == 0) { cursor += 5; printf("\""); continue; }
if (strncmp(&download_buffer[cursor], " ", 6) == 0) { cursor += 5; printf(" "); continue; }
if (current != '\r' && current != '\t' && current != '\n') {
if (current == ' ') {
blank_space_counter++;
} else {
blank_space_counter = 0;
}
if (blank_space_counter <= 1) {
if (inside_heading) printf("%c", toupper((unsigned char)current));
else printf("%c", current);
}
}
}
}
}
printf("\n");
}
int main() {
char text_input_field[MAX_INPUT_SIZE];
char secure_query_buffer[MAX_INPUT_SIZE];
char target_routing_address[MAX_INPUT_SIZE + 64];
system("cls");
render_spruce_emblem();
// Modern human-like corporate agent text so websites send clean text layouts
HINTERNET wininet_core_handle = InternetOpenA("Mozilla/5.0 (Windows NT 10.0; Win64; x64) SpruceCore/0.5", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (!wininet_core_handle) {
update_console_style(COLOR_ERROR_RED, 0);
printf("[Fatal Error] Unable to lock active network configurations.\n");
return 1;
}
update_console_style(COLOR_LEAF_GREEN, 0);
printf("[System Core] FrogFind high-reliability search engine link established.\n");
while (1) {
update_console_style(COLOR_NAVY_CYAN, 0);
printf("\n===================================================\n");
printf(" SEARCH : Type 'search <keywords>'\n BROWSE : Type 'neverssl.com' or 'http://httpforever.com'\n EXIT : Type 'exit'\n");
printf(" SPRUCE BETA > ");
update_console_style(COLOR_ALERT_YELLOW, 0);
if (!fgets(text_input_field, sizeof(text_input_field), stdin)) continue;
text_input_field[strcspn(text_input_field, "\n")] = '\0';
text_input_field[strcspn(text_input_field, "\r")] = '\0';
if (strcmp(text_input_field, "exit") == 0) break;
if (strlen(text_input_field) == 0) continue;
if (strncmp(text_input_field, "search ", 7) == 0) {
generate_safe_search_query(secure_query_buffer, text_input_field + 7);
// NEW PIPELINE: Formats queries natively into FrogFind's lightning-fast scraping index
snprintf(target_routing_address, sizeof(target_routing_address), "http://wiby.me", secure_query_buffer);
} else {
if (strncmp(text_input_field, "http://", 7) == 0 || strncmp(text_input_field, "https://", 8) == 0) {
snprintf(target_routing_address, sizeof(target_routing_address), "%s", text_input_field);
} else {
snprintf(target_routing_address, sizeof(target_routing_address), "https://%s", text_input_field);
}
}
update_console_style(COLOR_SYSTEM_GRAY, 0);
printf("[Engine Log] Handshaking route pipeline to %s...\n", target_routing_address);
HINTERNET active_request_handle = InternetOpenUrlA(wininet_core_handle, target_routing_address, NULL, 0, INTERNET_FLAG_RELOAD, 0);
if (!active_request_handle) {
update_console_style(COLOR_ERROR_RED, 0);
printf("[Network Error] Handshake failed or target refused packets. (Code: %lu)\n", GetLastError());
continue;
}
system("cls");
render_spruce_emblem();
update_console_style(COLOR_NAVY_CYAN, 0);
printf("\n--- DISPLAY BUFFER RUNTIME: %s ---\n\n", target_routing_address);
process_network_html_stream(active_request_handle);
InternetCloseHandle(active_request_handle);
update_console_style(COLOR_NAVY_CYAN, 0);
printf("\n--- SECURE VIEWPORT DE-ALLOCATED ---\n");
}
InternetCloseHandle(wininet_core_handle);
update_console_style(COLOR_LEAF_GREEN, 0);
printf("\n[System Core] All modules safely terminated.\n");
return 0;
}