惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
Help Net Security
Help Net Security
Y
Y Combinator Blog
WordPress大学
WordPress大学
D
DataBreaches.Net
N
Netflix TechBlog - Medium
U
Unit 42
爱范儿
爱范儿
MyScale Blog
MyScale Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
D
Docker
H
Help Net Security
Stack Overflow Blog
Stack Overflow Blog
宝玉的分享
宝玉的分享
博客园_首页
Microsoft Security Blog
Microsoft Security Blog
Engineering at Meta
Engineering at Meta
Know Your Adversary
Know Your Adversary
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
T
Tenable Blog
S
Schneier on Security
V
Vulnerabilities – Threatpost
V
V2EX
T
Tor Project blog
Security Latest
Security Latest
S
Securelist
G
Google Developers Blog
NISL@THU
NISL@THU
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
小众软件
小众软件
Google Online Security Blog
Google Online Security Blog
阮一峰的网络日志
阮一峰的网络日志
W
WeLiveSecurity
IT之家
IT之家
I
InfoQ
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
月光博客
月光博客
I
Intezer
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
博客园 - 【当耐特】
The GitHub Blog
The GitHub Blog
Cloudbric
Cloudbric
Scott Helme
Scott Helme
The Cloudflare Blog
L
LINUX DO - 热门话题

博客园 - Kevin Wu

你是否也爱车 Asp..net 页面间跳转方法 Windows Server 2008 RC0正式发布、下载 通过Url抓取网页内容 如何生成静态页面的五种方案 (转)怎样用dos入侵局域网 闲里偷忙 [导入]学习网页制作: 用CSS来控制网页背景 (转)解决AJAX中使用UpdatePanel后再用Response.Write();等无法弹出对话框问题 3法 为你的aspx页面加上ajax enable - Kevin Wu 几种保持页面状态信息的讨论(转) 在Windows Servrer 2003下安装UDDI服务和UDDI .NET SDK JDK1.5+Tomcat5+MySql+Juddi 架设UDDI服务器 拒绝了对对象 'xp_cmdshell'(数据库 'master',所有者 'dbo')的 EXECUTE 权限 解决方法 无法将类型“ASP.login_aspx”转换为“System.Web.UI.WebControls.Login” 错误处理 终于考完试了~~~ 远程控制(2) 关于windows hook的提问 远程控制(1)
远程控制(3)
Kevin Wu · 2007-01-01 · via 博客园 - Kevin Wu

   本来想把这些都写在(2)里面的,想想还是写到(3)吧,这样比较容易看点

完成图片传送和显示,那么就开始控制,有了前面的基础,对于网络传输都有一定的了解了,那么我们再传其他东西也差不多道理.还不懂就得找本书看了..老实说,看书才是硬道理.

先看下面两个数据结构:

struct MouseEvent
{
    
private Byte[] type;
    
private Byte[] x;
    
private Byte[] y;

    
public MouseEvent(MouseEventType Type,int X,int Y)
    
{
        
this.type = BitConverter.GetBytes((int)Type);
        
this.x = BitConverter.GetBytes(X);
        
this.y = BitConverter.GetBytes(Y);
    }


    
public MouseEvent(Byte[] Type, Byte[] X, Byte[] Y)
    
{
        
this.type = Type;
        
this.x = X;
        
this.y = Y;
    }


    
public MouseEvent(Byte[] Content)
    
{
        type 
= new byte[4];
        x 
= new byte[4];
        y 
= new byte[4];
        
for (int i = 0; i < Content.Length; i++)
        
{
            
if (i >= 0 && i < 4)
                type[i] 
= Content[i];
            
if (i >= 4 && i < 8)
                x[i
-4= Content[i];
            
if (i >= 8 && i < 12)
                y[i
-8= Content[i];
        }

    }


    
public MouseEventType Type
    
{
        
get return (MouseEventType)BitConverter.ToInt32(type, 0); }
    }


    
public int X
    
{
        
get return BitConverter.ToInt32(x, 0); }
    }


    
public int Y
    
{
        
get return BitConverter.ToInt32(y, 0); }
    }


    
public Byte[] ToBytes()
    
{
        Byte[] Bytes 
= new Byte[12];
        type.CopyTo(Bytes, 
0);
        x.CopyTo(Bytes, 
4);
        y.CopyTo(Bytes, 
8);
        
return Bytes;
    }

}


enum MouseEventType : int
{
    MouseMove
=0,
    MouseLeftDown,
    MouseLeftUp,
    MouseRightDown,
    MouseRightUp,
    MouseClick,
    MouseDoubleClick
}

一个是鼠标事件的结构体,一个鼠标事件类型枚举
我们这次发送和接收的包,当然,还可以有键盘事件的包,我偷懒,没做网络传输就不说了,和(1)(2)差不多,上面的结构体也定义得可以用了.
说说流程吧
鼠标的事件都是在panel上的事件,move,click,doubleclick,左键右键就自己判断了,由于panel大小是和受控方屏幕大小一样,所以获得坐标就等同于受控方屏幕的坐标,这样,一个MouseEvent的包就可以组成了,发送.
受控放接收,直接构造函数构造一个新的MouseEvent(Byte[] Content).就可以通过结构体的属性获得相应的内容,说明一下,图片和事件的侦听和发送端口不能一样.这样就可以进行控制了.

怎么控制呢?这里就要调用win32 API了,还有用到委托,因为委托是线程安全的.
首先看一下声明吧,我们要用到的API

        [DllImport("user32")]
        
public static extern void mouse_event(MouseEventFlag flags, int dx, int dy, int dwData, int dwExtraInfo);
        [DllImport(
"user32")]
        
public static extern bool SetCursorPos(int X, int Y);

   然后鼠标事件类型的枚举:

public enum MouseEventFlag
{
    Move 
= 0x0001,
    LeftDown 
= 0x0002,
    LeftUp 
= 0x0004,
    RightDown 
= 0x0008,
    RightUp 
= 0x0010,
    MiddleDown 
= 0x0020,
    MiddleUp 
= 0x0040,
    XDown 
= 0x0080,
    XUp 
= 0x0100,
    Wheel 
= 0x0800,
    VirtualDesk 
= 0x4000,
    Absolute 
= 0x8000
}

声明委托与事件

        public delegate void DoMouseButtons(MouseEventFlag flags, int dx, int dy, int dwData, int dwExtraInfo);
        
public delegate bool DoMouseMove(int X, int Y);

        
private event DoMouseMove MouseMove;
        
private event DoMouseButtons MouseButton;

添加事件

            MouseButton += new DoMouseButtons(mouse_event);
            MouseMove 
+= new DoMouseMove(SetCursorPos);

到这里,我们就可以模拟鼠标的事件了

switch (MEvent.Type)
{
    
case MouseEventType.MouseMove:
        MouseMove(MEvent.X, MEvent.Y);
        
break;
    
case MouseEventType.MouseLeftDown:
        MouseButton(MouseEventFlag.LeftDown, MEvent.X, MEvent.Y, 
00);
        
break;
    
case MouseEventType.MouseLeftUp:
        MouseButton(MouseEventFlag.LeftUp, MEvent.X, MEvent.Y, 
00);
        
break;
    
case MouseEventType.MouseRightDown:
        MouseButton(MouseEventFlag.RightDown, MEvent.X, MEvent.Y, 
00);
        
break;
    
case MouseEventType.MouseRightUp:
        MouseButton(MouseEventFlag.RightUp, MEvent.X, MEvent.Y, 
00);
        
break;
    
case MouseEventType.MouseClick:
        MouseButton(MouseEventFlag.LeftDown, MEvent.X, MEvent.Y, 00);
        MouseButton(MouseEventFlag.LeftUp, MEvent.X, MEvent.Y, 
00);
        
break;
    
case MouseEventType.MouseDoubleClick:
        MouseButton(MouseEventFlag.LeftDown, MEvent.X, MEvent.Y, 00);
        MouseButton(MouseEventFlag.LeftDown, MEvent.X, MEvent.Y, 
00);
            MouseButton(MouseEventFlag.LeftUp, MEvent.X, MEvent.Y, 
00);
        MouseButton(MouseEventFlag.LeftUp, MEvent.X, MEvent.Y, 
00);
        
break;
}

鼠标双击的这个事件有点问题,有时候不行...

恩,完了,就这样,一个简单的远程控制就完成了,这个东西是我个人娱乐所作,虽然没有什么技术含量,但是通过这样,也可以学到很多东西,同时很多东西也加深了理解...

源码下载地址

今天是元旦佳节哦~

 祝大家猪年快乐!  年年进步!