⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ndr_stubless.c

📁 这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统
💻 C
📖 第 1 页 / 共 5 页
字号:
                RPC_STATUS Status;                pRpcMsg->BufferLength = stubMsg.BufferLength;                /* allocate buffer for [out] and [ret] params */                Status = I_RpcGetBuffer(pRpcMsg);                 if (Status)                    RpcRaiseException(Status);                stubMsg.BufferStart = pRpcMsg->Buffer;                stubMsg.BufferEnd = stubMsg.BufferStart + stubMsg.BufferLength;                stubMsg.Buffer = stubMsg.BufferStart;            }            break;        case STUBLESS_MARSHAL:        case STUBLESS_UNMARSHAL:        case STUBLESS_CALCSIZE:        case STUBLESS_FREE:            current_offset = parameter_start_offset;            current_stack_offset = 0;            /* NOTE: V1 style format does't terminate on the number_of_params             * condition as it doesn't have this attribute. Instead it             * terminates when the stack size given in the header is exceeded.             */            for (i = 0; i < number_of_params; i++)            {                if (bV2Format) /* new parameter format */                {                    const NDR_PARAM_OIF_BASETYPE *pParam =                        (const NDR_PARAM_OIF_BASETYPE *)&pFormat[current_offset];                    unsigned char *pArg;                    current_stack_offset = pParam->stack_offset;                    pArg = (unsigned char *)(args+current_stack_offset);                    TRACE("param[%d]: new format\n", i);                    TRACE("\tparam_attributes:"); dump_RPC_FC_PROC_PF(pParam->param_attributes); TRACE("\n");                    TRACE("\tstack_offset: 0x%x\n", current_stack_offset);                    TRACE("\tmemory addr (before): %p -> %p\n", pArg, *(unsigned char **)pArg);                    if (pParam->param_attributes.IsBasetype)                    {                        const unsigned char *pTypeFormat =                            &pParam->type_format_char;                        TRACE("\tbase type: 0x%02x\n", *pTypeFormat);                        switch (phase)                        {                        case STUBLESS_MARSHAL:                            if (pParam->param_attributes.IsOut || pParam->param_attributes.IsReturn)                            {                                if (pParam->param_attributes.IsSimpleRef)                                    call_marshaller(&stubMsg, *(unsigned char **)pArg, pTypeFormat);                                else                                    call_marshaller(&stubMsg, pArg, pTypeFormat);                            }                            break;                        case STUBLESS_FREE:                            if (pParam->param_attributes.ServerAllocSize)                                HeapFree(GetProcessHeap(), 0, *(void **)pArg);                            break;                        case STUBLESS_UNMARSHAL:                            if (pParam->param_attributes.ServerAllocSize)                                *(void **)pArg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,                                    pParam->param_attributes.ServerAllocSize * 8);                            if (pParam->param_attributes.IsIn)                            {                                if (pParam->param_attributes.IsSimpleRef)                                    call_unmarshaller(&stubMsg, (unsigned char **)pArg, pTypeFormat, 0);                                else                                    call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);                            }                            /* make a note of the address of the return value parameter for later */                            if (pParam->param_attributes.IsReturn)                                retval_ptr = (LONG_PTR *)pArg;                            break;                        case STUBLESS_CALCSIZE:                            if (pParam->param_attributes.IsOut || pParam->param_attributes.IsReturn)                            {                                if (pParam->param_attributes.IsSimpleRef)                                    call_buffer_sizer(&stubMsg, *(unsigned char **)pArg, pTypeFormat);                                else                                    call_buffer_sizer(&stubMsg, pArg, pTypeFormat);                            }                            break;                        default:                            RpcRaiseException(RPC_S_INTERNAL_ERROR);                        }                        current_offset += sizeof(NDR_PARAM_OIF_BASETYPE);                    }                    else                    {                        const NDR_PARAM_OIF_OTHER *pParamOther =                            (const NDR_PARAM_OIF_OTHER *)&pFormat[current_offset];                        const unsigned char * pTypeFormat =                            &(pStubDesc->pFormatTypes[pParamOther->type_offset]);                        TRACE("\tcomplex type 0x%02x\n", *pTypeFormat);                        switch (phase)                        {                        case STUBLESS_MARSHAL:                            if (pParam->param_attributes.IsOut || pParam->param_attributes.IsReturn)                            {                                if (pParam->param_attributes.IsByValue)                                    call_marshaller(&stubMsg, pArg, pTypeFormat);                                else                                    call_marshaller(&stubMsg, *(unsigned char **)pArg, pTypeFormat);                            }                            break;                        case STUBLESS_FREE:                            if (pParam->param_attributes.MustFree)                            {                                if (pParam->param_attributes.IsByValue)                                    call_freer(&stubMsg, pArg, pTypeFormat);                                else                                    call_freer(&stubMsg, *(unsigned char **)pArg, pTypeFormat);                            }                            if (pParam->param_attributes.IsOut &&                                !pParam->param_attributes.IsIn &&                                !pParam->param_attributes.IsByValue &&                                !pParam->param_attributes.ServerAllocSize)                            {                                stubMsg.pfnFree(*(void **)pArg);                            }                            if (pParam->param_attributes.ServerAllocSize)                                HeapFree(GetProcessHeap(), 0, *(void **)pArg);                            /* FIXME: call call_freer here for IN types with MustFree set */                            break;                        case STUBLESS_UNMARSHAL:                            if (pParam->param_attributes.ServerAllocSize)                                *(void **)pArg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,                                    pParam->param_attributes.ServerAllocSize * 8);                            if (pParam->param_attributes.IsIn)                            {                                if (pParam->param_attributes.IsByValue)                                    call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);                                else                                    call_unmarshaller(&stubMsg, (unsigned char **)pArg, pTypeFormat, 0);                            }                            else if (pParam->param_attributes.IsOut &&                                     !pParam->param_attributes.ServerAllocSize &&                                     !pParam->param_attributes.IsByValue)                            {                                DWORD size = calc_arg_size(&stubMsg, pTypeFormat);                                if(size)                                {                                    *(void **)pArg = NdrAllocate(&stubMsg, size);                                    memset(*(void **)pArg, 0, size);                                }                            }                            break;                        case STUBLESS_CALCSIZE:                            if (pParam->param_attributes.IsOut || pParam->param_attributes.IsReturn)                            {                                if (pParam->param_attributes.IsByValue)                                    call_buffer_sizer(&stubMsg, pArg, pTypeFormat);                                else                                    call_buffer_sizer(&stubMsg, *(unsigned char **)pArg, pTypeFormat);                            }                            break;                        default:                            RpcRaiseException(RPC_S_INTERNAL_ERROR);                        }                        current_offset += sizeof(NDR_PARAM_OIF_OTHER);                    }                    TRACE("\tmemory addr (after): %p -> %p\n", pArg, *(unsigned char **)pArg);                }                else /* old parameter format */                {                    const NDR_PARAM_OI_BASETYPE *pParam =                        (const NDR_PARAM_OI_BASETYPE *)&pFormat[current_offset];                    /* note: current_stack_offset starts after the This pointer                     * if present, so adjust this */                    unsigned short current_stack_offset_adjusted = current_stack_offset +                        ((pProcHeader->Oi_flags & RPC_FC_PROC_OIF_OBJECT) ? sizeof(void *) : 0);                    unsigned char *pArg = (unsigned char *)(args+current_stack_offset_adjusted);                    /* no more parameters; exit loop */                    if (current_stack_offset_adjusted >= stack_size)                        break;                    TRACE("param[%d]: old format\n", i);                    TRACE("\tparam_direction: 0x%x\n", pParam->param_direction);                    TRACE("\tstack_offset: 0x%x\n", current_stack_offset_adjusted);                    if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE ||                        pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)                    {                        const unsigned char *pTypeFormat =                            &pParam->type_format_char;                        TRACE("\tbase type 0x%02x\n", *pTypeFormat);                        switch (phase)                        {                        case STUBLESS_MARSHAL:                            if (pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)                                call_marshaller(&stubMsg, pArg, pTypeFormat);                            break;                        case STUBLESS_FREE:                            if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE)                                call_freer(&stubMsg, pArg, pTypeFormat);                            break;                        case STUBLESS_UNMARSHAL:                            if (pParam->param_direction == RPC_FC_IN_PARAM_BASETYPE)                                call_unmarshaller(&stubMsg, &pArg, pTypeFormat, 0);                            else if (pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)                                retval_ptr = (LONG_PTR *)pArg;                            break;                        case STUBLESS_CALCSIZE:                            if (pParam->param_direction == RPC_FC_RETURN_PARAM_BASETYPE)                                call_buffer_sizer(&stubMsg, pArg, pTypeFormat);                            break;                        default:                            RpcRaiseException(RPC_S_INTERNAL_ERROR);                        }                        current_stack_offset += call_memory_sizer(&stubMsg, pTypeFormat);                        current_offset += sizeof(NDR_PARAM_OI_BASETYPE);                    }                    else                    {                        const NDR_PARAM_OI_OTHER *pParamOther =                             (const NDR_PARAM_OI_OTHER *)&pFormat[current_offset];                        const unsigned char * pTypeFormat =                            &pStubDesc->pFormatTypes[pParamOther->type_offset];                        TRACE("\tcomplex type 0x%02x\n", *pTypeFormat);                        switch (phase)                        {                        case STUBLESS_MARSHAL:                            if (pParam->param_direction == RPC_FC_OUT_PARAM ||                                pParam->param_direction == RPC_FC_IN_OUT_PARAM ||                                pParam->param_direction == RPC_FC_RETURN_PARAM)                                call_marshaller(&stubMsg, *(unsigned char **)pArg, pTypeFormat);                            break;                        case STUBLESS_FREE:                            if (pParam->param_direction == RPC_FC_IN_OUT_PARAM ||                                pParam->param_direction == RPC_FC_IN_PARAM)                                call_freer(&stubMsg, *(unsigned char **)pArg, pTypeFormat);                            else if (pParam->param_direction == RPC_FC_OUT_PARAM)                                stubMsg.pfnFree(*(void **)pArg);                            break;                        case STUBLESS_UNMARSHAL:                            if (pParam->param_direction == RPC_FC_IN_OUT_PARAM ||                                pParam->param_direction == RPC_FC_IN_PARAM)                                call_unmarshaller(&stubMsg, (unsigned char **)pArg, pTypeFormat, 0);                            else if (pParam->param_direction == RPC_FC_RETURN_PARAM)                                retval_ptr = (LONG_PTR *)pArg;                            else if (pParam->param_direction == RPC_FC_OUT_PARAM)                            {                                DWORD size = calc_arg_size(&stubMsg, pTypeFormat);                                if(size)                                {                                    *(void **)pArg = NdrAllocate(&stubMsg, size);                                    memset(*(void **)pArg, 0, size);                                }                            }                            break;                        case STUBLESS_CALCSIZE:                            if (pParam->param_direction == RPC_FC_OUT_PARAM ||                                pParam->param_direction == RPC_FC_IN_OUT_PARAM ||                                pParam->param_direction == RPC_FC_RETURN_PARAM)                                call_buffer_sizer(&stubMsg, *(unsigned char **)pArg, pTypeFormat);                            break;                        default:                            RpcRaiseException(RPC_S_INTERNAL_ERROR);                        }                        current_stack_offset += pParamOther->stack_size * sizeof(INT);                        current_offset += sizeof(NDR_PARAM_OI_OTHER);                    }                }            }            break;        default:            ERR("shouldn't reach here. phase %d\n", phase);            break;        }    }    pRpcMsg->BufferLength = (unsigned int)(stubMsg.Buffer - (unsigned char *)pRpcMsg->Buffer);    if (ext_flags.HasNewCorrDesc)    {        /* free extra correlation package */        /* NdrCorrelationFree(&stubMsg); */    }    if (Oif_flags.HasPipes)    {        /* NdrPipesDone(...) */    }    /* free the full pointer translation tables */    if (pProcHeader->Oi_flags & RPC_FC_PROC_OIF_FULLPTR)        NdrFullPointerXlatFree(stubMsg.FullPtrXlatTables);    /* free server function stack */    HeapFree(GetProcessHeap(), 0, args);    return S_OK;}void WINAPI NdrServerCall2(PRPC_MESSAGE pRpcMsg){    DWORD dwPhase;    NdrStubCall2(NULL, NULL, pRpcMsg, &dwPhase);}

⌨️ 快捷键说明

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