-
Notifications
You must be signed in to change notification settings - Fork 58
added c++/cli library for easy integration in managed dotnet code #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
debashish2014
wants to merge
4
commits into
jonatan1024:master
Choose a base branch
from
debashish2014:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
be68b81
created a wrapper on top of clrinject to be used in managed code
debashish2014 01c99c8
added wrapper functions to inject a code into an app domain
debashish2014 96842fc
Reverted the Windows target platform to 8.1
debashish2014 11a8874
Modified the test app to automatically start victim app
debashish2014 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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.6.1" /> | ||
| </startup> | ||
| </configuration> |
This file contains hidden or 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,111 @@ | ||
| | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
|
|
||
| namespace InjectorApp | ||
| { | ||
| class Program | ||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| Process victimProcess = null; | ||
|
|
||
| try | ||
| { | ||
| victimProcess = Process.Start(PathOfVictimApp); | ||
| if (!victimProcess.IsRunning()) | ||
| return; | ||
|
|
||
| System.Threading.Thread.Sleep(TimeSpan.FromSeconds(6)); | ||
|
|
||
| Injector injector = new Injector(); | ||
|
|
||
| //Test enumeration | ||
| var result = injector.EnumerateAppDomains("victim.exe"); | ||
|
|
||
| if (result.Any()) | ||
| { | ||
| result.ForEach(runtime => | ||
| { | ||
| var runtimeStatus = runtime.IsRuntimeStarted ? "started" : "stopped"; | ||
| Console.WriteLine($"Runtime Version : {runtime.runtimeVersion} is {runtimeStatus}, and have following app domains:"); | ||
| int index = 0; | ||
| runtime.AppDomains.ForEach(appd => Console.WriteLine($"{++index}. {appd}")); | ||
| }); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("Enumeration yielded no result"); | ||
| } | ||
|
|
||
| Console.WriteLine(); | ||
|
|
||
| //Test injection in all app domains | ||
| //injector.InjectIntoProcess("victim.exe", PathOfProcessToInject); | ||
|
|
||
| //Test injection in the specified app domain | ||
| injector.InjectIntoProcess("victim.exe", PathOfProcessToInject, 3); | ||
|
|
||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.WriteLine(ex.InnerException); | ||
| } | ||
|
|
||
| Console.WriteLine("Press any key to exit."); | ||
| Console.ReadLine(); | ||
|
|
||
| victimProcess.Kill(); | ||
|
|
||
| } | ||
|
|
||
| public static string PathOfProcessToInject | ||
| { | ||
| get | ||
| { | ||
| return GetPath("invader"); | ||
| } | ||
| } | ||
|
|
||
| public static string PathOfVictimApp | ||
| { | ||
| get | ||
| { | ||
| return GetPath("victim"); | ||
| } | ||
| } | ||
|
|
||
| private static string GetPath(string appName) | ||
| { | ||
| var assembly = Assembly.GetExecutingAssembly(); | ||
| string codeBase = assembly.CodeBase; | ||
| UriBuilder uri = new UriBuilder(codeBase); | ||
| var projectRootDirectory = Directory.GetParent(Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path))).Parent.Parent.Parent; | ||
| string buildMode = codeBase.Contains("Debug") ? "Debug" : "Release"; | ||
| var assemblyName = AssemblyName.GetAssemblyName(assembly.FullName.Split(',')[0] + ".exe"); | ||
| var assemblyArchitecture = assemblyName.ProcessorArchitecture == ProcessorArchitecture.Amd64 ? "x64" : "x86"; | ||
| return $"{projectRootDirectory.FullName}\\{appName}\\bin\\{assemblyArchitecture}\\{buildMode}\\{appName}.exe"; | ||
| } | ||
| } | ||
|
|
||
| public static class ProcessExtensions | ||
| { | ||
| public static bool IsRunning(this Process process) | ||
| { | ||
| if (process == null) | ||
| throw new ArgumentNullException("process"); | ||
| try | ||
| { | ||
| Process.GetProcessById(process.Id); | ||
| } | ||
| catch (ArgumentException) | ||
| { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,36 @@ | ||
| using System.Reflection; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| // General Information about an assembly is controlled through the following | ||
| // set of attributes. Change these attribute values to modify the information | ||
| // associated with an assembly. | ||
| [assembly: AssemblyTitle("InjectorApp")] | ||
| [assembly: AssemblyDescription("")] | ||
| [assembly: AssemblyConfiguration("")] | ||
| [assembly: AssemblyCompany("")] | ||
| [assembly: AssemblyProduct("InjectorApp")] | ||
| [assembly: AssemblyCopyright("Copyright © 2019")] | ||
| [assembly: AssemblyTrademark("")] | ||
| [assembly: AssemblyCulture("")] | ||
|
|
||
| // Setting ComVisible to false makes the types in this assembly not visible | ||
| // to COM components. If you need to access a type in this assembly from | ||
| // COM, set the ComVisible attribute to true on that type. | ||
| [assembly: ComVisible(false)] | ||
|
|
||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
| [assembly: Guid("ccc57338-7ddc-4106-bf33-2538188d17ea")] | ||
|
|
||
| // Version information for an assembly consists of the following four values: | ||
| // | ||
| // Major Version | ||
| // Minor Version | ||
| // Build Number | ||
| // Revision | ||
| // | ||
| // You can specify all the values or you can default the Build and Revision Numbers | ||
| // by using the '*' as shown below: | ||
| // [assembly: AssemblyVersion("1.0.*")] | ||
| [assembly: AssemblyVersion("1.0.0.0")] | ||
| [assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains hidden or 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,76 @@ | ||
| <?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>{CCC57338-7DDC-4106-BF33-2538188D17EA}</ProjectGuid> | ||
| <OutputType>Exe</OutputType> | ||
| <RootNamespace>InjectorApp</RootNamespace> | ||
| <AssemblyName>InjectorApp</AssemblyName> | ||
| <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
| <FileAlignment>512</FileAlignment> | ||
| <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
| <Deterministic>true</Deterministic> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
| <PlatformTarget>x86</PlatformTarget> | ||
| <DebugSymbols>true</DebugSymbols> | ||
| <DebugType>full</DebugType> | ||
| <Optimize>false</Optimize> | ||
| <OutputPath>bin\Debug\</OutputPath> | ||
| <DefineConstants>DEBUG;TRACE</DefineConstants> | ||
| <ErrorReport>prompt</ErrorReport> | ||
| <WarningLevel>4</WarningLevel> | ||
| <Prefer32Bit>false</Prefer32Bit> | ||
| </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 Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> | ||
| <PlatformTarget>x86</PlatformTarget> | ||
| <OutputPath>bin\x86\Debug\</OutputPath> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> | ||
| <PlatformTarget>x86</PlatformTarget> | ||
| <OutputPath>bin\x86\Release\</OutputPath> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> | ||
| <PlatformTarget>x64</PlatformTarget> | ||
| <OutputPath>bin\x64\Debug\</OutputPath> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> | ||
| <PlatformTarget>x64</PlatformTarget> | ||
| <OutputPath>bin\x64\Release\</OutputPath> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Reference Include="System" /> | ||
| <Reference Include="System.Core" /> | ||
| <Reference Include="System.Xml.Linq" /> | ||
| <Reference Include="System.Data.DataSetExtensions" /> | ||
| <Reference Include="Microsoft.CSharp" /> | ||
| <Reference Include="System.Data" /> | ||
| <Reference Include="System.Net.Http" /> | ||
| <Reference Include="System.Xml" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Compile Include="Program.cs" /> | ||
| <Compile Include="Properties\AssemblyInfo.cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <None Include="App.config" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\clrinject-lib\clrinject-lib.vcxproj"> | ||
| <Project>{9dc43a8d-8596-4704-9982-c2bad7087de9}</Project> | ||
| <Name>clrinject-lib</Name> | ||
| </ProjectReference> | ||
| </ItemGroup> | ||
| <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
| </Project> |
This file contains hidden or 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,21 @@ | ||
|
|
||
| using namespace System; | ||
| using namespace System::Reflection; | ||
| using namespace System::Runtime::CompilerServices; | ||
| using namespace System::Runtime::InteropServices; | ||
| using namespace System::Security::Permissions; | ||
|
|
||
| [assembly:AssemblyTitleAttribute(L"clrinjectlib")]; | ||
| [assembly:AssemblyDescriptionAttribute(L"")]; | ||
| [assembly:AssemblyConfigurationAttribute(L"")]; | ||
| [assembly:AssemblyCompanyAttribute(L"")]; | ||
| [assembly:AssemblyProductAttribute(L"clrinjectlib")]; | ||
| [assembly:AssemblyCopyrightAttribute(L"Copyright (c) 2019")]; | ||
| [assembly:AssemblyTrademarkAttribute(L"")]; | ||
| [assembly:AssemblyCultureAttribute(L"")]; | ||
|
|
||
| [assembly:AssemblyVersionAttribute("1.0.*")]; | ||
|
|
||
| [assembly:ComVisible(false)]; | ||
|
|
||
| [assembly:CLSCompliantAttribute(true)]; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed Runtime and AppDomain to avoid conflicts with dotnet namespace