-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcefdebug.c
106 lines (76 loc) · 2.4 KB
/
cefdebug.c
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
#include <stdio.h>
#if defined(_WIN32)
# include <winsock2.h>
# include <windows.h>
# include <iphlpapi.h>
# include "wineditline/src/editline/readline.h"
#elif defined(__linux__)
# include <readline.h>
# include <readline/history.h>
#endif
#include "libwebsockets.h"
#include "cefscan.h"
void print_usage(const char *name)
{
lwsl_err("usage: %s [--code=CODE] [--url=URL]\n", name);
}
int main(int argc, const char **argv)
{
uint16_t *portlist;
char **wsurls;
char *result;
char *line;
void *handle;
const char *url, *code;
//lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_INFO, NULL);
lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE, NULL);
url = lws_cmdline_option(argc, argv, "--url");
code = lws_cmdline_option(argc, argv, "--code");
if (lws_cmdline_option(argc, argv, "-h")
|| lws_cmdline_option(argc, argv, "-u")
|| lws_cmdline_option(argc, argv, "-v")) {
print_usage(*argv);
return 1;
}
// If no URL or code specified, scan for debuggers.
if (!url && !code) {
int32_t count;
count = get_listening_ports("127.0.0.1", &portlist);
lwsl_user("There are %d tcp sockets in state listen.\n", count);
if (count <= 0)
return 0;
count = get_websocket_urls("127.0.0.1", portlist, &wsurls);
lwsl_user("There were %d servers that appear to be CEF debuggers.\n", count);
if (count >= 0) {
for (int i = 0; i < count; i++) {
lwsl_user("%s\n", wsurls[i]);
free(wsurls[i]);
}
}
free(wsurls);
free(portlist);
}
// If URL, but no code, then enter interactive mode.
if (url && !code) {
handle = dbg_open_handle(url);
while ((line = readline(">>> "))) {
if (strcmp(line, "quit") == 0)
break;
result = dbg_eval_expression(handle, line);
lwsl_user("<<< %s\n", result);
add_history(line);
rl_free(line);
}
dbg_close_handle(handle);
}
// If URL and code, enter evaluation mode.
if (url && code) {
handle = dbg_open_handle(url);
result = dbg_eval_expression(handle, code);
dbg_close_handle(handle);
lwsl_user(">>> %s\n", code);
lwsl_user("<<< %s\n", result);
free(result);
}
return 0;
}