commit 12a37bfb12eee0b67547e7fd8bda6c4421c59be1 Author: 世元 李 <1498045907@qq.com> Date: Wed Mar 11 19:17:00 2020 +0800 first test diff --git a/cs2_chs/$(SolutionDir)$(Configuration)/cs2_chs.exe b/cs2_chs/$(SolutionDir)$(Configuration)/cs2_chs.exe new file mode 100644 index 0000000..d69ae9f Binary files /dev/null and b/cs2_chs/$(SolutionDir)$(Configuration)/cs2_chs.exe differ diff --git a/cs2_chs/$(SolutionDir)$(Configuration)/cs2_chs.exe.config b/cs2_chs/$(SolutionDir)$(Configuration)/cs2_chs.exe.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/cs2_chs/$(SolutionDir)$(Configuration)/cs2_chs.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cs2_chs/$(SolutionDir)$(Configuration)/cs2_chs.pdb b/cs2_chs/$(SolutionDir)$(Configuration)/cs2_chs.pdb new file mode 100644 index 0000000..2536bd7 Binary files /dev/null and b/cs2_chs/$(SolutionDir)$(Configuration)/cs2_chs.pdb differ diff --git a/cs2_chs/App.config b/cs2_chs/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/cs2_chs/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cs2_chs/App.xaml b/cs2_chs/App.xaml new file mode 100644 index 0000000..ed497a1 --- /dev/null +++ b/cs2_chs/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/cs2_chs/App.xaml.cs b/cs2_chs/App.xaml.cs new file mode 100644 index 0000000..4a15ef8 --- /dev/null +++ b/cs2_chs/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace cs2_chs +{ + /// + /// App.xaml 的交互逻辑 + /// + public partial class App : Application + { + } +} diff --git a/cs2_chs/MainWindow.xaml b/cs2_chs/MainWindow.xaml new file mode 100644 index 0000000..ff18332 --- /dev/null +++ b/cs2_chs/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/cs2_chs/MainWindow.xaml.cs b/cs2_chs/MainWindow.xaml.cs new file mode 100644 index 0000000..e5f18bb --- /dev/null +++ b/cs2_chs/MainWindow.xaml.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +using System.Runtime.InteropServices; +namespace cs2_chs +{ + /// + /// MainWindow.xaml 的交互逻辑 + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/cs2_chs/Properties/AssemblyInfo.cs b/cs2_chs/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5d1e214 --- /dev/null +++ b/cs2_chs/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("cs2_chs")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("cs2_chs")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +//若要开始生成可本地化的应用程序,请设置 +//.csproj 文件中的 CultureYouAreCodingWith +//例如,如果您在源文件中使用的是美国英语, +//使用的是美国英语,请将 设置为 en-US。 然后取消 +//对以下 NeutralResourceLanguage 特性的注释。 更新 +//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //主题特定资源词典所处位置 + //(未在页面中找到资源时使用, + //或应用程序资源字典中找到时使用) + ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 + //(未在页面中找到资源时使用, + //、应用程序或任何主题专用资源字典中找到时使用) +)] + + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/cs2_chs/Properties/Resources.Designer.cs b/cs2_chs/Properties/Resources.Designer.cs new file mode 100644 index 0000000..c0c81b2 --- /dev/null +++ b/cs2_chs/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace cs2_chs.Properties +{ + + + /// + /// 强类型资源类,用于查找本地化字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的缓存 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("cs2_chs.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 覆盖当前线程的 CurrentUICulture 属性 + /// 使用此强类型的资源类的资源查找。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/cs2_chs/Properties/Resources.resx b/cs2_chs/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/cs2_chs/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/cs2_chs/Properties/Settings.Designer.cs b/cs2_chs/Properties/Settings.Designer.cs new file mode 100644 index 0000000..3652886 --- /dev/null +++ b/cs2_chs/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace cs2_chs.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/cs2_chs/Properties/Settings.settings b/cs2_chs/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/cs2_chs/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/cs2_chs/bin/Debug/cs2_chs.exe b/cs2_chs/bin/Debug/cs2_chs.exe new file mode 100644 index 0000000..d69ae9f Binary files /dev/null and b/cs2_chs/bin/Debug/cs2_chs.exe differ diff --git a/cs2_chs/bin/Debug/cs2_chs.exe.config b/cs2_chs/bin/Debug/cs2_chs.exe.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/cs2_chs/bin/Debug/cs2_chs.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cs2_chs/bin/Debug/cs2_chs.pdb b/cs2_chs/bin/Debug/cs2_chs.pdb new file mode 100644 index 0000000..2536bd7 Binary files /dev/null and b/cs2_chs/bin/Debug/cs2_chs.pdb differ diff --git a/cs2_chs/cs2_chs.csproj b/cs2_chs/cs2_chs.csproj new file mode 100644 index 0000000..aae3387 --- /dev/null +++ b/cs2_chs/cs2_chs.csproj @@ -0,0 +1,98 @@ + + + + + Debug + AnyCPU + {460F93FF-C32C-455C-A2F6-BB81E86961AE} + WinExe + cs2_chs + cs2_chs + v4.7.2 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + + + AnyCPU + true + full + false + ..\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + \ No newline at end of file diff --git a/cs2_chs/obj/Debug/App.g.cs b/cs2_chs/obj/Debug/App.g.cs new file mode 100644 index 0000000..bbc227e --- /dev/null +++ b/cs2_chs/obj/Debug/App.g.cs @@ -0,0 +1,70 @@ +#pragma checksum "..\..\App.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "47A6ABC1F984D2628127870792B9669A74CD780D5065D75E37A3BA999C302E28" +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +using System; +using System.Diagnostics; +using System.Windows; +using System.Windows.Automation; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Markup; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Effects; +using System.Windows.Media.Imaging; +using System.Windows.Media.Media3D; +using System.Windows.Media.TextFormatting; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Shell; +using cs2_chs; + + +namespace cs2_chs { + + + /// + /// App + /// + public partial class App : System.Windows.Application { + + /// + /// InitializeComponent + /// + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] + public void InitializeComponent() { + + #line 5 "..\..\App.xaml" + this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative); + + #line default + #line hidden + } + + /// + /// Application Entry Point. + /// + [System.STAThreadAttribute()] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] + public static void Main() { + cs2_chs.App app = new cs2_chs.App(); + app.InitializeComponent(); + app.Run(); + } + } +} + diff --git a/cs2_chs/obj/Debug/App.g.i.cs b/cs2_chs/obj/Debug/App.g.i.cs new file mode 100644 index 0000000..bbc227e --- /dev/null +++ b/cs2_chs/obj/Debug/App.g.i.cs @@ -0,0 +1,70 @@ +#pragma checksum "..\..\App.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "47A6ABC1F984D2628127870792B9669A74CD780D5065D75E37A3BA999C302E28" +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +using System; +using System.Diagnostics; +using System.Windows; +using System.Windows.Automation; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Markup; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Effects; +using System.Windows.Media.Imaging; +using System.Windows.Media.Media3D; +using System.Windows.Media.TextFormatting; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Shell; +using cs2_chs; + + +namespace cs2_chs { + + + /// + /// App + /// + public partial class App : System.Windows.Application { + + /// + /// InitializeComponent + /// + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] + public void InitializeComponent() { + + #line 5 "..\..\App.xaml" + this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative); + + #line default + #line hidden + } + + /// + /// Application Entry Point. + /// + [System.STAThreadAttribute()] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] + public static void Main() { + cs2_chs.App app = new cs2_chs.App(); + app.InitializeComponent(); + app.Run(); + } + } +} + diff --git a/cs2_chs/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/cs2_chs/obj/Debug/DesignTimeResolveAssemblyReferences.cache new file mode 100644 index 0000000..b8c3223 Binary files /dev/null and b/cs2_chs/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/cs2_chs/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/cs2_chs/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..87ca6dd Binary files /dev/null and b/cs2_chs/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/cs2_chs/obj/Debug/MainWindow.baml b/cs2_chs/obj/Debug/MainWindow.baml new file mode 100644 index 0000000..854534a Binary files /dev/null and b/cs2_chs/obj/Debug/MainWindow.baml differ diff --git a/cs2_chs/obj/Debug/MainWindow.g.cs b/cs2_chs/obj/Debug/MainWindow.g.cs new file mode 100644 index 0000000..6815d9f --- /dev/null +++ b/cs2_chs/obj/Debug/MainWindow.g.cs @@ -0,0 +1,75 @@ +#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "9CB247877E61DAF477756184D7D540C5D7031D102648953613C3BAD73D2C4F26" +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +using System; +using System.Diagnostics; +using System.Windows; +using System.Windows.Automation; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Markup; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Effects; +using System.Windows.Media.Imaging; +using System.Windows.Media.Media3D; +using System.Windows.Media.TextFormatting; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Shell; +using cs2_chs; + + +namespace cs2_chs { + + + /// + /// MainWindow + /// + public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector { + + private bool _contentLoaded; + + /// + /// InitializeComponent + /// + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] + public void InitializeComponent() { + if (_contentLoaded) { + return; + } + _contentLoaded = true; + System.Uri resourceLocater = new System.Uri("/cs2_chs;component/mainwindow.xaml", System.UriKind.Relative); + + #line 1 "..\..\MainWindow.xaml" + System.Windows.Application.LoadComponent(this, resourceLocater); + + #line default + #line hidden + } + + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")] + void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { + this._contentLoaded = true; + } + } +} + diff --git a/cs2_chs/obj/Debug/MainWindow.g.i.cs b/cs2_chs/obj/Debug/MainWindow.g.i.cs new file mode 100644 index 0000000..6815d9f --- /dev/null +++ b/cs2_chs/obj/Debug/MainWindow.g.i.cs @@ -0,0 +1,75 @@ +#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "9CB247877E61DAF477756184D7D540C5D7031D102648953613C3BAD73D2C4F26" +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +using System; +using System.Diagnostics; +using System.Windows; +using System.Windows.Automation; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Markup; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Effects; +using System.Windows.Media.Imaging; +using System.Windows.Media.Media3D; +using System.Windows.Media.TextFormatting; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Shell; +using cs2_chs; + + +namespace cs2_chs { + + + /// + /// MainWindow + /// + public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector { + + private bool _contentLoaded; + + /// + /// InitializeComponent + /// + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] + public void InitializeComponent() { + if (_contentLoaded) { + return; + } + _contentLoaded = true; + System.Uri resourceLocater = new System.Uri("/cs2_chs;component/mainwindow.xaml", System.UriKind.Relative); + + #line 1 "..\..\MainWindow.xaml" + System.Windows.Application.LoadComponent(this, resourceLocater); + + #line default + #line hidden + } + + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")] + void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { + this._contentLoaded = true; + } + } +} + diff --git a/cs2_chs/obj/Debug/cs2_chs.Properties.Resources.resources b/cs2_chs/obj/Debug/cs2_chs.Properties.Resources.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/cs2_chs/obj/Debug/cs2_chs.Properties.Resources.resources differ diff --git a/cs2_chs/obj/Debug/cs2_chs.csproj.FileListAbsolute.txt b/cs2_chs/obj/Debug/cs2_chs.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..48ddf74 --- /dev/null +++ b/cs2_chs/obj/Debug/cs2_chs.csproj.FileListAbsolute.txt @@ -0,0 +1,20 @@ +D:\VSProject\cs2\cs2_united\cs2_chs\bin\Debug\cs2_chs.exe.config +D:\VSProject\cs2\cs2_united\cs2_chs\bin\Debug\cs2_chs.exe +D:\VSProject\cs2\cs2_united\cs2_chs\bin\Debug\cs2_chs.pdb +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\cs2_chs.csprojAssemblyReference.cache +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\MainWindow.g.cs +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\App.g.cs +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\cs2_chs_MarkupCompile.cache +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\cs2_chs_MarkupCompile.lref +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\MainWindow.baml +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\cs2_chs.g.resources +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\cs2_chs.Properties.Resources.resources +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\cs2_chs.csproj.GenerateResource.cache +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\cs2_chs.exe +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\cs2_chs.pdb +D:\VSProject\cs2\cs2_united\cs2_chs\$(SolutionDir)$(Configuration)\cs2_chs.exe.config +D:\VSProject\cs2\cs2_united\cs2_chs\$(SolutionDir)$(Configuration)\cs2_chs.exe +D:\VSProject\cs2\cs2_united\cs2_chs\$(SolutionDir)$(Configuration)\cs2_chs.pdb +D:\VSProject\cs2\cs2_united\Debug\cs2_chs.exe.config +D:\VSProject\cs2\cs2_united\Debug\cs2_chs.exe +D:\VSProject\cs2\cs2_united\Debug\cs2_chs.pdb diff --git a/cs2_chs/obj/Debug/cs2_chs.csproj.GenerateResource.cache b/cs2_chs/obj/Debug/cs2_chs.csproj.GenerateResource.cache new file mode 100644 index 0000000..f94fe4c Binary files /dev/null and b/cs2_chs/obj/Debug/cs2_chs.csproj.GenerateResource.cache differ diff --git a/cs2_chs/obj/Debug/cs2_chs.csprojAssemblyReference.cache b/cs2_chs/obj/Debug/cs2_chs.csprojAssemblyReference.cache new file mode 100644 index 0000000..f223ae8 Binary files /dev/null and b/cs2_chs/obj/Debug/cs2_chs.csprojAssemblyReference.cache differ diff --git a/cs2_chs/obj/Debug/cs2_chs.exe b/cs2_chs/obj/Debug/cs2_chs.exe new file mode 100644 index 0000000..05e92ed Binary files /dev/null and b/cs2_chs/obj/Debug/cs2_chs.exe differ diff --git a/cs2_chs/obj/Debug/cs2_chs.g.resources b/cs2_chs/obj/Debug/cs2_chs.g.resources new file mode 100644 index 0000000..0c6bc70 Binary files /dev/null and b/cs2_chs/obj/Debug/cs2_chs.g.resources differ diff --git a/cs2_chs/obj/Debug/cs2_chs.pdb b/cs2_chs/obj/Debug/cs2_chs.pdb new file mode 100644 index 0000000..8af7496 Binary files /dev/null and b/cs2_chs/obj/Debug/cs2_chs.pdb differ diff --git a/cs2_chs/obj/Debug/cs2_chs_MarkupCompile.cache b/cs2_chs/obj/Debug/cs2_chs_MarkupCompile.cache new file mode 100644 index 0000000..a4c6ef2 --- /dev/null +++ b/cs2_chs/obj/Debug/cs2_chs_MarkupCompile.cache @@ -0,0 +1,20 @@ +cs2_chs + + +winexe +C# +.cs +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\ +cs2_chs +none +false +DEBUG;TRACE +D:\VSProject\cs2\cs2_united\cs2_chs\App.xaml +11151548125 + +5-2017746502 +13-1505183044 +MainWindow.xaml; + +False + diff --git a/cs2_chs/obj/Debug/cs2_chs_MarkupCompile.i.cache b/cs2_chs/obj/Debug/cs2_chs_MarkupCompile.i.cache new file mode 100644 index 0000000..b30a3b9 --- /dev/null +++ b/cs2_chs/obj/Debug/cs2_chs_MarkupCompile.i.cache @@ -0,0 +1,20 @@ +cs2_chs + + +winexe +C# +.cs +D:\VSProject\cs2\cs2_united\cs2_chs\obj\Debug\ +cs2_chs +none +false +DEBUG;TRACE +D:\VSProject\cs2\cs2_united\cs2_chs\App.xaml +11151548125 + +61167299106 +13-1505183044 +MainWindow.xaml; + +False + diff --git a/cs2_chs/obj/Debug/cs2_chs_MarkupCompile.lref b/cs2_chs/obj/Debug/cs2_chs_MarkupCompile.lref new file mode 100644 index 0000000..63882a1 --- /dev/null +++ b/cs2_chs/obj/Debug/cs2_chs_MarkupCompile.lref @@ -0,0 +1,4 @@ + + +FD:\VSProject\cs2\cs2_united\cs2_chs\MainWindow.xaml;; + diff --git a/cs2_patch/BuildIn.cpp b/cs2_patch/BuildIn.cpp new file mode 100644 index 0000000..118f9a8 --- /dev/null +++ b/cs2_patch/BuildIn.cpp @@ -0,0 +1,128 @@ +#include "pch.h" +#include "BuildIn.h" +#include "Data.h" + +extern MicroData Index; +extern MicroBinary Data; + +extern HMODULE hMod; +extern "C" extern DLLAPI wchar_t ms_str[3096]; +extern "C" extern DLLAPI int nID; + + +signed int (*sub_5FC1C0)() = (signed int(*)(void))0x5FC1C0;//real function point +HMODULE SelfHandle = NULL; +bool start_falg = false; + +BOOL InjectDLL(HANDLE hProcess, LPCWSTR dllFilePathName) +{ + if (!hProcess) + return FALSE; + int cch = 1 + lstrlenW(dllFilePathName); + int cb = cch * sizeof(wchar_t); + + LPWSTR PszLibFileRemote = (LPWSTR)VirtualAllocEx(hProcess, NULL, cb, MEM_COMMIT, PAGE_READWRITE); + + if (!PszLibFileRemote) + return FALSE; + if (!WriteProcessMemory(hProcess, PszLibFileRemote, (LPVOID)dllFilePathName, cb, NULL)) + return FALSE; + HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE) + LoadLibraryW, PszLibFileRemote, 0, NULL); + if (!hThread) return FALSE; + WaitForSingleObject(hThread, INFINITE); + + return TRUE; +} + +DLLAPI HANDLE InjectSelfTo(wchar_t inptr[]) +{ + + HANDLE currentThread = NULL; + + LPPROCESS_INFORMATION info = new PROCESS_INFORMATION; + STARTUPINFO si = { sizeof(si) }; + do { + wchar_t m_CommandLine[] = L""; + BOOL hF = CreateProcess(inptr, NULL, + NULL, NULL, FALSE, + CREATE_SUSPENDED, NULL, NULL, &si, info); + if (!hF) { + MessageBox(0, L"ʧ", L"", MB_ICONERROR); + return 0; + } + // MessageBox(0, L"1", L"", 0); + wchar_t m_Path[MAX_PATH]; + GetModuleFileName(hMod, m_Path, MAX_PATH); + if (!InjectDLL(info->hProcess, m_Path)) { + MessageBoxA(0, "", "", 0); + return 0; + } + + currentThread = info->hThread; + } while (0); + + HANDLE hHookStart = CreateRemoteThread(info->hProcess, NULL, 0, (LPTHREAD_START_ROUTINE) + ::GetProcAddress(hMod, "start"), 0, 0, NULL); + + if (!hHookStart) + { + MessageBox(0, L"޷Զ߳(IAT HOOK)", L"", MB_ICONERROR); + return 0; + } + WaitForSingleObject(hHookStart, 0); + ResumeThread(info->hThread); + delete info; + + lstrcpyW(ms_str, L" "); + + Index.Load(); + Data.Load(); + return currentThread; +} + +signed int Fakesub_5FC1C0() +{ + DWORD leax, lebx, lecx, ledx, lesi, ledi; + __asm { + mov dword ptr[leax], eax + mov dword ptr[lebx], ebx + mov dword ptr[lecx], ecx + mov dword ptr[ledx], edx + mov dword ptr[lesi], esi + mov dword ptr[ledi], edi + } + // SetWindowTextW(m_hWnd, L"hook"); + ((int(*)(DWORD))::GetProcAddress(SelfHandle, "TranSplete"))(lecx); + // SetWindowTextW(m_hWnd, L"hook"); + __asm { + mov eax, dword ptr[leax] + mov ebx, dword ptr[lebx] + mov ecx, dword ptr[lecx] + mov edx, dword ptr[ledx] + mov esi, dword ptr[lesi] + mov edi, dword ptr[ledi] + } + + return sub_5FC1C0(); +} + +DLLAPI void start() +{ + + DetourRestoreAfterWith(); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach(&(PVOID&)sub_5FC1C0, Fakesub_5FC1C0); + DetourTransactionCommit(); + + start_falg = TRUE; +} + +void end() +{ + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourDetach(&(PVOID&)sub_5FC1C0, Fakesub_5FC1C0); + DetourTransactionCommit(); +} diff --git a/cs2_patch/BuildIn.h b/cs2_patch/BuildIn.h new file mode 100644 index 0000000..ff84271 --- /dev/null +++ b/cs2_patch/BuildIn.h @@ -0,0 +1,13 @@ +#pragma once +#include +#define DLLAPI __declspec(dllexport) + + +BOOL InjectDLL(HANDLE hProcess, LPCWSTR dllFilePathName);//Inject dll to the signal process +extern "C" DLLAPI HANDLE InjectSelfTo(wchar_t inptr[]);//Inject self + + +signed int Fakesub_5FC1C0();//hooked function point + +extern "C" DLLAPI void start();//start hook +void end();//end hook \ No newline at end of file diff --git a/cs2_patch/Data.cpp b/cs2_patch/Data.cpp new file mode 100644 index 0000000..607947c --- /dev/null +++ b/cs2_patch/Data.cpp @@ -0,0 +1,190 @@ +#include "pch.h" +#include "Data.h" + +MicroData Index(L"Index.ax", sizeof(IndexData)); +MicroBinary Data(L"Data.ax"); + + +extern HMODULE hMod; +extern "C" extern DLLAPI wchar_t ms_str[3096]; +extern "C" extern DLLAPI int nID; + +DLLAPI void CreateDataExport(WCHAR data[]) +{ + WCHAR sjp[3096]; + WCHAR scn[3096]; + + int lasger = GEtLargestID(); + + if (nID - lasger > 2) { + MessageBox(0, L"IDֵƺ̫Ծ\nȡεж", L"", MB_ICONERROR); + return; + } + if (!GetDataByID(nID - 1, sjp, scn)) { + + CreateDataByID(nID - 1, ms_str, 2 * (lstrlenW(ms_str) + 1), data, 2 * (lstrlenW(data) + 1)); + WCHAR abv[16]; + _itow_s(nID - 1, abv, 10); + wstring str; + str += L"ӦãID:"; + str += abv; + str += L"\n"; + str += ms_str; + str += L"->"; + str += data; + MessageBoxW(NULL, str.c_str(), L"ɹӷ", MB_ICONINFORMATION); + return; + } + else { + wstring nString = L"÷ĿѾڣǷҪ滻\n(عļĵܣܻռһЩʱ)\n"; + WCHAR abv[16]; + _itow_s(nID - 1, abv, 10); + nString += L"ID:"; + nString += abv; + nString += L"\n"; + nString += sjp; + int result = MessageBoxW(NULL, nString.c_str(), L"Ϣ", MB_ICONINFORMATION | MB_OKCANCEL); + + + if (result != IDOK) + return; + + + int p = 0; + while (GetDataByID(p, sjp, scn)) { + if (p == (nID - 1)) { + CreateDataByIDEx(L"~Index.ax", L"~Data.ax", p, sjp, 2 * (lstrlenW(sjp) + 1), data, 2 * (lstrlenW(data) + 1)); + } + else + { + CreateDataByIDEx(L"~Index.ax", L"~Data.ax", p, sjp, 2 * (lstrlenW(sjp) + 1), scn, 2 * (lstrlenW(scn) + 1)); + } + p++; + } + DeleteFile(L"Data.ax"); + DeleteFile(L"Index.ax"); + + rename("~Data.ax", "Data.ax"); + rename("~Index.ax", "Index.ax"); + return; + } +} + +BOOL CreateDataByIDEx(LPCWSTR name, LPCWSTR name2, int ID, LPCWSTR jpBuff, int ljp, LPCWSTR cnBuffer, int lcn) +{ + MicroData _Index(name, sizeof(IndexData)); + MicroBinary _Data(name2); + + _Index.Load(); + _Data.Load(); + + IndexData createData; + createData.Id = ID; + createData.JpLength = ljp; + createData.CnLength = lcn; + + createData.JpBass = Data.Size(); + _Data.Push(jpBuff, ljp); + createData.CnBass = Data.Size(); + _Data.Push(cnBuffer, lcn); + + _Index.Push(&createData); + _Index.Save(); + _Data.Save(); + return 0; +} + +BOOL CreateDataByID(int ID, LPCWSTR jpBuff, int ljp, LPCWSTR cnBuffer, int lcn) +{ + IndexData createData; + createData.Id = ID; + createData.JpLength = ljp; + createData.CnLength = lcn; + + createData.JpBass = Data.Size(); + Data.Push(jpBuff, ljp); + createData.CnBass = Data.Size(); + Data.Push(cnBuffer, lcn); + + Index.Push(&createData); + Index.Save(); + Data.Save(); + return 0; +} + +BOOL GetDataByJP(int* ID, LPCWSTR jpBuff, LPWSTR cnBuffer) +{ + IndexData index; + + WCHAR njp[3096]; + WCHAR ncn[3096]; + Index = 0; + do { + Index.Get(&index); + + Data = index.JpBass; + Data.Sub(njp, index.JpLength); + Data = index.CnBass; + Data.Sub(ncn, index.CnLength); + + if (lstrcmpW(jpBuff, njp) == 0) { + *ID = index.Id; + lstrcpyW(cnBuffer, ncn); + Index = 0; + Data = 0; + return 1; + } + + if (Index++) + continue; + else { + Data = 0; + Index = 0; + return 0; + } + } while (1); +} + +BOOL GetDataByID(int ID, LPWSTR jpBuff, LPWSTR cnBuffer) +{ + IndexData index; + Index = ID; + Index.Get(&index); + if (index.Id != ID) + { + Index = 0; + do { + Index.Get(&index); + if (index.Id == ID) + break; + if (Index++) + continue; + else { + Index = 0; + return 0; + } + } while (1); + } + + Data = index.JpBass; + Data.Sub(jpBuff, index.JpLength); + Data = index.CnBass; + Data.Sub(cnBuffer, index.CnLength); + Data = 0; + Index = 0; + return 1; +} + +int GEtLargestID() +{ + IndexData index; + int result = 0; + do { + Index.Get(&index); + if (index.Id > result) + result = index.Id; + } while (Index++); + + Index = 0; + return result; +} diff --git a/cs2_patch/Data.h b/cs2_patch/Data.h new file mode 100644 index 0000000..4f08c4b --- /dev/null +++ b/cs2_patch/Data.h @@ -0,0 +1,12 @@ +#pragma once +#include +#define DLLAPI __declspec(dllexport) + + + +BOOL CreateDataByIDEx(LPCWSTR name, LPCWSTR name2, int ID, LPCWSTR jpBuff, int ljp, LPCWSTR cnBuffer, int lcn); +extern "C" DLLAPI void CreateDataExport(WCHAR data[]); +BOOL CreateDataByID(int ID, LPCWSTR jpBuff, int ljp, LPCWSTR cnBuffer, int lcn); +BOOL GetDataByJP(int* ID, LPCWSTR jpBuff, LPWSTR cnBuffer); +BOOL GetDataByID(int ID, LPWSTR jpBuff, LPWSTR cnBuffer); +int GEtLargestID(); \ No newline at end of file diff --git a/cs2_patch/Debug/BuildIn.obj b/cs2_patch/Debug/BuildIn.obj new file mode 100644 index 0000000..75dd5f3 Binary files /dev/null and b/cs2_patch/Debug/BuildIn.obj differ diff --git a/cs2_patch/Debug/Data.obj b/cs2_patch/Debug/Data.obj new file mode 100644 index 0000000..23a415b Binary files /dev/null and b/cs2_patch/Debug/Data.obj differ diff --git a/cs2_patch/Debug/Replace.obj b/cs2_patch/Debug/Replace.obj new file mode 100644 index 0000000..ba3b73d Binary files /dev/null and b/cs2_patch/Debug/Replace.obj differ diff --git a/cs2_patch/Debug/cs2_patch.log b/cs2_patch/Debug/cs2_patch.log new file mode 100644 index 0000000..3e33a86 --- /dev/null +++ b/cs2_patch/Debug/cs2_patch.log @@ -0,0 +1,3 @@ + Replace.cpp +D:\VSProject\cs2\cs2_united\cs2_patch\Replace.cpp(56,23): warning C4018: “<”: 有符号/无符号不匹配 + cs2_patch.vcxproj -> D:\VSProject\cs2\cs2_united\Debug\cs2_patch.dll diff --git a/cs2_patch/Debug/cs2_patch.pch b/cs2_patch/Debug/cs2_patch.pch new file mode 100644 index 0000000..8b50f52 Binary files /dev/null and b/cs2_patch/Debug/cs2_patch.pch differ diff --git a/cs2_patch/Debug/cs2_patch.tlog/CL.command.1.tlog b/cs2_patch/Debug/cs2_patch.tlog/CL.command.1.tlog new file mode 100644 index 0000000..22911e3 Binary files /dev/null and b/cs2_patch/Debug/cs2_patch.tlog/CL.command.1.tlog differ diff --git a/cs2_patch/Debug/cs2_patch.tlog/CL.read.1.tlog b/cs2_patch/Debug/cs2_patch.tlog/CL.read.1.tlog new file mode 100644 index 0000000..fb1374e Binary files /dev/null and b/cs2_patch/Debug/cs2_patch.tlog/CL.read.1.tlog differ diff --git a/cs2_patch/Debug/cs2_patch.tlog/CL.write.1.tlog b/cs2_patch/Debug/cs2_patch.tlog/CL.write.1.tlog new file mode 100644 index 0000000..95fec7c Binary files /dev/null and b/cs2_patch/Debug/cs2_patch.tlog/CL.write.1.tlog differ diff --git a/cs2_patch/Debug/cs2_patch.tlog/cs2_patch.lastbuildstate b/cs2_patch/Debug/cs2_patch.tlog/cs2_patch.lastbuildstate new file mode 100644 index 0000000..1d6b564 --- /dev/null +++ b/cs2_patch/Debug/cs2_patch.tlog/cs2_patch.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v142:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0 +Debug|Win32|D:\VSProject\cs2\cs2_united\| diff --git a/cs2_patch/Debug/cs2_patch.tlog/cs2_patch.write.1u.tlog b/cs2_patch/Debug/cs2_patch.tlog/cs2_patch.write.1u.tlog new file mode 100644 index 0000000..d41f47a Binary files /dev/null and b/cs2_patch/Debug/cs2_patch.tlog/cs2_patch.write.1u.tlog differ diff --git a/cs2_patch/Debug/cs2_patch.tlog/link.command.1.tlog b/cs2_patch/Debug/cs2_patch.tlog/link.command.1.tlog new file mode 100644 index 0000000..ac1fe94 Binary files /dev/null and b/cs2_patch/Debug/cs2_patch.tlog/link.command.1.tlog differ diff --git a/cs2_patch/Debug/cs2_patch.tlog/link.delete.1.tlog b/cs2_patch/Debug/cs2_patch.tlog/link.delete.1.tlog new file mode 100644 index 0000000..f6b4c6a Binary files /dev/null and b/cs2_patch/Debug/cs2_patch.tlog/link.delete.1.tlog differ diff --git a/cs2_patch/Debug/cs2_patch.tlog/link.read.1.tlog b/cs2_patch/Debug/cs2_patch.tlog/link.read.1.tlog new file mode 100644 index 0000000..d8ce305 Binary files /dev/null and b/cs2_patch/Debug/cs2_patch.tlog/link.read.1.tlog differ diff --git a/cs2_patch/Debug/cs2_patch.tlog/link.write.1.tlog b/cs2_patch/Debug/cs2_patch.tlog/link.write.1.tlog new file mode 100644 index 0000000..c4f6920 Binary files /dev/null and b/cs2_patch/Debug/cs2_patch.tlog/link.write.1.tlog differ diff --git a/cs2_patch/Debug/dllmain.obj b/cs2_patch/Debug/dllmain.obj new file mode 100644 index 0000000..15792fa Binary files /dev/null and b/cs2_patch/Debug/dllmain.obj differ diff --git a/cs2_patch/Debug/pch.obj b/cs2_patch/Debug/pch.obj new file mode 100644 index 0000000..279c7be Binary files /dev/null and b/cs2_patch/Debug/pch.obj differ diff --git a/cs2_patch/Debug/vc142.idb b/cs2_patch/Debug/vc142.idb new file mode 100644 index 0000000..74780d0 Binary files /dev/null and b/cs2_patch/Debug/vc142.idb differ diff --git a/cs2_patch/Debug/vc142.pdb b/cs2_patch/Debug/vc142.pdb new file mode 100644 index 0000000..c431faa Binary files /dev/null and b/cs2_patch/Debug/vc142.pdb differ diff --git a/cs2_patch/MicroFile.dll b/cs2_patch/MicroFile.dll new file mode 100644 index 0000000..636556b Binary files /dev/null and b/cs2_patch/MicroFile.dll differ diff --git a/cs2_patch/MicroFile.h b/cs2_patch/MicroFile.h new file mode 100644 index 0000000..5a8e79a --- /dev/null +++ b/cs2_patch/MicroFile.h @@ -0,0 +1,157 @@ +#pragma once +#include + +#include +using namespace std; + +#define DLLAPI __declspec(dllexport) + +#ifndef ALGORITHM_EXPORTS +#define ALGORITHM_CLASS __declspec(dllimport) +#define ALGORITHM_TEMPLATE +#else //EXPORT +#define ALGORITHM_CLASS __declspec(dllexport) +#define ALGORITHM_TEMPLATE __declspec(dllexport) +#endif + + +#define ENCODE_BYTE 1 +#define ENCODE_WORD 2 +#define ENCODE_DWORD 4 + + class DLLAPI MicroFile +{ +public: + //ļļܲ4Gļ + MicroFile(LPCWSTR filename); + //رļڴ + ~MicroFile(); + //ļװڴ + virtual BOOL Load(); + //ļ + void Clear(); + //޸ + virtual BOOL Save(); + //ȡļС + DWORD Size(); + ///һļĩβ + void Push(LPCVOID sour, ULONG size); + ///һݴļĩβ + void Pop(LPVOID sour, ULONG size); + //ӵǰȡλýȡ + void Sub(LPVOID tart,int size); + + //ļ + BOOL Gate(LPVOID tart); + + virtual BOOL Get(LPBYTE tart) = 0; + virtual BOOL Set(BYTE sour) = 0; + + MicroFile& operator=(int sour); + + BYTE &operator*(); + BOOL operator++(int); + BOOL operator--(int); + BOOL operator-=(DWORD count); + BOOL operator+=(DWORD count); + + + +protected: + HANDLE m_file = NULL; + BYTE* fileData = NULL; + DWORD size; + wstring* name = new wstring; + BYTE* nPoint = NULL; +}; + +class DLLAPI MicroBinary :public MicroFile +{ +public: + MicroBinary(LPCWSTR filename); + ~MicroBinary(); + + + BOOL Get(LPWORD tart); + BOOL Get(LPDWORD tart); + BOOL Get(LPBYTE tart); + BOOL Set(BYTE sour); + BOOL Set(WORD sour); + BOOL Set(DWORD sour); + + MicroBinary& operator=(int sour); +private: + +}; + + +class DLLAPI MicroText:public MicroFile +{ +public: + MicroText(LPCWSTR filename,UINT code); + ~MicroText(); + + + BOOL Get(LPWSTR tart); + BOOL Get(LPSTR tart); + + BOOL Get(LPBYTE tart); + BOOL Set(BYTE sour); + + BOOL Set(LPCWSTR tart); + BOOL Set(LPCSTR tart); + + BOOL Save(); + BOOL Load(); + //MicroText& operator=(int sour); + void Push(LPCWSTR sour); + void Push(LPCSTR sour); + + + void Pop(LPWSTR tart,int snbize); + void Pop(LPSTR tart, int snbize); + void Clear(); + + DWORD Size(); + + MicroText& operator=(int sour); + + char& operator*(); + WCHAR& operator&(); + + BOOL operator++(int); + BOOL operator--(int); + + //void Sub(LPBYTE tart, int size); +private: + int m_code; + wstring* wData = new wstring; + string* Data = new string; +}; + + +class DLLAPI MicroData :public MicroFile +{ +public: + MicroData(LPCWSTR filename, DWORD nsize); + ~MicroData(); + + + void operator=(int sour); + + BOOL operator++(int); + BOOL operator--(int); + BOOL operator-=(DWORD count); + BOOL operator+=(DWORD count); + void Push(LPCVOID sour); + ///һݴļĩβ + void Pop(LPVOID tart); + DWORD Size(); + BOOL Get(LPBYTE tart); + BOOL Set(BYTE sour); + + BOOL Get(LPVOID tart); + BOOL Set(LPCVOID sour); +private: + int structure; +}; diff --git a/cs2_patch/MicroFile.lib b/cs2_patch/MicroFile.lib new file mode 100644 index 0000000..92173b3 Binary files /dev/null and b/cs2_patch/MicroFile.lib differ diff --git a/cs2_patch/Replace.cpp b/cs2_patch/Replace.cpp new file mode 100644 index 0000000..7c071a7 --- /dev/null +++ b/cs2_patch/Replace.cpp @@ -0,0 +1,175 @@ +#include "pch.h" +#include "Replace.h" + +int npID = 0; +extern HMODULE hModL; +extern "C" extern DLLAPI wchar_t ms_str[3096]; +extern "C" extern DLLAPI int nID; + +void BuildCV(TESTDATA* pcv, TESTDATA flt, DWORD posinCross, DWORD posInLine, DWORD m_count, WCHAR nchar) +{ + pcv->ForCast = flt.ForCast; + pcv->nLine = posinCross; + pcv->nChar = nchar; + pcv->nCross = posInLine; + pcv->Flag1 = flt.Flag1; + pcv->Flag2 = flt.Flag2; + pcv->Flag3 = flt.Flag3; + pcv->Flag4 = flt.Flag4; + pcv->Flagn4 = flt.Flagn4; + pcv->Flag5 = flt.Flag5; + pcv->Flag6 = flt.Flag6; + pcv->count = m_count; + pcv->Flag7 = posInLine; + pcv->Flag8 = flt.Flag8; + pcv->Flagn8 = flt.Flagn8; + + pcv->FlagnW = flt.FlagnW; + pcv->FlagnQ = flt.FlagnQ; + pcv->nWQ = flt.nWQ; + pcv->ntime = flt.ntime; + pcv->ntime2 = flt.ntime2; + + pcv->Over1 = flt.Over1; + pcv->Over2 = flt.Over2; + + return; +} + +void ApplyStringToCV(LPCWSTR ws, DWORD pDf, int id) +{ + + + wstring localString = ws; + if (!pDf)return; + if (!ws)return; + DWORD Df = *(DWORD*)pDf;//Df ݵָ + if (!Df)return;//Ϊֹ + TESTDATA* nCView = (TESTDATA*)Df;//ʹһTESTDATA*ָDf + DWORD pOld; + VirtualProtect(nCView, 10 + (localString.length() * 2), PAGE_READWRITE, &pOld); + TESTDATA loadFirst = *nCView;//һ + int posInLine = 0;//λ + int posinCross = 0xD;//λ + + // SetWindowTextW(m_hWnd, L"ѭ"); + for (int i = 0; i < localString.length(); i++) + { + if (localString[i] == L'\n') + { + BuildCV(nCView, loadFirst, posinCross, posInLine, i * 2, 0); + nCView++; + BuildCV(nCView, loadFirst, posinCross, posInLine, i * 2, 0XFFFF); + nCView++; + posinCross += 0x28; + posInLine = 0; + } + else + { + BuildCV(nCView, loadFirst, posinCross, posInLine, i * 2, localString[i]); + nCView++; + posInLine += 0X1A; + } + } + // SetWindowTextW(m_hWnd, L"ѭ"); + *(DWORD*)(pDf + 4) = (DWORD)nCView; + + VirtualProtect(nCView, 10 + (localString.length() * 2), pOld, NULL); +} + +DLLAPI int TranSplete(DWORD lp) +{ + if (!lp)return -1; + DWORD ppDf = *(DWORD*)(lp + 0x2B0); + if (!ppDf)return -1; + DWORD pDf = *(DWORD*)(ppDf + 8); + if (!pDf)return -1; + DWORD Df = *(DWORD*)pDf; + if (!Df)return -1; + DWORD pEnd = *(DWORD*)(pDf + 4); + if (!pEnd)return -1; + + WCHAR sjp[1024]; + WCHAR scn[1024]; + + DWORD Num = (pEnd - Df) / 96; + + wstring nStr; + TESTDATA* nCView = (TESTDATA*)Df; + + for (DWORD i = 0; i < Num; i++) { + if (nCView->nChar == 0xFFFF) { + + } + else if (nCView->nChar == 0) { + nStr += L'\n'; + } + else { + nStr += nCView->nChar; + } + + nCView++; + } + npID++; + // MessageBoxW(0,L"0",L"",0); + WCHAR csjp[1024]; + WCHAR cscn[1024]; + int ppId = 0; + if (!GetDataByID(nID - 1, csjp, cscn)) { + if (nID != 0) + if (!GetDataByJP(&ppId, nStr.c_str(), cscn)) + return -1; + } + + // MessageBoxW(0, L"1", L"", 0); + if (lstrcmpW(nStr.c_str(), cscn) == 0) { + + // MessageBoxW(0, nStr.c_str(), L"", 0); + return -1; + } + + // MessageBoxW(0, L"2", L"", 0); + if (wcsstr(nStr.c_str(), L"")) { + + return -1; + } + if (wcsstr(nStr.c_str(), L"")) + return -1; + + if (wcsstr(nStr.c_str(), L"դդդ")) + return -1; + + // MessageBoxW(0, L"3", L"", 0); + + lstrcpyW(ms_str, nStr.c_str()); + + // MessageBoxW(0, L"4", L"", 0); + + if (!GetDataByID(nID, sjp, scn)) { + int pID = 0; + if (GetDataByJP(&pID, nStr.c_str(), scn)) { + nID = pID + 1; + ApplyStringToCV(scn, pDf, pID); + return 0; + } + } + else + { + if (lstrcmpW(sjp, nStr.c_str()) == 0) { + ApplyStringToCV(scn, pDf, nID); + } + else + { + int pID = 0; + if (GetDataByJP(&pID, nStr.c_str(), scn)) { + nID = pID + 1; + ApplyStringToCV(scn, pDf, pID); + return 0; + } + else + nID = pID; + } + } + nID++; + return 0; +} diff --git a/cs2_patch/Replace.h b/cs2_patch/Replace.h new file mode 100644 index 0000000..09c3007 --- /dev/null +++ b/cs2_patch/Replace.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include "Data.h" +#define DLLAPI __declspec(dllexport) + +typedef unsigned long long QWORD; +struct TESTDATA { + DWORD ForCast;//; + wchar_t nChar; + + WORD Flag1;//;ΪBAAD + DWORD Flag2;//FFC8C8C8 + DWORD Flag3;//FF352519 + + DWORD nCross; + DWORD nLine; + + DWORD Flag4; //0000001A + DWORD Flagn4;//0000001A + QWORD Flag5; //0 + + DWORD Flag6; //FFFFFFFF + DWORD count; //mayba it shows the position of string + + DWORD Flag7; + + DWORD Flag8; //0000000100000001 + DWORD Flagn8; + + DWORD FlagnW;//1 + QWORD FlagnQ;//0 + DWORD ntime;//1E + DWORD ntime2;//1E + DWORD nWQ;//0 + + DWORD Over1; + QWORD Over2; +}; + +void BuildCV(TESTDATA* pcv, TESTDATA flt, DWORD posinCross, DWORD posInLine, DWORD m_count, WCHAR nchar); +void ApplyStringToCV(LPCWSTR ws, DWORD pDf, int id); +extern "C" DLLAPI int TranSplete(DWORD lp); diff --git a/cs2_patch/cs2_patch.vcxproj b/cs2_patch/cs2_patch.vcxproj new file mode 100644 index 0000000..ed91023 --- /dev/null +++ b/cs2_patch/cs2_patch.vcxproj @@ -0,0 +1,181 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {DB403E75-A69B-4B8E-AD02-9CF48E7C93A7} + Win32Proj + cs2patch + 10.0 + + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + true + WIN32;_DEBUG;CS2PATCH_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + false + + + 1073741824 + + + + + Use + Level3 + true + _DEBUG;CS2PATCH_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + false + + + + + Use + Level3 + true + true + true + WIN32;NDEBUG;CS2PATCH_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + true + false + + + + + Use + Level3 + true + true + true + NDEBUG;CS2PATCH_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + true + false + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + \ No newline at end of file diff --git a/cs2_patch/cs2_patch.vcxproj.filters b/cs2_patch/cs2_patch.vcxproj.filters new file mode 100644 index 0000000..a37be32 --- /dev/null +++ b/cs2_patch/cs2_patch.vcxproj.filters @@ -0,0 +1,54 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + + + + \ No newline at end of file diff --git a/cs2_patch/cs2_patch.vcxproj.user b/cs2_patch/cs2_patch.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/cs2_patch/cs2_patch.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/cs2_patch/detours.lib b/cs2_patch/detours.lib new file mode 100644 index 0000000..5d674fb Binary files /dev/null and b/cs2_patch/detours.lib differ diff --git a/cs2_patch/detours.pdb b/cs2_patch/detours.pdb new file mode 100644 index 0000000..c874eea Binary files /dev/null and b/cs2_patch/detours.pdb differ diff --git a/cs2_patch/dllmain.cpp b/cs2_patch/dllmain.cpp new file mode 100644 index 0000000..cdb2bb0 --- /dev/null +++ b/cs2_patch/dllmain.cpp @@ -0,0 +1,40 @@ +// dllmain.cpp : 定义 DLL 应用程序的入口点。 +#include "pch.h" +#include "Data.h" +#include "BuildIn.h" + +#pragma data_seg("PublicData") // 声明共享数据段,并命名该数据段 + +HMODULE hMod = NULL; +extern "C" DLLAPI wchar_t ms_str[3096] = { 0 }; +extern "C" DLLAPI int nID = 0; + +#pragma data_seg() +#pragma comment(linker, "/section:PublicData,rws") + + +extern HMODULE SelfHandle ; +extern bool start_falg ; + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + SelfHandle = hModule; + break; + case DLL_THREAD_ATTACH: + break; + case DLL_THREAD_DETACH: + break; + case DLL_PROCESS_DETACH: + if (start_falg) + end(); + break; + } + return TRUE; +} + diff --git a/cs2_patch/framework.h b/cs2_patch/framework.h new file mode 100644 index 0000000..3561e91 --- /dev/null +++ b/cs2_patch/framework.h @@ -0,0 +1,34 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include + +#include "MicroFile.h" +#pragma comment(lib,"MicroFile.lib") + +#include "include/detours.h" +#pragma comment (lib,"detours.lib") + +#include +#include +using namespace std; + +#define DLLAPI __declspec(dllexport) + +struct IndexData { + int Id; + DWORD JpBass; + DWORD JpLength; + DWORD CnBass; + DWORD CnLength; +}; + + + +char IpfData[16]; +#define PutInt(a) _itoa_s(a,IpfData,10);MessageBoxA(0,IpfData,"num",0); + + + + diff --git a/cs2_patch/include/.DS_Store b/cs2_patch/include/.DS_Store new file mode 100644 index 0000000..3a6a985 Binary files /dev/null and b/cs2_patch/include/.DS_Store differ diff --git a/cs2_patch/include/detours.h b/cs2_patch/include/detours.h new file mode 100644 index 0000000..068b57c --- /dev/null +++ b/cs2_patch/include/detours.h @@ -0,0 +1,1078 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Core Detours Functionality (detours.h of detours.lib) +// +// Microsoft Research Detours Package, Version 4.0.1 +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// + +#pragma once +#ifndef _DETOURS_H_ +#define _DETOURS_H_ + +#define DETOURS_VERSION 0x4c0c1 // 0xMAJORcMINORcPATCH + +////////////////////////////////////////////////////////////////////////////// +// + +#undef DETOURS_X64 +#undef DETOURS_X86 +#undef DETOURS_IA64 +#undef DETOURS_ARM +#undef DETOURS_ARM64 +#undef DETOURS_BITS +#undef DETOURS_32BIT +#undef DETOURS_64BIT + +#if defined(_X86_) +#define DETOURS_X86 +#define DETOURS_OPTION_BITS 64 + +#elif defined(_AMD64_) +#define DETOURS_X64 +#define DETOURS_OPTION_BITS 32 + +#elif defined(_IA64_) +#define DETOURS_IA64 +#define DETOURS_OPTION_BITS 32 + +#elif defined(_ARM_) +#define DETOURS_ARM + +#elif defined(_ARM64_) +#define DETOURS_ARM64 + +#else +#error Unknown architecture (x86, amd64, ia64, arm, arm64) +#endif + +#ifdef _WIN64 +#undef DETOURS_32BIT +#define DETOURS_64BIT 1 +#define DETOURS_BITS 64 +// If all 64bit kernels can run one and only one 32bit architecture. +//#define DETOURS_OPTION_BITS 32 +#else +#define DETOURS_32BIT 1 +#undef DETOURS_64BIT +#define DETOURS_BITS 32 +// If all 64bit kernels can run one and only one 32bit architecture. +//#define DETOURS_OPTION_BITS 32 +#endif + +#define VER_DETOURS_BITS DETOUR_STRINGIFY(DETOURS_BITS) + +////////////////////////////////////////////////////////////////////////////// +// + +#if (_MSC_VER < 1299) +typedef LONG LONG_PTR; +typedef ULONG ULONG_PTR; +#endif + +///////////////////////////////////////////////// SAL 2.0 Annotations w/o SAL. +// +// These definitions are include so that Detours will build even if the +// compiler doesn't have full SAL 2.0 support. +// +#ifndef DETOURS_DONT_REMOVE_SAL_20 + +#ifdef DETOURS_TEST_REMOVE_SAL_20 +#undef _Analysis_assume_ +#undef _Benign_race_begin_ +#undef _Benign_race_end_ +#undef _Field_range_ +#undef _Field_size_ +#undef _In_ +#undef _In_bytecount_ +#undef _In_count_ +#undef _In_opt_ +#undef _In_opt_bytecount_ +#undef _In_opt_count_ +#undef _In_opt_z_ +#undef _In_range_ +#undef _In_reads_ +#undef _In_reads_bytes_ +#undef _In_reads_opt_ +#undef _In_reads_opt_bytes_ +#undef _In_reads_or_z_ +#undef _In_z_ +#undef _Inout_ +#undef _Inout_opt_ +#undef _Inout_z_count_ +#undef _Out_ +#undef _Out_opt_ +#undef _Out_writes_ +#undef _Outptr_result_maybenull_ +#undef _Readable_bytes_ +#undef _Success_ +#undef _Writable_bytes_ +#undef _Pre_notnull_ +#endif + +#if defined(_Deref_out_opt_z_) && !defined(_Outptr_result_maybenull_) +#define _Outptr_result_maybenull_ _Deref_out_opt_z_ +#endif + +#if defined(_In_count_) && !defined(_In_reads_) +#define _In_reads_(x) _In_count_(x) +#endif + +#if defined(_In_opt_count_) && !defined(_In_reads_opt_) +#define _In_reads_opt_(x) _In_opt_count_(x) +#endif + +#if defined(_In_opt_bytecount_) && !defined(_In_reads_opt_bytes_) +#define _In_reads_opt_bytes_(x) _In_opt_bytecount_(x) +#endif + +#if defined(_In_bytecount_) && !defined(_In_reads_bytes_) +#define _In_reads_bytes_(x) _In_bytecount_(x) +#endif + +#ifndef _In_ +#define _In_ +#endif + +#ifndef _In_bytecount_ +#define _In_bytecount_(x) +#endif + +#ifndef _In_count_ +#define _In_count_(x) +#endif + +#ifndef _In_opt_ +#define _In_opt_ +#endif + +#ifndef _In_opt_bytecount_ +#define _In_opt_bytecount_(x) +#endif + +#ifndef _In_opt_count_ +#define _In_opt_count_(x) +#endif + +#ifndef _In_opt_z_ +#define _In_opt_z_ +#endif + +#ifndef _In_range_ +#define _In_range_(x,y) +#endif + +#ifndef _In_reads_ +#define _In_reads_(x) +#endif + +#ifndef _In_reads_bytes_ +#define _In_reads_bytes_(x) +#endif + +#ifndef _In_reads_opt_ +#define _In_reads_opt_(x) +#endif + +#ifndef _In_reads_opt_bytes_ +#define _In_reads_opt_bytes_(x) +#endif + +#ifndef _In_reads_or_z_ +#define _In_reads_or_z_ +#endif + +#ifndef _In_z_ +#define _In_z_ +#endif + +#ifndef _Inout_ +#define _Inout_ +#endif + +#ifndef _Inout_opt_ +#define _Inout_opt_ +#endif + +#ifndef _Inout_z_count_ +#define _Inout_z_count_(x) +#endif + +#ifndef _Out_ +#define _Out_ +#endif + +#ifndef _Out_opt_ +#define _Out_opt_ +#endif + +#ifndef _Out_writes_ +#define _Out_writes_(x) +#endif + +#ifndef _Outptr_result_maybenull_ +#define _Outptr_result_maybenull_ +#endif + +#ifndef _Writable_bytes_ +#define _Writable_bytes_(x) +#endif + +#ifndef _Readable_bytes_ +#define _Readable_bytes_(x) +#endif + +#ifndef _Success_ +#define _Success_(x) +#endif + +#ifndef _Pre_notnull_ +#define _Pre_notnull_ +#endif + +#ifdef DETOURS_INTERNAL + +#pragma warning(disable:4615) // unknown warning type (suppress with older compilers) + +#ifndef _Benign_race_begin_ +#define _Benign_race_begin_ +#endif + +#ifndef _Benign_race_end_ +#define _Benign_race_end_ +#endif + +#ifndef _Field_size_ +#define _Field_size_(x) +#endif + +#ifndef _Field_range_ +#define _Field_range_(x,y) +#endif + +#ifndef _Analysis_assume_ +#define _Analysis_assume_(x) +#endif + +#endif // DETOURS_INTERNAL +#endif // DETOURS_DONT_REMOVE_SAL_20 + +////////////////////////////////////////////////////////////////////////////// +// +#ifndef GUID_DEFINED +#define GUID_DEFINED +typedef struct _GUID +{ + DWORD Data1; + WORD Data2; + WORD Data3; + BYTE Data4[ 8 ]; +} GUID; + +#ifdef INITGUID +#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + const GUID name \ + = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } +#else +#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + const GUID name +#endif // INITGUID +#endif // !GUID_DEFINED + +#if defined(__cplusplus) +#ifndef _REFGUID_DEFINED +#define _REFGUID_DEFINED +#define REFGUID const GUID & +#endif // !_REFGUID_DEFINED +#else // !__cplusplus +#ifndef _REFGUID_DEFINED +#define _REFGUID_DEFINED +#define REFGUID const GUID * const +#endif // !_REFGUID_DEFINED +#endif // !__cplusplus + +#ifndef ARRAYSIZE +#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) +#endif + +// +////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/////////////////////////////////////////////////// Instruction Target Macros. +// +#define DETOUR_INSTRUCTION_TARGET_NONE ((PVOID)0) +#define DETOUR_INSTRUCTION_TARGET_DYNAMIC ((PVOID)(LONG_PTR)-1) +#define DETOUR_SECTION_HEADER_SIGNATURE 0x00727444 // "Dtr\0" + +extern const GUID DETOUR_EXE_RESTORE_GUID; +extern const GUID DETOUR_EXE_HELPER_GUID; + +#define DETOUR_TRAMPOLINE_SIGNATURE 0x21727444 // Dtr! +typedef struct _DETOUR_TRAMPOLINE DETOUR_TRAMPOLINE, *PDETOUR_TRAMPOLINE; + +/////////////////////////////////////////////////////////// Binary Structures. +// +#pragma pack(push, 8) +typedef struct _DETOUR_SECTION_HEADER +{ + DWORD cbHeaderSize; + DWORD nSignature; + DWORD nDataOffset; + DWORD cbDataSize; + + DWORD nOriginalImportVirtualAddress; + DWORD nOriginalImportSize; + DWORD nOriginalBoundImportVirtualAddress; + DWORD nOriginalBoundImportSize; + + DWORD nOriginalIatVirtualAddress; + DWORD nOriginalIatSize; + DWORD nOriginalSizeOfImage; + DWORD cbPrePE; + + DWORD nOriginalClrFlags; + DWORD reserved1; + DWORD reserved2; + DWORD reserved3; + + // Followed by cbPrePE bytes of data. +} DETOUR_SECTION_HEADER, *PDETOUR_SECTION_HEADER; + +typedef struct _DETOUR_SECTION_RECORD +{ + DWORD cbBytes; + DWORD nReserved; + GUID guid; +} DETOUR_SECTION_RECORD, *PDETOUR_SECTION_RECORD; + +typedef struct _DETOUR_CLR_HEADER +{ + // Header versioning + ULONG cb; + USHORT MajorRuntimeVersion; + USHORT MinorRuntimeVersion; + + // Symbol table and startup information + IMAGE_DATA_DIRECTORY MetaData; + ULONG Flags; + + // Followed by the rest of the IMAGE_COR20_HEADER +} DETOUR_CLR_HEADER, *PDETOUR_CLR_HEADER; + +typedef struct _DETOUR_EXE_RESTORE +{ + DWORD cb; + DWORD cbidh; + DWORD cbinh; + DWORD cbclr; + + PBYTE pidh; + PBYTE pinh; + PBYTE pclr; + + IMAGE_DOS_HEADER idh; + union { + IMAGE_NT_HEADERS inh; // all environments have this +#ifdef IMAGE_NT_OPTIONAL_HDR32_MAGIC // some environments do not have this + IMAGE_NT_HEADERS32 inh32; +#endif +#ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC // some environments do not have this + IMAGE_NT_HEADERS64 inh64; +#endif +#ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC // some environments do not have this + BYTE raw[sizeof(IMAGE_NT_HEADERS64) + + sizeof(IMAGE_SECTION_HEADER) * 32]; +#else + BYTE raw[0x108 + sizeof(IMAGE_SECTION_HEADER) * 32]; +#endif + }; + DETOUR_CLR_HEADER clr; + +} DETOUR_EXE_RESTORE, *PDETOUR_EXE_RESTORE; + +#ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC +C_ASSERT(sizeof(IMAGE_NT_HEADERS64) == 0x108); +#endif + +// The size can change, but assert for clarity due to the muddying #ifdefs. +#ifdef _WIN64 +C_ASSERT(sizeof(DETOUR_EXE_RESTORE) == 0x688); +#else +C_ASSERT(sizeof(DETOUR_EXE_RESTORE) == 0x678); +#endif + +typedef struct _DETOUR_EXE_HELPER +{ + DWORD cb; + DWORD pid; + DWORD nDlls; + CHAR rDlls[4]; +} DETOUR_EXE_HELPER, *PDETOUR_EXE_HELPER; + +#pragma pack(pop) + +#define DETOUR_SECTION_HEADER_DECLARE(cbSectionSize) \ +{ \ + sizeof(DETOUR_SECTION_HEADER),\ + DETOUR_SECTION_HEADER_SIGNATURE,\ + sizeof(DETOUR_SECTION_HEADER),\ + (cbSectionSize),\ + \ + 0,\ + 0,\ + 0,\ + 0,\ + \ + 0,\ + 0,\ + 0,\ + 0,\ +} + +/////////////////////////////////////////////////////////////// Helper Macros. +// +#define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x) +#define DETOURS_STRINGIFY_(x) #x + +///////////////////////////////////////////////////////////// Binary Typedefs. +// +typedef BOOL (CALLBACK *PF_DETOUR_BINARY_BYWAY_CALLBACK)( + _In_opt_ PVOID pContext, + _In_opt_ LPCSTR pszFile, + _Outptr_result_maybenull_ LPCSTR *ppszOutFile); + +typedef BOOL (CALLBACK *PF_DETOUR_BINARY_FILE_CALLBACK)( + _In_opt_ PVOID pContext, + _In_ LPCSTR pszOrigFile, + _In_ LPCSTR pszFile, + _Outptr_result_maybenull_ LPCSTR *ppszOutFile); + +typedef BOOL (CALLBACK *PF_DETOUR_BINARY_SYMBOL_CALLBACK)( + _In_opt_ PVOID pContext, + _In_ ULONG nOrigOrdinal, + _In_ ULONG nOrdinal, + _Out_ ULONG *pnOutOrdinal, + _In_opt_ LPCSTR pszOrigSymbol, + _In_opt_ LPCSTR pszSymbol, + _Outptr_result_maybenull_ LPCSTR *ppszOutSymbol); + +typedef BOOL (CALLBACK *PF_DETOUR_BINARY_COMMIT_CALLBACK)( + _In_opt_ PVOID pContext); + +typedef BOOL (CALLBACK *PF_DETOUR_ENUMERATE_EXPORT_CALLBACK)(_In_opt_ PVOID pContext, + _In_ ULONG nOrdinal, + _In_opt_ LPCSTR pszName, + _In_opt_ PVOID pCode); + +typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FILE_CALLBACK)(_In_opt_ PVOID pContext, + _In_opt_ HMODULE hModule, + _In_opt_ LPCSTR pszFile); + +typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK)(_In_opt_ PVOID pContext, + _In_ DWORD nOrdinal, + _In_opt_ LPCSTR pszFunc, + _In_opt_ PVOID pvFunc); + +// Same as PF_DETOUR_IMPORT_FUNC_CALLBACK but extra indirection on last parameter. +typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK_EX)(_In_opt_ PVOID pContext, + _In_ DWORD nOrdinal, + _In_opt_ LPCSTR pszFunc, + _In_opt_ PVOID* ppvFunc); + +typedef VOID * PDETOUR_BINARY; +typedef VOID * PDETOUR_LOADED_BINARY; + +//////////////////////////////////////////////////////////// Transaction APIs. +// +LONG WINAPI DetourTransactionBegin(VOID); +LONG WINAPI DetourTransactionAbort(VOID); +LONG WINAPI DetourTransactionCommit(VOID); +LONG WINAPI DetourTransactionCommitEx(_Out_opt_ PVOID **pppFailedPointer); + +LONG WINAPI DetourUpdateThread(_In_ HANDLE hThread); + +LONG WINAPI DetourAttach(_Inout_ PVOID *ppPointer, + _In_ PVOID pDetour); + +LONG WINAPI DetourAttachEx(_Inout_ PVOID *ppPointer, + _In_ PVOID pDetour, + _Out_opt_ PDETOUR_TRAMPOLINE *ppRealTrampoline, + _Out_opt_ PVOID *ppRealTarget, + _Out_opt_ PVOID *ppRealDetour); + +LONG WINAPI DetourDetach(_Inout_ PVOID *ppPointer, + _In_ PVOID pDetour); + +BOOL WINAPI DetourSetIgnoreTooSmall(_In_ BOOL fIgnore); +BOOL WINAPI DetourSetRetainRegions(_In_ BOOL fRetain); +PVOID WINAPI DetourSetSystemRegionLowerBound(_In_ PVOID pSystemRegionLowerBound); +PVOID WINAPI DetourSetSystemRegionUpperBound(_In_ PVOID pSystemRegionUpperBound); + +////////////////////////////////////////////////////////////// Code Functions. +// +PVOID WINAPI DetourFindFunction(_In_ LPCSTR pszModule, + _In_ LPCSTR pszFunction); +PVOID WINAPI DetourCodeFromPointer(_In_ PVOID pPointer, + _Out_opt_ PVOID *ppGlobals); +PVOID WINAPI DetourCopyInstruction(_In_opt_ PVOID pDst, + _Inout_opt_ PVOID *ppDstPool, + _In_ PVOID pSrc, + _Out_opt_ PVOID *ppTarget, + _Out_opt_ LONG *plExtra); +BOOL WINAPI DetourSetCodeModule(_In_ HMODULE hModule, + _In_ BOOL fLimitReferencesToModule); + +///////////////////////////////////////////////////// Loaded Binary Functions. +// +HMODULE WINAPI DetourGetContainingModule(_In_ PVOID pvAddr); +HMODULE WINAPI DetourEnumerateModules(_In_opt_ HMODULE hModuleLast); +PVOID WINAPI DetourGetEntryPoint(_In_opt_ HMODULE hModule); +ULONG WINAPI DetourGetModuleSize(_In_opt_ HMODULE hModule); +BOOL WINAPI DetourEnumerateExports(_In_ HMODULE hModule, + _In_opt_ PVOID pContext, + _In_ PF_DETOUR_ENUMERATE_EXPORT_CALLBACK pfExport); +BOOL WINAPI DetourEnumerateImports(_In_opt_ HMODULE hModule, + _In_opt_ PVOID pContext, + _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile, + _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK pfImportFunc); + +BOOL WINAPI DetourEnumerateImportsEx(_In_opt_ HMODULE hModule, + _In_opt_ PVOID pContext, + _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile, + _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK_EX pfImportFuncEx); + +_Writable_bytes_(*pcbData) +_Readable_bytes_(*pcbData) +_Success_(return != NULL) +PVOID WINAPI DetourFindPayload(_In_opt_ HMODULE hModule, + _In_ REFGUID rguid, + _Out_ DWORD *pcbData); + +_Writable_bytes_(*pcbData) +_Readable_bytes_(*pcbData) +_Success_(return != NULL) +PVOID WINAPI DetourFindPayloadEx(_In_ REFGUID rguid, + _Out_ DWORD * pcbData); + +DWORD WINAPI DetourGetSizeOfPayloads(_In_opt_ HMODULE hModule); + +///////////////////////////////////////////////// Persistent Binary Functions. +// + +PDETOUR_BINARY WINAPI DetourBinaryOpen(_In_ HANDLE hFile); + +_Writable_bytes_(*pcbData) +_Readable_bytes_(*pcbData) +_Success_(return != NULL) +PVOID WINAPI DetourBinaryEnumeratePayloads(_In_ PDETOUR_BINARY pBinary, + _Out_opt_ GUID *pGuid, + _Out_ DWORD *pcbData, + _Inout_ DWORD *pnIterator); + +_Writable_bytes_(*pcbData) +_Readable_bytes_(*pcbData) +_Success_(return != NULL) +PVOID WINAPI DetourBinaryFindPayload(_In_ PDETOUR_BINARY pBinary, + _In_ REFGUID rguid, + _Out_ DWORD *pcbData); + +PVOID WINAPI DetourBinarySetPayload(_In_ PDETOUR_BINARY pBinary, + _In_ REFGUID rguid, + _In_reads_opt_(cbData) PVOID pData, + _In_ DWORD cbData); +BOOL WINAPI DetourBinaryDeletePayload(_In_ PDETOUR_BINARY pBinary, _In_ REFGUID rguid); +BOOL WINAPI DetourBinaryPurgePayloads(_In_ PDETOUR_BINARY pBinary); +BOOL WINAPI DetourBinaryResetImports(_In_ PDETOUR_BINARY pBinary); +BOOL WINAPI DetourBinaryEditImports(_In_ PDETOUR_BINARY pBinary, + _In_opt_ PVOID pContext, + _In_opt_ PF_DETOUR_BINARY_BYWAY_CALLBACK pfByway, + _In_opt_ PF_DETOUR_BINARY_FILE_CALLBACK pfFile, + _In_opt_ PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbol, + _In_opt_ PF_DETOUR_BINARY_COMMIT_CALLBACK pfCommit); +BOOL WINAPI DetourBinaryWrite(_In_ PDETOUR_BINARY pBinary, _In_ HANDLE hFile); +BOOL WINAPI DetourBinaryClose(_In_ PDETOUR_BINARY pBinary); + +/////////////////////////////////////////////////// Create Process & Load Dll. +// +typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEA)( + _In_opt_ LPCSTR lpApplicationName, + _Inout_opt_ LPSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOA lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation); + +typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEW)( + _In_opt_ LPCWSTR lpApplicationName, + _Inout_opt_ LPWSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCWSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOW lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation); + +BOOL WINAPI DetourCreateProcessWithDllA(_In_opt_ LPCSTR lpApplicationName, + _Inout_opt_ LPSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOA lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _In_ LPCSTR lpDllName, + _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); + +BOOL WINAPI DetourCreateProcessWithDllW(_In_opt_ LPCWSTR lpApplicationName, + _Inout_opt_ LPWSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCWSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOW lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _In_ LPCSTR lpDllName, + _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); + +#ifdef UNICODE +#define DetourCreateProcessWithDll DetourCreateProcessWithDllW +#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEW +#else +#define DetourCreateProcessWithDll DetourCreateProcessWithDllA +#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEA +#endif // !UNICODE + +BOOL WINAPI DetourCreateProcessWithDllExA(_In_opt_ LPCSTR lpApplicationName, + _Inout_opt_ LPSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOA lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _In_ LPCSTR lpDllName, + _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); + +BOOL WINAPI DetourCreateProcessWithDllExW(_In_opt_ LPCWSTR lpApplicationName, + _Inout_opt_ LPWSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCWSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOW lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _In_ LPCSTR lpDllName, + _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); + +#ifdef UNICODE +#define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExW +#else +#define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExA +#endif // !UNICODE + +BOOL WINAPI DetourCreateProcessWithDllsA(_In_opt_ LPCSTR lpApplicationName, + _Inout_opt_ LPSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOA lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _In_ DWORD nDlls, + _In_reads_(nDlls) LPCSTR *rlpDlls, + _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); + +BOOL WINAPI DetourCreateProcessWithDllsW(_In_opt_ LPCWSTR lpApplicationName, + _Inout_opt_ LPWSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCWSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOW lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _In_ DWORD nDlls, + _In_reads_(nDlls) LPCSTR *rlpDlls, + _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); + +#ifdef UNICODE +#define DetourCreateProcessWithDlls DetourCreateProcessWithDllsW +#else +#define DetourCreateProcessWithDlls DetourCreateProcessWithDllsA +#endif // !UNICODE + +BOOL WINAPI DetourProcessViaHelperA(_In_ DWORD dwTargetPid, + _In_ LPCSTR lpDllName, + _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); + +BOOL WINAPI DetourProcessViaHelperW(_In_ DWORD dwTargetPid, + _In_ LPCSTR lpDllName, + _In_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); + +#ifdef UNICODE +#define DetourProcessViaHelper DetourProcessViaHelperW +#else +#define DetourProcessViaHelper DetourProcessViaHelperA +#endif // !UNICODE + +BOOL WINAPI DetourProcessViaHelperDllsA(_In_ DWORD dwTargetPid, + _In_ DWORD nDlls, + _In_reads_(nDlls) LPCSTR *rlpDlls, + _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); + +BOOL WINAPI DetourProcessViaHelperDllsW(_In_ DWORD dwTargetPid, + _In_ DWORD nDlls, + _In_reads_(nDlls) LPCSTR *rlpDlls, + _In_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); + +#ifdef UNICODE +#define DetourProcessViaHelperDlls DetourProcessViaHelperDllsW +#else +#define DetourProcessViaHelperDlls DetourProcessViaHelperDllsA +#endif // !UNICODE + +BOOL WINAPI DetourUpdateProcessWithDll(_In_ HANDLE hProcess, + _In_reads_(nDlls) LPCSTR *rlpDlls, + _In_ DWORD nDlls); + +BOOL WINAPI DetourUpdateProcessWithDllEx(_In_ HANDLE hProcess, + _In_ HMODULE hImage, + _In_ BOOL bIs32Bit, + _In_reads_(nDlls) LPCSTR *rlpDlls, + _In_ DWORD nDlls); + +BOOL WINAPI DetourCopyPayloadToProcess(_In_ HANDLE hProcess, + _In_ REFGUID rguid, + _In_reads_bytes_(cbData) PVOID pvData, + _In_ DWORD cbData); +BOOL WINAPI DetourRestoreAfterWith(VOID); +BOOL WINAPI DetourRestoreAfterWithEx(_In_reads_bytes_(cbData) PVOID pvData, + _In_ DWORD cbData); +BOOL WINAPI DetourIsHelperProcess(VOID); +VOID CALLBACK DetourFinishHelperProcess(_In_ HWND, + _In_ HINSTANCE, + _In_ LPSTR, + _In_ INT); + +// +////////////////////////////////////////////////////////////////////////////// +#ifdef __cplusplus +} +#endif // __cplusplus + +//////////////////////////////////////////////// Detours Internal Definitions. +// +#ifdef __cplusplus +#ifdef DETOURS_INTERNAL + +#define NOTHROW +// #define NOTHROW (nothrow) + +////////////////////////////////////////////////////////////////////////////// +// +#if (_MSC_VER < 1299) +#include +typedef IMAGEHLP_MODULE IMAGEHLP_MODULE64; +typedef PIMAGEHLP_MODULE PIMAGEHLP_MODULE64; +typedef IMAGEHLP_SYMBOL SYMBOL_INFO; +typedef PIMAGEHLP_SYMBOL PSYMBOL_INFO; + +static inline +LONG InterlockedCompareExchange(_Inout_ LONG *ptr, _In_ LONG nval, _In_ LONG oval) +{ + return (LONG)::InterlockedCompareExchange((PVOID*)ptr, (PVOID)nval, (PVOID)oval); +} +#else +#pragma warning(push) +#pragma warning(disable:4091) // empty typedef +#include +#pragma warning(pop) +#endif + +#ifdef IMAGEAPI // defined by DBGHELP.H +typedef LPAPI_VERSION (NTAPI *PF_ImagehlpApiVersionEx)(_In_ LPAPI_VERSION AppVersion); + +typedef BOOL (NTAPI *PF_SymInitialize)(_In_ HANDLE hProcess, + _In_opt_ LPCSTR UserSearchPath, + _In_ BOOL fInvadeProcess); +typedef DWORD (NTAPI *PF_SymSetOptions)(_In_ DWORD SymOptions); +typedef DWORD (NTAPI *PF_SymGetOptions)(VOID); +typedef DWORD64 (NTAPI *PF_SymLoadModule64)(_In_ HANDLE hProcess, + _In_opt_ HANDLE hFile, + _In_ LPSTR ImageName, + _In_opt_ LPSTR ModuleName, + _In_ DWORD64 BaseOfDll, + _In_opt_ DWORD SizeOfDll); +typedef BOOL (NTAPI *PF_SymGetModuleInfo64)(_In_ HANDLE hProcess, + _In_ DWORD64 qwAddr, + _Out_ PIMAGEHLP_MODULE64 ModuleInfo); +typedef BOOL (NTAPI *PF_SymFromName)(_In_ HANDLE hProcess, + _In_ LPSTR Name, + _Out_ PSYMBOL_INFO Symbol); + +typedef struct _DETOUR_SYM_INFO +{ + HANDLE hProcess; + HMODULE hDbgHelp; + PF_ImagehlpApiVersionEx pfImagehlpApiVersionEx; + PF_SymInitialize pfSymInitialize; + PF_SymSetOptions pfSymSetOptions; + PF_SymGetOptions pfSymGetOptions; + PF_SymLoadModule64 pfSymLoadModule64; + PF_SymGetModuleInfo64 pfSymGetModuleInfo64; + PF_SymFromName pfSymFromName; +} DETOUR_SYM_INFO, *PDETOUR_SYM_INFO; + +PDETOUR_SYM_INFO DetourLoadImageHlp(VOID); + +#endif // IMAGEAPI + +#if defined(_INC_STDIO) && !defined(_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS) +#error detours.h must be included before stdio.h (or at least define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS earlier) +#endif +#define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS 1 + +#ifndef DETOUR_TRACE +#if DETOUR_DEBUG +#define DETOUR_TRACE(x) printf x +#define DETOUR_BREAK() __debugbreak() +#include +#include +#else +#define DETOUR_TRACE(x) +#define DETOUR_BREAK() +#endif +#endif + +#if 1 || defined(DETOURS_IA64) + +// +// IA64 instructions are 41 bits, 3 per bundle, plus 5 bit bundle template => 128 bits per bundle. +// + +#define DETOUR_IA64_INSTRUCTIONS_PER_BUNDLE (3) + +#define DETOUR_IA64_TEMPLATE_OFFSET (0) +#define DETOUR_IA64_TEMPLATE_SIZE (5) + +#define DETOUR_IA64_INSTRUCTION_SIZE (41) +#define DETOUR_IA64_INSTRUCTION0_OFFSET (DETOUR_IA64_TEMPLATE_SIZE) +#define DETOUR_IA64_INSTRUCTION1_OFFSET (DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTION_SIZE) +#define DETOUR_IA64_INSTRUCTION2_OFFSET (DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTION_SIZE + DETOUR_IA64_INSTRUCTION_SIZE) + +C_ASSERT(DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTIONS_PER_BUNDLE * DETOUR_IA64_INSTRUCTION_SIZE == 128); + +__declspec(align(16)) struct DETOUR_IA64_BUNDLE +{ + public: + union + { + BYTE data[16]; + UINT64 wide[2]; + }; + + enum { + A_UNIT = 1u, + I_UNIT = 2u, + M_UNIT = 3u, + B_UNIT = 4u, + F_UNIT = 5u, + L_UNIT = 6u, + X_UNIT = 7u, + }; + struct DETOUR_IA64_METADATA + { + ULONG nTemplate : 8; // Instruction template. + ULONG nUnit0 : 4; // Unit for slot 0 + ULONG nUnit1 : 4; // Unit for slot 1 + ULONG nUnit2 : 4; // Unit for slot 2 + }; + + protected: + static const DETOUR_IA64_METADATA s_rceCopyTable[33]; + + UINT RelocateBundle(_Inout_ DETOUR_IA64_BUNDLE* pDst, _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra) const; + + bool RelocateInstruction(_Inout_ DETOUR_IA64_BUNDLE* pDst, + _In_ BYTE slot, + _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra) const; + + // 120 112 104 96 88 80 72 64 56 48 40 32 24 16 8 0 + // f. e. d. c. b. a. 9. 8. 7. 6. 5. 4. 3. 2. 1. 0. + + // 00 + // f.e. d.c. b.a. 9.8. 7.6. 5.4. 3.2. 1.0. + // 0000 0000 0000 0000 0000 0000 0000 001f : Template [4..0] + // 0000 0000 0000 0000 0000 03ff ffff ffe0 : Zero [ 41.. 5] + // 0000 0000 0000 0000 0000 3c00 0000 0000 : Zero [ 45.. 42] + // 0000 0000 0007 ffff ffff c000 0000 0000 : One [ 82.. 46] + // 0000 0000 0078 0000 0000 0000 0000 0000 : One [ 86.. 83] + // 0fff ffff ff80 0000 0000 0000 0000 0000 : Two [123.. 87] + // f000 0000 0000 0000 0000 0000 0000 0000 : Two [127..124] + BYTE GetTemplate() const; + // Get 4 bit opcodes. + BYTE GetInst0() const; + BYTE GetInst1() const; + BYTE GetInst2() const; + BYTE GetUnit(BYTE slot) const; + BYTE GetUnit0() const; + BYTE GetUnit1() const; + BYTE GetUnit2() const; + // Get 37 bit data. + UINT64 GetData0() const; + UINT64 GetData1() const; + UINT64 GetData2() const; + + // Get/set the full 41 bit instructions. + UINT64 GetInstruction(BYTE slot) const; + UINT64 GetInstruction0() const; + UINT64 GetInstruction1() const; + UINT64 GetInstruction2() const; + void SetInstruction(BYTE slot, UINT64 instruction); + void SetInstruction0(UINT64 instruction); + void SetInstruction1(UINT64 instruction); + void SetInstruction2(UINT64 instruction); + + // Get/set bitfields. + static UINT64 GetBits(UINT64 Value, UINT64 Offset, UINT64 Count); + static UINT64 SetBits(UINT64 Value, UINT64 Offset, UINT64 Count, UINT64 Field); + + // Get specific read-only fields. + static UINT64 GetOpcode(UINT64 instruction); // 4bit opcode + static UINT64 GetX(UINT64 instruction); // 1bit opcode extension + static UINT64 GetX3(UINT64 instruction); // 3bit opcode extension + static UINT64 GetX6(UINT64 instruction); // 6bit opcode extension + + // Get/set specific fields. + static UINT64 GetImm7a(UINT64 instruction); + static UINT64 SetImm7a(UINT64 instruction, UINT64 imm7a); + static UINT64 GetImm13c(UINT64 instruction); + static UINT64 SetImm13c(UINT64 instruction, UINT64 imm13c); + static UINT64 GetSignBit(UINT64 instruction); + static UINT64 SetSignBit(UINT64 instruction, UINT64 signBit); + static UINT64 GetImm20a(UINT64 instruction); + static UINT64 SetImm20a(UINT64 instruction, UINT64 imm20a); + static UINT64 GetImm20b(UINT64 instruction); + static UINT64 SetImm20b(UINT64 instruction, UINT64 imm20b); + + static UINT64 SignExtend(UINT64 Value, UINT64 Offset); + + BOOL IsMovlGp() const; + + VOID SetInst(BYTE Slot, BYTE nInst); + VOID SetInst0(BYTE nInst); + VOID SetInst1(BYTE nInst); + VOID SetInst2(BYTE nInst); + VOID SetData(BYTE Slot, UINT64 nData); + VOID SetData0(UINT64 nData); + VOID SetData1(UINT64 nData); + VOID SetData2(UINT64 nData); + BOOL SetNop(BYTE Slot); + BOOL SetNop0(); + BOOL SetNop1(); + BOOL SetNop2(); + + public: + BOOL IsBrl() const; + VOID SetBrl(); + VOID SetBrl(UINT64 target); + UINT64 GetBrlTarget() const; + VOID SetBrlTarget(UINT64 target); + VOID SetBrlImm(UINT64 imm); + UINT64 GetBrlImm() const; + + UINT64 GetMovlGp() const; + VOID SetMovlGp(UINT64 gp); + + VOID SetStop(); + + UINT Copy(_Out_ DETOUR_IA64_BUNDLE *pDst, _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra = NULL) const; +}; +#endif // DETOURS_IA64 + +#ifdef DETOURS_ARM + +#define DETOURS_PFUNC_TO_PBYTE(p) ((PBYTE)(((ULONG_PTR)(p)) & ~(ULONG_PTR)1)) +#define DETOURS_PBYTE_TO_PFUNC(p) ((PBYTE)(((ULONG_PTR)(p)) | (ULONG_PTR)1)) + +#endif // DETOURS_ARM + +////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +#define DETOUR_OFFLINE_LIBRARY(x) \ +PVOID WINAPI DetourCopyInstruction##x(_In_opt_ PVOID pDst, \ + _Inout_opt_ PVOID *ppDstPool, \ + _In_ PVOID pSrc, \ + _Out_opt_ PVOID *ppTarget, \ + _Out_opt_ LONG *plExtra); \ + \ +BOOL WINAPI DetourSetCodeModule##x(_In_ HMODULE hModule, \ + _In_ BOOL fLimitReferencesToModule); \ + +DETOUR_OFFLINE_LIBRARY(X86) +DETOUR_OFFLINE_LIBRARY(X64) +DETOUR_OFFLINE_LIBRARY(ARM) +DETOUR_OFFLINE_LIBRARY(ARM64) +DETOUR_OFFLINE_LIBRARY(IA64) + +#undef DETOUR_OFFLINE_LIBRARY + +////////////////////////////////////////////////////////////////////////////// +// +// Helpers for manipulating page protection. +// + +_Success_(return != FALSE) +BOOL WINAPI DetourVirtualProtectSameExecuteEx(_In_ HANDLE hProcess, + _In_ PVOID pAddress, + _In_ SIZE_T nSize, + _In_ DWORD dwNewProtect, + _Out_ PDWORD pdwOldProtect); + +_Success_(return != FALSE) +BOOL WINAPI DetourVirtualProtectSameExecute(_In_ PVOID pAddress, + _In_ SIZE_T nSize, + _In_ DWORD dwNewProtect, + _Out_ PDWORD pdwOldProtect); +#ifdef __cplusplus +} +#endif // __cplusplus + +////////////////////////////////////////////////////////////////////////////// + +#define MM_ALLOCATION_GRANULARITY 0x10000 + +////////////////////////////////////////////////////////////////////////////// + +#endif // DETOURS_INTERNAL +#endif // __cplusplus + +#endif // _DETOURS_H_ +// +//////////////////////////////////////////////////////////////// End of File. diff --git a/cs2_patch/include/detver.h b/cs2_patch/include/detver.h new file mode 100644 index 0000000..f0aae9b --- /dev/null +++ b/cs2_patch/include/detver.h @@ -0,0 +1,27 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Common version parameters. +// +// Microsoft Research Detours Package, Version 4.0.1 +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// + +#define _USING_V110_SDK71_ 1 +#include "winver.h" +#if 0 +#include +#include +#else +#ifndef DETOURS_STRINGIFY +#define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x) +#define DETOURS_STRINGIFY_(x) #x +#endif + +#define VER_FILEFLAGSMASK 0x3fL +#define VER_FILEFLAGS 0x0L +#define VER_FILEOS 0x00040004L +#define VER_FILETYPE 0x00000002L +#define VER_FILESUBTYPE 0x00000000L +#endif +#define VER_DETOURS_BITS DETOUR_STRINGIFY(DETOURS_BITS) diff --git a/cs2_patch/pch.cpp b/cs2_patch/pch.cpp new file mode 100644 index 0000000..b6fb8f4 --- /dev/null +++ b/cs2_patch/pch.cpp @@ -0,0 +1,5 @@ +// pch.cpp: 与预编译标头对应的源文件 + +#include "pch.h" + +// 当使用预编译的头时,需要使用此源文件,编译才能成功。 diff --git a/cs2_patch/pch.h b/cs2_patch/pch.h new file mode 100644 index 0000000..9660927 --- /dev/null +++ b/cs2_patch/pch.h @@ -0,0 +1,13 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +// 添加要在此处预编译的标头 +#include "framework.h" + +#endif //PCH_H diff --git a/cs2_united.sln b/cs2_united.sln new file mode 100644 index 0000000..30e9492 --- /dev/null +++ b/cs2_united.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29806.167 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cs2_chs", "cs2_chs\cs2_chs.csproj", "{460F93FF-C32C-455C-A2F6-BB81E86961AE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cs2_patch", "cs2_patch\cs2_patch.vcxproj", "{DB403E75-A69B-4B8E-AD02-9CF48E7C93A7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {460F93FF-C32C-455C-A2F6-BB81E86961AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {460F93FF-C32C-455C-A2F6-BB81E86961AE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {460F93FF-C32C-455C-A2F6-BB81E86961AE}.Debug|x64.ActiveCfg = Debug|Any CPU + {460F93FF-C32C-455C-A2F6-BB81E86961AE}.Debug|x64.Build.0 = Debug|Any CPU + {460F93FF-C32C-455C-A2F6-BB81E86961AE}.Debug|x86.ActiveCfg = Debug|Any CPU + {460F93FF-C32C-455C-A2F6-BB81E86961AE}.Debug|x86.Build.0 = Debug|Any CPU + {460F93FF-C32C-455C-A2F6-BB81E86961AE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {460F93FF-C32C-455C-A2F6-BB81E86961AE}.Release|Any CPU.Build.0 = Release|Any CPU + {460F93FF-C32C-455C-A2F6-BB81E86961AE}.Release|x64.ActiveCfg = Release|Any CPU + {460F93FF-C32C-455C-A2F6-BB81E86961AE}.Release|x64.Build.0 = Release|Any CPU + {460F93FF-C32C-455C-A2F6-BB81E86961AE}.Release|x86.ActiveCfg = Release|Any CPU + {460F93FF-C32C-455C-A2F6-BB81E86961AE}.Release|x86.Build.0 = Release|Any CPU + {DB403E75-A69B-4B8E-AD02-9CF48E7C93A7}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {DB403E75-A69B-4B8E-AD02-9CF48E7C93A7}.Debug|x64.ActiveCfg = Debug|x64 + {DB403E75-A69B-4B8E-AD02-9CF48E7C93A7}.Debug|x64.Build.0 = Debug|x64 + {DB403E75-A69B-4B8E-AD02-9CF48E7C93A7}.Debug|x86.ActiveCfg = Debug|Win32 + {DB403E75-A69B-4B8E-AD02-9CF48E7C93A7}.Debug|x86.Build.0 = Debug|Win32 + {DB403E75-A69B-4B8E-AD02-9CF48E7C93A7}.Release|Any CPU.ActiveCfg = Release|Win32 + {DB403E75-A69B-4B8E-AD02-9CF48E7C93A7}.Release|x64.ActiveCfg = Release|x64 + {DB403E75-A69B-4B8E-AD02-9CF48E7C93A7}.Release|x64.Build.0 = Release|x64 + {DB403E75-A69B-4B8E-AD02-9CF48E7C93A7}.Release|x86.ActiveCfg = Release|Win32 + {DB403E75-A69B-4B8E-AD02-9CF48E7C93A7}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FF5271CA-BF61-4BFC-9D04-7079CF76FC9D} + EndGlobalSection +EndGlobal