EvilZone

Programming and Scripting => C - C++ => : bubzuru September 22, 2012, 06:59:39 PM

: (SOLVED)Dll Help
: bubzuru September 22, 2012, 06:59:39 PM
im trying to write a dll that kills the process that loads it. (seems stupid but i have my reasons)

: (c)
#include <windows.h>
#include <stdio.h>

BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                       DWORD reason        /* Reason this function is being called. */ ,
                       LPVOID reserved     /* Not used. */ )
{
    switch (reason)
    {
      case DLL_PROCESS_ATTACH:     
        OutputDebugString("Hello From The Dll");
        ExitProcess(-69);   
        break;
      case DLL_PROCESS_DETACH:
        ExitProcess(-69);
        break;
      case DLL_THREAD_ATTACH:
        ExitProcess(-69);
        break;
      case DLL_THREAD_DETACH:
        ExitProcess(-69);
        break;
    }
    /* Returns TRUE on success, FALSE on failure */
    return TRUE;
}

the person that sent me the code also sent a compiled dll (that works) but
when i compile the code then load the dll it doesnt work

here is the program im using to load the dll
: (c)
#include <cstdlib>
#include <iostream>
#include <windows.h>

using namespace std;

int main(int argc, char *argv[])
{
    char* DllName = "TestDll.dll"; /* Name of the dll to be loaded */
   
    /* Load the dll */
    printf("trying to load %s \n", DllName);
    HMODULE EmployeDll = LoadLibrary(DllName); 
   
    /* Give some output */
    if(EmployeDll != 0)
    {
       printf("%s is loaded into memory \n\n", DllName);
      //FreeLibrary(EmployeDll); /* Unload the dll from memory */
    }
    else
      printf("error loading %s into memory \n\n", DllName);
     
    /* And then say goodbye */
    system("PAUSE");
    return EXIT_SUCCESS;
}

any ideas why the code is not working ?
: Re: Dll Help
: bubzuru September 23, 2012, 12:44:07 AM
has anyone tryd compiling\testing this

its really strange that it wont work for me but works for him. what is wrong ?
: Re: (SOLVED)Dll Help
: bubzuru September 23, 2012, 01:45:33 AM
ok DevC++ sucks ass. problem was DllMain isnt actualy the real entry point in a DevC++ app so it never fires (strange compiler) i switched to a c project and it works now

you guys will like what im doing will post a vid soon
: Re: (SOLVED)Dll Help
: Daemon September 23, 2012, 02:51:14 AM
triple posts bubzuru...you know better than that :P

but anyways, i was going to make this my next priority but since you've swapped to a C project I'll tone it down a bit. plus im waiting for a question to get answered.... anyways, grats on getting it working
: Re: (SOLVED)Dll Help
: bubzuru September 23, 2012, 02:50:08 PM
triple posts bubzuru...you know better than that :P

but anyways, i was going to make this my next priority but since you've swapped to a C project I'll tone it down a bit. plus im waiting for a question to get answered.... anyways, grats on getting it working


i love to double post :) xx

the 3rd post was just to give an answer.  and the answer is, the compiler is shit.
so anyone having the same problem , switch compiler or make it a C project if you dont need any C++ functionality (i dont for this project)

now we all know that calling Shell32 functions or killing the host process in DllMain is obviously non-kosha. but hey if you need to in a c++ dll. dont use DevC++

hope this will help some people with the same problem because i searchd google and didnt find an answer (i had to look at the asm in a debugger) maybe we should give the thread a better title