libfreerdp-core: expand NDR API

This commit is contained in:
Marc-André Moreau 2012-04-28 23:37:07 -04:00
parent 3e2b185989
commit e9e8e51332
2 changed files with 137 additions and 12 deletions

View File

@ -26,13 +26,92 @@
* http://dvlabs.tippingpoint.com/blog/2007/11/24/msrpc-ndr-types/
*/
CLIENT_CALL_RETURN NdrClientCall2(PMIDL_STUB_DESC pStubDescriptor, PFORMAT_STRING pFormat, ...)
void ndr_print_param_attributes(unsigned short attributes)
{
if (attributes & PARAM_ATTRIBUTE_SERVER_ALLOC_SIZE)
printf("ServerAllocSize, ");
if (attributes & PARAM_ATTRIBUTE_SAVE_FOR_ASYNC_FINISH)
printf("SaveForAsyncFinish, ");
if (attributes & PARAM_ATTRIBUTE_IS_DONT_CALL_FREE_INST)
printf("IsDontCallFreeInst, ");
if (attributes & PARAM_ATTRIBUTE_IS_SIMPLE_REF)
printf("IsSimpleRef, ");
if (attributes & PARAM_ATTRIBUTE_IS_BY_VALUE)
printf("IsByValue, ");
if (attributes & PARAM_ATTRIBUTE_IS_BASE_TYPE)
printf("IsBaseType, ");
if (attributes & PARAM_ATTRIBUTE_IS_RETURN)
printf("IsReturn, ");
if (attributes & PARAM_ATTRIBUTE_IS_OUT)
printf("IsOut, ");
if (attributes & PARAM_ATTRIBUTE_IS_IN)
printf("IsIn, ");
if (attributes & PARAM_ATTRIBUTE_IS_PIPE)
printf("IsPipe, ");
if (attributes & PARAM_ATTRIBUTE_MUST_FREE)
printf("MustFree, ");
if (attributes & PARAM_ATTRIBUTE_MUST_SIZE)
printf("MustSize, ");
}
void ndr_process_args(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, void** fpuArgs, unsigned short numberParams)
{
unsigned int i;
NDR_PARAM* params;
PFORMAT_STRING fmt;
unsigned char* arg;
params = (NDR_PARAM*) pFormat;
printf("Params = \n{\n");
for (i = 0; i < numberParams; i++)
{
arg = pStubMsg->StackTop + params[i].StackOffset;
fmt = (PFORMAT_STRING) &pStubMsg->StubDesc->pFormatTypes[params[i].Type.Offset];
printf("\t#%d\t", i);
ndr_print_param_attributes(params[i].Attributes);
if (params[i].Attributes & PARAM_ATTRIBUTE_IS_IN)
{
}
printf("\n");
}
printf("}\n");
}
void NdrClientInitializeNew(PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg,
PMIDL_STUB_DESC pStubDesc, unsigned int ProcNum)
{
pRpcMessage->Handle = NULL;
pRpcMessage->RpcFlags = 0;
pRpcMessage->ProcNum = ProcNum;
pRpcMessage->DataRepresentation = 0;
pRpcMessage->ReservedForRuntime = NULL;
pRpcMessage->RpcInterfaceInformation = pStubDesc->RpcInterfaceInformation;
pStubMsg->RpcMsg = pRpcMessage;
pStubMsg->BufferStart = NULL;
pStubMsg->BufferEnd = NULL;
pStubMsg->BufferLength = 0;
pStubMsg->StackTop = NULL;
pStubMsg->StubDesc = pStubDesc;
}
CLIENT_CALL_RETURN ndr_client_call(PMIDL_STUB_DESC pStubDescriptor, PFORMAT_STRING pFormat, void** stackTop, void** fpuStack)
{
RPC_MESSAGE rpcMsg;
unsigned char oiFlags;
unsigned short procNum;
unsigned short stackSize;
unsigned char numberParams;
NDR_PROC_HEADER* procHeader;
MIDL_STUB_MESSAGE stubMsg;
CLIENT_CALL_RETURN client_call_return;
procNum = stackSize = numberParams = 0;
@ -60,9 +139,26 @@ CLIENT_CALL_RETURN NdrClientCall2(PMIDL_STUB_DESC pStubDescriptor, PFORMAT_STRIN
}
}
NdrClientInitializeNew(&rpcMsg, &stubMsg, pStubDescriptor, procNum);
stubMsg.StackTop = (unsigned char*) stackTop;
printf("ProcHeader: ProcNum:%d OiFlags: 0x%02X, handleType: 0x%02X StackSize: %d NumberParams: %d\n",
procNum, oiFlags, procHeader->HandleType, stackSize, numberParams);
ndr_process_args(&stubMsg, pFormat, fpuStack, numberParams);
return client_call_return;
}
CLIENT_CALL_RETURN NdrClientCall2(PMIDL_STUB_DESC pStubDescriptor, PFORMAT_STRING pFormat, ...)
{
va_list args;
CLIENT_CALL_RETURN client_call_return;
va_start(args, pFormat);
client_call_return = ndr_client_call(pStubDescriptor, pFormat, va_arg(args, void**), NULL);
va_end(args);
return client_call_return;
}

View File

@ -132,6 +132,9 @@ typedef void (*NDR_NOTIFY_ROUTINE)(void);
typedef const unsigned char* PFORMAT_STRING;
typedef struct _MIDL_STUB_DESC MIDL_STUB_DESC;
typedef MIDL_STUB_DESC* PMIDL_STUB_DESC;
typedef struct _MIDL_STUB_MESSAGE
{
PRPC_MESSAGE RpcMsg;
@ -142,7 +145,9 @@ typedef struct _MIDL_STUB_MESSAGE
unsigned long BufferLength;
unsigned long MemorySize;
unsigned char* Memory;
} MIDL_STUB_MESSAGE, *PMIDL_STUB_MESSAGE;
unsigned char* StackTop;
PMIDL_STUB_DESC StubDesc;
} MIDL_STUB_MESSAGE, *PMIDL_STUB_MESSAGE;
typedef struct _MIDL_STUB_MESSAGE MIDL_STUB_MESSAGE, *PMIDL_STUB_MESSAGE;
@ -186,7 +191,7 @@ typedef struct _COMM_FAULT_OFFSETS
typedef void* NDR_CS_ROUTINES;
typedef void* NDR_EXPR_DESC;
typedef struct _MIDL_STUB_DESC
struct _MIDL_STUB_DESC
{
void* RpcInterfaceInformation;
void* (*pfnAllocate)(size_t);
@ -218,17 +223,41 @@ typedef struct _MIDL_STUB_DESC
const NDR_CS_ROUTINES* CsRoutineTables;
void* ProxyServerInfo;
const NDR_EXPR_DESC* pExprInfo;
} MIDL_STUB_DESC;
};
typedef const MIDL_STUB_DESC *PMIDL_STUB_DESC;
#define OI2_FLAG_SERVER_MUST_SIZE 0x01
#define OI2_FLAG_CLIENT_MUST_SIZE 0x02
#define OI2_FLAG_HAS_RETURN 0x04
#define OI2_FLAG_HAS_PIPES 0x08
#define OI2_FLAG_HAS_ASYNC_UUID 0x20
#define OI2_FLAG_HAS_EXTENSIONS 0x40
#define OI2_FLAG_HAS_ASYNC_HANDLE 0x80
#define OI2_FLAG_SERVER_MUST_SIZE 0x01
#define OI2_FLAG_CLIENT_MUST_SIZE 0x02
#define OI2_FLAG_HAS_RETURN 0x04
#define OI2_FLAG_HAS_PIPES 0x08
#define OI2_FLAG_HAS_ASYNC_UUID 0x20
#define OI2_FLAG_HAS_EXTENSIONS 0x40
#define OI2_FLAG_HAS_ASYNC_HANDLE 0x80
#define PARAM_ATTRIBUTE_SERVER_ALLOC_SIZE 0xE000
#define PARAM_ATTRIBUTE_SAVE_FOR_ASYNC_FINISH 0x0400
#define PARAM_ATTRIBUTE_IS_DONT_CALL_FREE_INST 0x0200
#define PARAM_ATTRIBUTE_IS_SIMPLE_REF 0x0100
#define PARAM_ATTRIBUTE_IS_BY_VALUE 0x0080
#define PARAM_ATTRIBUTE_IS_BASE_TYPE 0x0040
#define PARAM_ATTRIBUTE_IS_RETURN 0x0020
#define PARAM_ATTRIBUTE_IS_OUT 0x0010
#define PARAM_ATTRIBUTE_IS_IN 0x0008
#define PARAM_ATTRIBUTE_IS_PIPE 0x0004
#define PARAM_ATTRIBUTE_MUST_FREE 0x0002
#define PARAM_ATTRIBUTE_MUST_SIZE 0x0001
typedef struct
{
unsigned short Attributes;
unsigned short StackOffset;
union
{
unsigned char FormatChar;
unsigned short Offset;
} Type;
} NDR_PARAM;
typedef struct
{