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. Adam Optimization Algorithm

    曾经多次看到别人说起,在选择Optimizer的时候默认就选Adam.这样的建议其实比较尴尬,如果有一点科学精神的人,其实就会想问为什么,并搞懂这一切,这也是我开这个Optimizer系列的原因之一. ...

  2. JavaScript 高级程序设计(第3版)第一章 (js简介)

    1.我比js早一年 2.web浏览器是ECMAScript实现的宿主环境之一. 其它实现ECMAScript的宿主环境包括Node和Adobe Flash 3.ECMAScript主要规定js的组成部 ...

  3. jQuery基础--音乐视频操作

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. mysql优化工具(索引优化)

    mysql优化工具 1.pt-duplicate-key-checker(检查数据库的重复索引),这款工具可以帮助我们找到重复的索引并且还会给你删除重复索引的建议语句,非常好用. 2.

  5. tensorflow学习框架(炼数成金网络版学习记录)

    chapter1 #变量 import tensorflow as tf x = tf.Variable([1,2]) a = tf.constant([3,3]) #增加一个减法op sub = t ...

  6. [暑假集训Day1T1]黑暗城堡

    因为D[i]表示i号节点到1号节点的最短路径,所以可以先以1为源点跑一边SPFA,预处理出每个点到1号节点的最短路.之后开始考虑所谓的“最短路径生成树”,在这棵生成树中有以下性质:当fa[i]==no ...

  7. Java 8实战之读书笔记五:超越Java 8

    四.超越Java 8 第13章 函数式的思考 下面是这一章中你应该掌握的关键概念.      从长远看,减少共享的可变数据结构能帮助你降低维护和调试程序的代价.      函数式编程支持无副作用的 ...

  8. this的指向问题 call apply bind 中的this

    在函数中this指向谁:     函数中的this指向谁,是由函数被调用的那一刻就确定下来的 平时确定一个函数中的this是谁,我们需要通过调用模式来确定 1. 函数调用模式 this ---> ...

  9. RabbitMQ ——简单队列

    一 .概述 我们不从开始就讲述基本的概念,尤其是在Rabbitmq之中有些概念确实比较难以理解,我们首先做的就是将光放提供的消息模型 进行实现,然后再总结一下Rabbitmq之中的基本概念. 二 .基 ...

  10. 330-支持PXIE带FMC接口的Xilinx FPGA XC7K325T PCIeX8 接口卡平台

    支持PXIE带FMC接口的Xilinx FPGA XC7K325T PCIeX8 接口卡平台 一.板卡概述     本板卡基于Xilinx公司的FPGAXC7K325T-2FFG900 芯片,pin_ ...