-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibdd_trojan.cpp
67 lines (52 loc) · 1.64 KB
/
libdd_trojan.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
#include "libdd_trojan.hpp"
int init_trojan(trojan_sess_t *sess,
recv_buffer_t recv_cbk,
send_buffer_t send_cbk
) {
memset(sess, 0, sizeof(sess));
sess->dd_recv = recv_cbk;
sess->dd_send = send_cbk;
sess->current_id = 2; // either 2 or 3 alternates
return EXIT_SUCCESS;
}
int send_msg(trojan_sess_t *sess, const char *msg) {
if (sess == NULL || msg == NULL) return EXIT_FAILURE;
uint8_t msg_len = ((uint8_t) strlen(msg))-1;
// initialize header
fitf_t fitf;
memset(&fitf, 0, sizeof(fitf_t));
init_fitf(sess, &fitf, msg_len);
sess->active_msg = fitf;
// send file transfer header
// sent at the start of a session
send_fitf(sess, &fitf);
// send the msg
send_msg_chunks(sess, msg);
return EXIT_SUCCESS;
}
int init_fitf(trojan_sess_t *sess, fitf_t* fitf, uint8_t msg_len) {
fitf->msg_len = msg_len;
return EXIT_SUCCESS;
}
int send_fitf(trojan_sess_t *sess, fitf_t* fitf) {
sess->dd_send((uint8_t*) fitf, FITF_LEN);
return EXIT_SUCCESS;
}
int send_msg_chunks(trojan_sess_t *sess, const char *msg) {
uint8_t msg_len = sess->active_msg.msg_len;
uint8_t bytes_read = 0;
while (bytes_read < msg_len) {
chunk_t curr_chunk;
memset(&curr_chunk, 0, sizeof(chunk_t));
curr_chunk.id = sess->current_id;
memcpy(curr_chunk.data, msg + bytes_read, CHUNK_LEN/8);
sess->dd_send((uint8_t*) &curr_chunk, CHUNK_LEN + CHUNK_ID_LEN);
bytes_read++;
if (sess->current_id == 2) {
++(sess->current_id);
} else {
--(sess->current_id);
}
}
return EXIT_SUCCESS;
}