Dll Ejection menu

User Tag List

Thread: Dll Ejection

Results 1 to 5 of 5
  1. #1
    Sel3n's Avatar Member
    Reputation
    10
    Join Date
    Jul 2009
    Posts
    115
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dll Ejection

    Hi,

    I'm trying to write a dll injector/ejector.

    My inject code work fully but my eject code notify my dll is ejected but isn't ejected...

    It is my eject code

    Code:
    private static bool EjectModule()
            {
                IntPtr hProcess = new IntPtr(0);
                IntPtr hModule = new IntPtr(0);
                int LenWrite = DllName.Length + 1;
    
                hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, (uint)loadedPID);
    
                try
                {
                    IntPtr ModDll32 = GetModuleHandle("kernel32.dll");
                    IntPtr MyModDll = GetModuleHandle(nameofdll);
                    if (ModDll32 != null)
                    {
                        hModule = VirtualAllocEx(hProcess, IntPtr.Zero, (UIntPtr)LenWrite, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
                        if (MyModDll != null && hModule != null)
                        {
                            IntPtr hDllThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, GetProcAddress(GetModuleHandle("kernel32.dll"), "FreeLibrary"), hModule, 0, 0);
                            if (hDllThread != null)
                            {
                                if (WaitForSingleObject(hDllThread, INFINITE) != WAIT_FAILED)
                                {
                                    CloseHandle(hDllThread);
                                    CloseHandle(hProcess);
                                    Console.WriteLine("Dll ejected succesfully!");
                                    //loadedPID = 0;
                                    Console.WriteLine("Press any key to continue...");
                                    Console.ReadKey();
                                    return true;
                                }
                                else
                                {
                                    CloseHandle(hDllThread);
                                    throw new Exception("unknow error =S");
                                }
                            }
                            else throw new Exception("CreateRemoteThread failed"); 
                        }
                        else throw new Exception("Can't found injected dll, or can't allocate memory");
                    }
                    else throw new Exception("Can't found kernel32.dll");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failure on trying eject module");
                    Console.WriteLine("Exception :");
                    Console.WriteLine(e.ToString());
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();
                    return false;
                }
    
                CloseHandle(hProcess);
            }
    I thinks this code fail at
    Code:
    IntPtr hDllThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, GetProcAddress(GetModuleHandle("kernel32.dll"), "FreeLibrary"), hModule, 0, 0);
    Thanks in advance.

    Dll Ejection
  2. #2
    insignia96's Avatar Banned
    Reputation
    33
    Join Date
    Oct 2008
    Posts
    304
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wtf is dll ejection?

  3. #3
    Sel3n's Avatar Member
    Reputation
    10
    Join Date
    Jul 2009
    Posts
    115
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The opposite of dll injection, no?

  4. #4
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your code makes no sense.

    You can't just call GetModuleHandle in your loader with the name of the DLL you've injected and expect it to return a valid handle...

    You need to enumerate the modules REMOTELY with ToolHelp32Snapshot, or, save the value returned by LoadLibrary in your injection code. Though, that only works on x86 because thread exit codes are stored as DWORDs and on x64 you need a 64-bit address, so the top half may be truncated.

    Hence, if you want to do it properly you must enumerate the modules remotely to get the address, then call FreeLibrary on the base of the module once you've found it.

  5. #5
    Sel3n's Avatar Member
    Reputation
    10
    Join Date
    Jul 2009
    Posts
    115
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Cypher, I didn't know "ToolHelp32Snapshot", but it's very usefull (MSDN pawaa =)


    Thanks!

Similar Threads

  1. [DLL] New PvpSystem
    By Gastricpenguin in forum World of Warcraft Emulator Servers
    Replies: 63
    Last Post: 03-15-2008, 05:22 AM
  2. Replies: 6
    Last Post: 10-05-2007, 02:59 PM
  3. Using DLL's to inject values without CE.
    By Matsy in forum World of Warcraft Bots and Programs
    Replies: 7
    Last Post: 06-29-2007, 02:26 PM
  4. so whats scan.dll?
    By Grass in forum World of Warcraft General
    Replies: 1
    Last Post: 02-27-2007, 07:14 AM
  5. .DLL Injector & Language Hack
    By tehshadow in forum World of Warcraft Bots and Programs
    Replies: 18
    Last Post: 11-07-2006, 10:38 PM
All times are GMT -5. The time now is 03:33 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search