修改为NativeAOT

This commit is contained in:
sin365 2023-08-31 19:20:41 +08:00
parent a17979ba63
commit 5503c2618e
39 changed files with 103 additions and 229 deletions

Binary file not shown.

View File

@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308 VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCmdC", "RCmdC\RCmdC.csproj", "{30C7A3A2-1742-4ADF-9EE3-3D2AEB85B83F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RCmdS", "RCmdS\RCmdS.csproj", "{DACF16DF-7CC6-41BB-89B5-46E45212F226}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCmdS", "RCmdS\RCmdS.csproj", "{6FC15228-663A-48E3-AE5D-FA4112EAC8B0}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCmdC", "RCmdC\RCmdC.csproj", "{921D8E14-C8C2-4C0A-B9F9-1C141792C13F}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -13,14 +13,14 @@ Global
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{30C7A3A2-1742-4ADF-9EE3-3D2AEB85B83F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DACF16DF-7CC6-41BB-89B5-46E45212F226}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30C7A3A2-1742-4ADF-9EE3-3D2AEB85B83F}.Debug|Any CPU.Build.0 = Debug|Any CPU {DACF16DF-7CC6-41BB-89B5-46E45212F226}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30C7A3A2-1742-4ADF-9EE3-3D2AEB85B83F}.Release|Any CPU.ActiveCfg = Release|Any CPU {DACF16DF-7CC6-41BB-89B5-46E45212F226}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30C7A3A2-1742-4ADF-9EE3-3D2AEB85B83F}.Release|Any CPU.Build.0 = Release|Any CPU {DACF16DF-7CC6-41BB-89B5-46E45212F226}.Release|Any CPU.Build.0 = Release|Any CPU
{6FC15228-663A-48E3-AE5D-FA4112EAC8B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {921D8E14-C8C2-4C0A-B9F9-1C141792C13F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6FC15228-663A-48E3-AE5D-FA4112EAC8B0}.Debug|Any CPU.Build.0 = Debug|Any CPU {921D8E14-C8C2-4C0A-B9F9-1C141792C13F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FC15228-663A-48E3-AE5D-FA4112EAC8B0}.Release|Any CPU.ActiveCfg = Release|Any CPU {921D8E14-C8C2-4C0A-B9F9-1C141792C13F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FC15228-663A-48E3-AE5D-FA4112EAC8B0}.Release|Any CPU.Build.0 = Release|Any CPU {921D8E14-C8C2-4C0A-B9F9-1C141792C13F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,12 +1,10 @@
using System; using System.Net.Sockets;
using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading;
namespace RCmdC namespace RCmdC
{ {
internal class Program internal class Program
{ {
private static Socket clientSocket = null; private static Socket clientSocket = null;
@ -15,9 +13,44 @@ namespace RCmdC
private static void Main(string[] args) private static void Main(string[] args)
{ {
string ip = null;
int port = 0;
bool flag1 = false;
do
{
Console.WriteLine("输入目标IP或域名");
string param = Console.ReadLine().Trim();
if (!string.IsNullOrEmpty(param))
{
ip = param;
flag1 = true;
}
else
{
Console.WriteLine("请正确输入");
}
} while(!flag1);
bool flag2 = false;
do
{
Console.WriteLine("输入目标端口");
string param = Console.ReadLine().Trim();
if (int.TryParse(param, out int _port))
{
port = _port;
flag2 = true;
}
else
{
Console.WriteLine("请正确输入");
}
} while (!flag2);
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// 客户端不需要绑定, 需要连接 // 客户端不需要绑定, 需要连接
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10492); //服务端IP和端口 IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(ip), port); //服务端IP和端口
clientSocket.Connect(endPoint); clientSocket.Connect(endPoint);
Console.WriteLine("连接到服务器"); Console.WriteLine("连接到服务器");

View File

@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Client")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Client")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("30c7a3a2-1742-4adf-9ee3-3d2aeb85b83f")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -1,48 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <Project Sdk="Microsoft.NET.Sdk">
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{30C7A3A2-1742-4ADF-9EE3-3D2AEB85B83F}</ProjectGuid>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>Client</RootNamespace> <TargetFramework>net7.0</TargetFramework>
<AssemblyName>Client</AssemblyName> <ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <Nullable>enable</Nullable>
<FileAlignment>512</FileAlignment> <!-- AOT -->
<Deterministic>true</Deterministic> <PublishAot>true</PublishAot>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> </Project>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

6
RCmdC/RCmdC.csproj.user Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>D:\RCmd\RCmdC\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>

View File

@ -1,4 +0,0 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]

View File

@ -1 +0,0 @@
b9e2f5818204bdd53d14ebaabe7f49179a76e75e

View File

@ -1,6 +0,0 @@
D:\AxibugRCMD\AxiConC\bin\Debug\Client.exe
D:\AxibugRCMD\AxiConC\bin\Debug\Client.pdb
D:\AxibugRCMD\AxiConC\obj\Debug\AxiConC.csproj.AssemblyReference.cache
D:\AxibugRCMD\AxiConC\obj\Debug\AxiConC.csproj.CoreCompileInputs.cache
D:\AxibugRCMD\AxiConC\obj\Debug\Client.exe
D:\AxibugRCMD\AxiConC\obj\Debug\Client.pdb

View File

@ -1 +0,0 @@
b9e2f5818204bdd53d14ebaabe7f49179a76e75e

View File

@ -1,6 +0,0 @@
D:\AxibugRCMD\Client\bin\Debug\Client.exe
D:\AxibugRCMD\Client\bin\Debug\Client.pdb
D:\AxibugRCMD\Client\obj\Debug\Client.csproj.AssemblyReference.cache
D:\AxibugRCMD\Client\obj\Debug\Client.csproj.CoreCompileInputs.cache
D:\AxibugRCMD\Client\obj\Debug\Client.exe
D:\AxibugRCMD\Client\obj\Debug\Client.pdb

View File

@ -1,12 +1,7 @@
using System; using System.Diagnostics;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Sockets; using System.Net.Sockets;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Threading;
using System.IO;
namespace RCmdS namespace RCmdS
{ {
@ -22,6 +17,18 @@ namespace RCmdS
private static void Main(string[] args) private static void Main(string[] args)
{ {
//装载启动参数
string[] CmdLineArgs = Environment.GetCommandLineArgs();
int port = 10492;
if (CmdLineArgs.Count() >= 2 && int.TryParse(CmdLineArgs[1].Trim('/').Trim(), out int result))
{
port = result;
}
else
{
Console.WriteLine("参数错误,使用默认端口。需要指定端口命令 >RCmdS <端口> ");
}
p = new Process(); p = new Process();
p.StartInfo.FileName = "cmd.exe"; //待执行的文件路径 p.StartInfo.FileName = "cmd.exe"; //待执行的文件路径
@ -33,18 +40,13 @@ namespace RCmdS
p.Start(); p.Start();
severSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); severSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 10492); IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, port);
severSocket.Bind(endPoint); // 绑定 severSocket.Bind(endPoint); // 绑定
severSocket.Listen(1); // 设置最大连接数 severSocket.Listen(1); // 设置最大连接数
Console.WriteLine("开始监听"); Console.WriteLine($"开始监听 {port}");
//Console.WriteLine("进程ID"+Process.GetCurrentProcess().Id);
Thread thread = new Thread(ListenClientConnect); // 开启线程监听客户端连接 Thread thread = new Thread(ListenClientConnect); // 开启线程监听客户端连接
thread.Start("连接成功"); thread.Start("连接成功");
//Thread thread_1 = new Thread(TEST); // 开启线程监听客户端连接
//thread_1.Start("连接成功");
ThreadPool.QueueUserWorkItem(new WaitCallback(delegate ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
{ {
while (true) while (true)
@ -146,4 +148,4 @@ namespace RCmdS
p.StandardInput.WriteLine(cmd); p.StandardInput.WriteLine(cmd);
} }
} }
} }

View File

@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Server")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Server")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("6fc15228-663a-48e3-ae5d-fa4112eac8b0")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -1,48 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <Project Sdk="Microsoft.NET.Sdk">
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6FC15228-663A-48E3-AE5D-FA4112EAC8B0}</ProjectGuid>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>Server</RootNamespace> <TargetFramework>net7.0</TargetFramework>
<AssemblyName>Server</AssemblyName> <ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <Nullable>enable</Nullable>
<FileAlignment>512</FileAlignment> <!-- AOT -->
<Deterministic>true</Deterministic> <PublishAot>true</PublishAot>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> </Project>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

6
RCmdS/RCmdS.csproj.user Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>D:\RCmd\RCmdS\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>

View File

@ -1,4 +0,0 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]

View File

@ -1 +0,0 @@
b9e2f5818204bdd53d14ebaabe7f49179a76e75e

View File

@ -1,6 +0,0 @@
D:\AxibugRCMD\AxiConS\bin\Debug\Server.exe
D:\AxibugRCMD\AxiConS\bin\Debug\Server.pdb
D:\AxibugRCMD\AxiConS\obj\Debug\AxiConS.csproj.AssemblyReference.cache
D:\AxibugRCMD\AxiConS\obj\Debug\AxiConS.csproj.CoreCompileInputs.cache
D:\AxibugRCMD\AxiConS\obj\Debug\Server.exe
D:\AxibugRCMD\AxiConS\obj\Debug\Server.pdb

View File

@ -1 +0,0 @@
b9e2f5818204bdd53d14ebaabe7f49179a76e75e

View File

@ -1,6 +0,0 @@
D:\AxibugRCMD\Server\bin\Debug\Server.exe
D:\AxibugRCMD\Server\bin\Debug\Server.pdb
D:\AxibugRCMD\Server\obj\Debug\Server.csproj.AssemblyReference.cache
D:\AxibugRCMD\Server\obj\Debug\Server.csproj.CoreCompileInputs.cache
D:\AxibugRCMD\Server\obj\Debug\Server.exe
D:\AxibugRCMD\Server\obj\Debug\Server.pdb

View File

@ -1,15 +1,22 @@
# RCmd # RCmd
RCmd , 全称 RemoteCmd。 RCmd , 全称 RemoteCmd。
是一个皓月自写的远程控制Windows CMD的工具。 是一个皓月自写的远程控制Windows CMD的工具。
基于TCP Socket 实现。 基于TCP Socket 实现。
分为: 分为:
客户端 RCmdC (操作者) 客户端 RCmdC (操作者)
服务端 RCmdS (被操作者) 服务端 RCmdS (被操作者)
为考虑在因某种原因无法安装运行时的环境下(笑) 为考虑在因某种原因无法安装运行时的环境下(笑)
直接提供.Net FX 4 版本.(内核自带)
故意不考虑 .Net6/7++ 直接使用NativeAOT编译本地代码
不依赖.Net Runtime到处运行
请合理使用。 请合理使用。