修改截图调用方式,加入可选的尺寸参数

This commit is contained in:
2025-03-22 10:19:54 +08:00
parent d8b3c87347
commit b5fcc72f63
5 changed files with 103 additions and 10 deletions

View File

@@ -29,6 +29,8 @@ type RdpClient struct {
pdu *pdu.Client // PDU协议层
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("", "", "")
}

View File

@@ -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)
}

View File

@@ -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())
}

View File

@@ -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
}

87
shotrdp.h Normal file
View File

@@ -0,0 +1,87 @@
/* Code generated by cmd/cgo; DO NOT EDIT. */
/* package command-line-arguments */
#line 1 "cgo-builtin-export-prolog"
#include <stddef.h>
#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 <stdlib.h>
#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 <complex.h>
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