-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
643 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29613.14 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicInjector", "BasicInjector\BasicInjector.csproj", "{2CA1DBD7-D08A-48E5-B0A6-DC351B319BB3}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{2CA1DBD7-D08A-48E5-B0A6-DC351B319BB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2CA1DBD7-D08A-48E5-B0A6-DC351B319BB3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2CA1DBD7-D08A-48E5-B0A6-DC351B319BB3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2CA1DBD7-D08A-48E5-B0A6-DC351B319BB3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {3B10084C-C40A-43C1-8266-3F06D77B8D14} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="BasicInjector.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:BasicInjector" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace BasicInjector | ||
{ | ||
/// <summary> | ||
/// Interaktionslogik für "App.xaml" | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?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>{2CA1DBD7-D08A-48E5-B0A6-DC351B319BB3}</ProjectGuid> | ||
<OutputType>WinExe</OutputType> | ||
<RootNamespace>BasicInjector</RootNamespace> | ||
<AssemblyName>BasicInjector</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<WarningLevel>4</WarningLevel> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xaml"> | ||
<RequiredTargetFramework>4.0</RequiredTargetFramework> | ||
</Reference> | ||
<Reference Include="WindowsBase" /> | ||
<Reference Include="PresentationCore" /> | ||
<Reference Include="PresentationFramework" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ApplicationDefinition Include="App.xaml"> | ||
<Generator>MSBuild:Compile</Generator> | ||
<SubType>Designer</SubType> | ||
</ApplicationDefinition> | ||
<Page Include="MainWindow.xaml"> | ||
<Generator>MSBuild:Compile</Generator> | ||
<SubType>Designer</SubType> | ||
</Page> | ||
<Compile Include="App.xaml.cs"> | ||
<DependentUpon>App.xaml</DependentUpon> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<Compile Include="Injection.cs" /> | ||
<Compile Include="MainWindow.xaml.cs"> | ||
<DependentUpon>MainWindow.xaml</DependentUpon> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs"> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DesignTime>True</DesignTime> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
<Compile Include="Properties\Settings.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Settings.settings</DependentUpon> | ||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | ||
</Compile> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
<None Include="Properties\Settings.settings"> | ||
<Generator>SettingsSingleFileGenerator</Generator> | ||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | ||
</None> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
namespace BasicInjector | ||
{ | ||
internal class Injection | ||
{ | ||
[DllImport("kernel32.dll", SetLastError = true)] | ||
private static extern IntPtr OpenProcess(uint dwDesiredAccess, int bInheritHandle, uint dwProcessId); | ||
|
||
[DllImport("kernel32.dll", SetLastError = true)] | ||
private static extern int CloseHandle(IntPtr hObject); | ||
|
||
[DllImport("kernel32.dll", SetLastError = true)] | ||
private static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); | ||
|
||
[DllImport("kernel32.dll", SetLastError = true)] | ||
private static extern IntPtr GetModuleHandle(string lpModuleName); | ||
|
||
[DllImport("kernel32.dll", SetLastError = true)] | ||
private static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, IntPtr dwSize, uint flAllocationType, uint flProtect); | ||
|
||
[DllImport("kernel32.dll", SetLastError = true)] | ||
private static extern int WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] buffer, uint size, int lpNumberOfBytesWritten); | ||
|
||
[DllImport("kernel32.dll", SetLastError = true)] | ||
private static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttribute, IntPtr dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId); | ||
|
||
|
||
const int PROCESS_CREATE_THREAD = 0x0002; | ||
const int PROCESS_QUERY_INFORMATION = 0x0400; | ||
const int PROCESS_VM_OPERATION = 0x0008; | ||
const int PROCESS_VM_WRITE = 0x0020; | ||
const int PROCESS_VM_READ = 0x0010; | ||
|
||
// used for memory allocation | ||
const uint MEM_COMMIT = 0x00001000; | ||
const uint MEM_RESERVE = 0x00002000; | ||
const uint PAGE_READWRITE = 4; | ||
|
||
public bool InjectionPrep(string DLLLoc, int procID) | ||
{ | ||
if (!File.Exists(DLLLoc)) | ||
{ | ||
System.Windows.MessageBox.Show("No DLL selected.", "ERROR"); | ||
return false; | ||
} | ||
return this.StartInjection(Convert.ToUInt32(procID), DLLLoc); | ||
} | ||
|
||
public bool StartInjection(uint pid, string dllToInject) | ||
{ | ||
IntPtr intPtr = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, 0, pid); | ||
if (intPtr == IntPtr.Zero) | ||
{ | ||
return false; | ||
} | ||
IntPtr procAddress = Injection.GetProcAddress(Injection.GetModuleHandle("kernel32.dll"), "LoadLibraryA"); | ||
if (procAddress == IntPtr.Zero) | ||
{ | ||
return false; | ||
} | ||
IntPtr intPtr2 = Injection.VirtualAllocEx(intPtr, (IntPtr)null, (IntPtr)dllToInject.Length, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); | ||
if (intPtr2 == IntPtr.Zero) | ||
{ | ||
return false; | ||
} | ||
byte[] bytes = Encoding.ASCII.GetBytes(dllToInject); | ||
if (Injection.WriteProcessMemory(intPtr, intPtr2, bytes, (uint)bytes.Length, 0) == 0) | ||
{ | ||
return false; | ||
} | ||
if (Injection.CreateRemoteThread(intPtr, (IntPtr)null, IntPtr.Zero, procAddress, intPtr2, 0u, (IntPtr)null) == IntPtr.Zero) | ||
{ | ||
return false; | ||
} | ||
Injection.CloseHandle(intPtr); | ||
MainWindow._instance.AppendTextBox("Injection was successful"); | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Window x:Class="BasicInjector.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:BasicInjector" | ||
mc:Ignorable="d" | ||
Title="Wolve-Inject" Height="450" Width="300" | ||
ResizeMode="CanMinimize"> | ||
<Grid> | ||
<Button x:Name="inject" Content="Inject" HorizontalAlignment="Left" Margin="190,47,0,0" VerticalAlignment="Top" Width="80" RenderTransformOrigin="-2.547,-0.95" Click="Inject_Click"/> | ||
<Button x:Name="openDllDirec" Content="Open DLL" HorizontalAlignment="Left" Margin="164,10,0,0" VerticalAlignment="Top" Width="120" Click="OpenDllDirec_Click"/> | ||
<TextBox x:Name="logbox" HorizontalAlignment="Left" Height="339" Margin="10,72,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="274" RenderTransformOrigin="0.033,-0.13"/> | ||
<ComboBox x:Name="procListBox" HorizontalAlignment="Left" Margin="10,45,0,0" VerticalAlignment="Top" Width="120" SelectionChanged="ComboBox_SelectionChanged"/> | ||
<Button x:Name="refreshButton" Content="Refresh Process List" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="132" Click="RefreshButton_Click"/> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace BasicInjector | ||
{ | ||
/// <summary> | ||
/// Interaktionslogik für MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
public static MainWindow _instance; | ||
private Injection inj = new Injection(); | ||
string dllloc; | ||
|
||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
_instance = this; | ||
GetRunningApps(); | ||
} | ||
|
||
void GetRunningApps() | ||
{ | ||
foreach (Process p in Process.GetProcesses(".")) | ||
{ | ||
try | ||
{ | ||
if (p.MainWindowTitle.Length > 0) | ||
{ | ||
ComboboxItem combobox = new ComboboxItem(); | ||
combobox.Text = p.MainWindowTitle; | ||
combobox.Value = p.Id; | ||
procListBox.Items.Add(combobox); | ||
} | ||
} | ||
catch { } | ||
} | ||
} | ||
|
||
private void Inject_Click(object sender, RoutedEventArgs e) | ||
{ | ||
if (procListBox.SelectedItem == null) | ||
{ | ||
System.Windows.MessageBox.Show("No Selected Process", "ERROR"); | ||
return; | ||
} | ||
int id = Convert.ToInt32((procListBox.SelectedItem as ComboboxItem).Value); | ||
if (!inj.InjectionPrep(dllloc, id)) | ||
{ | ||
System.Windows.MessageBox.Show("Couldnt inject the DLL!", "ERROR"); | ||
return; | ||
} | ||
} | ||
|
||
private void OpenDllDirec_Click(object sender, RoutedEventArgs e) | ||
{ | ||
Microsoft.Win32.OpenFileDialog openFileDlg = new Microsoft.Win32.OpenFileDialog(); | ||
openFileDlg.Filter = "dll|*.DLL"; | ||
// Launch OpenFileDialog by calling ShowDialog method | ||
Nullable<bool> result = openFileDlg.ShowDialog(); | ||
// Get the selected file name and display in a TextBox. | ||
// Load content of file in a TextBlock | ||
if (result == true) | ||
{ | ||
dllloc = openFileDlg.FileName; | ||
AppendTextBox("Loading DLL: " + dllloc); | ||
} | ||
} | ||
|
||
public void AppendTextBox(string value) | ||
{ | ||
logbox.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, | ||
new Action(delegate () | ||
{ | ||
logbox.Text += value + Environment.NewLine; | ||
})); | ||
} | ||
|
||
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) | ||
{ | ||
if (procListBox.Items.Count != 0) | ||
{ | ||
AppendTextBox("Changed Process to: " + (procListBox.SelectedValue as ComboboxItem).Text + "\nProcess ID: " + (procListBox.SelectedValue as ComboboxItem).Value); | ||
} | ||
} | ||
|
||
private void RefreshButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
procListBox.Items.Clear(); | ||
GetRunningApps(); | ||
} | ||
} | ||
|
||
public class ComboboxItem | ||
{ | ||
public string Text { get; set; } | ||
public object Value { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return Text; | ||
} | ||
} | ||
} |
Oops, something went wrong.