Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: Libcod for windows

  1. #1
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts

    Libcod for windows

    I am gonna try to port libcod to windows. In the newer windows it is made harder to inject DLL's. But it is possible.

    I tested the solution below and it works on windows 8.1.
    https://github.com/stephenfewer/ReflectiveDLLInjection
    Code:
    Usage: inject.exe [pid] [dll_file]
    My first goal will be overriding the closer function.

    Edit: added latest version as attachment
    Edit 2: if you are getting a unknown function error, it is caused because the dll is linked to mysql. (copy libmysql.dll from lib/ with your libcod dll)
    http://killtube.org/showthread.php?1...ll=1#post10967

    Edit 3: It might be that pushing a vector or entity doesn't work. (unverified)

    Latest source code: https://github.com/M-itch/libcod_win
    CoD2 1.0: http://killtube.org/showthread.php?1...ll=1#post11117
    CoD2 1.3: http://killtube.org/showthread.php?1...ull=1#post8864
    Attached Files Attached Files
    Last edited by Mitch; 9th January 2015 at 21:27. Reason: Added GitHub link

  2. The Following 6 Users Say Thank You to Mitch For This Useful Post:

    guiismiti (11th September 2014),Jeplaa (19th December 2013),kung foo man (19th December 2013),Leal (19th December 2013),RobsoN (19th December 2013),smect@ (5th February 2014)

  3. #2
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Closer isn't working yet but I can now easily inject the DLL.

    Inject console application (needs to be run as administrator)
    PHP Code:
    #include <stdio.h>
    #include <windows.h>
    #include <tlhelp32.h>

    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 );
    }

    int mainintchar *[] ) {
        
    PROCESSENTRY32 entry;
        
    entry.dwSize sizeofPROCESSENTRY32 );

        
    HANDLE snapshot CreateToolhelp32SnapshotTH32CS_SNAPPROCESSNULL );

        if ( 
    Process32Firstsnapshot, &entry ) == TRUE ) {
            while ( 
    Process32Nextsnapshot, &entry ) == TRUE ) {
                if ( 
    stricmpentry.szExeFile"CoD2MP_s.exe" ) == ) {
                    
    EnableDebugPriv();

                    
    char dirPath[MAX_PATH];
                    
    char fullPath[MAX_PATH];

                    
    GetCurrentDirectoryMAX_PATHdirPath );

                    
    snprintf fullPathMAX_PATH"%s\\libcod_win.dll"dirPath );

                    
    HANDLE hProcess OpenProcessPROCESS_CREATE_THREAD PROCESS_VM_OPERATION PROCESS_VM_WRITEFALSEentry.th32ProcessID );
                    
    LPVOID libAddr = (LPVOID)GetProcAddressGetModuleHandle"kernel32.dll" ), "LoadLibraryA" );
                    
    LPVOID llParam = (LPVOID)VirtualAllocExhProcessNULLstrlenfullPath ), MEM_RESERVE MEM_COMMITPAGE_READWRITE );

                    
    WriteProcessMemoryhProcessllParamfullPathstrlenfullPath ), NULL );
                    
    CreateRemoteThreadhProcessNULLNULL, (LPTHREAD_START_ROUTINE)libAddrllParamNULLNULL );
                    
    CloseHandlehProcess );
                }
            }
        }

        
    CloseHandlesnapshot );

        return 
    0;

    (Credits goes to http://stackoverflow.com/a/873659)

    DLL
    PHP Code:
    #include "main.h"

    int cdecl_injected_closer()
    {
        
    MessageBoxANULL"CLOSER""libcod"MB_OK );
        return 
    1337;
    }

    void init()
    {
        
    int *addressToCloserPointer = (int *)0x0070955B;
        *
    addressToCloserPointer = (int) cdecl_injected_closer;
    }

    extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLLDWORD fdwReasonLPVOID lpvReserved)
    {
        switch (
    fdwReason)
        {
            case 
    DLL_PROCESS_ATTACH:
                
    MessageBoxANULL"[PLUGIN LOADED]""libcod"MB_OK );
                
    init();
                break;

            case 
    DLL_PROCESS_DETACH:
                
    // detach from process
                
    break;

            case 
    DLL_THREAD_ATTACH:
                
    // attach to thread
                
    break;

            case 
    DLL_THREAD_DETACH:
                
    // detach from thread
                
    break;
        }
        return 
    TRUE// succesful

    header
    PHP Code:
    #ifndef __MAIN_H__
    #define __MAIN_H__

    #include <windows.h>

    /*  To use this exported function of dll, include this header
     *  in your project.
     */

    #ifdef BUILD_DLL
        #define DLL_EXPORT __declspec(dllexport)
    #else
        #define DLL_EXPORT __declspec(dllimport)
    #endif


    #ifdef __cplusplus
    extern "C"
    {
    #endif

    #ifdef __cplusplus
    }
    #endif

    #endif // __MAIN_H__ 

  4. #3
    Private First Class php's Avatar
    Join Date
    Nov 2012
    Posts
    142
    Thanks
    28
    Thanked 116 Times in 59 Posts
    If anyone is looking for libcod CoD 1.5 Windows, have a look at this; https://github.com/riicchhaarrd/MDLL/
    OT; Why would you want to make it available for Windows 8(.1), since I doubt servers use that to host.

  5. The Following 2 Users Say Thank You to php For This Useful Post:

    kung foo man (20th December 2013),smect@ (20th December 2013)

  6. #4
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by php View Post
    If anyone is looking for libcod CoD 1.5 Windows, have a look at this; https://github.com/riicchhaarrd/MDLL/
    OT; Why would you want to make it available for Windows 8(.1), since I doubt servers use that to host.
    Because i use 8.1 myself and it is easier to test when it works on the os i use on my laptop.

    Edit: and the dll is the same for all windows version, but you need to inject it on 7/8.

    I am gonna try to print the start message in the console. (it is less annoying than a popup)
    Last edited by Mitch; 20th December 2013 at 15:19.

  7. #5
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    I got currently the closer function hooked and i can read parameters from the closer function from the stack. (cod2 1.3)

    I cleaned up the code and started merging stuff from libcod.
    https://github.com/M-itch/libcod_win

    Status:
    - Retrieve gsc function parameters: working
    - pushStackInt, pushStackString, pushStackFloat, stackPushArray, stackPushArrayLast, pushStackVector: working
    - pushStackEntity (get spectatorclient): not working
    - mysql support: working
    - setvelocity: working
    - disableGlobalPlayerCollision: working
    - getip, getport: working
    - io::print (200): working
    - stance: working
    - get buttons: untested (likely to work)
    Last edited by Mitch; 16th January 2015 at 21:00.

  8. The Following User Says Thank You to Mitch For This Useful Post:

    Ni3ls (17th February 2014)