2012-05-05 05:50:32 +04:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* Microsoft Remote Procedure Call (MSRPC)
|
|
|
|
*
|
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <winpr/rpc.h>
|
2012-10-29 04:55:19 +04:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
#include "ndr_correlation.h"
|
|
|
|
#include "ndr_private.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Correlation Descriptors: http://msdn.microsoft.com/en-us/library/windows/desktop/aa373607/
|
|
|
|
*
|
|
|
|
* correlation_type<1>
|
|
|
|
* correlation_operator<1>
|
|
|
|
* offset<2>
|
|
|
|
* [robust_flags<2>]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
PFORMAT_STRING NdrpComputeCount(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
|
|
|
|
PFORMAT_STRING pFormat, ULONG_PTR* pCount)
|
2012-05-05 05:50:32 +04:00
|
|
|
{
|
|
|
|
LPVOID ptr = NULL;
|
|
|
|
ULONG_PTR data = 0;
|
|
|
|
unsigned char type;
|
|
|
|
unsigned short offset;
|
|
|
|
unsigned char conformance;
|
|
|
|
unsigned char correlation_type;
|
|
|
|
unsigned char correlation_operator;
|
|
|
|
correlation_type = pFormat[0];
|
|
|
|
type = correlation_type & 0x0F;
|
|
|
|
conformance = correlation_type & 0xF0;
|
|
|
|
correlation_operator = pFormat[1];
|
2019-11-06 17:24:51 +03:00
|
|
|
offset = *(unsigned short*)&pFormat[2];
|
2012-05-05 05:50:32 +04:00
|
|
|
|
|
|
|
if (conformance == FC_NORMAL_CONFORMANCE)
|
|
|
|
{
|
|
|
|
ptr = pMemory;
|
|
|
|
}
|
|
|
|
else if (conformance == FC_POINTER_CONFORMANCE)
|
|
|
|
{
|
|
|
|
ptr = pStubMsg->Memory;
|
|
|
|
}
|
|
|
|
else if (conformance == FC_TOP_LEVEL_CONFORMANCE)
|
|
|
|
{
|
|
|
|
ptr = pStubMsg->StackTop;
|
|
|
|
}
|
2014-08-18 19:22:22 +04:00
|
|
|
else if (conformance == FC_CONSTANT_CONFORMANCE)
|
2012-05-05 05:50:32 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
data = offset | ((DWORD)pFormat[1] << 16);
|
2012-05-05 05:50:32 +04:00
|
|
|
*pCount = data;
|
|
|
|
}
|
|
|
|
else if (conformance == FC_TOP_LEVEL_MULTID_CONFORMANCE)
|
|
|
|
{
|
|
|
|
if (pStubMsg->StackTop)
|
|
|
|
ptr = pStubMsg->StackTop;
|
|
|
|
}
|
2013-08-29 12:59:00 +04:00
|
|
|
else
|
|
|
|
return pFormat;
|
2012-05-05 05:50:32 +04:00
|
|
|
|
|
|
|
switch (correlation_operator)
|
|
|
|
{
|
|
|
|
case FC_DEREFERENCE:
|
2019-01-28 12:55:24 +03:00
|
|
|
if (!ptr)
|
|
|
|
return pFormat;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
ptr = *(LPVOID*)((char*)ptr + offset);
|
2012-05-05 05:50:32 +04:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_DIV_2:
|
2019-11-06 17:24:51 +03:00
|
|
|
ptr = (char*)ptr + offset;
|
2012-05-05 05:50:32 +04:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_MULT_2:
|
2019-11-06 17:24:51 +03:00
|
|
|
ptr = (char*)ptr + offset;
|
2012-05-05 05:50:32 +04:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_SUB_1:
|
2019-11-06 17:24:51 +03:00
|
|
|
ptr = (char*)ptr + offset;
|
2012-05-05 05:50:32 +04:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_ADD_1:
|
2019-11-06 17:24:51 +03:00
|
|
|
ptr = (char*)ptr + offset;
|
2012-05-05 05:50:32 +04:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_CALLBACK:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "warning: NdrpComputeConformance FC_CALLBACK unimplemented");
|
|
|
|
}
|
|
|
|
break;
|
2012-05-05 05:50:32 +04:00
|
|
|
}
|
|
|
|
|
2013-08-29 17:30:22 +04:00
|
|
|
if (!ptr)
|
|
|
|
return pFormat;
|
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case FC_LONG:
|
2019-11-06 17:24:51 +03:00
|
|
|
data = *(LONG*)ptr;
|
2012-05-05 05:50:32 +04:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_ULONG:
|
2019-11-06 17:24:51 +03:00
|
|
|
data = *(ULONG*)ptr;
|
2012-05-05 05:50:32 +04:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_SHORT:
|
2019-11-06 17:24:51 +03:00
|
|
|
data = *(SHORT*)ptr;
|
2012-05-05 05:50:32 +04:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_USHORT:
|
2019-11-06 17:24:51 +03:00
|
|
|
data = *(USHORT*)ptr;
|
2012-05-05 05:50:32 +04:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_CHAR:
|
|
|
|
case FC_SMALL:
|
2019-11-06 17:24:51 +03:00
|
|
|
data = *(CHAR*)ptr;
|
2012-05-05 05:50:32 +04:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_BYTE:
|
|
|
|
case FC_USMALL:
|
2019-11-06 17:24:51 +03:00
|
|
|
data = *(BYTE*)ptr;
|
2012-05-05 05:50:32 +04:00
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_HYPER:
|
2019-11-06 17:24:51 +03:00
|
|
|
data = (ULONG_PTR) * (ULONGLONG*)ptr;
|
2012-05-05 05:50:32 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (correlation_operator)
|
|
|
|
{
|
|
|
|
case FC_ZERO:
|
|
|
|
case FC_DEREFERENCE:
|
|
|
|
*pCount = data;
|
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_DIV_2:
|
|
|
|
*pCount = data / 1;
|
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_MULT_2:
|
|
|
|
*pCount = data * 1;
|
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_SUB_1:
|
|
|
|
*pCount = data - 1;
|
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_ADD_1:
|
|
|
|
*pCount = data + 1;
|
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2012-05-05 05:50:32 +04:00
|
|
|
case FC_CALLBACK:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pStubMsg->fHasNewCorrDesc)
|
|
|
|
pFormat += 6;
|
|
|
|
else
|
|
|
|
pFormat += 4;
|
|
|
|
|
|
|
|
return pFormat;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
PFORMAT_STRING NdrpComputeConformance(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
|
|
|
|
PFORMAT_STRING pFormat)
|
2012-05-05 05:50:32 +04:00
|
|
|
{
|
|
|
|
return NdrpComputeCount(pStubMsg, pMemory, pFormat, &pStubMsg->MaxCount);
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
PFORMAT_STRING NdrpComputeVariance(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,
|
|
|
|
PFORMAT_STRING pFormat)
|
2012-05-05 05:50:32 +04:00
|
|
|
{
|
|
|
|
ULONG_PTR ActualCount = pStubMsg->ActualCount;
|
|
|
|
pFormat = NdrpComputeCount(pStubMsg, pMemory, pFormat, &ActualCount);
|
2019-11-06 17:24:51 +03:00
|
|
|
pStubMsg->ActualCount = (ULONG)ActualCount;
|
2012-05-05 05:50:32 +04:00
|
|
|
return pFormat;
|
|
|
|
}
|
2012-10-29 04:55:19 +04:00
|
|
|
|
|
|
|
#endif
|