 |
Цитата: |
 |
|
|
|
|
|
|
|
а в чем собственно разница, есть куча тем инжекторов на C#, вот даже соседняя тема http://zhyk.ru/forum/showthread.php?t=151269 , а DLL так же пишите как и прогу, а после просто вызываете ее в новом потоке в нужном приложении |
|
 |
|
 |
|
Так я с начало прогу сделал) все работает, потом по убирал лишнее, сделал длл, заинжектил и ничего не изменилось) в общем я такой вопрос задал, потому, что в одном из уроков которые я смотрю и читаю, говорилось, что проблемно с длл на c#) наверное человек ошибся) в общем спасибо буду пробовать, мож я чего в коде накосячил))
вот код:
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Diagnostics;
namespace MoneyDLL
{
public class Class1
{
#region Подключенные библиотеки WINAPI
[
Flags]
public enum ProcessAccessFlags :
uint
{
All = 0x001F0FFF,
Terminate = 0x00000001,
CreateThread = 0x00000002,
VirtualMemoryOperation = 0x00000008,
VirtualMemoryRead = 0x00000010,
VirtualMemoryWrite = 0x00000020,
DuplicateHandle = 0x00000040,
CreateProcess = 0x000000080,
SetQuota = 0x00000100,
SetInformation = 0x00000200,
QueryInformation = 0x00000400,
QueryLimitedInformation = 0x00001000,
Synchronize = 0x00100000
}
[
Flags]
public enum AllocationType
{
Commit = 0x1000,
Reserve = 0x2000,
Decommit = 0x4000,
Release = 0x8000,
Reset = 0x80000,
Physical = 0x400000,
TopDown = 0x100000,
WriteWatch = 0x200000,
LargePages = 0x20000000
}
[
Flags]
public enum MemoryProtection
{
Execute = 0x10,
ExecuteRead = 0x20,
ExecuteReadWrite = 0x40,
ExecuteWriteCopy = 0x80,
NoAccess = 0x01,
ReadOnly = 0x02,
ReadWrite = 0x04,
WriteCopy = 0x08,
GuardModifierflag = 0x100,
NoCacheModifierflag = 0x200,
WriteCombineModifierflag = 0x400
}
[
Flags]
public enum FreeType
{
Decommit = 0x4000,
Release = 0x8000,
}
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(ProcessAccessFlags processAccess, bool bInheritHandle, int processId);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int nSize, out IntPtr lpNumberOfBytesWritten);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, FreeType dwFreeType);
#endregion
public int pID;
//ID процесса
public Class1()
{
GetProces(
"mb_warband");
MakeCave();
}
public void GetProces(
string name)
//Получаем значение pID
{
var pList =
Process.GetProcesses();
foreach (
var process
in pList)
{
if (process.ProcessName == name)
{
pID = process.Id;
//MessageBox.Show("Процесс найден");
break;
}
}
if (pID == 0)
{
//Console.WriteLine("Процесс не найден!");
}
}
public void MakeCave()
{
if (pID != 0)
{
//Console.WriteLine("Process Id: " + pID);
var handle = OpenProcess(
ProcessAccessFlags.All,
false, pID);
if (handle !=
IntPtr.Zero)
{
var valueon =
new byte[] { 0xC7, 0x80, 0xD0, 0x05, 0x00, 0x00, 0x40, 0x42, 0x0F, 0x00 };
// Байты команд на которые поменяются оригинальные команды
var valueoff =
new byte[] { 0x89, 0x88, 0xD0, 0x05, 0x00, 0x00 };
// Байты оригинальной команды
var caveAddress = (
Int32)(VirtualAllocEx(handle,
IntPtr.Zero, (
uint)(valueon.Length + 5),
AllocationType.Commit,
MemoryProtection.ExecuteReadWrite));
var addressFrom = 0x0058556F;
// Адрес, на котором происходит комманда
var addressTo = addressFrom - caveAddress - valueon.Length;
var buffer =
new byte[valueoff.Length];
buffer[0] = 0xE9;
var f =
BitConverter.GetBytes(caveAddress - addressFrom - 5);
Array.Copy(f, 0, buffer, 1, f.Length);
for (
var i = buffer.Length - 1; i < valueoff.Length; i++)
{
buffer[i] = 0x90;
}
var dummy = new IntPtr();
var caveBuffer =
new byte[valueon.Length + 5];
Array.Copy(valueon, caveBuffer, valueon.Length);
caveBuffer[valueon.Length] = 0xE9;
var retAddress =
BitConverter.GetBytes(addressTo);
Array.Copy(retAddress, 0, caveBuffer, valueon.Length + 1, retAddress.Length);
WriteProcessMemory(handle, (
IntPtr)caveAddress, caveBuffer, (
int)caveBuffer.Length,
out dummy);
var dummy1 =
new IntPtr();
WriteProcessMemory(handle, (
IntPtr)addressFrom, buffer, (
int)buffer.Length,
out dummy1);
//VirtualFreeEx(handle, (IntPtr)0x09E90000, 0, FreeType.Release); //Освобождает выделенную память, подумать над тем, как сделать освобождение памяти после того как отключать дллку
CloseHandle(handle);
}
}
}
}
}