Results 1 to 10 of 31

Thread: Libcod for windows

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    I don't know, got another idea, which is working fine now

    Modified your InjectDLL source, to keep it constantly watching the process list for CoD2 and then waiting till the server is closing. After that, it searches again for the process name. Example:

    InjectLibcod.bat
    Code:
    start InjectDLL.exe SERVER.exe libcod2_1_3.dll
    The new source of it:
    PHP Code:
    #include <stdio.h>
    #define _WIN32_WINNT 0x500
    #include <windows.h>
    #include <tlhelp32.h>

    void EnableDebugPriv();
    void CALLBACK WaitOrTimerCallback(PVOID lpParameterBOOLEAN TimerOrWaitFired);
    int GetProcessByName(char *nameHANDLE *outProcessHandleint *outProcessID);
    void InjectDLL(HANDLE hProcesschar *name);
    void WaitForProcessAndInjectDLL(char *name_processchar *name_dll);
    void LoopInjecting();

    void EnableDebugPriv() {
        
    HANDLE hToken;
        
    LUID luid;
        
    TOKEN_PRIVILEGES tkp;
        
    OpenProcessTokenGetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES TOKEN_QUERY, &hToken );
        
    LookupPrivilegeValueNULLSE_DEBUG_NAME, &luid );
        
    tkp.PrivilegeCount 1;
        
    tkp.Privileges[0].Luid luid;
        
    tkp.Privileges[0].Attributes SE_PRIVILEGE_ENABLED;
        
    AdjustTokenPrivilegeshTokenfalse, &tkpsizeoftkp ), NULLNULL );
        
    CloseHandlehToken );
    }

    void CALLBACK WaitOrTimerCallback(PVOID lpParameterBOOLEAN TimerOrWaitFired) {
        
    //MessageBox(0, "The process has exited.", "INFO", MB_OK);
        
    LoopInjecting();
    }

    int GetProcessByName(char *nameHANDLE *outProcessHandleint *outProcessID) {
        
    PROCESSENTRY32 entry;
        
    entry.dwSize sizeofPROCESSENTRY32 );
        
    HANDLE snapshot CreateToolhelp32SnapshotTH32CS_SNAPPROCESSNULL );
        
    HANDLE hProcess;
        if ( 
    Process32Firstsnapshot, &entry ) != TRUE )
            return 
    0;
        while (
    Process32Nextsnapshot, &entry ) == TRUE) {
            if (
    stricmpentry.szExeFilename) != 0)
                continue;
            
    // printf("Found: %s\n", entry.szExeFile);
            // PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION | PROCESS_VM_WRITE
            
    *outProcessHandle OpenProcess(PROCESS_ALL_ACCESSFALSEentry.th32ProcessID);
            *
    outProcessID entry.th32ProcessID;
            return 
    1;
        }
        
    CloseHandlesnapshot );
        return 
    0;
    }

    void InjectDLL(HANDLE hProcesschar *name) {
        
    char dirPath[MAX_PATH];
        
    char fullPath[MAX_PATH];
        
    GetCurrentDirectoryMAX_PATHdirPath );
        
    snprintf fullPathMAX_PATH"%s\\%s"dirPathname);
        
    printf("Injecting: %s\n"fullPath);
        
    LPVOID libAddr = (LPVOID)GetProcAddressGetModuleHandle"kernel32.dll" ), "LoadLibraryA" );
        
    LPVOID llParam = (LPVOID)VirtualAllocExhProcessNULLstrlenfullPath ) + 1MEM_RESERVE MEM_COMMITPAGE_READWRITE );
        
    printf("libAddr=%.8p llParam=%.8p\n"libAddrllParam);
        
    bool written WriteProcessMemoryhProcessllParamfullPathstrlenfullPath ) + 1NULL );
        
    HANDLE threadID CreateRemoteThreadhProcessNULLNULL, (LPTHREAD_START_ROUTINE)libAddrllParamNULLNULL );
        
    //CloseHandle( hProcess );
        
    printf("Finished injecting DLL success=%d thread #%d\n"writtenthreadID);
    }

    void WaitForProcessAndInjectDLL(char *name_processchar *name_dll) {
        
    printf("WaitForProcessAndInjectDLL(process=%s, dll=%s);\n"name_processname_dll);
        
    HANDLE hProcess;
        
    int processID;
        while (
    1) {
            
    int ret GetProcessByName(name_process, &hProcess, &processID);
            if (
    ret == 0) {
                
    printf(".");
                
    Sleep(1000);
                continue;
            }
            
    printf("\nprocessID=%d\n"processID);
            
    InjectDLL(hProcessname_dll);
            
    HANDLE hNewHandle;
            
    RegisterWaitForSingleObject(&hNewHandlehProcessWaitOrTimerCallbackNULLINFINITEWT_EXECUTEONLYONCE);
            break;
        }
    }

    int argc;
    char **argv;
    void LoopInjecting() {
        
    // CoD2MP_s.exe
        
    WaitForProcessAndInjectDLL(argv[1], argv[2]); // process, dll
    }
    int main(int cchar **v) {
        
    argc c;
        
    argv v;
        if (
    argc 2) {
            
    printf("Please provide process-name and dll-name!\nExample: InjectDLL SERVER.exe libcod2_1_3.dll");
            
    getchar();
            return 
    1;
        }
        
    EnableDebugPriv();
        
    LoopInjecting();
        
    getchar();
        return 
    0;

    Download: libcod_win.zip

    Click image for larger version. 

Name:	libcod_win.jpg 
Views:	362 
Size:	85.6 KB 
ID:	744
    timescale 0.01

  2. The Following 3 Users Say Thank You to kung foo man For This Useful Post:

    guiismiti (5th April 2017),Mitch (3rd September 2014),Ni3ls (2nd September 2014)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •