Hey all,

I'm gonna explain you how make a self injecting program in C#.
I hope you guys thinks its usefull and have a nice reading 

Requirements:
Visual Studio 20xx (I use Visual Studio 2010)
VInj (A nice library to inject managed dll's, its can be downloaded at the bottom.)
Simple Knowlege of C#

Getting Started
First we have to create a simple C# console project, in my case i call it SelfInjector.
Make sure the project framework is set to .NET Framework 2.0, else you'll get an error.

Then we have to copy the 2 DLL files from the VInj.rar into the solution and set the "Copy to Ouput" to Copy if Newer or Always.

Now that we have done this we add the VInjDn.dll as a reference to our project.

If everything goes as planned you'll get a project like this

Setting up the injector
Now were gonna start programming the injector.

What were gonna do is getting the process by name and then Inject our program into the target process with VInj.

First we define a string for the name of the target process. i use BlackOps as a example.
This part will be in the Main method.

Code:
string targetProcess = "BlackOps";

now we are going to get the process by name. which will be right under it.

Code:
Process remote_process = Process.GetProcessesByName(targetProcess)[0];

Ok, now we are getting to the part where we are going to inject our program into the process
this is done using the InjectableProcess from the VInj library.
The inject method returns a result which we can use if our program has been successfully injected.

Code:
InjectableProcess ip = InjectableProcess.Create(remote_process.Handle);
int result = ip.Inject(Application.ExecutablePath, Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".Main");
if (result == 0)
{
Console.WriteLine("Failed to inject.");
Console.ReadKey();
return;
}

We return directly after the failure message because it doesnt make any sense to go on :P

And this is it for the injector, after the IF you can also make something so you know if it is successfully injected or something.

Here a screenshot of how your code should look like.

Making the EntryPoint for the injection.
Now were gonna make the entrypoint, from here you can do whatever you like to do.

First we make a new class file and name it Main (including the Capital)

Now we remove the constructor because we dont need any, the entrypoint is called as an other method.

Ok i just fast forward this part because its small and i will just post a bare bone template for the Main.cs

Code:
public class Main : VInjDn.IInjectable
{
public int OnCommand(VInjDn.LiquidCommand command)
{ return ;
} public int OnLoad()
{
Thread t = new Thread(EntryThread);
t.Start();
return ;
} public int OnUnload()
{
return ;
} private void EntryThread()
{
MessageBox.Show("Injected!");
}
}

As you can see there are 4 methods in the Main.cs

The OnCommand can be used with the IPC of vinj to receive command given by the Program.cs through VInj.

The OnLoad is where the real entrypoint is, here we create a new thread so the game wont freeze when we inject our program.

The OnUnload, well do i really have to explain this?

The EntryThread is the method thats called my the thread thats created in the OnLoad, here you can do all your work while the game is running 
I just show a messagebox so you can see that the program is injected.

Well thats all for now!

The full project can be downloaded, link is at the bottom of this post, also some credits to the guys who made VInj, i dont really know who made it but those persons will know :P

I hope you enjoyed this tutorial and maybe more are coming!

Tutorial 2: Changing values without Read/WriteMemory
Tutorial 3: Hooking functions with EasyHook
Tutorial 4: Direct3D9 Hook with EasyHook and SlimDX!

C# Self Injector into non managed process的更多相关文章

  1. ebs R12.2启动报错"failed to start a managed process after the maximum retry limit"

    启动日志: Error --> Process (index=1,uid=1739599208,pid=4479) failed to start a managed process after ...

  2. WCF学习系列一【WCF Interview Questions-Part 1 翻译系列】

    http://www.topwcftutorials.net/2012/08/wcf-faqs-part1.html WCF Interview Questions – Part 1 This WCF ...

  3. EBS R12.2.0启动时报"httpd.pid: Permission denied"错误

    启动应用服务: $ /app/oracle/apps/VIS/fs1/inst/apps/VIS_erptest/admin/scripts/adstrtal.sh apps/apps 报出如下错误: ...

  4. Learning WCF Chapter1 Creating a New Service from Scratch

    You’re about to be introduced to the WCF service. This lab isn’t your typical “Hello World”—it’s “He ...

  5. Learing WCF Chapter1 Fundamental WCF Concepts

    At its core,WCF is a development platform for service-oriented applications. As I mentioned earlier, ...

  6. 一步一个坑 - WinDbg调试.NET程序

    引言 第一次用WinDbg来排查问题,花了很多时间踩坑,记录一下希望对后面的同学有些帮助. 客户现场软件出现偶发性的界面卡死现象一直找不出原因,就想着让客户用任务管理器生成了一个dump文件发给我,我 ...

  7. 轻量级DI框架Guice使用详解

    背景 在日常写一些小工具或者小项目的时候,有依赖管理和依赖注入的需求,但是Spring(Boot)体系作为DI框架过于重量级,于是需要调研一款微型的DI框架.Guice是Google出品的一款轻量级的 ...

  8. Skywalking Swck Agent注入实现分析

    项目地址: GitHub - apache/skywalking-swck: Apache SkyWalking Cloud on Kubernetes 项目简介: A bridge project ...

  9. Linux Process VS Thread VS LWP

    Process program program==code+data; 一个进程可以对应多个程序,一个程序也可以变成多个进程.程序可以作为一种软件资源长期保存,以文件的形式存放在硬盘 process: ...

随机推荐

  1. Using Tensorflow SavedModel Format to Save and Do Predictions

    We are now trying to deploy our Deep Learning model onto Google Cloud. It is required to use Google ...

  2. Angular 输入中的禁止特定输入值--Validator 与 Directive 实现

    1 前言 最近在项目中涉及表单的情况下,需要对用户输入进行过滤,比如填写用户名的时候不可以使用空格或者特殊符号,这里有几个解决方法: 使用 Angular 的正则同步验证器 使用 RxJS对输入的值进 ...

  3. 基于Select模型的Windows TCP服务端和客户端程序示例

    最近跟着刘远东老师的<C++百万并发网络通信引擎架构与实现(服务端.客户端.跨平台)>,Bilibili视频地址为C++百万并发网络通信引擎架构与实现(服务端.客户端.跨平台),重新复习下 ...

  4. mysql 5.7 事务隔离级别

    事务的隔离级别分为:未提交读(read uncommitted).已提交读(read committed).可重复读(repeatable read).串行化(serializable). 未提交读: ...

  5. [Codeforces712D] Memory and Scores(DP+前缀和优化)(不用单调队列)

    [Codeforces712D] Memory and Scores(DP+前缀和优化)(不用单调队列) 题面 两个人玩游戏,共进行t轮,每人每轮从[-k,k]中选出一个数字,将其加到自己的总分中.已 ...

  6. BZOJ 1912(树的直径+LCA)

    题面 传送门 分析 显然,如果不加边,每条边都要走2次,总答案为2(n-1) 考虑k=1的朴素情况: 加一条边(a,b),这条边和树上a->b的路径形成一个环,这个环上的边只需要走一遍,所以答案 ...

  7. BZOJ 5450 轰炸 (强连通缩点+DAG最长路)

    <题目链接> 题目大意: 有n座城市,城市之间建立了m条有向的地下通道.你需要发起若干轮轰炸,每轮可以轰炸任意多个城市.但每次轰炸的城市中,不能存在两个不同的城市i,j满足可以通过地道从城 ...

  8. C#面试 笔试题 三

    1.传入某个属性的set方法的隐含参数的名称是什么? value,它的类型和属性所声名的类型相同.   2.C#支持多重继承么? 类之间不支持,接口之间支持.类对接口叫做实现,不叫继承. 3.C#中所 ...

  9. cronsun任务管理器部署文档

    一.cronsun介绍 1)cronsun产生的背景 大量的 crontab 任务散布在各台服务器,带来了很高的维护成本 任务没有按时执行,甚至失败了很久才发现,需要重试或排查 crontab 分散在 ...

  10. ASE Alpha Sprint - backend scrum 10

    本次scrum于2019.11.15在sky garden进行,持续30分钟 参与人: Xin Kang, Zhikai Chen, Jia Ning, Hao Wang 请假: Lihao Ran, ...