Changeset 2764


Ignore:
Timestamp:
Aug 13, 2006, 10:58:34 PM (19 years ago)
Author:
bird
Message:

Fixed that 'ing hook problem. ARG!!!

Location:
trunk/synergy
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/synergy/Makefile.kmk

    r2763 r2764  
    187187
    188188PROGRAMS = \
    189     synergys \
    190         synergyc \
     189        synergyc
     190#    synergys \
    191191
    192192synergyc_SOURCES = \
  • trunk/synergy/lib/platform/CPMScreen.cpp

    r2763 r2764  
    691691}
    692692
    693 HMODULE
    694 CPMScreen::openHookLibrary(const char* name)
    695 {
    696         // load the hook library - try with qualified name first.
    697         HMODULE hmod = NULLHANDLE;
    698     APIRET rc = ERROR_FILE_NOT_FOUND;
    699     char szFullName[CCHMAXPATH + 10];
    700     if (!_execname(szFullName, CCHMAXPATH)) {
    701         char *psz = strrchr(szFullName, '\\');
     693/**
     694 * Gets the path to the directory with the executable.
     695 * Has trailing slash.
     696 *
     697 * @returns pszBuf.
     698 * @returns NULL on buffer overflow.
     699 * @param   pszBuf      Where to store the path.
     700 * @param   cchBuf      The buffer size.
     701 */
     702static char *
     703getExecDir(char *pszBuf, size_t cchBuf)
     704{
     705    char *psz = NULL;
     706    if (!_execname(pszBuf,cchBuf)) {
     707        char *psz = strrchr(pszBuf, '\\');
    702708        if (!psz || strrchr(psz, '/')) {
    703709            psz = strrchr(psz, '/');
    704710        }
    705711        if (psz) {
    706             strcat(strcpy(psz + 1, name), ".DLL");
     712            psz[1] = '\0';
     713            return pszBuf;
    707714        }
    708             rc = DosLoadModule(NULL, 0, (PCSZ)szFullName, &hmod);
    709715    }
    710 
    711     // if that failed, try with the bare name.
    712     if (rc != NO_ERROR) {
    713             rc = DosLoadModule(NULL, 0, (PCSZ)name, &hmod);
    714     } else {
    715         name = szFullName;
     716    return NULL;
     717}
     718
     719HMODULE
     720CPMScreen::openHookLibrary(const char* name)
     721{
     722    //
     723    // Load the hook dll as a global DLL.
     724    //
     725    // The kernel/PM will fuck up if it's loaded with a path (i.e. non global).
     726    // What happend was that the DLL wasn't actually loaded into the other
     727    // processes for some stupid reason, leading to nasty crashes and even
     728    // weirder behaviour.
     729    //
     730    char szPath[CCHMAXPATH + 10];
     731    char szCwd[CCHMAXPATH];
     732    if (    getcwd(szCwd, sizeof(szCwd)) == NULL
     733        ||  getExecDir(szPath, sizeof(szPath)) == NULL
     734        ||  chdir(szPath) != 0) {
     735                LOG((CLOG_ERR "can't get cwd or exec dir or failed to change path to the exec dir!"));
     736                throw XScreenOpenFailure();
    716737    }
     738        HMODULE hmod;
     739    APIRET rc = DosLoadModule(NULL, 0, (PCSZ)name, &hmod);
     740    chdir(szCwd);
    717741        if (rc != NO_ERROR) {
    718742                LOG((CLOG_ERR "Failed to load hook library (%s), rc=%d ", name, rc));
     
    720744        }
    721745
    722         // look up functions
     746        // resolve the functions
    723747        if (    (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_fakeMsg",       (PPFN)&m_fakeMsg )) != NO_ERROR
    724748        ||      (rc = DosQueryProcAddr(hmod, 0, (PCSZ)"_setSides",      (PPFN)&m_setSides)) != NO_ERROR
  • trunk/synergy/lib/platform/CPMSynergyHook.cpp

    r2763 r2764  
    9292/** Error description. */
    9393const char          *g_pszErrorMsg;
    94 /** Set if the dummy hook is installed. */
    95 bool                 g_fDummyHook;
    9694/** @} */
    9795
     
    288286
    289287
    290 #define NO_DUMMY_HOOK 1
    291 #ifndef NO_DUMMY_HOOK
    292 /**
    293  * Dummy hook.
    294  */
    295 static VOID EXPENTRY SendMsgHook(HAB hab, PSMHSTRUCT psmh, BOOL fInterTask)
    296 {
    297     /* nop */
    298 }
    299 #endif
    300 
    301 
    302 
    303288//
    304289// external functions
     
    382367    }
    383368
    384 #ifndef NO_DUMMY_HOOK
    385     /*
    386      * Install the fake hook.
    387      */
    388     if (g_fDummyHook)
    389         WinReleaseHook(WinQueryAnchorBlock(HWND_DESKTOP), NULLHANDLE, HK_SENDMSG, (PFN)SendMsgHook, g_hmod);
    390     g_fDummyHook = WinSetHook(WinQueryAnchorBlock(HWND_DESKTOP), NULLHANDLE, HK_SENDMSG, (PFN)SendMsgHook, g_hmod);
    391     if (!g_fDummyHook) {
    392         return false;
    393     }
    394 #endif
    395 
    396369    g_fSynergyInitialized = true;
    397370    return true;
     
    420393    /* parnaoia */
    421394    uninstall(hab);
    422 
    423 #ifndef NO_DUMMY_HOOK
    424     // release the dummy hook.
    425     if (WinReleaseHook(hab, NULLHANDLE, HK_SENDMSG, (PFN)SendMsgHook, g_hmod))
    426         g_fDummyHook = false;
    427 #endif
    428395
    429396    g_hmqSynergy = NULLHANDLE;
     
    564531
    565532
     533//
     534// Message faking.
     535//
     536
    566537/**
    567538 * Hook callback used to insert message into the system queue.
     
    579550static BOOL EXPENTRY MsgInputHook(HAB hab, PQMSG pqmsg, BOOL fSkip, PBOOL pfNoRecord)
    580551{
    581     /*
    582      * FUCKING HELL!
    583      *
    584      * For whatever fucking reason, PM fails to load the hook dll into
    585      * a bunch of processes. We still get here for some peculiar reasons,
    586      * and thus we can try deal with it...
    587      */
    588     BOOL fUnload = FALSE;
    589     HMODULE hmod;
    590     ULONG offObj, iObj;
    591     APIRET rc = DosQueryModFromEIP(&hmod, &iObj, 0, NULL, &offObj, (ULONG)&MsgInputHook);
    592     if (rc != NO_ERROR) {
    593         if (DosLoadModule(NULL, 0, (PCSZ)"d:/coding/libc/trunk/out/os2.x86/debug/dist/bin/synrgyhk.dll", &hmod)) {
    594             return FALSE;
    595         }
    596         fUnload = TRUE;
    597     }
    598 
    599552    /*
    600553     * We've only got one message, so everything is dead simple.
     
    616569    }
    617570
    618     /*
    619      * If we loaded the dll we must unload it.
    620      * Don't wanna have any DLLs stuck in foreign processes.
    621      */
    622     if (fUnload)
    623         DosFreeModule(hmod);
    624571    return TRUE;
    625572}
Note: See TracChangeset for help on using the changeset viewer.