Skip to content

Commit

Permalink
Merge pull request #167 from ivanbiljan/connectionloop
Browse files Browse the repository at this point in the history
Add ConnectionLoop Modification
  • Loading branch information
QuiCM authored Aug 1, 2019
2 parents 1f1901a + d77d2de commit a38d00f
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 2 deletions.
27 changes: 25 additions & 2 deletions TShock.4.OTAPI.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.7
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.156
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerrariaServerAPI", "TerrariaServerAPI\TerrariaServerAPI.csproj", "{6877506E-ADC6-4142-98A6-79E4FA02855A}"
EndProject
Expand All @@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShock.Modifications.SSC",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShock.Modifications.Platform", "TShock.Modifications.Platform\TShock.Modifications.Platform.csproj", "{AC441C8A-EA6B-416F-9961-FA944131AFB6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShock.Modifications.ConnectionLoop", "TShock.Modifications.ConnectionLoop\TShock.Modifications.ConnectionLoop.csproj", "{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -138,8 +140,29 @@ Global
{AC441C8A-EA6B-416F-9961-FA944131AFB6}.Release|x64.Build.0 = Release|Any CPU
{AC441C8A-EA6B-416F-9961-FA944131AFB6}.Release|x86.ActiveCfg = Release|Any CPU
{AC441C8A-EA6B-416F-9961-FA944131AFB6}.Release|x86.Build.0 = Release|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Debug|x64.ActiveCfg = Debug|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Debug|x64.Build.0 = Debug|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Debug|x86.ActiveCfg = Debug|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Debug|x86.Build.0 = Debug|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Mono|Any CPU.ActiveCfg = Release|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Mono|Any CPU.Build.0 = Release|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Mono|x64.ActiveCfg = Release|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Mono|x64.Build.0 = Release|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Mono|x86.ActiveCfg = Release|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Mono|x86.Build.0 = Release|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Release|Any CPU.Build.0 = Release|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Release|x64.ActiveCfg = Release|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Release|x64.Build.0 = Release|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Release|x86.ActiveCfg = Release|Any CPU
{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {34CE5BEA-93DE-4029-BD2E-85A2D6AFB362}
EndGlobalSection
EndGlobal
45 changes: 45 additions & 0 deletions TShock.Modifications.ConnectionLoop/ConnectionLoop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
using OTAPI.Patcher.Engine;
using OTAPI.Patcher.Engine.Extensions.ILProcessor;
using OTAPI.Patcher.Engine.Modification;
using Terraria;

namespace TShock.Modifications.ConnectionLoop
{
/// <summary>
/// This modification is used to inject a network check which ensures that the sever does not enter an infinite loop
/// when clients repeatedly connect and disconnect.
/// </summary>
public sealed class ConnectionLoop : ModificationBase
{
/// <inheritdoc />
public override IEnumerable<string> AssemblyTargets =>
new[] {"OTAPI, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null"};

/// <inheritdoc />
public override string Description => "Patching connection loop exploit...";

/// <inheritdoc />
public override void Run()
{
var checkBytes = Method(() => Terraria.NetMessage.CheckBytesDirect(0));

// Find the proper instruction range => if (i < num2)
var targetInstruction = checkBytes.Body.Instructions.Single(i =>
i.OpCode == OpCodes.Blt_S && i.Previous.OpCode == OpCodes.Ldloc_S &&
i.Previous.Previous.OpCode == OpCodes.Ldloc_3);
checkBytes.Body.GetILProcessor().InsertAfter(targetInstruction,
new[]
{
Instruction.Create(OpCodes.Ldloc_S, checkBytes.Body.Variables[4]),
Instruction.Create(OpCodes.Ldc_I4_0),
Instruction.Create(OpCodes.Beq_S, targetInstruction.Operand as Instruction)
}.AsEnumerable());
}
}
}
36 changes: 36 additions & 0 deletions TShock.Modifications.ConnectionLoop/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TShock.Modifications.ConnectionLoop")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TShock.Modifications.ConnectionLoop")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b466e59a-8a07-46b1-b7c7-33dbc3a0c375")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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>{B466E59A-8A07-46B1-B7C7-33DBC3A0C375}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TShock.Modifications.ConnectionLoop</RootNamespace>
<AssemblyName>TShock.Modifications.ConnectionLoop</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Rocks, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="OTAPI, Version=1.3.5.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OTAPI.2.0.0.32\lib\net451\OTAPI.dll</HintPath>
</Reference>
<Reference Include="OTAPI.Patcher.Engine">
<HintPath>..\prebuilt\OTAPI.Patcher.Engine.dll</HintPath>
</Reference>
<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="ConnectionLoop.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions TShock.Modifications.ConnectionLoop/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Mono.Cecil" version="0.9.6.4" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
<package id="OTAPI" version="2.0.0.32" targetFramework="net452" />
</packages>

0 comments on commit a38d00f

Please # to comment.