securekeys.c

来自「该BSP是基于PXA270+WINCE的BSP」· C语言 代码 · 共 130 行

C
130
字号
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
//  File:  SecureKeys.c
//
//  This file implements the IOCTL_HAL_GETREGSECUREKEYS handler.
//
#include <windows.h>
#include <oal.h>

//------------------------------------------------------------------------------
//
//  Function:  OALIoCtlHalGetRegSecureKeys
//
//  Implements a common IOCTL_HAL_GETREGSECUREKEYS handler.  
//
BOOL OALIoCtlHalGetRegSecureKeys( 
    UINT32 dwIoControlCode, VOID *lpInBuf, UINT32 nInBufSize, VOID *lpOutBuf, 
    UINT32 nOutBufSize, UINT32* lpBytesReturned)
{

    BOOL rc = FALSE;

    // Differentiate based on platform type
    if (g_oalIoCtlPlatform == OAL_IOCTL_PLATFORM_SMARTPHONE ||
        g_oalIoCtlPlatform == OAL_IOCTL_PLATFORM_POCKETPC)
        {
        // List of Secure registry keys
        RegSecureKey OEMSecNames[] =
            {
            { REGSEC_HKLM | REGSEC_HKCU, 8,  L"security" },
            { REGSEC_HKLM, 6, L"loader" }
            };

        RegSecureKeyList OEMSecList =
            {
            sizeof(OEMSecNames) / sizeof(RegSecureKey),
            OEMSecNames,
            };

        DWORD nameIdx;
        DWORD bufSize;

        // size of structs without names
        bufSize = sizeof(OEMSecList) + sizeof(OEMSecNames);

        for (nameIdx = 0; nameIdx < OEMSecList.dwNumKeys; nameIdx++) 
            {
            bufSize += OEMSecNames[nameIdx].wLen * sizeof(WCHAR); // no nulls
            }

        // First call: return the required buffer size
        if (!lpInBuf && !nInBufSize && lpOutBuf && (nOutBufSize == sizeof(DWORD))) 
            {
            *((DWORD*)lpOutBuf) = bufSize;
            if (lpBytesReturned)
                {
                *lpBytesReturned = sizeof(bufSize);
                }
            
            rc = TRUE;
            }
        // Second call: fill the provided buffer
        // nOutBufSize should be the same as returned on first call
        else 
            {
            if (!lpInBuf && !nInBufSize && lpOutBuf && (nOutBufSize >= bufSize)) 
                {                
                RegSecureKeyList *pKeys = (RegSecureKeyList*)lpOutBuf;

                // pStr moves through the buffer as strings are written
                LPWSTR pStr = (LPWSTR)((LPBYTE)lpOutBuf + sizeof(OEMSecList) + sizeof(OEMSecNames));

                pKeys->dwNumKeys = OEMSecList.dwNumKeys;
                pKeys->pList = (RegSecureKey*) ((LPBYTE)lpOutBuf + sizeof(OEMSecList));

                for (nameIdx = 0; nameIdx < OEMSecList.dwNumKeys; nameIdx++) 
                    {
                    pKeys->pList[nameIdx].wRoots = OEMSecNames[nameIdx].wRoots;
                    pKeys->pList[nameIdx].wLen = OEMSecNames[nameIdx].wLen;
                    pKeys->pList[nameIdx].pName = pStr;
                    memcpy(pStr, OEMSecNames[nameIdx].pName, OEMSecNames[nameIdx].wLen * sizeof(WCHAR));

                    pStr += OEMSecNames[nameIdx].wLen;
                    }

                if (lpBytesReturned)
                    {
                    *lpBytesReturned = bufSize;
                    }

                rc = TRUE;
                } 
            }
        }
    else
        {
        // First call: return buffer size of 0.  We should not be called again.
        if (!lpInBuf && !nInBufSize && lpOutBuf && (nOutBufSize == sizeof(DWORD))) 
            {
            *((DWORD*)lpOutBuf) = (DWORD)0;
            if (lpBytesReturned)
                {
                *lpBytesReturned = sizeof(DWORD);
                }

            rc = TRUE;
            }
        }

    if (rc == FALSE)
        {
        // Invalid args
        NKSetLastError(ERROR_INVALID_PARAMETER);
        }

    OALMSG(OAL_IOCTL&&OAL_FUNC, (L"-OALIoCtlHalGetRegSecureKeys(rc = %d)\r\n", rc));
    return (rc);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?