Browse Source

Add TcpTunnel;Abort DotLoader

HOME 1 year ago
parent
commit
7d1f799081

+ 14 - 0
DotLoader/DotLoader.csproj

@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>exe</OutputType>
+	  <TargetFramework>net472</TargetFramework>
+	  <!--<TargetFramework>net5.0-windows</TargetFramework>-->
+    <!--<UseWindowsForms>true</UseWindowsForms>-->
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
+
+</Project>

+ 24 - 0
DotLoader/Program.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Threading.Tasks;
+
+namespace DotLoader
+{
+    static class Program
+    {
+        /// <summary>
+        ///  The main entry point for the application.
+        /// </summary>
+        [STAThread]
+        static void Main()
+        {
+
+            Environment.CurrentDirectory = @"Z:\dandanplay_11_5_2\dandanplay_11_5_2-x86";
+            var mainAssembly = Assembly.LoadFile(@"Z:\dandanplay_11_5_2\dandanplay_11_5_2-x86\dandanplay.exe");
+            var ep = mainAssembly.EntryPoint;
+            ep.Invoke(null,null);
+        }
+    }
+}

+ 13 - 1
StrangeTools.sln

@@ -14,7 +14,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileNameCharsetConvert", "F
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileExpander", "FileExpander\FileExpander.csproj", "{7A3E4609-7FDD-4CE9-8671-82F7049F51B0}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessageBox", "MessageBox\MessageBox.csproj", "{7EDCED25-C644-4545-BDF1-E6D13ECB3C0D}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessageBox", "MessageBox\MessageBox.csproj", "{7EDCED25-C644-4545-BDF1-E6D13ECB3C0D}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotLoader", "DotLoader\DotLoader.csproj", "{FAF6A76A-BE48-435B-B45A-A5AEB9A48F01}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcpTunnel", "TcpTunnel\TcpTunnel.csproj", "{9FA46C6F-A981-4303-8256-EC9B6536BFE5}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -38,6 +42,14 @@ Global
 		{7EDCED25-C644-4545-BDF1-E6D13ECB3C0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{7EDCED25-C644-4545-BDF1-E6D13ECB3C0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{7EDCED25-C644-4545-BDF1-E6D13ECB3C0D}.Release|Any CPU.Build.0 = Release|Any CPU
+		{FAF6A76A-BE48-435B-B45A-A5AEB9A48F01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{FAF6A76A-BE48-435B-B45A-A5AEB9A48F01}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{FAF6A76A-BE48-435B-B45A-A5AEB9A48F01}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{FAF6A76A-BE48-435B-B45A-A5AEB9A48F01}.Release|Any CPU.Build.0 = Release|Any CPU
+		{9FA46C6F-A981-4303-8256-EC9B6536BFE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{9FA46C6F-A981-4303-8256-EC9B6536BFE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{9FA46C6F-A981-4303-8256-EC9B6536BFE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{9FA46C6F-A981-4303-8256-EC9B6536BFE5}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 33 - 0
TcpTunnel/App.config

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <configSections>
+        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
+            <section name="TcpTunnel.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+        </sectionGroup>
+    </configSections>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
+    </startup>
+    <applicationSettings>
+        <TcpTunnel.Properties.Settings>
+            <setting name="AccessToken" serializeAs="String">
+                <value>foo</value>
+            </setting>
+            <setting name="Direction" serializeAs="String">
+                <value>in</value>
+            </setting>
+            <setting name="TargetHost" serializeAs="String">
+                <value>192.168.254.254</value>
+            </setting>
+            <setting name="TargetPort" serializeAs="String">
+                <value>1234</value>
+            </setting>
+            <setting name="ListenOn" serializeAs="String">
+                <value>0.0.0.0</value>
+            </setting>
+            <setting name="ListenPort" serializeAs="String">
+                <value>4321</value>
+            </setting>
+        </TcpTunnel.Properties.Settings>
+    </applicationSettings>
+</configuration>

+ 152 - 0
TcpTunnel/Program.cs

@@ -0,0 +1,152 @@
+using System;
+using System.Diagnostics;
+using System.Linq;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace TcpTunnel
+{
+    internal class Program
+    {
+        private static void Main(string[] args)
+        {
+            //#if DEBUG
+            //            Debugger.Launch();
+            //            Debugger.Break();
+            //#endif
+
+            if (args.Length != 6)
+            {
+                Console.WriteLine($"Usage: <cl|sv> <token> <listenAddress> <listenPort> <targetHost> <targetPort>");
+                return;
+            }
+
+            var isCl = args[0] == "cl";
+            var token = args[1];
+
+            if (!IPAddress.TryParse(args[2], out var listenAddress))
+            {
+                Console.WriteLine("invalid listen address");
+                return;
+            }
+
+            if (!int.TryParse(args[3], out var listenPort))
+            {
+                Console.WriteLine("invalid listen port");
+                return;
+            }
+
+            var targetHost = args[4];
+
+            if (!int.TryParse(args[5], out var targetPort))
+            {
+                Console.WriteLine("invalid target port");
+                return;
+            }
+
+            var listener = new TcpListener(listenAddress, listenPort);
+            listener.Start(1);
+
+            Console.WriteLine($"Listening on {listener.LocalEndpoint}");
+            var connectionCount = 0;
+
+            var tokenBuf = Encoding.UTF8.GetBytes(token);
+
+            listener.BeginAcceptTcpClient(AsyncCallback, null);
+            void AsyncCallback(IAsyncResult ar)
+            {
+                var cn = Interlocked.Increment(ref connectionCount);
+
+
+                listener.BeginAcceptTcpClient(AsyncCallback, null);
+
+                var ibClient = listener.EndAcceptTcpClient(ar);
+
+
+                Console.WriteLine($"[#{cn:0000}]Income from {ibClient.Client.RemoteEndPoint}");
+                var ibStream = ibClient.GetStream();
+
+                NetworkStream obStream = null;
+                TcpClient obClient = null;
+                if (isCl)
+                {
+                    Console.WriteLine($"[#{cn:0000}]Connecting to target...");
+                    obClient = new TcpClient(targetHost, targetPort);
+                    obStream = obClient.GetStream();
+
+                    Console.WriteLine($"[#{cn:0000}]Connected sending token...");
+                    obStream.WriteByte((byte)tokenBuf.Length);
+                    obStream.Write(tokenBuf, 0, tokenBuf.Length);
+                }
+                else
+                {
+                    Console.WriteLine($"[#{cn:0000}]Checking token...");
+
+                    var tol = ibStream.ReadByte();
+                    if (tol != tokenBuf.Length)
+                    {
+                        Console.WriteLine($"[#{cn:0000}]Invalid token length closing");
+
+                        Thread.Sleep(1000);
+                        ibStream.Close();
+                        ibClient.Close();
+
+                        Console.WriteLine($"[#{cn:0000}]Invalid token length closed");
+                        return;
+                    }
+
+                    var buf = new byte[tol];
+                    ibStream.Read(buf, 0, tol);
+                    if (!buf.SequenceEqual(tokenBuf))
+                    {
+                        Console.WriteLine($"[#{cn:0000}]Invalid token closing");
+
+                        Thread.Sleep(1000);
+                        ibStream.Close();
+                        ibClient.Close();
+
+                        Console.WriteLine($"[#{cn:0000}]Invalid token closed");
+                        return;
+                    }
+
+                    Console.WriteLine($"[#{cn:0000}]Auth OK, Connecting to target...");
+                    obClient = new TcpClient(targetHost, targetPort);
+                    obStream = obClient.GetStream();
+                }
+
+                if (ibClient.Connected && obClient.Connected)
+                {
+                    Console.WriteLine($"[#{cn:0000}]Start tunneling");
+                    
+                    ibClient.ReceiveTimeout = 120000;
+                    ibClient.SendTimeout = 120000;
+                    obClient.ReceiveTimeout = 120000;
+                    obClient.SendTimeout = 120000;
+
+                    var i2o = Task.Factory.StartNew(delegate { ibStream.CopyTo(obStream); });
+                    var o2i = Task.Factory.StartNew(delegate { obStream.CopyTo(ibStream); });
+
+                    Task.WaitAny(i2o, o2i);
+                    Console.WriteLine($"[#{cn:0000}]End tunnel");
+                }
+                else
+                {
+                    Console.WriteLine($"[#{cn:0000}]No connected.");
+                }
+
+                ibClient?.Dispose();
+                obClient?.Dispose();
+            }
+
+            Console.WriteLine("Press ENTER to Stop");
+            Console.ReadLine();
+            Console.WriteLine("Stopping...");
+            listener.Stop();
+            Console.WriteLine("Stopped,press ENTER to exit");
+            Console.ReadLine();
+        }
+    }
+}

+ 36 - 0
TcpTunnel/Properties/AssemblyInfo.cs

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

+ 53 - 0
TcpTunnel/TcpTunnel.csproj

@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<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>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{9FA46C6F-A981-4303-8256-EC9B6536BFE5}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>TcpTunnel</RootNamespace>
+    <AssemblyName>TcpTunnel</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <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.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>