sin365 8 months ago
parent
commit
d2332be438
  1. 77
      AxibugInject/AxibugInject.csproj
  2. 88
      AxibugInject/ConsoleShow.cs
  3. 23
      AxibugInject/Filelog.cs
  4. 123
      AxibugInject/Main.cs
  5. 36
      AxibugInject/Properties/AssemblyInfo.cs
  6. BIN
      AxibugInject/RefLib/EasyHook.dll
  7. BIN
      AxibugInject/SN.snk
  8. 31
      AxibugRedirector.sln
  9. 6
      AxibugRedirector/App.config
  10. 80
      AxibugRedirector/AxibugRedirector.csproj
  11. 50
      AxibugRedirector/Config.cs
  12. BIN
      AxibugRedirector/EasyHook.dll
  13. BIN
      AxibugRedirector/EasyHook32.dll
  14. BIN
      AxibugRedirector/EasyHook64.dll
  15. 239
      AxibugRedirector/Program.cs
  16. 36
      AxibugRedirector/Properties/AssemblyInfo.cs
  17. 73
      AxibugRedirector/Properties/app.manifest
  18. 1
      AxibugRedirector/bin/Debug/config.cfg

77
AxibugInject/AxibugInject.csproj

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{95E6AA00-47C3-4B1F-9F18-21164573D89C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ClassLibrary1</RootNamespace>
<AssemblyName>AxibugInject</AssemblyName>
<TargetFrameworkVersion>v4.8</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>
<PlatformTarget>x86</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</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>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>SN.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="EasyHook, Version=2.7.4761.0, Culture=neutral, PublicKeyToken=4b580fca19d0b0c5, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>RefLib\EasyHook.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<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="ConsoleShow.cs" />
<Compile Include="Filelog.cs" />
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="RefLib\EasyHook.dll" />
</ItemGroup>
<ItemGroup>
<None Include="SN.snk" />
</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>

88
AxibugInject/ConsoleShow.cs

@ -0,0 +1,88 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace ClassLibrary1
{
static class ConsoleShow
{
static bool bFlag = false;
public static void Log(string str)
{
if (!bFlag)
{
bFlag = true;
AllocConsole();
// stdout's handle seems to always be equal to 7
IntPtr defaultStdout = new IntPtr(7);
IntPtr currentStdout = GetStdHandle(StdOutputHandle);
if (currentStdout != defaultStdout)
// reset stdout
SetStdHandle(StdOutputHandle, defaultStdout);
// reopen stdout
TextWriter writer = new StreamWriter(Console.OpenStandardOutput())
{ AutoFlush = true };
Console.SetOut(writer);
}
WriteLine(str);
FileLog.Log(str);
}
/// <summary>
/// 启动控制台
/// </summary>
/// <returns></returns>
[DllImport("kernel32.dll")]
public static extern bool AllocConsole();
/// <summary>
/// 释放控制台
/// </summary>
/// <returns></returns>
[DllImport("kernel32.dll")]
public static extern bool FreeConsole();
// P/Invoke required:
private const UInt32 StdOutputHandle = 0xFFFFFFF5;
[DllImport("kernel32.dll")]
private static extern IntPtr GetStdHandle(UInt32 nStdHandle);
[DllImport("kernel32.dll")]
private static extern void SetStdHandle(UInt32 nStdHandle, IntPtr handle);
/// <summary>
/// 输出信息
/// </summary>
/// <param name="format"></param>
/// <param name="args"></param>
public static void WriteLine(string format, params object[] args)
{
WriteLine(string.Format(format, args));
}
/// <summary>
/// 输出信息
/// </summary>
/// <param name="output"></param>
public static void WriteLine(string output)
{
Console.ForegroundColor = GetConsoleColor(output);
Console.WriteLine(@"[{0}]{1}", DateTimeOffset.Now, output);
}
/// <summary>
/// 根据输出文本选择控制台文字颜色
/// </summary>
/// <param name="output"></param>
/// <returns></returns>
private static ConsoleColor GetConsoleColor(string output)
{
if (output.StartsWith("警告")) return ConsoleColor.Yellow;
if (output.StartsWith("错误")) return ConsoleColor.Red;
if (output.StartsWith("注意")) return ConsoleColor.Green;
return ConsoleColor.Gray;
}
}
}

23
AxibugInject/Filelog.cs

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ClassLibrary1
{
public class FileLog
{
public static string logpath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\\AxibugRedirectorLog.txt";
public static void Log(string sourceStr)
{
try
{
File.AppendAllText(logpath, "\n"+DateTime.Now.ToString("yyyyMMdd HH:mm:ss: ") + sourceStr);
}
catch { }
}
}
}

123
AxibugInject/Main.cs

@ -0,0 +1,123 @@
using System;
using System.Text;
using System.Runtime.InteropServices;
using EasyHook;
using System.Threading;
using System.Windows.Forms;
using ClassLibrary1;
using System.Collections.Generic;
namespace AxibugInject
{
[Serializable]
public class HookParameter
{
public string Msg { get; set; }
public int HostProcessId { get; set; }
public string RedirectorArrs { get; set; }
}
public class Main : IEntryPoint
{
public LocalHook GetHostByNameHook = null;
public static Dictionary<string, string> mDictHostToIP = new Dictionary<string, string>();
public Main(
RemoteHooking.IContext context,
string channelName
, HookParameter parameter
)
{
string[] RedirectorArrs = parameter.RedirectorArrs.Split('|');
try
{
for(int i = 0;i < RedirectorArrs.Length;i++)
{
string line = RedirectorArrs[i].Trim();
if (string.IsNullOrEmpty(line))
continue;
string[] arr = RedirectorArrs[i].Trim().Split(':');
if (arr.Length < 2)
continue;
mDictHostToIP[arr[0].Trim()] = arr[1].Trim();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
MessageBox.Show(parameter.Msg + ",并加载:" + mDictHostToIP.Count + "个重定向配置", "Hooked");
}
public void Run(
RemoteHooking.IContext context,
string channelName
, HookParameter parameter
)
{
try
{
GetHostByNameHook = LocalHook.Create(
LocalHook.GetProcAddress("ws2_32.dll", "gethostbyname"),
new DGetHostByName(GetHostByName_Hooked),
this);
GetHostByNameHook.ThreadACL.SetExclusiveACL(new int[1]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
try
{
while (true)
{
Thread.Sleep(10);
}
}
catch
{
}
}
#region gethostname
[DllImport("ws2_32.dll", EntryPoint = "gethostbyname", CharSet = CharSet.Ansi)]
public static extern IntPtr gethostbyname(String name);
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Ansi)]
delegate IntPtr DGetHostByName(String name);
static IntPtr GetHostByName_Hooked(
String name)
{
try
{
Main This = (Main)HookRuntimeInfo.Callback;
if (mDictHostToIP.ContainsKey(name.ToLower()))
{
ConsoleShow.Log($"[访问并重定向]{name}->{mDictHostToIP[name]}");
name = mDictHostToIP[name.ToLower()];
}
else
{
ConsoleShow.Log("[访问]:" + name);
}
}
catch
{
}
// call original API...
return gethostbyname(
name);
}
#endregion
}
}

36
AxibugInject/Properties/AssemblyInfo.cs

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("ClassLibrary1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClassLibrary1")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("40eec29a-79ae-44f9-bf49-070082434c95")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 内部版本号
// 修订号
//
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

BIN
AxibugInject/RefLib/EasyHook.dll

Binary file not shown.

BIN
AxibugInject/SN.snk

Binary file not shown.

31
AxibugRedirector.sln

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AxibugInject", "AxibugInject\AxibugInject.csproj", "{95E6AA00-47C3-4B1F-9F18-21164573D89C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AxibugRedirector", "AxibugRedirector\AxibugRedirector.csproj", "{DE13F3EF-8DB0-4900-A169-AFF59B15631F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{95E6AA00-47C3-4B1F-9F18-21164573D89C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95E6AA00-47C3-4B1F-9F18-21164573D89C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95E6AA00-47C3-4B1F-9F18-21164573D89C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95E6AA00-47C3-4B1F-9F18-21164573D89C}.Release|Any CPU.Build.0 = Release|Any CPU
{DE13F3EF-8DB0-4900-A169-AFF59B15631F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE13F3EF-8DB0-4900-A169-AFF59B15631F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE13F3EF-8DB0-4900-A169-AFF59B15631F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE13F3EF-8DB0-4900-A169-AFF59B15631F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D78C063-A26B-48C6-8DCF-B40D03871A90}
EndGlobalSection
EndGlobal

6
AxibugRedirector/App.config

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>

80
AxibugRedirector/AxibugRedirector.csproj

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DE13F3EF-8DB0-4900-A169-AFF59B15631F}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>AxibugRedirector</RootNamespace>
<AssemblyName>AxibugRedirector</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="EasyHook, Version=2.7.4761.0, Culture=neutral, PublicKeyToken=4b580fca19d0b0c5, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\EasyHook.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.EnterpriseServices" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="Properties\app.manifest" />
</ItemGroup>
<ItemGroup>
<Content Include="EasyHook.dll" />
<Content Include="EasyHook32.dll" />
<Content Include="EasyHook64.dll" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AxibugInject\AxibugInject.csproj">
<Project>{95e6aa00-47c3-4b1f-9f18-21164573d89c}</Project>
<Name>AxibugInject</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

50
AxibugRedirector/Config.cs

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AxibugRedirector
{
//public struct CfgInfo
//{
// public string hostname;
// public string targetIP;
//}
public static class Config
{
public static bool LoadConfig(out Dictionary<string, string> dictHostToIP)
{
dictHostToIP = new Dictionary<string, string>();
try
{
StreamReader sr = new StreamReader(System.Environment.CurrentDirectory + "//config.cfg", Encoding.Default);
String line;
while (!string.IsNullOrEmpty((line = sr.ReadLine())))
{
if (!line.Contains(":"))
continue;
try
{
dictHostToIP[line.Split(':')[0].Trim()] = line.Split(':')[1].Trim();
}
catch
{
continue;
}
}
sr.Close();
if (dictHostToIP.Count > 0)
return true;
else
return false;
}
catch (Exception ex)
{
Console.WriteLine("配置文件异常:" + ex.ToString());
return false;
}
}
}
}

BIN
AxibugRedirector/EasyHook.dll

Binary file not shown.

BIN
AxibugRedirector/EasyHook32.dll

Binary file not shown.

BIN
AxibugRedirector/EasyHook64.dll

Binary file not shown.

239
AxibugRedirector/Program.cs

@ -0,0 +1,239 @@
using AxibugInject;
using EasyHook;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace AxibugRedirector
{
internal class Program
{
static Dictionary<string, string> mDictHostToIP;
static string mHostToIPArr;
static void Main(string[] args)
{
if (!Config.LoadConfig(out Dictionary<string, string> dictHostToIP))
{
Console.WriteLine("请检查配置文件!");
Console.ReadLine();
return;
}
mDictHostToIP = dictHostToIP;
Console.WriteLine("配置文件加载完毕!");
foreach (var d in mDictHostToIP)
{
Console.WriteLine($"{d.Key}->{d.Value}");
mHostToIPArr += $"{d.Key}:{d.Value}|";
}
Console.WriteLine("Pipie Server加载!");
bool bflag = false;
while (!bflag)
{
Console.WriteLine("----请指定进程----");
Console.WriteLine("[1]使用PID注入,[2]使用进程名(不带exe)[3]指定exe路径,启动exe后hook");
string readStr = Console.ReadLine();
if (int.TryParse(readStr, out int type))
{
if (type == 1)
{
Console.Write("请输入目标进程PID:");
if (int.TryParse(readStr, out int pid))
{
if (DoInjectByPid(pid))
{
bflag = true;
}
}
}
else if (type == 2)
{
Console.Write("使用进程名(不带exe):");
string readName = Console.ReadLine();
if (string.IsNullOrEmpty(readName))
{
continue;
}
if (GetPidForProName(readName, out int targetPid))
{
if (DoInjectByPid(targetPid))
{
bflag = true;
}
}
else
{
Console.WriteLine("进程不存在");
}
}
else if (type == 3)
{
Console.Write("指定exe路径,启动exe后hook:");
string path = Console.ReadLine();
if (string.IsNullOrEmpty(path))
{
continue;
}
if (StartProcessWithHook(path))
{
bflag = true;
}
}
}
}
Console.WriteLine("已就绪");
while(true)
Console.ReadLine();
}
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);
private static bool RegGACAssembly()
{
var dllName = "EasyHook.dll";
var dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dllName);
if (!RuntimeEnvironment.FromGlobalAccessCache(Assembly.LoadFrom(dllPath)))
{
new System.EnterpriseServices.Internal.Publish().GacInstall(dllPath);
Thread.Sleep(100);
}
dllName = "AxibugInject.dll";
dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dllName);
new System.EnterpriseServices.Internal.Publish().GacRemove(dllPath);
if (!RuntimeEnvironment.FromGlobalAccessCache(Assembly.LoadFrom(dllPath)))
{
new System.EnterpriseServices.Internal.Publish().GacInstall(dllPath);
Thread.Sleep(100);
}
return true;
}
private static bool InstallHookInternal(int processId)
{
try
{
var parameter = new HookParameter
{
Msg = "已经成功注入目标进程",
HostProcessId = RemoteHooking.GetCurrentProcessId(),
RedirectorArrs = mHostToIPArr
};
RemoteHooking.Inject(
processId,
InjectionOptions.Default,
typeof(HookParameter).Assembly.Location,
typeof(HookParameter).Assembly.Location,
string.Empty,
parameter
);
}
catch (Exception ex)
{
Debug.Print(ex.ToString());
return false;
}
return true;
}
private static bool IsWin64Emulator(int processId)
{
var process = Process.GetProcessById(processId);
if (process == null)
return false;
if ((Environment.OSVersion.Version.Major > 5)
|| ((Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor >= 1)))
{
bool retVal;
return !(IsWow64Process(process.Handle, out retVal) && retVal);
}
return false; // not on 64-bit Windows Emulator
}
public static bool DoInjectByPid(int Pid)
{
var p = Process.GetProcessById(Pid);
if (p == null)
{
Console.WriteLine("指定的进程不存在!");
return false;
}
if (IsWin64Emulator(p.Id) != IsWin64Emulator(Process.GetCurrentProcess().Id))
{
var currentPlat = IsWin64Emulator(Process.GetCurrentProcess().Id) ? 64 : 32;
var targetPlat = IsWin64Emulator(p.Id) ? 64 : 32;
Console.WriteLine(string.Format("当前程序是{0}位程序,目标进程是{1}位程序,请调整编译选项重新编译后重试!", currentPlat, targetPlat));
return false;
}
RegGACAssembly();
InstallHookInternal(p.Id);
return true;
}
public static bool GetPidForProName(string ProcessName,out int targetPid)
{
Process[] process = Process.GetProcessesByName(ProcessName);
if (process.Length > 0)
{
targetPid = process.FirstOrDefault().Id;
return true;
}
else
{
targetPid = -1;
return false;
}
}
#region 运行时处理
public static bool StartProcessWithHook(string path)
{
var pro = new Process();
try
{
pro.StartInfo.FileName = path;
pro.EnableRaisingEvents = true;
//退出函数
//pro.Exited += new EventHandler(StaticComm.LianJiNiang_ProcessExit);
//pro.TotalProcessorTime
pro.StartInfo.UseShellExecute = true;
//参数
//pro.StartInfo.Arguments = StaticComm.getLink(0);
pro.Start();
pro.WaitForInputIdle();
//Thread.Sleep(1000);
}
catch (Exception ex)
{
Console.WriteLine("失败:"+ex.ToString());
return false;
}
return DoInjectByPid(pro.Id);
}
#endregion
}
}

36
AxibugRedirector/Properties/AssemblyInfo.cs

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

73
AxibugRedirector/Properties/app.manifest

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC 清单选项
如果想要更改 Windows 用户帐户控制级别,请使用
以下节点之一替换 requestedExecutionLevel 节点。
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
如果你的应用程序需要此虚拟化来实现向后兼容性,则移除此
元素。
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
Windows 版本的列表。取消评论适当的元素,
Windows 将自动选择最兼容的环境。 -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- 指示该应用程序可感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
选择加入。选择加入此设置的 Windows 窗体应用程序(面向 .NET Framework 4.6)还应
在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。
将应用程序设为感知长路径。请参阅 https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
-->
<!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>

1
AxibugRedirector/bin/Debug/config.cfg

@ -0,0 +1 @@
baidu.com:127.0.0.1
Loading…
Cancel
Save