Solved Can't inject .dll twice??

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

heanz

Newbie
Full Member
Mar 28, 2015
7
97
1
Hey guys. I made a simple internal test.dll that writes text to the csgo console, it's working fine.
But only once.

I can't run this code a second time by injecting the .dll once again.
Only if I close and re-open csgo.exe, of course.

Is there any way, to cleanly kill the .dll so that you could sucessfully reattach it again?
Reason: It is already annyoing me to reopen the game every time i recompile my internal hack! :D

I have tried many different things already:

1. Trying to detach with Extreme Injector

2. Doing the injection by myself by calling CreateRemoteThread()

3. Cleaning up the VirtualAllocEx() afterwards, with VirtualFreeEx()

4. Trying to put a Beep() at DLL_PROCESS_DETACH, but never heard it

5. Cleaning up my new created dll thread with FreeLibraryAndExitThread(handleToDllThread, 1) in the last line of code

If you need any sources, please tell.
Driving me nuts! Thanks for your time.
 
  • Like
Reactions: WiinnerMLG

heanz

Newbie
Full Member
Mar 28, 2015
7
97
1
Got it to work:

C++:
DWORD __stdcall EjectThread( LPVOID lpParameter )
{
        Sleep( 100 );

        FreeLibraryAndExitThread( hLocalModule, 0 );

        return 0;
}


//Make sure this the last thing you do in your dll. In mycase:

DWORD __stdcall Init( LPVOID lpParameter )
{
        //Do your thing -> write to console


        CreateThread( 0, 0, EjectThread, 0, 0, 0 );
        return 0;
}
 
  • Love
Reactions: WiinnerMLG

Solaire

Respected Hacker
Dank Tier VIP
Dec 15, 2013
1,051
16,353
62
Hey guys. I made a simple internal test.dll that writes text to the csgo console, it's working fine.
But only once.

I can't run this code a second time by injecting the .dll once again.
Only if I close and re-open csgo.exe, of course.

Is there any way, to cleanly kill the .dll so that you could sucessfully reattach it again?
Reason: It is already annyoing me to reopen the game every time i recompile my internal hack! :D

I have tried many different things already:

1. Trying to detach with Extreme Injector

2. Doing the injection by myself by calling CreateRemoteThread()

3. Cleaning up the VirtualAllocEx() afterwards, with VirtualFreeEx()

4. Trying to put a Beep() at DLL_PROCESS_DETACH, but never heard it

5. Cleaning up my new created dll thread with FreeLibraryAndExitThread(handleToDllThread, 1) in the last line of code

If you need any sources, please tell.
Driving me nuts! Thanks for your time.
Could you share your DLLMain please? Might be good to see what calls you make there.
 

heanz

Newbie
Full Member
Mar 28, 2015
7
97
1
Could you share your DLLMain please? Might be good to see what calls you make there.
Of course. DLLMain merely consists of:

C++:
case DLL_PROCESS_ATTACH:
		CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Init, NULL, 0, NULL);
This is my whole injector.

When I use like "Extreme Injector" I also can't inject twice, except i change the Mapping Type!

When using ProcessExplorer it seems the .dll residdes there forever.
 
Last edited:

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,092
78,998
2,372
How does Slrgrbrgr.dll modify the game? Do you unhook and end your other threads before ejecting your .dll? Have you tried the "Unload Module" button in extreme injector, that works for me perfectly I wish I had the source code for that function.
 

till0sch

Respected Hacker
Dank Tier VIP
Dank Tier Donator
Oct 14, 2012
1,104
12,593
51
Maybe the injector has still opened the file?
If you want to know, get Unlocker and check that. Also should you validate whether your DLL does really get freed.

DLLMain doesn't get executed if you don't free the library before.. Which explains your Beep().


Another idea: Winject is an injector which also has the capability of ejecting instead of injecting modules. See if then your Beep() gets called.

Just make sure to make the main exe not crash through not removed hooks :)
 

Solaire

Respected Hacker
Dank Tier VIP
Dec 15, 2013
1,051
16,353
62
Unloading DLL's is not hard.

C++:
DWORD WINAPI WisrdHax(HINSTANCE hModule){
    do{
        if (GetAsyncKeyState(VK_NUMPAD9)){
            break;
        }
    } while (1);

    // Remove FreeConsole if you don't allocate one
    FreeConsole();
    FreeLibraryAndExitThread(hModule, NULL);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){
    HANDLE ourThread;

    switch (fdwReason){
    case DLL_PROCESS_ATTACH:
        ourThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)WisrdHax, hinstDLL, 0, 0);

        // You can get rid of the stuff after this if you don't want a console window
        AllocConsole();
        freopen("CONIN$", "r", stdin);
        freopen("CONOUT$", "w", stdout);
        freopen("CONOUT$", "w", stderr);
        break;

    case DLL_THREAD_DETACH:
        break;
    }

    return TRUE;
}
If you aren't using CRT injection, this may not work. I don't fully know how other injection types may influence the ability of the FreeLibraryAndExitThread call.
 
Last edited:

Solaire

Respected Hacker
Dank Tier VIP
Dec 15, 2013
1,051
16,353
62
@Krampus I thought AttachConsole expected a process ID not the dwReason ?!


:wat:
That's a really good point you bring up, I've just now realized. I believe I either got that as an example on the internet, or from a long time ago through Spock. As to why it works... I'm doing some deeper research atm to find out.

EDIT:
Solved, thanks Till! AllocConsole is what brings the console up. Attach console threw the error ERROR_ACCESS_DENIED. Fixing the source above.
 
Last edited:
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods