Beispiel #1
0
static LPITEMIDLIST _ILReadFromSharedMemory(PCWSTR strField)
{
    LPITEMIDLIST ret = NULL;

    // Ensure it really is an IDLIST-formatted parameter
    // Format for IDLIST params: ":pid:shared"
    if (*strField != L':')
        return NULL;

    HANDLE hData = (HANDLE) StrToIntW(strField + 1);
    PWSTR strSecond = StrChrW(strField + 1, L':');

    if (strSecond)
    {
        int pid = StrToIntW(strSecond + 1);
        void* pvShared = SHLockShared(hData, pid);
        if (pvShared)
        {
            ret = ILClone((LPCITEMIDLIST) pvShared);
            SHUnlockShared(pvShared);
            SHFreeShared(hData, pid);
        }
    }
    return ret;
}
Beispiel #2
0
UINT WINAPI SHAppBarMessage(DWORD dwMessage, PAPPBARDATA pabd)
{
    HWND hwndTray;
    COPYDATASTRUCT cds;
    TRAYAPPBARDATA tabd;
    BOOL fret;
    LPRECT lprc = NULL;

    hwndTray = FindWindow(c_szTrayClass, NULL);
    if (!hwndTray || (pabd->cbSize > SIZEOF(tabd.abd)))
    {
        return(FALSE);
    }

    tabd.abd = *pabd;
    tabd.dwMessage = dwMessage;
    tabd.hSharedRect = NULL;
    tabd.dwProcId = GetCurrentProcessId();

    cds.dwData = TCDM_APPBAR;
    cds.cbData = SIZEOF(tabd);
    cds.lpData = &tabd;

    switch (dwMessage) {
    case ABM_QUERYPOS:
    case ABM_SETPOS:
    case ABM_GETTASKBARPOS:
        tabd.hSharedRect = SHAllocShared(NULL, SIZEOF(RECT), tabd.dwProcId);
        if (tabd.hSharedRect == NULL)
            return FALSE;
        break;
    }

    fret = (SendMessage(hwndTray, WM_COPYDATA, (WPARAM)pabd->hWnd, (LPARAM)&cds));

    if (tabd.hSharedRect) {
        lprc = (LPRECT)SHLockShared(tabd.hSharedRect,tabd.dwProcId);
        if (lprc == NULL)
        {
            fret = FALSE;
        }
        else
        {
            pabd->rc = *lprc;
            SHUnlockShared(lprc);
        }
        SHFreeShared(tabd.hSharedRect,tabd.dwProcId);
    }
    return fret;
}
Beispiel #3
0
PIE_THREAD_PARAM_BLOCK ParseSharedPacket(HANDLE hData)
{
    HNFBlock * hnfData;
    PBYTE block;
    int pid;
    PIE_THREAD_PARAM_BLOCK params = NULL;

    if (!hData)
        goto cleanup0;

    pid = GetCurrentProcessId();
    block = (PBYTE) SHLockShared(hData, pid);

    hnfData = (HNFBlock *) block;
    if (!block)
        goto cleanup2;

    if (hnfData->cbSize < sizeof(HNFBlock))
        goto cleanup2;

    params = SHCreateIETHREADPARAM(0, hnfData->offset8, 0, 0);
    if (!params)
        goto cleanup2;

    params->dwFlags = hnfData->offset4;
    params->offset8 = hnfData->offset8;
    params->offset74 = hnfData->offsetC;
    params->offsetD8 = hnfData->offset10;
    params->offset84 = hnfData->offset14;
    params->offset88 = hnfData->offset18;
    params->offset8C = hnfData->offset1C;
    params->offset90 = hnfData->offset20;
    params->offset94 = hnfData->offset24;
    params->offset98 = hnfData->offset28;
    params->offset9C = hnfData->offset2C;
    params->offsetA0 = hnfData->offset30;

    block += sizeof(*hnfData);
    if (hnfData->directoryPidlLength)
    {
        LPITEMIDLIST pidl = NULL;
        if (*block)
            pidl = ILClone((LPITEMIDLIST) block);
        params->directoryPIDL = pidl;

        block += hnfData->directoryPidlLength;
    }

    if (hnfData->pidlSize7C)
    {
        LPITEMIDLIST pidl = NULL;
        if (*block)
            pidl = ILClone((LPITEMIDLIST) block);
        params->offset7C = pidl;

        block += hnfData->pidlSize80;
    }

    if (hnfData->pidlSize80)
    {
        if (!(params->offset84 & 0x8000))
        {
            params->offset80 = *(LPITEMIDLIST *) block;
        }
        else
        {
            LPITEMIDLIST pidl = NULL;
            if (*block)
                pidl = ILClone((LPITEMIDLIST) block);
            params->offset80 = pidl;
        }

        block += hnfData->pidlSize80;
    }

    if (hnfData->pathLength)
    {
        CComPtr<IShellFolder> psfDesktop;
        PWSTR strPath = (PWSTR) block;

        if (FAILED(SHGetDesktopFolder(&psfDesktop)))
        {
            params->directoryPIDL = NULL;
            goto cleanup0;
        }

        if (FAILED(psfDesktop->ParseDisplayName(NULL, NULL, strPath, NULL, &params->directoryPIDL, NULL)))
        {
            params->directoryPIDL = NULL;
            goto cleanup0;
        }
    }

cleanup2:
    SHUnlockShared(hnfData);
    SHFreeShared(hData, pid);

cleanup0:
    if (!params->directoryPIDL)
    {
        SHDestroyIETHREADPARAM(params);
        return NULL;
    }

    return params;
}
Beispiel #4
0
HANDLE MakeSharedPacket(IEThreadParamBlock * threadParams, LPCWSTR strPath, int dwProcessId)
{
    HNFBlock* hnfData;
    UINT sharedBlockSize = sizeof(*hnfData);
    UINT directoryPidlLength = 0;
    UINT pidlSize7C = 0;
    UINT pidlSize80 = 0;
    UINT pathLength = 0;
    LPITEMIDLIST pidl80 = threadParams->offset80;

    // Count the total length of the message packet

    // directory PIDL
    if (threadParams->directoryPIDL)
    {
        directoryPidlLength = ILGetSize(threadParams->directoryPIDL);
        sharedBlockSize += directoryPidlLength;
        DbgPrint("directoryPidlLength=%d\n", directoryPidlLength);
    }

    // another PIDL
    if (threadParams->offset7C)
    {
        pidlSize7C = ILGetSize(threadParams->offset7C);
        sharedBlockSize += pidlSize7C;
        DbgPrint("pidlSize7C=%d\n", pidlSize7C);
    }

    // This flag indicates the presence of another pidl?
    if (!(threadParams->offset84 & 0x8000))
    {
        if (pidl80)
        {
            pidlSize80 = ILGetSize(pidl80);
            sharedBlockSize += pidlSize80;
            DbgPrint("pidlSize80=%d\n", pidlSize7C);
        }
    }
    else
    {
        DbgPrint("pidl80 sent by value = %p\n", pidl80);
        pidlSize80 = 4;
        sharedBlockSize += pidlSize80;
    }

    // The path string
    if (strPath)
    {
        pathLength = 2 * lstrlenW(strPath) + 2;
        sharedBlockSize += pathLength;
        DbgPrint("pathLength=%d\n", pidlSize7C);
    }

    DbgPrint("sharedBlockSize=%d\n", sharedBlockSize);

    // Allocate and fill the shared section
    HANDLE hShared = SHAllocShared(0, sharedBlockSize, dwProcessId);
    if (!hShared)
    {
        DbgPrint("Shared section alloc error.\n");
        return 0;
    }

    PBYTE target = (PBYTE) SHLockShared(hShared, dwProcessId);
    if (!target)
    {
        DbgPrint("Shared section lock error. %d\n", GetLastError());
        SHFreeShared(hShared, dwProcessId);
        return 0;
    }

    // Basic information
    hnfData = (HNFBlock*) target;
    hnfData->cbSize = sharedBlockSize;
    hnfData->offset4 = (DWORD) (threadParams->dwFlags);
    hnfData->offset8 = (DWORD) (threadParams->offset8);
    hnfData->offsetC = (DWORD) (threadParams->offset74);
    hnfData->offset10 = (DWORD) (threadParams->offsetD8);
    hnfData->offset14 = (DWORD) (threadParams->offset84);
    hnfData->offset18 = (DWORD) (threadParams->offset88);
    hnfData->offset1C = (DWORD) (threadParams->offset8C);
    hnfData->offset20 = (DWORD) (threadParams->offset90);
    hnfData->offset24 = (DWORD) (threadParams->offset94);
    hnfData->offset28 = (DWORD) (threadParams->offset98);
    hnfData->offset2C = (DWORD) (threadParams->offset9C);
    hnfData->offset30 = (DWORD) (threadParams->offsetA0);
    hnfData->directoryPidlLength = 0;
    hnfData->pidlSize7C = 0;
    hnfData->pidlSize80 = 0;
    hnfData->pathLength = 0;
    target += sizeof(*hnfData);

    // Copy the directory pidl contents
    if (threadParams->directoryPIDL)
    {
        memcpy(target, threadParams->directoryPIDL, directoryPidlLength);
        target += directoryPidlLength;
        hnfData->directoryPidlLength = directoryPidlLength;
    }

    // Copy the other pidl contents
    if (threadParams->offset7C)
    {
        memcpy(target, threadParams->offset7C, pidlSize7C);
        target += pidlSize7C;
        hnfData->pidlSize7C = pidlSize7C;
    }

    // copy the third pidl
    if (threadParams->offset84 & 0x8000)
    {
        *(LPITEMIDLIST*) target = pidl80;
        target += pidlSize80;
        hnfData->pidlSize80 = pidlSize80;
    }
    else if (pidl80)
    {
        memcpy(target, pidl80, pidlSize80);
        target += pidlSize80;
        hnfData->pidlSize80 = pidlSize80;
    }

    // and finally the path string
    if (strPath)
    {
        memcpy(target, strPath, pathLength);
        hnfData->pathLength = pathLength;
    }

    SHUnlockShared(hnfData);

    return hShared;
}