FreeRDP
Loading...
Searching...
No Matches
ndr.h File Reference

NDR encoder and decoder ([C706] chapter 14, [MS-RPCE] 2.2.5 and 2.2.6) More...

#include <winpr/stream.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  WinPrNdrMessageDescr
 message descriptor More...
 
struct  WinPrNdrFieldStruct
 descriptor of a field in a structure More...
 
struct  WinPrNdrStructDescr
 structure descriptor More...
 
struct  WinPrNdrUnionArm
 an arm of a non-encapsulated union More...
 
struct  WinPrNdrUnionDescr
 a non-encapsulated union ([switch_type()]) More...
 
struct  WinPrNdrDeferredEntry
 a deferred pointer, a referent to read after the current construct More...
 
struct  WinPrNdrVaryingArrayHints
 hints for a conformant varying array More...
 
struct  WinPrNdrArrayHints
 hints for a conformant array More...
 

Macros

#define WINPR_NDR_PTR_NULL   (0UL)
 the referent id of a null pointer
 
#define WINPR_NDR_SIMPLE_TYPE_DECL(PREFIX, LOWER, UPPER)
 declares the functions and the message descriptor of a simple type
 
#define WINPR_NDR_ARRAY_OF_TYPE_DECL(PREFIX, TYPE, UPPERTYPE)
 declares the functions and the message descriptors of the arrays of a simple type
 
#define WINPR_NDR_STRUCT_MESSAGE_DEFINE(PREFIX, CTYPE)
 defines a static message type for a structure
 
#define WINPR_NDR_ARRAY_MESSAGE_DEFINE(PREFIX, ITEMPREFIX, CTYPE)
 defines a static message type for a conformant array of ITEMPREFIX##_descr_s items
 
#define WINPR_NDR_UNION_MESSAGE_DEFINE(PREFIX, CTYPE)
 defines a static message type for a non-encapsulated union
 

Typedefs

typedef UINT32 winpr_ndr_refid
 a referent id, the wire value of a pointer (WINPR_NDR_PTR_NULL for a null pointer)
 
typedef BOOL(* WINPR_NDR_READER_FN) (WinPrNdrDecoder *context, wStream *s, const void *hints, void *target)
 reads a message
 
typedef BOOL(* WINPR_NDR_WRITER_FN) (WinPrNdrEncoder *context, wStream *s, const void *hints, const void *obj)
 writes a message
 
typedef void(* WINPR_NDR_DESTROY_FN) (const void *hints, void *obj)
 releases the content of a message, not the message storage itself
 
typedef void(* WINPR_NDR_DUMP_FN) (wLog *logger, UINT32 lvl, size_t indentLevel, const void *obj)
 dumps a message in the logs
 
typedef const WinPrNdrMessageDescr * WinPrNdrMessageType
 a message type, a pointer on its descriptor
 

Enumerations

enum  WinPrNdrTypeArity { WINPR_NDR_ARITY_SIMPLE , WINPR_NDR_ARITY_ARRAYOF , WINPR_NDR_ARITY_VARYING_ARRAYOF , WINPR_NDR_ARITY_SELF_ALLOCATED }
 arity of a message More...
 
enum  WinPrNdrPointerType {
  WINPR_NDR_NOT_POINTER , WINPR_NDR_POINTER_NON_NULL , WINPR_NDR_POINTER , WINPR_NDR_FIXED_ARRAY ,
  WINPR_NDR_POINTER_FULL
}
 pointer or not and if null is accepted More...
 

Functions

WINPR_API void winpr_ndr_encoder_free (WinPrNdrEncoder *context)
 frees an encoder
 
static INLINE void winpr_ndr_encoder_destroy (WinPrNdrEncoder **pcontext)
 frees an encoder and resets the pointer
 
WINPR_API WinPrNdrEncoder * winpr_ndr_encoder_new (BOOL bigEndianDrep, BYTE version)
 creates an encoder
 
WINPR_API WinPrNdrEncoder * winpr_ndr_encoder_from_decoder (const WinPrNdrDecoder *src)
 creates an encoder with the same endianness and version as a decoder, to answer the message it decoded
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_header (WinPrNdrEncoder *context, wStream *s)
 writes the common type header ([MS-RPCE] 2.2.6.1): version, endianness, header length and filler
 
 WINPR_NDR_SIMPLE_TYPE_DECL (winpr_ndr, uint8, UINT8)
 
 WINPR_NDR_SIMPLE_TYPE_DECL (winpr_ndr, int8, INT8)
 
 WINPR_NDR_SIMPLE_TYPE_DECL (winpr_ndr, uint16, UINT16)
 
 WINPR_NDR_SIMPLE_TYPE_DECL (winpr_ndr, int16, INT16)
 
 WINPR_NDR_SIMPLE_TYPE_DECL (winpr_ndr, int32, INT32)
 
 WINPR_NDR_SIMPLE_TYPE_DECL (winpr_ndr, uint32, UINT32)
 
 WINPR_NDR_SIMPLE_TYPE_DECL (winpr_ndr, int64, INT64)
 
 WINPR_NDR_SIMPLE_TYPE_DECL (winpr_ndr, uint64, UINT64)
 
 WINPR_NDR_ARRAY_OF_TYPE_DECL (winpr_ndr, uint8, BYTE)
 
 WINPR_NDR_ARRAY_OF_TYPE_DECL (winpr_ndr, uint16, UINT16)
 
WINPR_API void winpr_ndr_encoder_bytes_written (WinPrNdrEncoder *context, size_t len)
 accounts for bytes written directly in the stream, for the alignments
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_align (WinPrNdrEncoder *context, wStream *s, size_t sz)
 writes zero padding to align the current object offset
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_data (WinPrNdrEncoder *context, wStream *s, const void *data, size_t sz)
 writes raw bytes, without alignment
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_start_object (WinPrNdrEncoder *context, wStream *s)
 starts a serialized object ([MS-RPCE] 2.2.6 type serialization version 1)
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_end_object (WinPrNdrEncoder *context, wStream *s)
 ends the serialized object started with winpr_ndr_encoder_start_object()
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_toplevel_refid (WinPrNdrEncoder *context, wStream *s)
 writes a new referent id for a non-null top-level pointer
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_uconformant_varying_array (WinPrNdrEncoder *context, wStream *s, const WinPrNdrVaryingArrayHints *hints, WinPrNdrMessageType itemType, const void *src)
 writes a conformant varying array: its maximum count, offset 0, actual count and the items
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_uconformant_array (WinPrNdrEncoder *context, wStream *s, UINT32 len, WinPrNdrMessageType itemType, const BYTE *ptr)
 writes a conformant array: its count and the items
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_fromDescr (WinPrNdrEncoder *context, wStream *s, const WinPrNdrStructDescr *descr, const void *src)
 writes a structure from its descriptor
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_union (WinPrNdrEncoder *context, wStream *s, const WinPrNdrUnionDescr *descr, UINT32 switchValue, const void *src)
 writes the discriminant and the arm of a union
 
WINPR_ATTR_NODISCARD WINPR_API winpr_ndr_refid winpr_ndr_pointer_refid (const void *ptr)
 a referent id built from the value of a pointer
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_allocatePtr (WinPrNdrEncoder *context, const void *ptr, winpr_ndr_refid *prefId, BOOL *pnewPtr)
 allocates the referent id of an embedded pointer
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_treat_deferreds (WinPrNdrEncoder *context, wStream *s)
 writes the pending deferred referents
 
WINPR_API void winpr_ndr_decoder_free (WinPrNdrDecoder *context)
 frees a decoder
 
static INLINE void winpr_ndr_decoder_destroy (WinPrNdrDecoder **pcontext)
 frees a decoder and resets the pointer
 
WINPR_API WinPrNdrDecoder * winpr_ndr_decoder_new (BOOL bigEndianDrep, BYTE version)
 creates a decoder
 
WINPR_API WinPrNdrDecoder * winpr_ndr_decoder_new_fromStream (wStream *s)
 reads the common type header ([MS-RPCE] 2.2.6.1) and creates a decoder for its version and endianness
 
WINPR_API void winpr_ndr_decoder_bytes_read (WinPrNdrDecoder *context, size_t len)
 accounts for bytes read directly from the stream, for the alignments
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_object (WinPrNdrDecoder *context, wStream *s, wStream *object)
 reads the private header of a serialized object ([MS-RPCE] 2.2.6 type serialization version 1)
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_push_deferreds (WinPrNdrDecoder *context, WinPrNdrDeferredEntry *deferreds, size_t ndeferred)
 adds deferred pointers, read by the next winpr_ndr_decoder_treat_deferreds()
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_treat_deferreds (WinPrNdrDecoder *context, wStream *s)
 reads the pending deferred referents
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_refpointer (WinPrNdrDecoder *context, wStream *s, UINT32 *refId)
 reads a referent id
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_pointer_ex (WinPrNdrDecoder *context, wStream *s, const char *name, WinPrNdrMessageType descr, void *hints, void **target)
 reads a full pointer ([ptr])
 
WINPR_API void winpr_ndr_pointer_release (void *ptr)
 releases a referent
 
WINPR_API void * winpr_ndr_pointer_new (WinPrNdrMessageType descr, const void *hints, size_t size)
 allocates a referent
 
WINPR_API void * winpr_ndr_pointer_ref (void *ptr)
 takes a reference on a referent
 
WINPR_ATTR_NODISCARD WINPR_API size_t winpr_ndr_pointer_size (const void *ptr)
 the size of a referent, as allocated by winpr_ndr_pointer_new()
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_skip_bytes (WinPrNdrDecoder *context, wStream *s, size_t nbytes)
 skips bytes
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_align (WinPrNdrDecoder *context, wStream *s, size_t sz)
 skips the padding to align the current object offset
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_wchar (WinPrNdrDecoder *context, wStream *s, WCHAR *ptr)
 reads a WCHAR, aligned on 2 bytes
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_wchar (WinPrNdrEncoder *context, wStream *s, const WCHAR *ptr)
 writes a WCHAR stored in UTF-16LE, aligned on 2 bytes
 
WINPR_ATTR_NODISCARD WINPR_API WinPrNdrMessageType winpr_ndr_wchar_descr (void)
 the message type of winpr_ndr_wchar_descr_s
 
 WINPR_NDR_ARRAY_OF_TYPE_DECL (winpr_ndr, wchar, WCHAR)
 the arrays of WCHAR, stored in UTF-16LE in memory: use them for strings instead of the uint16 arrays, which store the items in host byte order
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_pointedMessageEx (WinPrNdrDecoder *context, wStream *s, winpr_ndr_refid ptrId, WinPrNdrMessageType descr, void *hints, void **target)
 reads the referent of a unique pointer
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_fromDescr (WinPrNdrDecoder *context, wStream *s, const WinPrNdrStructDescr *descr, void *target)
 reads a structure from its descriptor
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_union (WinPrNdrDecoder *context, wStream *s, const WinPrNdrUnionDescr *descr, UINT32 switchValue, void *target)
 reads a union, its discriminant must be switchValue
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_uconformant_array (WinPrNdrDecoder *context, wStream *s, const WinPrNdrArrayHints *hints, WinPrNdrMessageType itemType, void *vtarget)
 reads a conformant array: its count and the items
 
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_uconformant_varying_array (WinPrNdrDecoder *context, wStream *s, const WinPrNdrVaryingArrayHints *hints, WinPrNdrMessageType itemType, void *ptarget)
 reads a conformant varying array: its maximum count, offset, actual count and the items
 
WINPR_ATTR_NODISCARD WINPR_API WinPrNdrMessageType winpr_ndr_string_conformant_descr (void)
 the message type of winpr_ndr_string_conformant_descr_s
 
WINPR_ATTR_NODISCARD WINPR_API WinPrNdrMessageType winpr_ndr_string_varying_descr (void)
 the message type of winpr_ndr_string_varying_descr_s
 
WINPR_ATTR_NODISCARD WINPR_API WinPrNdrMessageType winpr_ndr_wstring_varying_descr (void)
 the message type of winpr_ndr_wstring_varying_descr_s
 
WINPR_API void winpr_ndr_struct_dump_fromDescr (wLog *logger, UINT32 lvl, size_t identLevel, const WinPrNdrStructDescr *descr, const void *obj)
 dumps a structure in the logs from its descriptor
 
WINPR_API void winpr_ndr_struct_destroy (const WinPrNdrStructDescr *descr, void *pptr)
 releases the content of a structure from its descriptor
 
WINPR_ATTR_NODISCARD WINPR_API UINT32 winpr_ndr_union_switch_value (const WinPrNdrUnionDescr *descr, const void *switchField)
 the value of the [switch_is()] field of a union
 
WINPR_API void winpr_ndr_union_destroy (const WinPrNdrUnionDescr *descr, UINT32 switchValue, void *obj)
 releases the content of the arm switchValue of a union
 

Variables

WINPR_API const WinPrNdrMessageDescr winpr_ndr_wchar_descr_s
 a WCHAR, stored in UTF-16LE in memory
 
WINPR_API const WinPrNdrMessageDescr winpr_ndr_string_conformant_descr_s
 conformant string of char, read in a char* allocated with winpr_ndr_pointer_new()
 
WINPR_API const WinPrNdrMessageDescr winpr_ndr_string_varying_descr_s
 [string] char*: a conformant varying string of char, read in a char* allocated with winpr_ndr_pointer_new()
 
WINPR_API const WinPrNdrMessageDescr winpr_ndr_wstring_varying_descr_s
 [string] wchar_t*: a conformant varying string of WCHAR, read in a WCHAR* allocated with winpr_ndr_pointer_new()
 

Detailed Description

NDR encoder and decoder ([C706] chapter 14, [MS-RPCE] 2.2.5 and 2.2.6)

WinPR: Windows Portable Runtime NDR (Network Data Representation) encoding and decoding

Copyright 2024 David Fort conta.nosp@m.ct@h.nosp@m.arden.nosp@m.ing-.nosp@m.consu.nosp@m.ltin.nosp@m.g.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.

Messages are described with descriptors (WinPrNdrMessageDescr, WinPrNdrStructDescr, WinPrNdrUnionDescr), and read, written, dumped and destroyed from these descriptors.

The encoder (WinPrNdrEncoder) and the decoder (WinPrNdrDecoder) keep the alignment offset of the current object and the pending deferred pointers: the referents of the embedded pointers are written after the construct that contains them, so writing or reading a message is followed by a call to winpr_ndr_encoder_treat_deferreds() or winpr_ndr_decoder_treat_deferreds().

All the pointers returned by the decoder are reference counted referents allocated with winpr_ndr_pointer_new(), they must not be passed to free() but released with winpr_ndr_pointer_release() (winpr_ndr_struct_destroy() releases the pointers of a structure).

Since
version 3.33.0

Definition in file ndr.h.


Data Structure Documentation

◆ WinPrNdrMessageDescr

struct WinPrNdrMessageDescr

message descriptor

Since
version 3.33.0

Definition at line 293 of file ndr.h.

Collaboration diagram for WinPrNdrMessageDescr:
Data Fields
WinPrNdrTypeArity arity
WINPR_NDR_DESTROY_FN destroyFn

releases its content, can be nullptr

WINPR_NDR_DUMP_FN dumpFn

dumps it in the logs, can be nullptr

size_t itemSize

size of the C type (of an item for an array)

WINPR_NDR_READER_FN readFn

reads the message

WINPR_NDR_WRITER_FN writeFn

writes the message

◆ WinPrNdrFieldStruct

struct WinPrNdrFieldStruct

descriptor of a field in a structure

Since
version 3.33.0

Definition at line 327 of file ndr.h.

Collaboration diagram for WinPrNdrFieldStruct:
Data Fields
size_t fixedArraySize

size in bytes of the inline storage of an array

SSIZE_T hintsField

index of the field holding the hints of this field (the size of an array...), -1 if none

const char * name

name of the field, for the logs

WinPrNdrPointerType pointerType

how the field is stored

UINT32 rangeMax

for an integer field: [range(0, rangeMax)], not checked if 0

size_t structOffset

offset of the field in the structure

WinPrNdrMessageType typeDescr

type of the field (of its referent for a pointer)

◆ WinPrNdrStructDescr

struct WinPrNdrStructDescr

structure descriptor

Since
version 3.33.0

Definition at line 342 of file ndr.h.

Collaboration diagram for WinPrNdrStructDescr:
Data Fields
size_t alignment

alignment of the structure (its largest member), 0 if unspecified

const WinPrNdrFieldStruct * fields

the fields, in their wire order

const char * name

name of the structure, for the logs

size_t nfields

number of fields

◆ WinPrNdrUnionArm

struct WinPrNdrUnionArm

an arm of a non-encapsulated union

Since
version 3.33.0

Definition at line 353 of file ndr.h.

Collaboration diagram for WinPrNdrUnionArm:
Data Fields
UINT32 discriminant

the [case()] value of the arm

WinPrNdrFieldStruct field

the arm, its structOffset is relative to the union and it has no hints. An arm without typeDescr has no body

◆ WinPrNdrUnionDescr

struct WinPrNdrUnionDescr

a non-encapsulated union ([switch_type()])

On the wire the union is its discriminant followed by the selected arm, aligned on its own type.

Since
version 3.33.0

Definition at line 367 of file ndr.h.

Collaboration diagram for WinPrNdrUnionDescr:
Data Fields
const WinPrNdrUnionArm * arms

the arms

const WinPrNdrUnionArm * defaultArm

the [default] arm, its discriminant is ignored. Without it an unknown discriminant is an error

const char * name

name of the union, for the logs

size_t narms

number of arms

size_t switchSize

size of the discriminant and of the [switch_is()] field: 2 for a short or an enum, 4 for a long (the default when 0)

◆ WinPrNdrDeferredEntry

struct WinPrNdrDeferredEntry

a deferred pointer, a referent to read after the current construct

Since
version 3.33.0

Definition at line 381 of file ndr.h.

Collaboration diagram for WinPrNdrDeferredEntry:
Data Fields
BOOL allocate

the referent is allocated with winpr_ndr_pointer_new() (or by the reader of a self allocated type)

void * hints

hints of the referent, valid until the deferred is treated

WinPrNdrMessageType msg

the type of the referent

const char * name

name of the pointer, for the logs

winpr_ndr_refid ptrId

the referent id read for the pointer

void * target

if allocate is set, the pointer field that receives the referent, otherwise the storage the referent is read into

◆ WinPrNdrVaryingArrayHints

struct WinPrNdrVaryingArrayHints

hints for a conformant varying array

Since
version 3.33.0

Definition at line 525 of file ndr.h.

Data Fields
UINT32 length

the actual count

UINT32 maxLength

the maximum count

◆ WinPrNdrArrayHints

struct WinPrNdrArrayHints

hints for a conformant array

Since
version 3.33.0

Definition at line 552 of file ndr.h.

Data Fields
UINT32 count

the number of items

Macro Definition Documentation

◆ WINPR_NDR_ARRAY_MESSAGE_DEFINE

#define WINPR_NDR_ARRAY_MESSAGE_DEFINE (   PREFIX,
  ITEMPREFIX,
  CTYPE 
)
Value:
static BOOL PREFIX##_read(WinPrNdrDecoder* context, wStream* s, const void* hints, void* obj) \
{ \
return winpr_ndr_decoder_read_uconformant_array(context, s, hints, &ITEMPREFIX##_descr_s, \
obj); \
} \
static BOOL PREFIX##_write(WinPrNdrEncoder* context, wStream* s, const void* hints, \
const void* obj) \
{ \
WINPR_ASSERT(hints); \
const WinPrNdrArrayHints* ahints = hints; \
return winpr_ndr_encoder_write_uconformant_array(context, s, ahints->count, \
&ITEMPREFIX##_descr_s, obj); \
} \
static void PREFIX##_destroy(const void* hints, void* obj) \
{ \
WINPR_ASSERT(hints); \
const WinPrNdrArrayHints* ahints = hints; \
CTYPE* items = obj; \
for (UINT32 i = 0; i < ahints->count; i++) \
ITEMPREFIX##_destroy(nullptr, &items[i]); \
} \
static const WinPrNdrMessageDescr PREFIX##_descr_s = { \
WINPR_NDR_ARITY_ARRAYOF, sizeof(CTYPE), PREFIX##_read, \
PREFIX##_write, PREFIX##_destroy, nullptr \
}
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_uconformant_array(WinPrNdrDecoder *context, wStream *s, const WinPrNdrArrayHints *hints, WinPrNdrMessageType itemType, void *vtarget)
reads a conformant array: its count and the items
Definition ndr.c:1361
@ WINPR_NDR_ARITY_ARRAYOF
Definition ndr.h:281
UINT32 count
Definition ndr.h:554
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_uconformant_array(WinPrNdrEncoder *context, wStream *s, UINT32 len, WinPrNdrMessageType itemType, const BYTE *ptr)
writes a conformant array: its count and the items
Definition ndr.c:935
hints for a conformant array
Definition ndr.h:553
message descriptor
Definition ndr.h:294

defines a static message type for a conformant array of ITEMPREFIX##_descr_s items

Defines PREFIX##_descr_s, the hints of the array field are a WinPrNdrArrayHints.

Since
version 3.33.0

Definition at line 151 of file ndr.h.

153 { \
154 return winpr_ndr_decoder_read_uconformant_array(context, s, hints, &ITEMPREFIX##_descr_s, \
155 obj); \
156 } \
157 static BOOL PREFIX##_write(WinPrNdrEncoder* context, wStream* s, const void* hints, \
158 const void* obj) \
159 { \
160 WINPR_ASSERT(hints); \
161 const WinPrNdrArrayHints* ahints = hints; \
162 return winpr_ndr_encoder_write_uconformant_array(context, s, ahints->count, \
163 &ITEMPREFIX##_descr_s, obj); \
164 } \
165 static void PREFIX##_destroy(const void* hints, void* obj) \
166 { \
167 WINPR_ASSERT(hints); \
168 const WinPrNdrArrayHints* ahints = hints; \
169 CTYPE* items = obj; \
170 for (UINT32 i = 0; i < ahints->count; i++) \
171 ITEMPREFIX##_destroy(nullptr, &items[i]); \
172 } \
173 static const WinPrNdrMessageDescr PREFIX##_descr_s = { \
174 WINPR_NDR_ARITY_ARRAYOF, sizeof(CTYPE), PREFIX##_read, \
175 PREFIX##_write, PREFIX##_destroy, nullptr \
176 }

◆ WINPR_NDR_ARRAY_OF_TYPE_DECL

#define WINPR_NDR_ARRAY_OF_TYPE_DECL (   PREFIX,
  TYPE,
  UPPERTYPE 
)
Value:
WINPR_ATTR_NODISCARD \
WINPR_API BOOL PREFIX##_decoder_read_##TYPE##Array(WinPrNdrDecoder* context, wStream* s, \
const void* hints, void* v); \
WINPR_ATTR_NODISCARD \
WINPR_API BOOL PREFIX##_encoder_write_##TYPE##Array(WinPrNdrEncoder* context, wStream* s, \
const void* hints, const void* v); \
WINPR_API void PREFIX##_destroy_##TYPE##Array(const void* hints, void* obj); \
WINPR_API extern const WinPrNdrMessageDescr PREFIX##_##TYPE##Array_descr_s; \
WINPR_ATTR_NODISCARD \
WINPR_API WinPrNdrMessageType PREFIX##_##TYPE##Array_descr(void); \
\
WINPR_ATTR_NODISCARD \
WINPR_API BOOL PREFIX##_decoder_read_##TYPE##VaryingArray( \
WinPrNdrDecoder* context, wStream* s, const void* hints, void* v); \
WINPR_ATTR_NODISCARD \
WINPR_API BOOL PREFIX##_encoder_write_##TYPE##VaryingArray( \
WinPrNdrEncoder* context, wStream* s, const void* hints, const void* v); \
WINPR_API extern const WinPrNdrMessageDescr PREFIX##_##TYPE##VaryingArray_descr_s; \
WINPR_ATTR_NODISCARD \
WINPR_API WinPrNdrMessageType PREFIX##_##TYPE##VaryingArray_descr(void)

declares the functions and the message descriptors of the arrays of a simple type

For the items of type TYPE (stored in a UPPERTYPE) this declares:

  • the conformant array: PREFIX##_decoder_read_##TYPE##Array(), PREFIX##_encoder_write_##TYPE##Array(), PREFIX##_destroy_##TYPE##Array() and the message descriptor PREFIX##_##TYPE##Array_descr_s / PREFIX##_##TYPE##Array_descr(), its hints are a WinPrNdrArrayHints;
  • the conformant varying array: PREFIX##_decoder_read_##TYPE##VaryingArray(), PREFIX##_encoder_write_##TYPE##VaryingArray() and the message descriptor PREFIX##_##TYPE##VaryingArray_descr_s / PREFIX##_##TYPE##VaryingArray_descr(), its hints are a WinPrNdrVaryingArrayHints.
Since
version 3.33.0

Definition at line 91 of file ndr.h.

◆ WINPR_NDR_PTR_NULL

#define WINPR_NDR_PTR_NULL   (0UL)

the referent id of a null pointer

Since
version 3.33.0

Definition at line 48 of file ndr.h.

◆ WINPR_NDR_SIMPLE_TYPE_DECL

#define WINPR_NDR_SIMPLE_TYPE_DECL (   PREFIX,
  LOWER,
  UPPER 
)
Value:
WINPR_ATTR_NODISCARD \
WINPR_API BOOL PREFIX##_decoder_read_##LOWER(WinPrNdrDecoder* context, wStream* s, UPPER* v); \
WINPR_ATTR_NODISCARD \
WINPR_API BOOL PREFIX##_decoder_read_##LOWER##_(WinPrNdrDecoder* context, wStream* s, \
const void* hints, void* v); \
WINPR_ATTR_NODISCARD \
WINPR_API BOOL PREFIX##_encoder_write_##LOWER(WinPrNdrEncoder* context, wStream* s, UPPER v); \
WINPR_ATTR_NODISCARD \
WINPR_API BOOL PREFIX##_encoder_write_##LOWER##_(WinPrNdrEncoder* context, wStream* s, \
const void* hints, const void* v); \
WINPR_API extern const WinPrNdrMessageDescr PREFIX##_##LOWER##_descr_s; \
WINPR_ATTR_NODISCARD \
WINPR_API WinPrNdrMessageType PREFIX##_##LOWER##_descr(void)

declares the functions and the message descriptor of a simple type

For a type named LOWER (stored in a UPPER) this declares:

  • PREFIX##_decoder_read_##LOWER() and PREFIX##_encoder_write_##LOWER(), that read and write a value aligned on its size;
  • PREFIX##_decoder_read_##LOWER##_() and PREFIX##_encoder_write_##LOWER##_(), the same with the WINPR_NDR_READER_FN / WINPR_NDR_WRITER_FN prototypes;
  • PREFIX##_##LOWER##_descr_s and PREFIX##_##LOWER##_descr(), the message descriptor of the type.
Since
version 3.33.0

Definition at line 62 of file ndr.h.

◆ WINPR_NDR_STRUCT_MESSAGE_DEFINE

#define WINPR_NDR_STRUCT_MESSAGE_DEFINE (   PREFIX,
  CTYPE 
)
Value:
static BOOL PREFIX##_read(WinPrNdrDecoder* context, wStream* s, const void* hints, void* obj) \
{ \
WINPR_UNUSED(hints); \
return winpr_ndr_decoder_read_fromDescr(context, s, &PREFIX##_struct, obj); \
} \
static BOOL PREFIX##_write(WinPrNdrEncoder* context, wStream* s, const void* hints, \
const void* obj) \
{ \
WINPR_UNUSED(hints); \
return winpr_ndr_encoder_write_fromDescr(context, s, &PREFIX##_struct, obj); \
} \
static void PREFIX##_destroy(const void* hints, void* obj) \
{ \
WINPR_UNUSED(hints); \
winpr_ndr_struct_destroy(&PREFIX##_struct, obj); \
} \
static void PREFIX##_dump(wLog* logger, UINT32 lvl, size_t indentLevel, const void* obj) \
{ \
winpr_ndr_struct_dump_fromDescr(logger, lvl, indentLevel, &PREFIX##_struct, obj); \
} \
static const WinPrNdrMessageDescr PREFIX##_descr_s = { WINPR_NDR_ARITY_SIMPLE, sizeof(CTYPE), \
PREFIX##_read, PREFIX##_write, \
PREFIX##_destroy, PREFIX##_dump }
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_fromDescr(WinPrNdrDecoder *context, wStream *s, const WinPrNdrStructDescr *descr, void *target)
reads a structure from its descriptor
Definition ndr.c:1695
@ WINPR_NDR_ARITY_SIMPLE
Definition ndr.h:280
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_fromDescr(WinPrNdrEncoder *context, wStream *s, const WinPrNdrStructDescr *descr, const void *src)
writes a structure from its descriptor
Definition ndr.c:1032

defines a static message type for a structure

Defines PREFIX##_descr_s for the CTYPE structure described by the WinPrNdrStructDescr PREFIX##_struct.

Since
version 3.33.0

Definition at line 120 of file ndr.h.

122 { \
123 WINPR_UNUSED(hints); \
124 return winpr_ndr_decoder_read_fromDescr(context, s, &PREFIX##_struct, obj); \
125 } \
126 static BOOL PREFIX##_write(WinPrNdrEncoder* context, wStream* s, const void* hints, \
127 const void* obj) \
128 { \
129 WINPR_UNUSED(hints); \
130 return winpr_ndr_encoder_write_fromDescr(context, s, &PREFIX##_struct, obj); \
131 } \
132 static void PREFIX##_destroy(const void* hints, void* obj) \
133 { \
134 WINPR_UNUSED(hints); \
135 winpr_ndr_struct_destroy(&PREFIX##_struct, obj); \
136 } \
137 static void PREFIX##_dump(wLog* logger, UINT32 lvl, size_t indentLevel, const void* obj) \
138 { \
139 winpr_ndr_struct_dump_fromDescr(logger, lvl, indentLevel, &PREFIX##_struct, obj); \
140 } \
141 static const WinPrNdrMessageDescr PREFIX##_descr_s = { WINPR_NDR_ARITY_SIMPLE, sizeof(CTYPE), \
142 PREFIX##_read, PREFIX##_write, \
143 PREFIX##_destroy, PREFIX##_dump }

◆ WINPR_NDR_UNION_MESSAGE_DEFINE

#define WINPR_NDR_UNION_MESSAGE_DEFINE (   PREFIX,
  CTYPE 
)
Value:
static BOOL PREFIX##_read(WinPrNdrDecoder* context, wStream* s, const void* hints, void* obj) \
{ \
WINPR_ASSERT(hints); \
return winpr_ndr_decoder_read_union(context, s, &PREFIX##_union, \
winpr_ndr_union_switch_value(&PREFIX##_union, hints), \
obj); \
} \
static BOOL PREFIX##_write(WinPrNdrEncoder* context, wStream* s, const void* hints, \
const void* obj) \
{ \
WINPR_ASSERT(hints); \
return winpr_ndr_encoder_write_union(context, s, &PREFIX##_union, \
winpr_ndr_union_switch_value(&PREFIX##_union, hints), \
obj); \
} \
static void PREFIX##_destroy(const void* hints, void* obj) \
{ \
if (hints) \
winpr_ndr_union_destroy(&PREFIX##_union, \
winpr_ndr_union_switch_value(&PREFIX##_union, hints), obj); \
} \
static const WinPrNdrMessageDescr PREFIX##_descr_s = { WINPR_NDR_ARITY_SIMPLE, sizeof(CTYPE), \
PREFIX##_read, PREFIX##_write, \
PREFIX##_destroy, nullptr }
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_union(WinPrNdrDecoder *context, wStream *s, const WinPrNdrUnionDescr *descr, UINT32 switchValue, void *target)
reads a union, its discriminant must be switchValue
Definition ndr.c:1922
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_union(WinPrNdrEncoder *context, wStream *s, const WinPrNdrUnionDescr *descr, UINT32 switchValue, const void *src)
writes the discriminant and the arm of a union
Definition ndr.c:1903
WINPR_ATTR_NODISCARD WINPR_API UINT32 winpr_ndr_union_switch_value(const WinPrNdrUnionDescr *descr, const void *switchField)
the value of the [switch_is()] field of a union
Definition ndr.c:1830

defines a static message type for a non-encapsulated union

Defines PREFIX##_descr_s for the CTYPE union described by the WinPrNdrUnionDescr PREFIX##_union. The hints of the union field are the field of its [switch_is()], a UINT16 or a UINT32 depending on the switchSize of the union.

Since
version 3.33.0

Definition at line 186 of file ndr.h.

188 { \
189 WINPR_ASSERT(hints); \
190 return winpr_ndr_decoder_read_union(context, s, &PREFIX##_union, \
191 winpr_ndr_union_switch_value(&PREFIX##_union, hints), \
192 obj); \
193 } \
194 static BOOL PREFIX##_write(WinPrNdrEncoder* context, wStream* s, const void* hints, \
195 const void* obj) \
196 { \
197 WINPR_ASSERT(hints); \
198 return winpr_ndr_encoder_write_union(context, s, &PREFIX##_union, \
199 winpr_ndr_union_switch_value(&PREFIX##_union, hints), \
200 obj); \
201 } \
202 static void PREFIX##_destroy(const void* hints, void* obj) \
203 { \
204 if (hints) \
205 winpr_ndr_union_destroy(&PREFIX##_union, \
206 winpr_ndr_union_switch_value(&PREFIX##_union, hints), obj); \
207 } \
208 static const WinPrNdrMessageDescr PREFIX##_descr_s = { WINPR_NDR_ARITY_SIMPLE, sizeof(CTYPE), \
209 PREFIX##_read, PREFIX##_write, \
210 PREFIX##_destroy, nullptr }

Typedef Documentation

◆ WINPR_NDR_DESTROY_FN

typedef void(* WINPR_NDR_DESTROY_FN) (const void *hints, void *obj)

releases the content of a message, not the message storage itself

Parameters
hintsthe hints of the message, can be nullptr
objthe message
Since
version 3.33.0

Definition at line 262 of file ndr.h.

◆ WINPR_NDR_DUMP_FN

typedef void(* WINPR_NDR_DUMP_FN) (wLog *logger, UINT32 lvl, size_t indentLevel, const void *obj)

dumps a message in the logs

Parameters
loggerthe logger to use
lvlthe log level
indentLevelthe number of tabs to prepend to each line
objthe message
Since
version 3.33.0

Definition at line 272 of file ndr.h.

◆ WINPR_NDR_READER_FN

typedef BOOL(* WINPR_NDR_READER_FN) (WinPrNdrDecoder *context, wStream *s, const void *hints, void *target)

reads a message

Parameters
contextthe decoder
sthe stream to read from
hintsthe hints of the message (the size of an array...), can be nullptr
targetwhere the message is stored
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 241 of file ndr.h.

◆ winpr_ndr_refid

typedef UINT32 winpr_ndr_refid

a referent id, the wire value of a pointer (WINPR_NDR_PTR_NULL for a null pointer)

Since
version 3.33.0

Definition at line 230 of file ndr.h.

◆ WINPR_NDR_WRITER_FN

typedef BOOL(* WINPR_NDR_WRITER_FN) (WinPrNdrEncoder *context, wStream *s, const void *hints, const void *obj)

writes a message

Parameters
contextthe encoder
sthe stream to write to
hintsthe hints of the message (the size of an array...), can be nullptr
objthe message to write
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 253 of file ndr.h.

◆ WinPrNdrMessageType

a message type, a pointer on its descriptor

Since
version 3.33.0

Definition at line 306 of file ndr.h.

Enumeration Type Documentation

◆ WinPrNdrPointerType

pointer or not and if null is accepted

Since
version 3.33.0
Enumerator
WINPR_NDR_NOT_POINTER 

the field is stored inline, an array of fixedArraySize bytes if fixedArraySize is not 0

WINPR_NDR_POINTER_NON_NULL 

[ref] or a unique pointer that can't be null

WINPR_NDR_POINTER 

unique pointer ([unique])

WINPR_NDR_FIXED_ARRAY 

unique pointer on a conformant array stored inline in the field (fixedArraySize bytes), the pointer is null when the array is empty

WINPR_NDR_POINTER_FULL 

full pointer ([ptr]): pointers with the same referent id share the same referent

Definition at line 311 of file ndr.h.

312 {
WinPrNdrPointerType
pointer or not and if null is accepted
Definition ndr.h:312
@ WINPR_NDR_NOT_POINTER
Definition ndr.h:313
@ WINPR_NDR_POINTER_FULL
Definition ndr.h:320
@ WINPR_NDR_FIXED_ARRAY
Definition ndr.h:317
@ WINPR_NDR_POINTER
Definition ndr.h:316
@ WINPR_NDR_POINTER_NON_NULL
Definition ndr.h:315

◆ WinPrNdrTypeArity

arity of a message

Since
version 3.33.0
Enumerator
WINPR_NDR_ARITY_SIMPLE 

a single item

WINPR_NDR_ARITY_ARRAYOF 

a conformant array, the hints are a WinPrNdrArrayHints

WINPR_NDR_ARITY_VARYING_ARRAYOF 

a conformant varying array, the hints are a WinPrNdrVaryingArrayHints

WINPR_NDR_ARITY_SELF_ALLOCATED 

the reader allocates the referent (strings...) with winpr_ndr_pointer_new(): the target is the pointer field, itemSize is the size of an element

Definition at line 278 of file ndr.h.

279 {
WinPrNdrTypeArity
arity of a message
Definition ndr.h:279
@ WINPR_NDR_ARITY_VARYING_ARRAYOF
Definition ndr.h:283
@ WINPR_NDR_ARITY_SELF_ALLOCATED
Definition ndr.h:285

Function Documentation

◆ WINPR_NDR_ARRAY_OF_TYPE_DECL()

WINPR_NDR_ARRAY_OF_TYPE_DECL ( winpr_ndr  ,
wchar  ,
WCHAR   
)

the arrays of WCHAR, stored in UTF-16LE in memory: use them for strings instead of the uint16 arrays, which store the items in host byte order

Since
version 3.34.0

◆ winpr_ndr_decoder_bytes_read()

WINPR_API void winpr_ndr_decoder_bytes_read ( WinPrNdrDecoder *  context,
size_t  len 
)

accounts for bytes read directly from the stream, for the alignments

Parameters
contextthe decoder
lenthe number of bytes read
Since
version 3.33.0

Definition at line 1158 of file ndr.c.

1159{
1160 WINPR_ASSERT(context);
1161 context->offset += len;
1162}

References winpr_ndr_decoder_bytes_read().

Referenced by winpr_ndr_decoder_bytes_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_destroy()

static INLINE void winpr_ndr_decoder_destroy ( WinPrNdrDecoder **  pcontext)
static

frees a decoder and resets the pointer

Parameters
pcontexta pointer on the decoder to free, must not be nullptr
Since
version 3.33.0

Definition at line 657 of file ndr.h.

658 {
659 WINPR_ASSERT(pcontext);
660 winpr_ndr_decoder_free(*pcontext);
661 *pcontext = nullptr;
662 }
WINPR_API void winpr_ndr_decoder_free(WinPrNdrDecoder *context)
frees a decoder
Definition ndr.c:1148

References winpr_ndr_decoder_free().

Here is the call graph for this function:

◆ winpr_ndr_decoder_free()

WINPR_API void winpr_ndr_decoder_free ( WinPrNdrDecoder *  context)

frees a decoder

The referents it decoded belong to their pointers and are not released.

Parameters
contextthe decoder to free, can be nullptr
Since
version 3.33.0

Definition at line 1148 of file ndr.c.

1149{
1150 if (context)
1151 {
1152 /* the referents belong to the pointers that reference them */
1153 HashTable_Free(context->referents);
1154 free(context);
1155 }
1156}

References winpr_ndr_decoder_free().

Referenced by winpr_ndr_decoder_destroy(), winpr_ndr_decoder_free(), and winpr_ndr_decoder_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_new()

WINPR_API WinPrNdrDecoder * winpr_ndr_decoder_new ( BOOL  bigEndianDrep,
BYTE  version 
)

creates a decoder

Parameters
bigEndianDrepTRUE to decode big endian data, FALSE for little endian
versionthe type serialization version
Returns
the new decoder, nullptr on failure
Since
version 3.33.0

Definition at line 1106 of file ndr.c.

1107{
1108 WinPrNdrDecoder* ret = calloc(1, sizeof(*ret));
1109 if (!ret)
1110 return nullptr;
1111
1112 ret->version = version;
1113 ret->bigEndianDrep = bigEndianDrep;
1114 ret->referents = HashTable_New(FALSE);
1115 if (!ret->referents)
1116 {
1118 return nullptr;
1119 }
1120
1121 return ret;
1122}

References winpr_ndr_decoder_free(), and winpr_ndr_decoder_new().

Referenced by winpr_ndr_decoder_new(), and winpr_ndr_decoder_new_fromStream().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_new_fromStream()

WINPR_API WinPrNdrDecoder * winpr_ndr_decoder_new_fromStream ( wStream *  s)

reads the common type header ([MS-RPCE] 2.2.6.1) and creates a decoder for its version and endianness

Only the version 1 is supported.

Parameters
sthe stream to read from, positioned after the header on success
Returns
the new decoder, nullptr on failure
Since
version 3.33.0

Definition at line 1124 of file ndr.c.

1125{
1126 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
1127 return nullptr;
1128
1129 BYTE version = Stream_Get_UINT8(s);
1130 BYTE drep = Stream_Get_UINT8(s);
1131 UINT16 headerLen = Stream_Get_UINT16(s);
1132
1133 if (version != 1)
1134 {
1135 WLog_ERR(TAG, "unsupported type serialization version %" PRIu8, version);
1136 return nullptr;
1137 }
1138
1139 if (headerLen < 4 || !Stream_CheckAndLogRequiredLength(TAG, s, headerLen - 4))
1140 return nullptr;
1141
1142 /* skip filler */
1143 Stream_Seek(s, headerLen - 4);
1144
1145 return winpr_ndr_decoder_new((drep != 0x10), version);
1146}
WINPR_API WinPrNdrDecoder * winpr_ndr_decoder_new(BOOL bigEndianDrep, BYTE version)
creates a decoder
Definition ndr.c:1106

References winpr_ndr_decoder_new(), and winpr_ndr_decoder_new_fromStream().

Referenced by winpr_ndr_decoder_new_fromStream().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_push_deferreds()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_push_deferreds ( WinPrNdrDecoder *  context,
WinPrNdrDeferredEntry *  deferreds,
size_t  ndeferred 
)

adds deferred pointers, read by the next winpr_ndr_decoder_treat_deferreds()

This is used by custom readers that read the referent ids of their pointers themselves. The entries are copied, the hints they reference must stay valid until they are treated.

Parameters
contextthe decoder
deferredsthe deferred pointers, in their wire order
ndeferredthe number of entries
Returns
TRUE on success, FALSE if there are too many pending deferred pointers
Since
version 3.33.0

Definition at line 1803 of file ndr.c.

1805{
1806 WINPR_ASSERT(context);
1807 WINPR_ASSERT(deferreds);
1808
1809 BOOL ok = TRUE;
1810 ndr_deferreds_enter(&context->deferreds);
1811 for (size_t i = 0; ok && (i < ndeferred); i++)
1812 ok = ndr_deferreds_add(&context->deferreds, &deferreds[i]);
1813
1814 return ndr_deferreds_leave(&context->deferreds, ok);
1815}

References winpr_ndr_decoder_push_deferreds().

Referenced by winpr_ndr_decoder_push_deferreds().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_read_align()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_align ( WinPrNdrDecoder *  context,
wStream *  s,
size_t  sz 
)

skips the padding to align the current object offset

Parameters
contextthe decoder
sthe stream to read from
szthe alignment, must not be 0
Returns
TRUE on success, FALSE if the stream is too short
Since
version 3.33.0

Definition at line 1176 of file ndr.c.

1177{
1178 WINPR_ASSERT(context);
1179
1180 size_t rest = context->offset % sz;
1181 if (rest)
1182 {
1183 size_t padding = (sz - rest);
1184 if (!Stream_CheckAndLogRequiredLength(TAG, s, padding))
1185 return FALSE;
1186
1187 Stream_Seek(s, padding);
1188 context->offset += padding;
1189 }
1190
1191 return TRUE;
1192}

References winpr_ndr_decoder_read_align().

Referenced by winpr_ndr_decoder_read_align(), and winpr_ndr_decoder_read_fromDescr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_read_fromDescr()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_fromDescr ( WinPrNdrDecoder *  context,
wStream *  s,
const WinPrNdrStructDescr *  descr,
void *  target 
)

reads a structure from its descriptor

The structure is aligned on descr->alignment, the referents of its pointers are deferred. On failure the structure may be partially filled, it is released with winpr_ndr_struct_destroy().

Parameters
contextthe decoder
sthe stream to read from
descrthe descriptor of the structure
targetthe structure, zeroed by the caller
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 1695 of file ndr.c.

1697{
1698 WINPR_ASSERT(context);
1699 WINPR_ASSERT(s);
1700 WINPR_ASSERT(descr);
1701 WINPR_ASSERT(target);
1702
1703 if ((descr->alignment > 1) && !winpr_ndr_decoder_read_align(context, s, descr->alignment))
1704 return FALSE;
1705
1706 BOOL ok = TRUE;
1707 ndr_deferreds_enter(&context->deferreds);
1708 for (size_t i = 0; ok && (i < descr->nfields); i++)
1709 ok = ndr_decoder_read_field(context, s, descr, &descr->fields[i], target);
1710
1711 return ndr_deferreds_leave(&context->deferreds, ok);
1712}
size_t alignment
Definition ndr.h:347
const WinPrNdrFieldStruct * fields
Definition ndr.h:346
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_align(WinPrNdrDecoder *context, wStream *s, size_t sz)
skips the padding to align the current object offset
Definition ndr.c:1176
size_t nfields
Definition ndr.h:345

References WinPrNdrStructDescr::alignment, WinPrNdrStructDescr::fields, WinPrNdrStructDescr::nfields, winpr_ndr_decoder_read_align(), and winpr_ndr_decoder_read_fromDescr().

Referenced by winpr_ndr_decoder_read_fromDescr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_read_object()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_object ( WinPrNdrDecoder *  context,
wStream *  s,
wStream *  object 
)

reads the private header of a serialized object ([MS-RPCE] 2.2.6 type serialization version 1)

The alignments are then relative to the start of the object data.

Parameters
contextthe decoder
sthe stream to read from, positioned after the object on success
objectreceives a static stream on the object data, to decode with this context. It points in the buffer of s.
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 1199 of file ndr.c.

1200{
1201 WINPR_ASSERT(context);
1202 WINPR_ASSERT(s);
1203 WINPR_ASSERT(object);
1204
1205 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
1206 return FALSE;
1207
1208 UINT32 len = 0;
1209 if (context->bigEndianDrep)
1210 Stream_Read_UINT32_BE(s, len);
1211 else
1212 Stream_Read_UINT32(s, len);
1213 Stream_Seek(s, 4); /* Filler */
1214
1215 if (!Stream_CheckAndLogRequiredLength(TAG, s, len))
1216 return FALSE;
1217
1218 Stream_StaticInit(object, Stream_PointerAs(s, BYTE), len);
1219 Stream_Seek(s, len);
1220
1221 /* alignments are relative to the start of the object data */
1222 context->offset = 0;
1223 return TRUE;
1224}

References winpr_ndr_decoder_read_object().

Referenced by winpr_ndr_decoder_read_object().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_read_pointedMessageEx()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_pointedMessageEx ( WinPrNdrDecoder *  context,
wStream *  s,
winpr_ndr_refid  ptrId,
WinPrNdrMessageType  descr,
void *  hints,
void **  target 
)

reads the referent of a unique pointer

The referent is allocated with winpr_ndr_pointer_new() (or by the reader of a self allocated type) and read. A referent id already used by another pointer is rejected.

Parameters
contextthe decoder
sthe stream to read from
ptrIdthe referent id of the pointer, nothing is read for WINPR_NDR_PTR_NULL
descrthe type of the referent
hintsthe hints of the referent, can be nullptr for a simple type
targetreceives the referent, nullptr for a null pointer
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 1741 of file ndr.c.

1744{
1745 WINPR_ASSERT(context);
1746 WINPR_ASSERT(s);
1747 WINPR_ASSERT(descr);
1748 WINPR_ASSERT(target);
1749
1750 *target = nullptr;
1751 if (!ptrId)
1752 return TRUE;
1753
1754 /* a unique pointer can't share its referent */
1755 if (HashTable_Contains(context->referents, (void*)(UINT_PTR)ptrId))
1756 {
1757 WLog_ERR(TAG, "unique pointer 0x%" PRIx32 " is aliased", ptrId);
1758 return FALSE;
1759 }
1760
1761 void* ret = nullptr;
1762 if (descr->arity == WINPR_NDR_ARITY_SELF_ALLOCATED)
1763 {
1764 /* the reader allocates the referent with winpr_ndr_pointer_new() */
1765 if (!descr->readFn(context, s, hints, (void*)&ret))
1766 return FALSE;
1767 if (!ret)
1768 return FALSE;
1769 }
1770 else
1771 {
1772 size_t size = 0;
1773 if (!ndr_referent_size("unique pointer", descr, hints, &size))
1774 return FALSE;
1775
1776 /* each item takes at least one byte on the wire, don't allocate for data that isn't
1777 * there */
1778 if ((descr->arity == WINPR_NDR_ARITY_ARRAYOF) &&
1779 !Stream_CheckAndLogRequiredLength(TAG, s, ndr_hintsCount(descr, hints)))
1780 return FALSE;
1781
1782 ret = winpr_ndr_pointer_new(descr, hints, size);
1783 if (!ret)
1784 return FALSE;
1785
1786 if (!descr->readFn(context, s, hints, ret))
1787 {
1789 return FALSE;
1790 }
1791 }
1792
1793 if (!ndr_decoder_register(context, ndr_referent(ret), ptrId, FALSE))
1794 {
1796 return FALSE;
1797 }
1798
1799 *target = ret;
1800 return TRUE;
1801}
WINPR_API void * winpr_ndr_pointer_new(WinPrNdrMessageType descr, const void *hints, size_t size)
allocates a referent
Definition ndr.c:1454
WINPR_API void winpr_ndr_pointer_release(void *ptr)
releases a referent
Definition ndr.c:1483
WINPR_NDR_READER_FN readFn
Definition ndr.h:297

References WinPrNdrMessageDescr::readFn, WINPR_NDR_ARITY_ARRAYOF, WINPR_NDR_ARITY_SELF_ALLOCATED, winpr_ndr_decoder_read_pointedMessageEx(), winpr_ndr_pointer_new(), and winpr_ndr_pointer_release().

Referenced by winpr_ndr_decoder_read_pointedMessageEx(), and winpr_ndr_decoder_treat_deferreds().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_read_pointer_ex()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_pointer_ex ( WinPrNdrDecoder *  context,
wStream *  s,
const char *  name,
WinPrNdrMessageType  descr,
void *  hints,
void **  target 
)

reads a full pointer ([ptr])

The first pointer with a referent id allocates a reference counted block for a referent of type descr, the referent is read with the deferred pointers. The next pointers with the same referent id get a new reference on that block, they must have the same type and the same size. Types allocating their referent (WINPR_NDR_ARITY_SELF_ALLOCATED) can't be used.

Parameters
contextthe decoder
sthe stream to read from
namethe name of the pointer, for the logs
descrthe type of the referent
hintsthe hints of the referent, they must be valid until the deferred pointers are treated
targetreceives the referent with a reference, nullptr for a null pointer
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 1596 of file ndr.c.

1598{
1599 WINPR_ASSERT(context);
1600
1601 ndr_deferreds_enter(&context->deferreds);
1602 const BOOL ok = ndr_decoder_read_full_pointer(context, s, name, descr, hints, target);
1603 return ndr_deferreds_leave(&context->deferreds, ok);
1604}

References winpr_ndr_decoder_read_pointer_ex().

Referenced by winpr_ndr_decoder_read_pointer_ex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_read_refpointer()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_refpointer ( WinPrNdrDecoder *  context,
wStream *  s,
UINT32 *  refId 
)

reads a referent id

Parameters
contextthe decoder
sthe stream to read from
refIdreceives the referent id, WINPR_NDR_PTR_NULL for a null pointer
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 1194 of file ndr.c.

1195{
1196 return winpr_ndr_decoder_read_uint32(context, s, refId);
1197}

References winpr_ndr_decoder_read_refpointer().

Referenced by winpr_ndr_decoder_read_refpointer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_read_uconformant_array()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_uconformant_array ( WinPrNdrDecoder *  context,
wStream *  s,
const WinPrNdrArrayHints *  hints,
WinPrNdrMessageType  itemType,
void *  vtarget 
)

reads a conformant array: its count and the items

For simple items the count must be hints->count, otherwise the items must fit in hints->count bytes. The referents of the pointers in the items are deferred after the array.

Parameters
contextthe decoder
sthe stream to read from
hintsthe expected size of the array, must not be nullptr
itemTypethe type of the items
vtargetreceives the items
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 1361 of file ndr.c.

1364{
1365 WINPR_ASSERT(context);
1366 WINPR_ASSERT(s);
1367 WINPR_ASSERT(itemType);
1368 WINPR_ASSERT(vtarget);
1369
1370 if (!hints)
1371 return FALSE;
1372
1373 if (itemType->itemSize == 0)
1374 return FALSE;
1375
1376 UINT32 count = 0;
1377 if (!winpr_ndr_decoder_read_uint32(context, s, &count))
1378 return FALSE;
1379
1380 if (!ndr_check_array_bound("conformant array", count, itemType, hints->count))
1381 return FALSE;
1382
1383 return ndr_decoder_read_items(context, s, count, itemType, vtarget);
1384}
size_t itemSize
Definition ndr.h:296

References WinPrNdrArrayHints::count, WinPrNdrMessageDescr::itemSize, and winpr_ndr_decoder_read_uconformant_array().

Referenced by winpr_ndr_decoder_read_uconformant_array().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_read_uconformant_varying_array()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_uconformant_varying_array ( WinPrNdrDecoder *  context,
wStream *  s,
const WinPrNdrVaryingArrayHints *  hints,
WinPrNdrMessageType  itemType,
void *  ptarget 
)

reads a conformant varying array: its maximum count, offset, actual count and the items

The actual and maximum counts of items must fit in hints->length and hints->maxLength bytes. The referents of the pointers in the items are deferred after the array.

Parameters
contextthe decoder
sthe stream to read from
hintsthe bounds of the array, must not be nullptr
itemTypethe type of the items
ptargetreceives the items
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 1341 of file ndr.c.

1344{
1345 WINPR_ASSERT(context);
1346 WINPR_ASSERT(s);
1347 WINPR_ASSERT(itemType);
1348 WINPR_ASSERT(target);
1349
1350 if (!hints)
1351 return FALSE;
1352
1353 UINT32 maxCount = 0;
1354 UINT32 length = 0;
1355 if (!ndr_read_varying_array_header(context, s, hints, itemType, &maxCount, &length))
1356 return FALSE;
1357
1358 return ndr_decoder_read_items(context, s, length, itemType, target);
1359}

References winpr_ndr_decoder_read_uconformant_varying_array().

Referenced by winpr_ndr_decoder_read_uconformant_varying_array().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_read_union()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_union ( WinPrNdrDecoder *  context,
wStream *  s,
const WinPrNdrUnionDescr *  descr,
UINT32  switchValue,
void *  target 
)

reads a union, its discriminant must be switchValue

Parameters
contextthe decoder
sthe stream to read from
descrthe descriptor of the union
switchValuethe value of the [switch_is()] field of the union
targetthe union
Returns
TRUE on success, FALSE if the discriminant doesn't match, has no arm, or on failure
Since
version 3.33.0

Definition at line 1922 of file ndr.c.

1924{
1925 WINPR_ASSERT(context);
1926 WINPR_ASSERT(target);
1927
1928 UINT32 discriminant = 0;
1929 if (!ndr_decoder_read_discriminant(context, s, descr, &discriminant))
1930 return FALSE;
1931
1932 if (discriminant != switchValue)
1933 {
1934 WLog_ERR(TAG,
1935 "%s: discriminant 0x%08" PRIx32 " doesn't match the switch value 0x%08" PRIx32,
1936 descr->name, discriminant, switchValue);
1937 return FALSE;
1938 }
1939
1940 WinPrNdrStructDescr armStruct = WINPR_C_ARRAY_INIT;
1941 const WinPrNdrUnionArm* arm = ndr_union_arm(descr, switchValue, &armStruct);
1942 if (!arm)
1943 return FALSE;
1944
1945 BOOL ok = TRUE;
1946 ndr_deferreds_enter(&context->deferreds);
1947 if (arm->field.typeDescr)
1948 ok = ndr_decoder_read_field(context, s, &armStruct, &arm->field, target);
1949 return ndr_deferreds_leave(&context->deferreds, ok);
1950}
WinPrNdrFieldStruct field
Definition ndr.h:356
const char * name
Definition ndr.h:369
WinPrNdrMessageType typeDescr
Definition ndr.h:334
structure descriptor
Definition ndr.h:343
an arm of a non-encapsulated union
Definition ndr.h:354

References WinPrNdrUnionArm::field, WinPrNdrUnionDescr::name, WinPrNdrFieldStruct::typeDescr, and winpr_ndr_decoder_read_union().

Referenced by winpr_ndr_decoder_read_union().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_read_wchar()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_wchar ( WinPrNdrDecoder *  context,
wStream *  s,
WCHAR *  ptr 
)

reads a WCHAR, aligned on 2 bytes

The character is stored in UTF-16LE like all the WinPR WCHAR strings, whatever the byte order of the host.

Parameters
contextthe decoder
sthe stream to read from
ptrreceives the character
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 631 of file ndr.c.

632{
633 WINPR_ASSERT(ptr);
634
635 UINT16 v = 0;
636 if (!winpr_ndr_decoder_read_uint16(context, s, &v))
637 return FALSE;
638
639 winpr_Data_Write_UINT16(ptr, v);
640 return TRUE;
641}

References winpr_ndr_decoder_read_wchar().

Referenced by winpr_ndr_decoder_read_wchar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_skip_bytes()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_skip_bytes ( WinPrNdrDecoder *  context,
wStream *  s,
size_t  nbytes 
)

skips bytes

Parameters
contextthe decoder
sthe stream to read from
nbytesthe number of bytes to skip
Returns
TRUE on success, FALSE if the stream is too short
Since
version 3.33.0

Definition at line 1164 of file ndr.c.

1165{
1166 WINPR_ASSERT(context);
1167
1168 if (!Stream_CheckAndLogRequiredLength(TAG, s, nbytes))
1169 return FALSE;
1170
1171 context->offset += nbytes;
1172 Stream_Seek(s, nbytes);
1173 return TRUE;
1174}

References winpr_ndr_decoder_skip_bytes().

Referenced by winpr_ndr_decoder_skip_bytes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_decoder_treat_deferreds()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_treat_deferreds ( WinPrNdrDecoder *  context,
wStream *  s 
)

reads the pending deferred referents

Parameters
contextthe decoder
sthe stream to read from
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 1714 of file ndr.c.

1715{
1716 WINPR_ASSERT(context);
1717 WINPR_ASSERT(s);
1718
1719 WinPrNdrDeferredEntry current = { 0 };
1720 while (ndr_deferreds_pop(&context->deferreds, &current))
1721 {
1722 WLog_VRB(TAG, "treating read deferred 0x%x for %s", current.ptrId, current.name);
1723
1724 BOOL ok = FALSE;
1725 if (current.allocate)
1726 ok = winpr_ndr_decoder_read_pointedMessageEx(context, s, current.ptrId, current.msg,
1727 current.hints, (void**)current.target);
1728 else
1729 ok = current.msg->readFn(context, s, current.hints, current.target);
1730
1731 if (!ok)
1732 {
1733 WLog_ERR(TAG, "error parsing deferred %s", current.name);
1734 return FALSE;
1735 }
1736 }
1737
1738 return TRUE;
1739}
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_decoder_read_pointedMessageEx(WinPrNdrDecoder *context, wStream *s, winpr_ndr_refid ptrId, WinPrNdrMessageType descr, void *hints, void **target)
reads the referent of a unique pointer
Definition ndr.c:1741
winpr_ndr_refid ptrId
Definition ndr.h:383
WinPrNdrMessageType msg
Definition ndr.h:390
const char * name
Definition ndr.h:384
a deferred pointer, a referent to read after the current construct
Definition ndr.h:382

References WinPrNdrDeferredEntry::allocate, WinPrNdrDeferredEntry::hints, WinPrNdrDeferredEntry::msg, WinPrNdrDeferredEntry::name, WinPrNdrDeferredEntry::ptrId, WinPrNdrMessageDescr::readFn, WinPrNdrDeferredEntry::target, winpr_ndr_decoder_read_pointedMessageEx(), and winpr_ndr_decoder_treat_deferreds().

Referenced by winpr_ndr_decoder_treat_deferreds().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_allocatePtr()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_allocatePtr ( WinPrNdrEncoder *  context,
const void *  ptr,
winpr_ndr_refid *  prefId,
BOOL *  pnewPtr 
)

allocates the referent id of an embedded pointer

The pointers are written as unique pointers: each non-null pointer gets its own referent id, and *pnewPtr is always set to TRUE.

Parameters
contextthe encoder
ptrthe pointer
prefIdreceives the referent id
pnewPtrreceives TRUE if the referent is to be written
Returns
TRUE on success, FALSE when the referent ids are exhausted
Since
version 3.33.0

Definition at line 1056 of file ndr.c.

1058{
1059 WINPR_ASSERT(context);
1060 WINPR_ASSERT(prefId);
1061 WINPR_ASSERT(pnewPtr);
1062 WINPR_UNUSED(ptr);
1063
1064 /* pointers are unique pointers: each non-null pointer has its own referent, the decoder
1065 * rejects aliased pointers */
1066 if (context->refIdCounter > UINT32_MAX - 4)
1067 return FALSE;
1068
1069 *pnewPtr = TRUE;
1070 *prefId = context->refIdCounter;
1071 context->refIdCounter += 4;
1072 return TRUE;
1073}

References winpr_ndr_encoder_allocatePtr().

Referenced by winpr_ndr_encoder_allocatePtr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_bytes_written()

WINPR_API void winpr_ndr_encoder_bytes_written ( WinPrNdrEncoder *  context,
size_t  len 
)

accounts for bytes written directly in the stream, for the alignments

Parameters
contextthe encoder
lenthe number of bytes written
Since
version 3.33.0

Definition at line 218 of file ndr.c.

219{
220 WINPR_ASSERT(context);
221 context->offset += len;
222}

References winpr_ndr_encoder_bytes_written().

Referenced by winpr_ndr_encoder_bytes_written(), and winpr_ndr_encoder_write_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_destroy()

static INLINE void winpr_ndr_encoder_destroy ( WinPrNdrEncoder **  pcontext)
static

frees an encoder and resets the pointer

Parameters
pcontexta pointer on the encoder to free, must not be nullptr
Since
version 3.33.0

Definition at line 405 of file ndr.h.

406 {
407 WINPR_ASSERT(pcontext);
408 winpr_ndr_encoder_free(*pcontext);
409 *pcontext = nullptr;
410 }
WINPR_API void winpr_ndr_encoder_free(WinPrNdrEncoder *context)
frees an encoder
Definition ndr.c:213

References winpr_ndr_encoder_free().

Here is the call graph for this function:

◆ winpr_ndr_encoder_end_object()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_end_object ( WinPrNdrEncoder *  context,
wStream *  s 
)

ends the serialized object started with winpr_ndr_encoder_start_object()

Pads the object data to a multiple of 8 bytes and fills the private header.

Parameters
contextthe encoder
sthe stream given to winpr_ndr_encoder_start_object()
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 282 of file ndr.c.

283{
284 WINPR_ASSERT(context);
285 WINPR_ASSERT(s);
286
287 if (!context->inObject)
288 {
289 WLog_ERR(TAG, "no object being serialized");
290 return FALSE;
291 }
292
293 const size_t start = context->objectStart + 8;
294 WINPR_ASSERT(Stream_GetPosition(s) >= start);
295
296 /* the length of the object buffer must be a multiple of 8 */
297 const size_t padding = (8 - ((Stream_GetPosition(s) - start) % 8)) % 8;
298 if (!Stream_EnsureRemainingCapacity(s, padding))
299 return FALSE;
300 Stream_Zero(s, padding);
301 context->offset += padding;
302
303 const size_t len = Stream_GetPosition(s) - start;
304 if (len > UINT32_MAX)
305 return FALSE;
306
307 BYTE* header = Stream_Buffer(s) + context->objectStart;
308 if (context->bigEndianDrep)
309 winpr_Data_Write_UINT32_BE(header, (UINT32)len);
310 else
311 winpr_Data_Write_UINT32(header, (UINT32)len);
312
313 context->inObject = FALSE;
314 return TRUE;
315}

References winpr_ndr_encoder_end_object().

Referenced by winpr_ndr_encoder_end_object().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_free()

WINPR_API void winpr_ndr_encoder_free ( WinPrNdrEncoder *  context)

frees an encoder

Parameters
contextthe encoder to free, can be nullptr
Since
version 3.33.0

Definition at line 213 of file ndr.c.

214{
215 free(context);
216}

References winpr_ndr_encoder_free().

Referenced by winpr_ndr_encoder_destroy(), and winpr_ndr_encoder_free().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_from_decoder()

WINPR_API WinPrNdrEncoder * winpr_ndr_encoder_from_decoder ( const WinPrNdrDecoder *  src)

creates an encoder with the same endianness and version as a decoder, to answer the message it decoded

Parameters
srcthe decoder
Returns
the new encoder, nullptr on failure
Since
version 3.33.0

Definition at line 206 of file ndr.c.

207{
208 WINPR_ASSERT(src);
209
210 return winpr_ndr_encoder_new(src->bigEndianDrep, src->version);
211}
WINPR_API WinPrNdrEncoder * winpr_ndr_encoder_new(BOOL bigEndianDrep, BYTE version)
creates an encoder
Definition ndr.c:194

References winpr_ndr_encoder_from_decoder(), and winpr_ndr_encoder_new().

Referenced by winpr_ndr_encoder_from_decoder().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_new()

WINPR_API WinPrNdrEncoder * winpr_ndr_encoder_new ( BOOL  bigEndianDrep,
BYTE  version 
)

creates an encoder

Parameters
bigEndianDrepTRUE to encode in big endian, FALSE for little endian
versionthe type serialization version written by winpr_ndr_encoder_write_header()
Returns
the new encoder, nullptr on failure
Since
version 3.33.0

Definition at line 194 of file ndr.c.

195{
196 WinPrNdrEncoder* ret = calloc(1, sizeof(*ret));
197 if (!ret)
198 return nullptr;
199
200 ret->version = version;
201 ret->bigEndianDrep = bigEndianDrep;
202 ret->refIdCounter = 0x20000;
203 return ret;
204}

References winpr_ndr_encoder_new().

Referenced by winpr_ndr_encoder_from_decoder(), and winpr_ndr_encoder_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_start_object()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_start_object ( WinPrNdrEncoder *  context,
wStream *  s 
)

starts a serialized object ([MS-RPCE] 2.2.6 type serialization version 1)

Writes a placeholder for the private header, the object data is to be written after. Only one object can be serialized at a time.

Parameters
contextthe encoder
sthe stream to write to
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 259 of file ndr.c.

260{
261 WINPR_ASSERT(context);
262 WINPR_ASSERT(s);
263
264 if (context->inObject)
265 {
266 WLog_ERR(TAG, "an object is already being serialized");
267 return FALSE;
268 }
269
270 if (!Stream_EnsureRemainingCapacity(s, 8))
271 return FALSE;
272
273 /* ObjectBufferLength, filled by winpr_ndr_encoder_end_object, and Filler */
274 context->objectStart = Stream_GetPosition(s);
275 Stream_Zero(s, 8);
276
277 context->inObject = TRUE;
278 context->offset = 0;
279 return TRUE;
280}

References winpr_ndr_encoder_start_object().

Referenced by winpr_ndr_encoder_start_object().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_treat_deferreds()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_treat_deferreds ( WinPrNdrEncoder *  context,
wStream *  s 
)

writes the pending deferred referents

Parameters
contextthe encoder
sthe stream to write to
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 1075 of file ndr.c.

1076{
1077 WINPR_ASSERT(context);
1078 WINPR_ASSERT(s);
1079
1080 WinPrNdrDeferredEntry current = { 0 };
1081 while (ndr_deferreds_pop(&context->deferreds, &current))
1082 {
1083 WLog_VRB(TAG, "treating write deferred for %s", current.name);
1084 if (!current.msg->writeFn(context, s, current.hints, current.target))
1085 {
1086 WLog_ERR(TAG, "error writing deferred %s", current.name);
1087 return FALSE;
1088 }
1089 }
1090
1091 return TRUE;
1092}
WINPR_NDR_WRITER_FN writeFn
Definition ndr.h:298

References WinPrNdrDeferredEntry::hints, WinPrNdrDeferredEntry::msg, WinPrNdrDeferredEntry::name, WinPrNdrDeferredEntry::target, winpr_ndr_encoder_treat_deferreds(), and WinPrNdrMessageDescr::writeFn.

Referenced by winpr_ndr_encoder_treat_deferreds().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_write_align()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_align ( WinPrNdrEncoder *  context,
wStream *  s,
size_t  sz 
)

writes zero padding to align the current object offset

Parameters
contextthe encoder
sthe stream to write to
szthe alignment, must not be 0
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 240 of file ndr.c.

241{
242 WINPR_ASSERT(context);
243
244 size_t rest = context->offset % sz;
245 if (rest)
246 {
247 size_t padding = (sz - rest);
248
249 if (!Stream_EnsureRemainingCapacity(s, padding))
250 return FALSE;
251
252 Stream_Zero(s, padding);
253 context->offset += padding;
254 }
255
256 return TRUE;
257}

References winpr_ndr_encoder_write_align().

Referenced by winpr_ndr_encoder_write_align(), and winpr_ndr_encoder_write_fromDescr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_write_data()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_data ( WinPrNdrEncoder *  context,
wStream *  s,
const void *  data,
size_t  sz 
)

writes raw bytes, without alignment

Parameters
contextthe encoder
sthe stream to write to
datathe bytes to write
szthe number of bytes
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 1094 of file ndr.c.

1095{
1096 if (!Stream_EnsureRemainingCapacity(s, sz))
1097 return FALSE;
1098
1099 Stream_Write(s, data, sz);
1101 return TRUE;
1102}
WINPR_API void winpr_ndr_encoder_bytes_written(WinPrNdrEncoder *context, size_t len)
accounts for bytes written directly in the stream, for the alignments
Definition ndr.c:218

References winpr_ndr_encoder_bytes_written(), and winpr_ndr_encoder_write_data().

Referenced by winpr_ndr_encoder_write_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_write_fromDescr()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_fromDescr ( WinPrNdrEncoder *  context,
wStream *  s,
const WinPrNdrStructDescr *  descr,
const void *  src 
)

writes a structure from its descriptor

The structure is aligned on descr->alignment, the referents of its pointers are deferred.

Parameters
contextthe encoder
sthe stream to write to
descrthe descriptor of the structure
srcthe structure
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 1032 of file ndr.c.

1034{
1035 WINPR_ASSERT(context);
1036 WINPR_ASSERT(s);
1037 WINPR_ASSERT(descr);
1038 WINPR_ASSERT(src);
1039
1040 if ((descr->alignment > 1) && !winpr_ndr_encoder_write_align(context, s, descr->alignment))
1041 return FALSE;
1042
1043 BOOL ok = TRUE;
1044 ndr_deferreds_enter(&context->deferreds);
1045 for (size_t i = 0; ok && (i < descr->nfields); i++)
1046 ok = ndr_encoder_write_field(context, s, descr, &descr->fields[i], src);
1047
1048 return ndr_deferreds_leave(&context->deferreds, ok);
1049}
WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_align(WinPrNdrEncoder *context, wStream *s, size_t sz)
writes zero padding to align the current object offset
Definition ndr.c:240

References WinPrNdrStructDescr::alignment, WinPrNdrStructDescr::fields, WinPrNdrStructDescr::nfields, winpr_ndr_encoder_write_align(), and winpr_ndr_encoder_write_fromDescr().

Referenced by winpr_ndr_encoder_write_fromDescr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_write_header()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_header ( WinPrNdrEncoder *  context,
wStream *  s 
)

writes the common type header ([MS-RPCE] 2.2.6.1): version, endianness, header length and filler

Parameters
contextthe encoder
sthe stream to write to
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 224 of file ndr.c.

225{
226 WINPR_ASSERT(context);
227
228 if (!Stream_EnsureRemainingCapacity(s, 8))
229 return FALSE;
230
231 Stream_Write_UINT8(s, context->version);
232 Stream_Write_UINT8(s, context->bigEndianDrep ? 0x00 : 0x10);
233 Stream_Write_UINT16(s, 0x8); /* header len */
234
235 BYTE filler[] = { 0xcc, 0xcc, 0xcc, 0xcc };
236 Stream_Write(s, filler, sizeof(filler));
237 return TRUE;
238}

References winpr_ndr_encoder_write_header().

Referenced by winpr_ndr_encoder_write_header().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_write_toplevel_refid()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_toplevel_refid ( WinPrNdrEncoder *  context,
wStream *  s 
)

writes a new referent id for a non-null top-level pointer

Parameters
contextthe encoder
sthe stream to write to
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 317 of file ndr.c.

318{
319 WINPR_ASSERT(context);
320
321 const winpr_ndr_refid refId = context->refIdCounter;
322 context->refIdCounter += 4;
323 return winpr_ndr_encoder_write_uint32(context, s, refId);
324}
UINT32 winpr_ndr_refid
a referent id, the wire value of a pointer (WINPR_NDR_PTR_NULL for a null pointer)
Definition ndr.h:230

References winpr_ndr_encoder_write_toplevel_refid().

Referenced by winpr_ndr_encoder_write_toplevel_refid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_write_uconformant_array()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_uconformant_array ( WinPrNdrEncoder *  context,
wStream *  s,
UINT32  len,
WinPrNdrMessageType  itemType,
const BYTE *  ptr 
)

writes a conformant array: its count and the items

The referents of the pointers in the items are deferred after the array.

Parameters
contextthe encoder
sthe stream to write to
lenthe number of items
itemTypethe type of the items
ptrthe items
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 935 of file ndr.c.

937{
938 WINPR_ASSERT(context);
939 WINPR_ASSERT(s);
940 WINPR_ASSERT(itemType);
941 WINPR_ASSERT(ptr);
942
943 if (!winpr_ndr_encoder_write_uint32(context, s, len))
944 return FALSE;
945
946 return ndr_encoder_write_items(context, s, len, itemType, ptr);
947}

References winpr_ndr_encoder_write_uconformant_array().

Referenced by winpr_ndr_encoder_write_uconformant_array().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_write_uconformant_varying_array()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_uconformant_varying_array ( WinPrNdrEncoder *  context,
wStream *  s,
const WinPrNdrVaryingArrayHints *  hints,
WinPrNdrMessageType  itemType,
const void *  src 
)

writes a conformant varying array: its maximum count, offset 0, actual count and the items

The referents of the pointers in the items are deferred after the array.

Parameters
contextthe encoder
sthe stream to write to
hintsthe counts of the array
itemTypethe type of the items
srcthe items, hints->length of them are written
Returns
TRUE on success, FALSE otherwise
Since
version 3.33.0

Definition at line 916 of file ndr.c.

920{
921 WINPR_ASSERT(context);
922 WINPR_ASSERT(s);
923 WINPR_ASSERT(hints);
924 WINPR_ASSERT(itemType);
925 WINPR_ASSERT(psrc);
926
927 if (!winpr_ndr_encoder_write_uint32(context, s, hints->maxLength) ||
928 !winpr_ndr_encoder_write_uint32(context, s, 0) ||
929 !winpr_ndr_encoder_write_uint32(context, s, hints->length))
930 return FALSE;
931
932 return ndr_encoder_write_items(context, s, hints->length, itemType, psrc);
933}

References WinPrNdrVaryingArrayHints::length, WinPrNdrVaryingArrayHints::maxLength, and winpr_ndr_encoder_write_uconformant_varying_array().

Referenced by winpr_ndr_encoder_write_uconformant_varying_array().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_write_union()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_union ( WinPrNdrEncoder *  context,
wStream *  s,
const WinPrNdrUnionDescr *  descr,
UINT32  switchValue,
const void *  src 
)

writes the discriminant and the arm of a union

Parameters
contextthe encoder
sthe stream to write to
descrthe descriptor of the union
switchValuethe discriminant, the value of the [switch_is()] field
srcthe union
Returns
TRUE on success, FALSE if there's no arm for switchValue or on failure
Since
version 3.33.0

Definition at line 1903 of file ndr.c.

1906{
1907 WINPR_ASSERT(context);
1908 WINPR_ASSERT(src);
1909
1910 WinPrNdrStructDescr armStruct = WINPR_C_ARRAY_INIT;
1911 const WinPrNdrUnionArm* arm = ndr_union_arm(descr, switchValue, &armStruct);
1912 if (!arm || !ndr_encoder_write_discriminant(context, s, descr, switchValue))
1913 return FALSE;
1914
1915 BOOL ok = TRUE;
1916 ndr_deferreds_enter(&context->deferreds);
1917 if (arm->field.typeDescr)
1918 ok = ndr_encoder_write_field(context, s, &armStruct, &arm->field, src);
1919 return ndr_deferreds_leave(&context->deferreds, ok);
1920}

References WinPrNdrUnionArm::field, WinPrNdrFieldStruct::typeDescr, and winpr_ndr_encoder_write_union().

Referenced by winpr_ndr_encoder_write_union().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_encoder_write_wchar()

WINPR_ATTR_NODISCARD WINPR_API BOOL winpr_ndr_encoder_write_wchar ( WinPrNdrEncoder *  context,
wStream *  s,
const WCHAR *  ptr 
)

writes a WCHAR stored in UTF-16LE, aligned on 2 bytes

Parameters
contextthe encoder
sthe stream to write to
ptrthe character
Returns
TRUE on success, FALSE otherwise
Since
version 3.34.0

Definition at line 643 of file ndr.c.

644{
645 WINPR_ASSERT(ptr);
646 return winpr_ndr_encoder_write_uint16(context, s, winpr_Data_Get_UINT16(ptr));
647}

References winpr_ndr_encoder_write_wchar().

Referenced by winpr_ndr_encoder_write_wchar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_pointer_new()

WINPR_API void * winpr_ndr_pointer_new ( WinPrNdrMessageType  descr,
const void *  hints,
size_t  size 
)

allocates a referent

All the pointers returned by the decoder are reference counted referents, released with winpr_ndr_pointer_release() (winpr_ndr_struct_destroy() releases the pointers of a structure). Self allocated types allocate their referent with this function, and so must the pointers of a structure built to be encoded and destroyed with winpr_ndr_struct_destroy().

Parameters
descrthe type of the referent, its destroy function is called when the referent is released, can be nullptr
hintsthe hints of the referent for the destroy function, copied, can be nullptr
sizethe size of the referent, it is zeroed
Returns
the referent with a reference, nullptr on failure
Since
version 3.33.0

Definition at line 1454 of file ndr.c.

1455{
1456 NdrReferent* ref = ndr_referent_new(descr, hints, size);
1457 WINPR_PRAGMA_DIAG_PUSH
1458 WINPR_DO_COVERITY_PRAGMA(
1459 coverity compliance block
1460 deviate 'RESOURCE_LEAK' 'returning a constant offset pointer, winpr_ndr_pointer_release does the inverse')
1461 return ref ? ref->payload.data : nullptr;
1462 WINPR_PRAGMA_DIAG_POP
1463}

References winpr_ndr_pointer_new().

Referenced by winpr_ndr_decoder_read_pointedMessageEx(), and winpr_ndr_pointer_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_pointer_ref()

WINPR_API void * winpr_ndr_pointer_ref ( void *  ptr)

takes a reference on a referent

Parameters
ptrthe referent, can be nullptr
Returns
ptr
Since
version 3.33.0

Definition at line 1473 of file ndr.c.

1474{
1475 if (!ptr)
1476 return nullptr;
1477
1478 NdrReferent* ref = ndr_referent(ptr);
1479 InterlockedIncrement(&ref->refCount);
1480 return ptr;
1481}

References winpr_ndr_pointer_ref().

Referenced by winpr_ndr_pointer_ref().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_pointer_refid()

WINPR_ATTR_NODISCARD WINPR_API winpr_ndr_refid winpr_ndr_pointer_refid ( const void *  ptr)

a referent id built from the value of a pointer

Parameters
ptrthe pointer
Returns
the low 32 bits of ptr, WINPR_NDR_PTR_NULL for nullptr
Since
version 3.33.0

Definition at line 1051 of file ndr.c.

1052{
1053 return (winpr_ndr_refid)((ULONG_PTR)ptr);
1054}

References winpr_ndr_pointer_refid().

Referenced by winpr_ndr_pointer_refid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_pointer_release()

WINPR_API void winpr_ndr_pointer_release ( void *  ptr)

releases a referent

When the last reference is released the referent is destroyed with the destroy function of its type, and freed.

Parameters
ptrthe referent, can be nullptr
Since
version 3.33.0

Definition at line 1483 of file ndr.c.

1484{
1485 if (!ptr)
1486 return;
1487
1488 NdrReferent* ref = ndr_referent(ptr);
1489 if (InterlockedDecrement(&ref->refCount) > 0)
1490 return;
1491
1492 if (ref->typeDescr && ref->typeDescr->destroyFn)
1493 ref->typeDescr->destroyFn(ref->hasHints ? &ref->hints : nullptr, ref->payload.data);
1494 ref->magic = 0;
1495 free(ref);
1496}

References winpr_ndr_pointer_release().

Referenced by winpr_ndr_decoder_read_pointedMessageEx(), winpr_ndr_pointer_release(), and winpr_ndr_struct_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_pointer_size()

WINPR_ATTR_NODISCARD WINPR_API size_t winpr_ndr_pointer_size ( const void *  ptr)

the size of a referent, as allocated by winpr_ndr_pointer_new()

Parameters
ptrthe referent, can be nullptr
Returns
the size of the referent, 0 for nullptr
Since
version 3.33.0

Definition at line 1465 of file ndr.c.

1466{
1467 if (!ptr)
1468 return 0;
1469
1470 return ndr_referent(WINPR_CAST_CONST_PTR_AWAY(ptr, void*))->size;
1471}

References winpr_ndr_pointer_size().

Referenced by winpr_ndr_pointer_size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_string_conformant_descr()

WINPR_ATTR_NODISCARD WINPR_API WinPrNdrMessageType winpr_ndr_string_conformant_descr ( void  )

the message type of winpr_ndr_string_conformant_descr_s

Returns
the message type
Since
version 3.33.0

Definition at line 735 of file ndr.c.

736{
738}
WINPR_API const WinPrNdrMessageDescr winpr_ndr_string_conformant_descr_s
conformant string of char, read in a char* allocated with winpr_ndr_pointer_new()
Definition ndr.c:726

References winpr_ndr_string_conformant_descr(), and winpr_ndr_string_conformant_descr_s.

Referenced by winpr_ndr_string_conformant_descr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_string_varying_descr()

WINPR_ATTR_NODISCARD WINPR_API WinPrNdrMessageType winpr_ndr_string_varying_descr ( void  )

the message type of winpr_ndr_string_varying_descr_s

Returns
the message type
Since
version 3.33.0

Definition at line 831 of file ndr.c.

832{
834}
WINPR_API const WinPrNdrMessageDescr winpr_ndr_string_varying_descr_s
[string] char*: a conformant varying string of char, read in a char* allocated with winpr_ndr_pointer...
Definition ndr.c:822

References winpr_ndr_string_varying_descr(), and winpr_ndr_string_varying_descr_s.

Referenced by winpr_ndr_string_varying_descr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_struct_destroy()

WINPR_API void winpr_ndr_struct_destroy ( const WinPrNdrStructDescr *  descr,
void *  pptr 
)

releases the content of a structure from its descriptor

The pointer fields are released with winpr_ndr_pointer_release() and reset, the inline fields are destroyed with the destroy function of their type. The storage of the structure itself is not freed.

Parameters
descrthe descriptor of the structure
pptrthe structure
Since
version 3.33.0

Definition at line 2005 of file ndr.c.

2006{
2007 WINPR_ASSERT(descr);
2008 WINPR_ASSERT(pptr);
2009
2010 for (size_t i = 0; i < descr->nfields; i++)
2011 {
2012 const WinPrNdrFieldStruct* field = &descr->fields[i];
2013 void* ptr = (BYTE*)pptr + field->structOffset;
2014 void* hints = nullptr;
2015
2016 if (field->hintsField >= 0)
2017 {
2018 /* computes the address of the hints field if any */
2019 WINPR_ASSERT((size_t)field->hintsField < descr->nfields);
2020 const WinPrNdrFieldStruct* hintsField = &descr->fields[field->hintsField];
2021
2022 hints = (BYTE*)pptr + hintsField->structOffset;
2023 }
2024
2025 switch (field->pointerType)
2026 {
2027 case WINPR_NDR_POINTER:
2030 {
2031 /* the referent is destroyed with its last reference */
2032 void** pptrField = (void**)ptr;
2033 winpr_ndr_pointer_release(*pptrField);
2034 *pptrField = nullptr;
2035 }
2036 break;
2037
2038 default:
2039 /* NOT_POINTER and FIXED_ARRAY fields are stored inline in the struct */
2040 if (field->typeDescr->destroyFn)
2041 field->typeDescr->destroyFn(hints, ptr);
2042 break;
2043 }
2044 }
2045}
size_t structOffset
Definition ndr.h:330
descriptor of a field in a structure
Definition ndr.h:328

References WinPrNdrMessageDescr::destroyFn, WinPrNdrStructDescr::fields, WinPrNdrFieldStruct::hintsField, WinPrNdrStructDescr::nfields, WinPrNdrFieldStruct::pointerType, WinPrNdrFieldStruct::structOffset, WinPrNdrFieldStruct::typeDescr, WINPR_NDR_POINTER, WINPR_NDR_POINTER_FULL, WINPR_NDR_POINTER_NON_NULL, winpr_ndr_pointer_release(), and winpr_ndr_struct_destroy().

Referenced by winpr_ndr_struct_destroy(), and winpr_ndr_union_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_struct_dump_fromDescr()

WINPR_API void winpr_ndr_struct_dump_fromDescr ( wLog *  logger,
UINT32  lvl,
size_t  identLevel,
const WinPrNdrStructDescr *  descr,
const void *  obj 
)

dumps a structure in the logs from its descriptor

Parameters
loggerthe logger to use
lvlthe log level
identLevelthe number of tabs to prepend to each line
descrthe descriptor of the structure
objthe structure
Since
version 3.33.0

Definition at line 1967 of file ndr.c.

1969{
1970 char tabArray[30 + 1];
1971 size_t ntabs = (identLevel <= 30) ? identLevel : 30;
1972
1973 memset(tabArray, '\t', ntabs);
1974 tabArray[ntabs] = 0;
1975
1976 WLog_Print(logger, lvl, "%s%s", tabArray, descr->name);
1977 for (size_t i = 0; i < descr->nfields; i++)
1978 {
1979 const WinPrNdrFieldStruct* field = &descr->fields[i];
1980 const BYTE* ptr = (const BYTE*)obj + field->structOffset;
1981
1982 switch (field->pointerType)
1983 {
1984 case WINPR_NDR_POINTER:
1987 ptr = *(WINPR_CAST_CONST_PTR_AWAY(ptr, const void**));
1988 break;
1991 break;
1992 default:
1993 WLog_ERR(TAG, "invalid field->pointerType");
1994 break;
1995 }
1996
1997 WLog_Print(logger, lvl, "%s*%s:", tabArray, field->name);
1998 if (field->typeDescr->dumpFn)
1999 field->typeDescr->dumpFn(logger, lvl, identLevel + 1, ptr);
2000 else
2001 WLog_Print(logger, lvl, "%s\t<no dump function>", tabArray);
2002 }
2003}
const char * name
Definition ndr.h:344

References WinPrNdrMessageDescr::dumpFn, WinPrNdrStructDescr::fields, WinPrNdrFieldStruct::name, WinPrNdrStructDescr::name, WinPrNdrStructDescr::nfields, WinPrNdrFieldStruct::pointerType, WinPrNdrFieldStruct::structOffset, WinPrNdrFieldStruct::typeDescr, WINPR_NDR_FIXED_ARRAY, WINPR_NDR_NOT_POINTER, WINPR_NDR_POINTER, WINPR_NDR_POINTER_FULL, WINPR_NDR_POINTER_NON_NULL, and winpr_ndr_struct_dump_fromDescr().

Referenced by winpr_ndr_struct_dump_fromDescr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_union_destroy()

WINPR_API void winpr_ndr_union_destroy ( const WinPrNdrUnionDescr *  descr,
UINT32  switchValue,
void *  obj 
)

releases the content of the arm switchValue of a union

Parameters
descrthe descriptor of the union
switchValuethe discriminant of the arm
objthe union
Since
version 3.33.0

Definition at line 1952 of file ndr.c.

1953{
1954 WINPR_ASSERT(descr);
1955 WINPR_ASSERT(obj);
1956
1957 const WinPrNdrUnionArm* arm = ndr_union_find_arm(descr, switchValue);
1958 if (!arm || !arm->field.typeDescr)
1959 return;
1960
1961 const WinPrNdrStructDescr armStruct = { descr->name, 1, &arm->field, 0 };
1962 winpr_ndr_struct_destroy(&armStruct, obj);
1963}
WINPR_API void winpr_ndr_struct_destroy(const WinPrNdrStructDescr *descr, void *pptr)
releases the content of a structure from its descriptor
Definition ndr.c:2005

References WinPrNdrUnionArm::field, WinPrNdrUnionDescr::name, WinPrNdrFieldStruct::typeDescr, winpr_ndr_struct_destroy(), and winpr_ndr_union_destroy().

Referenced by winpr_ndr_union_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_union_switch_value()

WINPR_ATTR_NODISCARD WINPR_API UINT32 winpr_ndr_union_switch_value ( const WinPrNdrUnionDescr *  descr,
const void *  switchField 
)

the value of the [switch_is()] field of a union

Parameters
descrthe descriptor of the union, its switchSize gives the size of the field
switchFieldthe [switch_is()] field, a UINT16 or a UINT32
Returns
the value of the field
Since
version 3.33.0

Definition at line 1830 of file ndr.c.

1831{
1832 WINPR_ASSERT(switchField);
1833
1834 if (ndr_union_switch_size(descr) == 2)
1835 return *(const UINT16*)switchField;
1836 return *(const UINT32*)switchField;
1837}

References winpr_ndr_union_switch_value().

Referenced by winpr_ndr_union_switch_value().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_wchar_descr()

WINPR_ATTR_NODISCARD WINPR_API WinPrNdrMessageType winpr_ndr_wchar_descr ( void  )

the message type of winpr_ndr_wchar_descr_s

Returns
the message type
Since
version 3.34.0

Definition at line 668 of file ndr.c.

669{
671}
WINPR_API const WinPrNdrMessageDescr winpr_ndr_wchar_descr_s
a WCHAR, stored in UTF-16LE in memory
Definition ndr.c:663

References winpr_ndr_wchar_descr(), and winpr_ndr_wchar_descr_s.

Referenced by winpr_ndr_wchar_descr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ winpr_ndr_wstring_varying_descr()

WINPR_ATTR_NODISCARD WINPR_API WinPrNdrMessageType winpr_ndr_wstring_varying_descr ( void  )

the message type of winpr_ndr_wstring_varying_descr_s

Returns
the message type
Since
version 3.33.0

Definition at line 898 of file ndr.c.

899{
901}
WINPR_API const WinPrNdrMessageDescr winpr_ndr_wstring_varying_descr_s
[string] wchar_t*: a conformant varying string of WCHAR, read in a WCHAR* allocated with winpr_ndr_po...
Definition ndr.c:893

References winpr_ndr_wstring_varying_descr(), and winpr_ndr_wstring_varying_descr_s.

Referenced by winpr_ndr_wstring_varying_descr().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ winpr_ndr_string_conformant_descr_s

WINPR_API const WinPrNdrMessageDescr winpr_ndr_string_conformant_descr_s
extern

conformant string of char, read in a char* allocated with winpr_ndr_pointer_new()

Since
version 3.33.0

Definition at line 726 of file ndr.c.

726 {
728 sizeof(char),
729 winpr_ndr_decoder_read_string_conformant,
730 winpr_ndr_encoder_write_string_conformant,
731 nullptr /* destroy */,
732 nullptr /* dump */
733};

Referenced by winpr_ndr_string_conformant_descr().

◆ winpr_ndr_string_varying_descr_s

WINPR_API const WinPrNdrMessageDescr winpr_ndr_string_varying_descr_s
extern

[string] char*: a conformant varying string of char, read in a char* allocated with winpr_ndr_pointer_new()

Since
version 3.33.0

Definition at line 822 of file ndr.c.

822 {
824 sizeof(char),
825 winpr_ndr_decoder_read_string_varying,
826 winpr_ndr_encoder_write_string_varying,
827 nullptr /* destroy */,
828 nullptr /* dump */
829};

Referenced by winpr_ndr_string_varying_descr().

◆ winpr_ndr_wchar_descr_s

WINPR_API const WinPrNdrMessageDescr winpr_ndr_wchar_descr_s
extern

a WCHAR, stored in UTF-16LE in memory

Since
version 3.34.0

Definition at line 663 of file ndr.c.

663 {
664 WINPR_NDR_ARITY_SIMPLE, sizeof(WCHAR), ndr_decoder_read_wchar_,
665 ndr_encoder_write_wchar_, nullptr, nullptr
666};

Referenced by winpr_ndr_wchar_descr().

◆ winpr_ndr_wstring_varying_descr_s

WINPR_API const WinPrNdrMessageDescr winpr_ndr_wstring_varying_descr_s
extern

[string] wchar_t*: a conformant varying string of WCHAR, read in a WCHAR* allocated with winpr_ndr_pointer_new()

Since
version 3.33.0

Definition at line 893 of file ndr.c.

893 {
894 WINPR_NDR_ARITY_SELF_ALLOCATED, sizeof(WCHAR), ndr_decoder_read_wstring_varying,
895 ndr_encoder_write_wstring_varying, nullptr /* destroy */, nullptr /* dump */
896};

Referenced by winpr_ndr_wstring_varying_descr().