I'm trying to figure out DLL injecting so i can...

Ask questions about cheating in any games you would like. Does not need to pertain to MicroMacro.
Post Reply
Message
Author
Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

I'm trying to figure out DLL injecting so i can...

#1 Post by Exempt » Sat Nov 20, 2010 8:39 pm

EDIT: I downloaded a DLL Injector called RemoteDLL to check if it's just my injector and it's saying the DLL is load but towards the end it gets this error.
LoadLibraryA on remote process failed with error: 87

I'm trying to figure out DLL injecting so I can use it to hook a function that decrypts packets later on.

My injector says that it Injected but nothing is happening at all afterwards.

My DLL source is just to check if It did inject...

Code: Select all

#include "dll.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

DLLIMPORT void Hello ()
{
    MessageBox (0, "Hello from injected DLL!\n", "Hi", MB_ICONINFORMATION);
}

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:
            Hello();
            break;

        case DLL_PROCESS_DETACH:
            Hello();
            break;

        case DLL_THREAD_ATTACH:
            Hello();
            break;

        case DLL_THREAD_DETACH:
            Hello();
            break;

    }       /* Returns TRUE on success, FALSE on failure */

    return TRUE;
}
The header...

Code: Select all

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */

DLLIMPORT void Hello (void);
#endif /* _DLL_H_ */
This is my Injectors source. The problem may he here?

Code: Select all

#include <windows.h>
#include <tlhelp32.h>
#include <shlwapi.h>
#include <conio.h>
#include <stdio.h>
#define WIN32_LEAN_AND_MEAN
#define CREATE_THREAD_ACCESS (PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ)

BOOL Inject(DWORD pID, const char * DLL_NAME);
DWORD GetTargetThreadIDFromProcName(const char * ProcName);

int main(int argc, char * argv[])
{
    // Retrieve process ID
    DWORD pID = GetTargetThreadIDFromProcName("notepad.exe");
    // Get the dll's full path name
    char buf[MAX_PATH] = {0};
    GetFullPathName("Project1.dll", MAX_PATH, buf, NULL);
    printf(buf);
    printf("\n");

    // Inject our main dll
    if(!Inject(pID, buf))
    {
        printf("DLL Not Loaded!");
    }else{
        printf("DLL Loaded!");
    }

    _getch();
    return 0;
}

BOOL Inject(DWORD pID, const char * DLL_NAME)
{
    HANDLE Proc;
    HMODULE hLib;
    char buf[50] = {0};
    LPVOID RemoteString, LoadLibAddy;

    if(!pID)
        return false;

    Proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
    if(!Proc)    {
        sprintf(buf, "OpenProcess() failed: %d", GetLastError());
        //MessageBox(NULL, buf, "Loader", MB_OK);
        printf(buf);
        return false;
    }
    LoadLibAddy = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
    // Allocate space in the process for our DLL
    RemoteString = (LPVOID)VirtualAllocEx(Proc, NULL, strlen(DLL_NAME), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
    // Write the string name of our DLL in the memory allocated
    WriteProcessMemory(Proc, (LPVOID)RemoteString, DLL_NAME, strlen(DLL_NAME), NULL);
    // Load our DLL
    CreateRemoteThread(Proc, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddy, (LPVOID)RemoteString, NULL, NULL);
    CloseHandle(Proc);
    return true;
}

DWORD GetTargetThreadIDFromProcName(const char * ProcName)
{
    PROCESSENTRY32 pe;
    HANDLE thSnapShot;
    BOOL retval, ProcFound = false;

    thSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if(thSnapShot == INVALID_HANDLE_VALUE)
    {
        //MessageBox(NULL, "Error: Unable to create toolhelp snapshot!", "2MLoader", MB_OK);
        printf("Error: Unable to create toolhelp snapshot!");
        return false;
    }
    pe.dwSize = sizeof(PROCESSENTRY32);
    retval = Process32First(thSnapShot, &pe);
    while(retval)
    {
        if(StrStrI(pe.szExeFile, ProcName))
        {
            return pe.th32ProcessID;
        }
        retval = Process32Next(thSnapShot, &pe);
    }
    return 0;
}

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: I'm trying to figure out DLL injecting so i can...

#2 Post by Administrator » Sun Nov 21, 2010 11:55 am

Error 87 is ERROR_INVALID_PARAMETER. Not sure where this is being caused (I'll leave this for you to debug).

Lets start here: are you compiling this as C or C++? Remember, C and C++ link differently, and C++ will mangle the names. For DLL injection, you should be compiling as C.

Here's a new header for you:

Code: Select all

#ifndef _DLL_H_
#define _DLL_H_

extern "C" {
    void Hello (void);
}

#endif /* _DLL_H_ */

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: I'm trying to figure out DLL injecting so i can...

#3 Post by Exempt » Sun Nov 21, 2010 8:23 pm

I was using C++, I'll try it as a c project and see where that goes... Hm, Do i need to use c for just the DLL or the injector aswell?


EDIT: Well, I tested with my DLL Injector and it failed but the DLL works now when i use RemoteDLL to Inject it.
EDIT: I figured out how to make my inject inject it now... :)

EDIT Again: I was also wonder if you might know how I can setup either Dev C++ or VC++ 2010 Express to work with altbase.h and the other ALT libs. I've got a really nice example code sniplet for an Injector I'd like to try out but I cannot get the ALT libs to work with VC 2010 Express.

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: I'm trying to figure out DLL injecting so i can...

#4 Post by Administrator » Mon Nov 22, 2010 6:31 pm

I'm not sure what ALT lib is, to be honest. VC++ and Dev-CPP are both pretty crap. I used to use Dev-CPP before, as well, and ran into many problems with specific libraries. You should consider giving Code::Blocks a try.

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: I'm trying to figure out DLL injecting so i can...

#5 Post by Exempt » Tue Nov 23, 2010 12:38 am

I will do that, thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests