forked from nscript-site/NScript.AndroidBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReceiver.cs
More file actions
106 lines (95 loc) · 2.92 KB
/
Receiver.cs
File metadata and controls
106 lines (95 loc) · 2.92 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
namespace NScript.AndroidBot
{
public enum device_msg_type
{
DEVICE_MSG_TYPE_CLIPBOARD,
};
public class device_msg
{
public device_msg_type type;
public string text;
}
public class Receiver
{
public Socket control_socket;
public Receiver(Socket socket)
{
this.control_socket = socket;
}
static unsafe int device_msg_deserialize(byte* buf, int len,
device_msg msg)
{
//if (len < 5)
//{
// // at least type + empty string length
// return 0; // not available
//}
//msg.type = (device_msg_type)buf[0];
//switch (msg.type)
//{
// case device_msg_type.DEVICE_MSG_TYPE_CLIPBOARD:
// {
// size_t clipboard_len = buffer_read32be(&buf[1]);
// if (clipboard_len > len - 5)
// {
// return 0; // not available
// }
// char* text = malloc(clipboard_len + 1);
// if (!text)
// {
// LOGW("Could not allocate text for clipboard");
// return -1;
// }
// if (clipboard_len)
// {
// memcpy(text, &buf[5], clipboard_len);
// }
// text[clipboard_len] = '\0';
// msg->clipboard.text = text;
// return 5 + clipboard_len;
// }
// default:
// LOGW("Unknown device message type: %d", (int)msg->type);
// return -1; // error, we cannot recover
//}
throw new NotImplementedException();
}
public static void process_msg(device_msg msg)
{
switch (msg.type)
{
case device_msg_type.DEVICE_MSG_TYPE_CLIPBOARD:
break;
}
}
static unsafe int process_msgs(byte* buf, int len)
{
int head = 0;
for (; ; )
{
device_msg msg = new device_msg();
int r = device_msg_deserialize(&buf[head], len - head, msg);
if (r == -1)
{
return -1;
}
if (r == 0)
{
return head;
}
process_msg(msg);
head += r;
if (head == len)
{
return head;
}
}
}
}
}