Pregunta

so am trying to make an injector to inject my dll that's uses Detours to hook a game client , it's simple , but there is a problem I don't know what's is wrong it works fine on Windows Vista+ but not working on XP... here is my codes

//the injector
#ifndef INJECTOR_H_INCLUDED
#define INJECTOR_H_INCLUDED

#include <windows.h>
class Injector
{
private:
    STARTUPINFOA *Startup;
    PROCESS_INFORMATION *Process;
    char *Directory;

    BOOL Start(char *Application);
public:
    Injector(char *Directory);
    ~Injector(void);

    BOOL Attach(char *Application, char *Dll);
};

#endif // INJECTOR_H_INCLUDED


#include "Injector.h"
#include <string>
#include <cstdio>
using namespace std;

Injector::Injector(char *Directory)
{
    int Size = strlen(Directory) + 1;
    Directory = new char[Size];
    MoveMemory(Directory, Directory, Size);

    Startup = new STARTUPINFOA();
    Process = new PROCESS_INFORMATION();
}


Injector::~Injector(void)
{
    delete[] Directory;
    delete Startup;
    delete Process;
}

BOOL Injector::Start(char *Application)
{
    char CommandLine[256];
    sprintf(CommandLine, "%s\\%s blacknull", Directory, Application);
    return CreateProcessA(NULL, CommandLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED, NULL, Directory, Startup, Process);
}
BOOL Injector::Attach(char *Application, char *Dll)
{
    if(Start(Application))
    {
        HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Process->dwProcessId);
        if(hProcess != NULL)
        {
            int Length = strlen(Dll) + 1;

            LPVOID RemoteMemory = VirtualAllocEx(hProcess, NULL, Length, MEM_COMMIT, PAGE_READWRITE);
            if(RemoteMemory != NULL)
            {
                if(WriteProcessMemory(hProcess, RemoteMemory, Dll, Length, NULL))
                {
                    FARPROC hLoadLibrary = GetProcAddress(GetModuleHandleA("Kernel32"), "LoadLibraryA");

                    HANDLE hThread = CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)hLoadLibrary, RemoteMemory, NULL, NULL);
                    if(hThread != NULL)
                    {
                        WaitForSingleObject(hThread, 5000);
                        VirtualFreeEx(hProcess, RemoteMemory, 0, MEM_RELEASE);
                        CloseHandle(hProcess);
                        ResumeThread(Process->hThread);
                        return TRUE;
                    }
                }
                VirtualFreeEx(hProcess, RemoteMemory, 0, MEM_RELEASE);
            }
            CloseHandle(hProcess);
        }
        ResumeThread(Process->hThread);
        return FALSE;
    }
    else
    {
        printf("CreateProcessA failed with the following error: %d\n", GetLastError());
        return FALSE;
    }
    return FALSE;
}

//the main dll with Detours
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "detours.h"
#include <WinSock2.h>
#include <shellapi.h> 

HINSTANCE (WINAPI *OriginalShell)(HWND hWnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, int nShowCmd) = ShellExecuteA;

HINSTANCE WINAPI DetouredShell(HWND hWnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, int nShowCmd)
{
    if(strcmp("http://co.91.com/signout/", lpFile) == 0)
    {
        lpFile = "http://www.google.com";
    }

    return OriginalShell(hWnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd);
} 


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
            DetourTransactionBegin();
            DetourUpdateThread(GetCurrentThread());
            DetourAttach(&(PVOID&)OriginalShell, DetouredShell);
            DetourTransactionCommit();
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

both built with VC++2010 , so its supposed to work but on Windows XP it launches the game but the dll not being injected, Idk what's wrong here!!

EDIT: well I believe it's because my XP is missing MSVCR100D.DLL , is there a way to make my dll not depend on it?

¿Fue útil?

Solución

To make your program not depending on msvcr100.dll/msvcr100d.dll open Project Properties->(Configuration Properties)->General->Use of MFC-> select "Use MFC in a Static Library". Plus set the configuration to "Release". It is "Debug" by default. Now build it again.

Or you can leave it "Shared" as by default, just change configuration to "Release" and add msvcr100.dll to your program. (Or install Visual C++ 2010 Redistributable package). Release build takes less MB.

Free Visual C++ edition is unable to build static MFC. Only paid or warez version of Visual Studio Professional or above.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top