-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathamd64proxy.cpp
More file actions
82 lines (72 loc) · 2.33 KB
/
amd64proxy.cpp
File metadata and controls
82 lines (72 loc) · 2.33 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
#include "amd64proxy.hpp"
#include <cstring>
// Packet structure definitions - use tight packing to match network protocol
#pragma pack(push, 1)
struct clockframe
{
uint64_t cf_rdi;
uint64_t cf_rsi;
uint64_t cf_rdx;
uint64_t cf_rcx;
uint64_t cf_r8;
uint64_t cf_r9;
uint64_t cf_r10;
uint64_t cf_r11;
uint64_t cf_r12;
uint64_t cf_r13;
uint64_t cf_r14;
uint64_t cf_r15;
uint64_t cf_rbp;
uint64_t cf_rbx;
uint64_t cf_rax;
uint64_t cf_gs;
uint64_t cf_fs;
uint64_t cf_es;
uint64_t cf_ds;
uint64_t cf_trapno; /* trap type (always T_PROTFLT for clock interrupts, but unused here) */
uint64_t cf_err; /* error code (0 for clock interrupts) */
uint64_t cf_rip; /* instruction pointer at interrupt */
uint64_t cf_cs; /* code segment at interrupt */
uint64_t cf_rflags; /* flags register at interrupt */
uint64_t cf_rsp; /* stack pointer at interrupt */
uint64_t cf_ss; /* stack segment at interrupt */
};
/* NetBSD x64 Panel structure */
struct netbsdx64_panel_state
{
struct clockframe ps_frame; /* panel switches - NetBSD clockframe structure */
};
/* NetBSD x64 Panel packet structure */
struct netbsdx64_panel_packet
{
struct panel_packet_header header;
struct netbsdx64_panel_state panel_state;
};
#pragma pack(pop)
AMD64Proxy::AMD64Proxy(unsigned short port)
: ProxyBase(port)
{
// Debug: Print structure sizes to verify pragma pack worked
log_info("Structure sizes: header=%zu bytes, panel_state=%zu bytes, total_packet=%zu bytes",
sizeof(panel_packet_header), sizeof(netbsdx64_panel_state), sizeof(netbsdx64_panel_packet));
}
std::string AMD64Proxy::udp_packet_to_json(std::span<const char> data)
{
// Parse the NetBSD x64 panel state
netbsdx64_panel_state panel_state;
if (!get_panel_state(data, panel_state))
return "";
auto& ps_frame = panel_state.ps_frame;
crow::json::wvalue json;
json["rax"] = to_hex(ps_frame.cf_rax);
json["rbx"] = to_hex(ps_frame.cf_rbx);
json["rcx"] = to_hex(ps_frame.cf_rcx);
json["rdx"] = to_hex(ps_frame.cf_rdx);
json["rdi"] = to_hex(ps_frame.cf_rdi);
json["rsi"] = to_hex(ps_frame.cf_rsi);
json["rbp"] = to_hex(ps_frame.cf_rbp);
json["rsp"] = to_hex(ps_frame.cf_rsp);
json["rip"] = to_hex(ps_frame.cf_rip);
json["rflags"] = to_hex(ps_frame.cf_rflags);
return json.dump();
}