Thread: C# Injector

Results 1 to 4 of 4
  1. #1
    mwxplayer's Avatar
    Join Date
    Aug 2012
    Gender
    male
    Location
    hax
    Posts
    584
    Reputation
    10
    Thanks
    2,666
    My Mood
    Doh

    C# Injector

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    
    
    namespace TeknoMW3_MultiHack_Loader
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            [DllImport("kernel32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            public static extern int ReadProcessMemory(int hProcess, int lpBaseAddress, string lpBuffer, int nSize, ref int lpNumberOfBytesWritten);
    
            [DllImport("kernel32", EntryPoint = "LoadLibraryA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            public static extern int LoadLibrary(string lpLibFileName);
    
            [DllImport("kernel32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            public static extern int WriteProcessMemory(System.IntPtr hProcess, int lpBaseAddress, string lpBuffer, int nSize, int lpNumberOfBytesWritten);
    
            [DllImport("kernel32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            public static extern int VirtualAllocEx(System.IntPtr hProcess, int lpAddress, int dwSize, int flAllocationType, int flProtect);
    
            [DllImport("kernel32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            public static extern int GetProcAddress(int hModule, string lpProcName);
    
            [DllImport("kernel32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            public static extern int CreateRemoteThread(System.IntPtr hProcess, int lpThreadAttributes, int dwStackSize, int lpStartAddress, int lpParameter, int dwCreationFlags, int lpThreadId);
    
            [DllImport("Kernel32", EntryPoint = "GetModuleHandleA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            private static extern int GetModuleHandle(string lpModuleName);
    
            [DllImport("kernel32.dll")]
            public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
    
            [DllImport("kernel32", EntryPoint = "CloseHandle")]
            private static extern int CloseHandle(System.IntPtr hObject);
    
            [DllImport("user32", EntryPoint = "FindWindowA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            private static extern int FindWindow(string lpClassName, string lpWindowName);
    
    
    
            void Inject()
            {
    
               
                System.IntPtr TargetProcessHandle;
                int TargetBufferSize;
                String pszLibFileRemote;
                int pfnStartAddr;
                Process[] TargetProcess = Process.GetProcessesByName("iw5mp");
                TargetProcessHandle = OpenProcess(0x1F0FFF, false, TargetProcess[0].Id);
                pszLibFileRemote = Application.StartupPath + ("\\TeknoMW3 MultiHack.dll");
                pfnStartAddr = GetProcAddress(GetModuleHandle("Kernel32.dll"), "LoadLibraryA");
                TargetBufferSize = 1 + pszLibFileRemote.Length;
                int Rtn;
                int LoadLibParamAdr;
                LoadLibParamAdr = VirtualAllocEx(TargetProcessHandle, 0, TargetBufferSize, 4096, 4);
                Rtn = WriteProcessMemory(TargetProcessHandle, LoadLibParamAdr, pszLibFileRemote, TargetBufferSize, 0);
                CreateRemoteThread(TargetProcessHandle, 0, 0, pfnStartAddr, LoadLibParamAdr, 0, 0);
                CloseHandle(TargetProcessHandle);
            }
            private void button1_Click(object sender, EventArgs e)
            {
                
            }
    
            private void label1_Click(object sender, EventArgs e)
            {
    
            }
    
          
            private void Form1_Load(object sender, EventArgs e)
            {
                timer1.Start();
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                Process[] TargetProcess = Process.GetProcessesByName("iw5mp");
              
    
                
                if (TargetProcess.Length == 0)
                { }
                else
                {
                    label2.Text = "Game Found";
                    Inject();
                    timer1.Stop();
                    this.Close();
                    
                }
            }
        }
    }
    the Problem is that it won't Inject i dunno If I'm doing anything wrong..
    .NET Frame Target : 3.5

  2. #2
    Geomatrical the 7th's Avatar
    Join Date
    Oct 2012
    Gender
    male
    Location
    ?
    Posts
    669
    Reputation
    17
    Thanks
    768
    Code:
    private bool InjectDll(int ProcessID, string DLLLocation)
    {
    	if (!System****.File.Exists(DLLLocation))
    		return false;
    	if (IntPtr.Size == 8)
    		return false;
    	int HProcess = OpenProcess(0x1f0fff, 1, ProcessID);
    	if (HProcess == 0)
    		return Die();
    	byte[] DLLBytes = System.Text.Encoding.ASCII.GetBytes(DLLLocation + ControlChars.NullChar);
    	int PathLocation = VirtualAllocEx(HProcess, 0, DLLBytes.Length, 0x1000, 0x4);
    	if (PathLocation == null)
    		return Die(HProcess);
    	int WPM = WriteProcessMemory(HProcess, PathLocation, DLLBytes, DLLBytes.Length, 0);
    	if (WPM == 0)
    		return Die(HProcess);
    	int KernelMod = GetModuleHandle("kernel32.dll");
    	int LoadLibraryAddress = GetProcAddress(KernelMod, "LoadLibraryA");
    	if (LoadLibraryAddress == 0)
    		return Die(HProcess);
    	int ProcessThread = CreateRemoteThread(HProcess, 0, 0, LoadLibraryAddress, PathLocation, 0, 0);
    	if (ProcessThread == 0)
    		return Die(HProcess);
    	int WaitValue = WaitForSingleObject(ProcessThread, 5000);
    	if (!(WaitValue == 0x0u))
    		return Die(HProcess, ProcessThread);
    	CloseHandle(ProcessThread);
    	CloseHandle(HProcess);
    	return true;
    }
    Last edited by Geomatrical the 7th; 01-05-2013 at 10:41 AM.

  3. The Following User Says Thank You to Geomatrical the 7th For This Useful Post:

    mwxplayer (01-05-2013)

  4. #3
    Geomatrical the 7th's Avatar
    Join Date
    Oct 2012
    Gender
    male
    Location
    ?
    Posts
    669
    Reputation
    17
    Thanks
    768
    Quote Originally Posted by Geomatrical the 7th View Post
    return Die();
    Also add this little function before that.

    Code:
    private bool Die(int HProcess = null, int LibraryThread = null)
    {
    	if (!(HProcess == null))
    		CloseHandle(HProcess);
    	if (!(LibraryThread == null))
    		CloseHandle(LibraryThread);
    	return false;
    }
    @ @mwxplayer

  5. The Following User Says Thank You to Geomatrical the 7th For This Useful Post:

    mwxplayer (01-05-2013)

  6. #4
    Jorndel's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    Norway
    Posts
    8,675
    Reputation
    905
    Thanks
    18,544
    My Mood
    Angelic
    The snippet provided appears to be converted from VB to C#:

    Updated with Syntax:
    http://pastebin.com/MKmDrUtB

    Original:
    #Region "Injectoc" #Region "Imports" Imports System.Runtime.InteropServices - Pastebin.com

    In that case, you can use this for understanding. (Since it's documented very "well" )
    Last edited by Jorndel; 01-05-2013 at 11:44 AM.

     
    Contributor 01.27.2012 - N/A
    Donator 07-17-2012 - Current
    Editor/Manager 12-16-12 - N/A
    Minion 01-10-2013 - 07.17.13
    Former Staff 09-20-2012 - 01-10-2013 / 07-17-2013 - Current
    Cocksucker 20-04-2013 - N/A

  7. The Following User Says Thank You to Jorndel For This Useful Post:

    mwxplayer (01-06-2013)

Similar Threads

  1. injector tut
    By mpghhackersrock123 in forum Hack Requests
    Replies: 1
    Last Post: 03-20-2013, 06:20 PM
  2. .dll injector
    By EleMentX in forum Gunz General
    Replies: 31
    Last Post: 07-08-2010, 11:44 AM
  3. WallHack - Omega Injector
    By Cr4azyPh4ntom in forum Soldier Front Hacks
    Replies: 40
    Last Post: 02-19-2009, 08:19 AM
  4. dll injector
    By ZeaS in forum Visual Basic Programming
    Replies: 18
    Last Post: 10-03-2007, 08:05 AM