This repository has been archived by the owner on Apr 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e2108f
commit 752eb28
Showing
34 changed files
with
3,584 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
73 changes: 73 additions & 0 deletions
73
src/FileTypeDDS/FileTypeBootstrap/FileTypeBootstrap.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" 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>{732BCC9E-8127-4906-92CA-BD1E3FDA64E5}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>FileTypeBootstrap</RootNamespace> | ||
<AssemblyName>FileTypeBootstrap</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<TargetFrameworkProfile /> | ||
</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> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</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> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="PaintDotNet.Base"> | ||
<HintPath>..\..\Dependencies\PaintDotNet.Base.dll</HintPath> | ||
</Reference> | ||
<Reference Include="PaintDotNet.Core"> | ||
<HintPath>..\..\Dependencies\PaintDotNet.Core.dll</HintPath> | ||
</Reference> | ||
<Reference Include="PaintDotNet.Data"> | ||
<HintPath>..\..\Dependencies\PaintDotNet.Data.dll</HintPath> | ||
</Reference> | ||
<Reference Include="PaintDotNet.Effects"> | ||
<HintPath>..\..\Dependencies\PaintDotNet.Effects.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Windows.Forms" /> | ||
<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="Global.cs" /> | ||
<Compile Include="Main.cs" /> | ||
<Compile Include="MethodInjector.cs" /> | ||
<Compile Include="PluginSupportInfo.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FileTypeBootstrap | ||
{ | ||
public class Global | ||
{ | ||
public static bool WasPatched = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
using PaintDotNet; | ||
using PaintDotNet.Effects; | ||
using PaintDotNet.PropertySystem; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FileTypeBootstrap | ||
{ | ||
public class InjectMethod | ||
{ | ||
public static bool IsInterfaceImplemented(Type derivedType, Type interfaceType) | ||
{ | ||
return false; | ||
} | ||
|
||
public static Document LoadWrap(Stream input) | ||
{ | ||
System.Windows.Forms.MessageBox.Show("LOL"); | ||
return null; | ||
} | ||
|
||
public static FileType[] InternalFileTypes() | ||
{ | ||
System.Windows.Forms.MessageBox.Show("LOL"); | ||
return null; | ||
} | ||
|
||
public void FileTypeCTOR() | ||
{ | ||
|
||
} | ||
} | ||
|
||
public class TestMeDo : PropertyBasedFileType | ||
{ | ||
public TestMeDo(): base("lol", FileTypeFlags.None, new string[]{".lol"}) | ||
{ | ||
|
||
} | ||
|
||
public override PropertyCollection OnCreateSavePropertyCollection() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected override Document OnLoad(Stream input) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
public class FileTypeBootstrapper : PropertyBasedEffect | ||
{ | ||
public FileTypeBootstrapper() | ||
: base(FileTypeBootstrapper.StaticName, FileTypeBootstrapper.StaticIcon, "FileTypeBootstrap", EffectFlags.ForceAliasedSelectionQuality) | ||
{ | ||
if (Global.WasPatched == false) | ||
{ | ||
// Prepare to inject wrapper methods | ||
var BaseAssembly = Assembly.GetEntryAssembly(); | ||
var BaseInjectType = BaseAssembly.GetType("PaintDotNet.Data.Dds.DdsFileType"); | ||
|
||
string test = ""; | ||
|
||
foreach (MethodInfo m in BaseInjectType.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly)) | ||
{ | ||
test += " " + m.Name; | ||
} | ||
|
||
System.Windows.Forms.MessageBox.Show("win" + test); | ||
|
||
// Get the wrapper method | ||
var WrapperMethod = BaseInjectType.GetMethod("OnLoad", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly); | ||
// We now got the method to wrap | ||
if (WrapperMethod != null) | ||
{ | ||
System.Windows.Forms.MessageBox.Show("Got target"); | ||
// Get it | ||
var PatchMethod = typeof(TestMeDo).GetMethod("OnLoad", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly); | ||
// Check | ||
if (PatchMethod != null) | ||
{ | ||
System.Windows.Forms.MessageBox.Show("Got patch, Patching..."); | ||
// Inject them | ||
MethodInjector.InjectMethod(WrapperMethod, PatchMethod); | ||
} | ||
} | ||
|
||
|
||
|
||
Global.WasPatched = true; | ||
} | ||
} | ||
|
||
// A blank name | ||
public static string StaticName { get { return string.Empty; } } | ||
// A blank icon | ||
public static Image StaticIcon { get { return null; } } | ||
|
||
// Implementation of an effect, not used | ||
protected override void OnRender(Rectangle[] rois, int startIndex, int length) | ||
{ | ||
} | ||
|
||
protected override PropertyCollection OnCreatePropertyCollection() | ||
{ | ||
// Default result | ||
return new PropertyCollection(new List<Property>()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FileTypeBootstrap | ||
{ | ||
internal class MethodInjector | ||
{ | ||
/// <summary> | ||
/// Replace the target function with the specified patched method | ||
/// </summary> | ||
/// <param name="Target">The target function to patch</param> | ||
/// <param name="Patch">The method to patch it with</param> | ||
public static void InjectMethod(MethodInfo Target, MethodInfo Patch) | ||
{ | ||
// Prepare methods | ||
RuntimeHelpers.PrepareMethod(Target.MethodHandle); | ||
RuntimeHelpers.PrepareMethod(Patch.MethodHandle); | ||
|
||
unsafe | ||
{ | ||
if (IntPtr.Size == 4) | ||
{ | ||
// Get offsets | ||
int* inj = (int*)Patch.MethodHandle.Value.ToPointer() + 2; | ||
int* tar = (int*)Target.MethodHandle.Value.ToPointer() + 2; | ||
// Check for debug | ||
if (Debugger.IsAttached) | ||
{ | ||
byte* injInst = (byte*)*inj; | ||
byte* tarInst = (byte*)*tar; | ||
|
||
int* injSrc = (int*)(injInst + 1); | ||
int* tarSrc = (int*)(tarInst + 1); | ||
|
||
*tarSrc = (((int)injInst + 5) + *injSrc) - ((int)tarInst + 5); | ||
} | ||
else | ||
{ | ||
*tar = *inj; | ||
} | ||
} | ||
else | ||
{ | ||
// Get offsets | ||
long* inj = (long*)Patch.MethodHandle.Value.ToPointer() + 1; | ||
long* tar = (long*)Target.MethodHandle.Value.ToPointer() + 1; | ||
// Check for debug | ||
if (Debugger.IsAttached) | ||
{ | ||
byte* injInst = (byte*)*inj; | ||
byte* tarInst = (byte*)*tar; | ||
|
||
|
||
int* injSrc = (int*)(injInst + 1); | ||
int* tarSrc = (int*)(tarInst + 1); | ||
|
||
*tarSrc = (((int)injInst + 5) + *injSrc) - ((int)tarInst + 5); | ||
} | ||
else | ||
{ | ||
*tar = *inj; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static void InjectConstructor(ConstructorInfo Target, ConstructorInfo Patch) | ||
{ | ||
// Prepare methods | ||
RuntimeHelpers.PrepareMethod(Target.MethodHandle); | ||
RuntimeHelpers.PrepareMethod(Patch.MethodHandle); | ||
|
||
unsafe | ||
{ | ||
if (IntPtr.Size == 4) | ||
{ | ||
// Get offsets | ||
int* inj = (int*)Patch.MethodHandle.Value.ToPointer() + 2; | ||
int* tar = (int*)Target.MethodHandle.Value.ToPointer() + 2; | ||
// Check for debug | ||
if (Debugger.IsAttached) | ||
{ | ||
byte* injInst = (byte*)*inj; | ||
byte* tarInst = (byte*)*tar; | ||
|
||
int* injSrc = (int*)(injInst + 1); | ||
int* tarSrc = (int*)(tarInst + 1); | ||
|
||
*tarSrc = (((int)injInst + 5) + *injSrc) - ((int)tarInst + 5); | ||
} | ||
else | ||
{ | ||
*tar = *inj; | ||
} | ||
} | ||
else | ||
{ | ||
// Get offsets | ||
long* inj = (long*)Patch.MethodHandle.Value.ToPointer() + 1; | ||
long* tar = (long*)Target.MethodHandle.Value.ToPointer() + 1; | ||
// Check for debug | ||
if (Debugger.IsAttached) | ||
{ | ||
byte* injInst = (byte*)*inj; | ||
byte* tarInst = (byte*)*tar; | ||
|
||
|
||
int* injSrc = (int*)(injInst + 1); | ||
int* tarSrc = (int*)(tarInst + 1); | ||
|
||
*tarSrc = (((int)injInst + 5) + *injSrc) - ((int)tarInst + 5); | ||
} | ||
else | ||
{ | ||
*tar = *inj; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using PaintDotNet; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FileTypeBootstrap | ||
{ | ||
public class PluginSupportInfo : IPluginSupportInfo | ||
{ | ||
public string Author | ||
{ | ||
get | ||
{ | ||
return "DTZxPorter"; | ||
} | ||
} | ||
|
||
public string Copyright | ||
{ | ||
get | ||
{ | ||
return "2017 DTZxPorter"; | ||
} | ||
} | ||
|
||
public string DisplayName | ||
{ | ||
get | ||
{ | ||
return "FileTypeBootstrap"; | ||
} | ||
} | ||
|
||
public Version Version | ||
{ | ||
get | ||
{ | ||
return new Version(1, 0, 0, 0); | ||
} | ||
} | ||
|
||
public Uri WebsiteUri | ||
{ | ||
get | ||
{ | ||
return new Uri("http://modme.co"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.