From b5fcc72f638707db1a44815902ee9003bd178abd Mon Sep 17 00:00:00 2001 From: yv1ing Date: Sat, 22 Mar 2025 10:19:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=88=AA=E5=9B=BE=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=96=B9=E5=BC=8F=EF=BC=8C=E5=8A=A0=E5=85=A5=E5=8F=AF?= =?UTF-8?q?=E9=80=89=E7=9A=84=E5=B0=BA=E5=AF=B8=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/{rdpClient.go => shotClient.go} | 18 ++-- .../{rdpClient_test.go => shotClient_test.go} | 2 +- mainDLL.go | 4 +- mainRPC.go | 2 +- shotrdp.h | 87 +++++++++++++++++++ 5 files changed, 103 insertions(+), 10 deletions(-) rename client/{rdpClient.go => shotClient.go} (90%) rename client/{rdpClient_test.go => shotClient_test.go} (83%) create mode 100644 shotrdp.h diff --git a/client/rdpClient.go b/client/shotClient.go similarity index 90% rename from client/rdpClient.go rename to client/shotClient.go index a22d99e..93dc6ac 100644 --- a/client/rdpClient.go +++ b/client/shotClient.go @@ -28,7 +28,9 @@ type RdpClient struct { sec *sec.Client // 安全层 pdu *pdu.Client // PDU协议层 - channels *plugin.Channels + channels *plugin.Channels + screenWidth int + screenHeight int } type Position struct { @@ -49,13 +51,17 @@ var ( positionMap = make(map[Position]*common.Bitmap) ) -func Newclient(host string, logLevel glog.LEVEL) *RdpClient { +func Newclient(host string, logLevel glog.LEVEL, screenWidth, screenHeight int) *RdpClient { _logger := log.New(os.Stdout, "", 0) glog.SetLogger(_logger) glog.SetLevel(logLevel) - return &RdpClient{Host: host} + return &RdpClient{ + Host: host, + screenWidth: screenWidth, + screenHeight: screenHeight, + } } func (client *RdpClient) Login(domain, username, password string) ([]byte, error) { @@ -130,7 +136,7 @@ func (client *RdpClient) initProtocolStack(conn net.Conn, domain, username, pass // 配置桌面信息 client.channels = plugin.NewChannels(client.sec) - client.mcs.SetClientDesktop(uint16(800), uint16(600)) + client.mcs.SetClientDesktop(uint16(client.screenWidth), uint16(client.screenHeight)) // 设置认证信息 client.sec.SetDomain(domain) @@ -214,7 +220,7 @@ func (client *RdpClient) setEventHandler() { 去除requestedProtocol中的PROTOCOL_HYBRID,避免使用NLA */ -func RealGetScreen(host string) ([]byte, error) { - client := Newclient(host, glog.INFO) +func RealGetScreen(host string, screenWidth, screenHeight int) ([]byte, error) { + client := Newclient(host, glog.INFO, screenWidth, screenHeight) return client.Login("", "", "") } diff --git a/client/rdpClient_test.go b/client/shotClient_test.go similarity index 83% rename from client/rdpClient_test.go rename to client/shotClient_test.go index 1212d4c..d6beb21 100644 --- a/client/rdpClient_test.go +++ b/client/shotClient_test.go @@ -13,7 +13,7 @@ func TestGetScreen(t *testing.T) { Windows 10 ✔ */ - imgBytes, err := RealGetScreen("127.0.0.1:3389") + imgBytes, err := RealGetScreen("127.0.0.1:3389", 1024, 800) if err != nil { t.Fatal(err) } diff --git a/mainDLL.go b/mainDLL.go index 981c95f..fd910a3 100644 --- a/mainDLL.go +++ b/mainDLL.go @@ -10,8 +10,8 @@ import ( ) //export GetScreen -func GetScreen(host *C.char, data **C.char, length *C.int) *C.char { - imgBytes, err := client.RealGetScreen(C.GoString(host)) +func GetScreen(host *C.char, data **C.char, length *C.int, width C.int, height C.int) *C.char { + imgBytes, err := client.RealGetScreen(C.GoString(host), int(width), int(height)) if err != nil { return C.CString(err.Error()) } diff --git a/mainRPC.go b/mainRPC.go index f912ded..77cecff 100644 --- a/mainRPC.go +++ b/mainRPC.go @@ -14,7 +14,7 @@ type Server struct { } func (server *Server) GetScreen(ctx context.Context, in *pb.Request) (*pb.Response, error) { - imgBytes, err := client.RealGetScreen(in.GetHost()) + imgBytes, err := client.RealGetScreen(in.GetHost(), 1024, 800) return &pb.Response{ImageBytes: imgBytes}, err } diff --git a/shotrdp.h b/shotrdp.h new file mode 100644 index 0000000..a7a6112 --- /dev/null +++ b/shotrdp.h @@ -0,0 +1,87 @@ +/* Code generated by cmd/cgo; DO NOT EDIT. */ + +/* package command-line-arguments */ + + +#line 1 "cgo-builtin-export-prolog" + +#include + +#ifndef GO_CGO_EXPORT_PROLOGUE_H +#define GO_CGO_EXPORT_PROLOGUE_H + +#ifndef GO_CGO_GOSTRING_TYPEDEF +typedef struct { const char *p; ptrdiff_t n; } _GoString_; +#endif + +#endif + +/* Start of preamble from import "C" comments. */ + + +#line 3 "mainDLL.go" + +#include + +#line 1 "cgo-generated-wrapper" + + +/* End of preamble from import "C" comments. */ + + +/* Start of boilerplate cgo prologue. */ +#line 1 "cgo-gcc-export-header-prolog" + +#ifndef GO_CGO_PROLOGUE_H +#define GO_CGO_PROLOGUE_H + +typedef signed char GoInt8; +typedef unsigned char GoUint8; +typedef short GoInt16; +typedef unsigned short GoUint16; +typedef int GoInt32; +typedef unsigned int GoUint32; +typedef long long GoInt64; +typedef unsigned long long GoUint64; +typedef GoInt64 GoInt; +typedef GoUint64 GoUint; +typedef size_t GoUintptr; +typedef float GoFloat32; +typedef double GoFloat64; +#ifdef _MSC_VER +#include +typedef _Fcomplex GoComplex64; +typedef _Dcomplex GoComplex128; +#else +typedef float _Complex GoComplex64; +typedef double _Complex GoComplex128; +#endif + +/* + static assertion to make sure the file is being used on architecture + at least with matching size of GoInt. +*/ +typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; + +#ifndef GO_CGO_GOSTRING_TYPEDEF +typedef _GoString_ GoString; +#endif +typedef void *GoMap; +typedef void *GoChan; +typedef struct { void *t; void *v; } GoInterface; +typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; + +#endif + +/* End of boilerplate cgo prologue. */ + +#ifdef __cplusplus +extern "C" { +#endif + +extern __declspec(dllexport) char* GetScreen(char* host, char** data, int* length, int width, int height); +extern __declspec(dllexport) void Free(char* p); + +#ifdef __cplusplus +} +#endif