-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
165 lines (146 loc) · 3.73 KB
/
main.cpp
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
//#include <pcap.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <time.h>
#include <malloc.h>
#include <pthread.h>
#include <fcntl.h>
#include <syslog.h>
#include <arpa/inet.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <assert.h>
#include <list>
#include "common.h"
#include "cb1st_handler.h"
#include "darkshell_handler.h"
#include "dslserverklr_handler.h"
#ifndef __GNUC__
//#include "stdafx.h"
#endif
void help()
{
cout << "RSA Sample utility" << "\n";
}
int main(int argc, char **argv)
{
// file to save decoded messages
char log_file[256] = "/tmp/cb1st.msg";
char data[10];
bbuffer buf;
// test bbuffer
buf.enqueue(log_file, strlen(log_file));
memset(data, 0, sizeof(data));
buf.dequeue(data, 4);
printf("%s\n", data);
printf("%s, len=%d\n", buf.data(), buf.len());
buf.dequeue(data, strlen(log_file) - 4);
printf("%s\n", data);
#if 0
if (argc < 2)
{
help();
exit(-1);
}
#endif
//bhandlerfactory *factory = new cb1stfactory();
bhandlerfactory *factory = new dshellfactory();
int i;
u_short listen_port = 0;
for (i = 1; i < argc; )
{
if (!strcmp("-p", argv[i]))
{
i++;
listen_port = atoi(argv[i]);
i ++;
}
else if (!strcmp("-port", argv[i]))
{
i++;
listen_port = atoi(argv[i]);
i ++;
}
else if (!strcmp("-t", argv[i]))
{
test_deflate();
i++;
}
else if (!strcmp("-o", argv[i]))
{
i++;
strcpy(log_file, argv[i]);
i++;
}
else if (!strcmp("-bot", argv[i]) || !strcmp("-b", argv[i]))
{
i++;
if (!strcmp("cb1st", argv[i]))
{
factory = new cb1stfactory();
}
else if (!strcmp("darkshell", argv[i])
||!strcmp("dshell", argv[i]))
{
factory = new dshellfactory();
}
else if (!strcmp("dsl", argv[i]))
{
factory = new dslfactory();
}
i++;
}
#if 0
else if (!strcmp("-o", argv[i]))
{
i++;
memset(output_file, 0, sizeof(output_file));
strncpy(output_file, argv[i], 254);
i++;
}
else if (!strcmp("-dns", argv[i]))
{
i++;
extract_dns = 1;
strcpy(filter_str, "udp port 53");
i++;
}
else if (!strcmp("-hex", argv[i]))
{
i++;
in_hex = 1;
printf("hex=%d\n", in_hex);
}
else //if (!strcmp("-h", argv[i]))
{
if (*argv[i] != '-')
{
strcpy(pcap_file, argv[i]);
i++;
}
else
{
printf("invalid options \"%s\"\n", argv[i]);
help();
exit(0);
}
}
#endif
}
bdispatcher dispatcher;
//bhandlerfactory *factory = dynamic_cast<bhandlerfactory*>(_factory);
//cb1stfactory factory;
int stdin = 0;
fcntl(stdin, O_NONBLOCK, 1);
bcommandhandler commander(stdin, factory);
/* add the STDIN to the master set */
dispatcher.add_handler(&commander);
blistener listener(INADDR_ANY, listen_port, &dispatcher, factory);
dispatcher.add_handler(&listener);
dispatcher.poll();
return 0;
}