Changeset 2924 for trunk/src


Ignore:
Timestamp:
Sep 15, 2016, 10:51:38 PM (9 years ago)
Author:
bird
Message:

GetProcAddress replacements.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kWorker/kWorker.c

    r2923 r2924  
    785785extern KWREPLACEMENTFUNCTION const g_aSandboxNativeReplacements[];
    786786extern KU32                  const g_cSandboxNativeReplacements;
     787
     788extern KWREPLACEMENTFUNCTION const g_aSandboxGetProcReplacements[];
     789extern KU32                  const g_cSandboxGetProcReplacements;
     790
    787791
    788792/** Create a larget BSS blob that with help of /IMAGEBASE:0x10000 should
     
    40884092        if (rc == 0)
    40894093        {
    4090             static int s_cDbgGets = 0;
    4091             s_cDbgGets++;
    4092             KW_LOG(("GetProcAddress(%s, %s) -> %p [%d]\n", pMod->pszPath, pszProc, (KUPTR)uValue, s_cDbgGets));
     4094            //static int s_cDbgGets = 0;
     4095            KU32 cchProc = kHlpStrLen(pszProc);
     4096            KU32 i = g_cSandboxGetProcReplacements;
     4097            while (i-- > 0)
     4098                if (   g_aSandboxGetProcReplacements[i].cchFunction == cchProc
     4099                    && kHlpMemComp(g_aSandboxGetProcReplacements[i].pszFunction, pszProc, cchProc) == 0)
     4100                {
     4101                    if (   !g_aSandboxGetProcReplacements[i].pszModule
     4102                        || kHlpStrICompAscii(g_aSandboxGetProcReplacements[i].pszModule, &pMod->pszPath[pMod->offFilename]) == 0)
     4103                    {
     4104                        if (   pMod->fExe
     4105                            || !g_aSandboxGetProcReplacements[i].fOnlyExe)
     4106                        {
     4107                            uValue = g_aSandboxGetProcReplacements[i].pfnReplacement;
     4108                            KW_LOG(("GetProcAddress(%s, %s) -> %p replaced\n", pMod->pszPath, pszProc, (KUPTR)uValue));
     4109                        }
     4110                        kwLdrModuleRelease(pMod);
     4111                        return (FARPROC)(KUPTR)uValue;
     4112                    }
     4113                }
     4114
     4115            KW_LOG(("GetProcAddress(%s, %s) -> %p\n", pMod->pszPath, pszProc, (KUPTR)uValue));
    40934116            kwLdrModuleRelease(pMod);
     4117            //s_cDbgGets++;
    40944118            //if (s_cGets >= 3)
    40954119            //    return (FARPROC)kwSandbox_BreakIntoDebugger;
     
    75307554
    75317555/**
     7556 * Functions that needs replacing when queried by GetProcAddress.
     7557 */
     7558KWREPLACEMENTFUNCTION const g_aSandboxGetProcReplacements[] =
     7559{
     7560    /*
     7561     * Kernel32.dll and friends.
     7562     */
     7563    { TUPLE("FlsAlloc"),                    NULL,       (KUPTR)kwSandbox_Kernel32_FlsAlloc },
     7564    { TUPLE("FlsFree"),                     NULL,       (KUPTR)kwSandbox_Kernel32_FlsFree },
     7565};
     7566/** Number of entries in g_aSandboxGetProcReplacements. */
     7567KU32 const                  g_cSandboxGetProcReplacements = K_ELEMENTS(g_aSandboxGetProcReplacements);
     7568
     7569
     7570/**
    75327571 * Control handler.
    75337572 *
     
    83078346    int rcExit;
    83088347    PKWTOOL pTool;
     8348
     8349    KW_LOG(("\n\nkSubmitHandleJobUnpacked: '%s' in '%s' cArgs=%u cEnvVars=%u cPostCmdArgs=%u\n",
     8350            pszExecutable, pszCwd, cArgs, cEnvVars, cPostCmdArgs));
     8351#ifdef KW_LOG_ENABLED
     8352    {
     8353        KU32 i;
     8354        for (i = 0; i < cArgs; i++)
     8355            KW_LOG(("  papszArgs[%u]=%s\n", i, papszArgs[i]));
     8356        for (i = 0; i < cPostCmdArgs; i++)
     8357            KW_LOG(("  papszPostCmdArgs[%u]=%s\n", i, papszPostCmdArgs[i]));
     8358    }
     8359#endif
    83098360
    83108361    /*
Note: See TracChangeset for help on using the changeset viewer.