C# Self Injector into non managed process
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.
string targetProcess = "BlackOps";
now we are going to get the process by name. which will be right under it.
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.
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
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的更多相关文章
- 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 ...
- WCF学习系列一【WCF Interview Questions-Part 1 翻译系列】
http://www.topwcftutorials.net/2012/08/wcf-faqs-part1.html WCF Interview Questions – Part 1 This WCF ...
- EBS R12.2.0启动时报"httpd.pid: Permission denied"错误
启动应用服务: $ /app/oracle/apps/VIS/fs1/inst/apps/VIS_erptest/admin/scripts/adstrtal.sh apps/apps 报出如下错误: ...
- 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 ...
- Learing WCF Chapter1 Fundamental WCF Concepts
At its core,WCF is a development platform for service-oriented applications. As I mentioned earlier, ...
- 一步一个坑 - WinDbg调试.NET程序
引言 第一次用WinDbg来排查问题,花了很多时间踩坑,记录一下希望对后面的同学有些帮助. 客户现场软件出现偶发性的界面卡死现象一直找不出原因,就想着让客户用任务管理器生成了一个dump文件发给我,我 ...
- 轻量级DI框架Guice使用详解
背景 在日常写一些小工具或者小项目的时候,有依赖管理和依赖注入的需求,但是Spring(Boot)体系作为DI框架过于重量级,于是需要调研一款微型的DI框架.Guice是Google出品的一款轻量级的 ...
- Skywalking Swck Agent注入实现分析
项目地址: GitHub - apache/skywalking-swck: Apache SkyWalking Cloud on Kubernetes 项目简介: A bridge project ...
- Linux Process VS Thread VS LWP
Process program program==code+data; 一个进程可以对应多个程序,一个程序也可以变成多个进程.程序可以作为一种软件资源长期保存,以文件的形式存放在硬盘 process: ...
随机推荐
- HUD-2112 HDU Today(最短路map标记)
题目链接:HUD-2112 HDU Today 思路: 1.最短路spfa模板. 2.map标记建图. 3.考虑距离为0或者-1的情况. 总结:下次map记得清空orz. AC代码: #include ...
- 泛微e-cology OA Beanshell组件远程代码执行漏洞复现CNNVD-201909-1041
靶机 影响版本 泛微e-cology<=9.0 https://github.com/jas502n/e-cology 部署 复现 /weaver/bsh.servlet.BshServlet ...
- Spring MVC处理
1.首先,用户发送请求,DispatcherServlet会拦截请求,但DispatcherServlet收到请求后不进行处理,而对URL进行解析得到相应的URI(资源标识符). 2.Dispatch ...
- 应该用forEach改变数组的值吗? 原生JS forEach()和map()遍历的异同点
应该用forEach改变数组的值吗? https://segmentfault.com/q/1010000013170900?utm_source=index-hottest 由于js中的数组是引用类 ...
- ubuntu下mysql定时备份
一:ubuntu下自动备份mysql数据库 转载来源:https://jingyan.baidu.com/article/ab0b563097cabac15afa7dbc.html 1.创建保存备份文 ...
- Python入门习题2.蟒蛇绘制(turtle库)
例2.调用turtle库中的若干函数来绘制蟒蛇,要求:(1)主体窗口宽650像素,高度350像素,窗口左侧与屏幕左侧像素距离200,窗口顶部与屏幕顶部像素距离200:(2)画笔落点在原点反向前进250 ...
- 虚拟机VMware,安装中标麒麟系统,64位的,版本6.0,并安装qt
为了使用qt开发,安装中标麒麟系统. 虚拟机中安装,本来安装的是32位麒麟系统,结果发现qt无法安装(官网提供的是64位的run程序). qt安装的是qt-opensource-linux-x64-5 ...
- python学习第二十天文件操作方法
字符有的存储在内存,有的存储在硬盘,文件也有增删改查的操作方法,open()方法,read()方法,readline()方法,close()文件关闭,write()写的方法,seek() 指针移动方法 ...
- smbstatus - 报告当前 samba 的联接状态
总览 smbstatus [-b] [-d] [-L] [-p] [-S] [-s configuration file] [-u username] 描述 此程序是 samba 套件的一部分. sm ...
- ubuntu-12.04.5-desktop-amd64 安装vmwaretools
百度文库地址:https://wenku.baidu.com/view/7c1cd211a216147917112820.html 注意:一定要把此文档中的vmwaretools 版本号换成你自己下载 ...