public string AddGenericMarshal(NdrBaseTypeReference ndr_type, CodeTypeReference type, string name, AdditionalArguments additional_args) { CodeTypeReference generic_type = additional_args.Generic ? (additional_args.GenericType ?? type.ToBaseRef()) : null; var method = AddMethod(MarshalHelper, $"Write_{_current_marshal_id++}", generic_type, null, name, new[] { type }, additional_args); MarshalMethods.Add(ndr_type, method); return(method.Name); }
public RpcTypeDescriptor(Type code_type, string unmarshal_method, MarshalHelperBuilder marshal_helper, string marshal_method, NdrBaseTypeReference ndr_type, NdrCorrelationDescriptor conformance, NdrCorrelationDescriptor variance, AdditionalArguments additional_marshal_args, AdditionalArguments additional_unmarshal_args) : this(new CodeTypeReference(code_type), code_type.IsValueType || typeof(NtObject).IsAssignableFrom(code_type), unmarshal_method, marshal_helper, marshal_method, ndr_type, conformance, variance, additional_marshal_args, additional_unmarshal_args) { BuiltinType = code_type; }
public string AddGenericUnmarshal(NdrBaseTypeReference ndr_type, CodeTypeReference type, string name, AdditionalArguments additional_args) { CodeTypeReference generic_type = additional_args.Generic ? (additional_args.GenericType ?? type.ToBaseRef()) : null; var method = AddMethod(UnmarshalHelper, $"Read_{_current_unmarshal_id++}", generic_type, type, name, new CodeTypeReference[0], additional_args); UnmarshalMethods.Add(ndr_type, method); return(method.Name); }
// Should implement this for each type rather than this. private RpcTypeDescriptor GetTypeDescriptor(NdrBaseTypeReference type) { if (!_type_descriptors.ContainsKey(type)) { _type_descriptors[type] = GetTypeDescriptorInternal(type); } return(_type_descriptors[type]); }
public RpcTypeDescriptor(string name, bool value_type, string unmarshal_method, MarshalHelperBuilder marshal_helper, string marshal_method, NdrBaseTypeReference ndr_type, NdrCorrelationDescriptor conformance, NdrCorrelationDescriptor variance, AdditionalArguments additional_marshal_args, AdditionalArguments additional_unmarshal_args) : this(new CodeTypeReference(name), value_type, unmarshal_method, marshal_helper, marshal_method, ndr_type, conformance, variance, additional_marshal_args, additional_unmarshal_args) { Constructed = true; Union = ndr_type is NdrUnionTypeReference; }
public RpcTypeDescriptor(string name, bool value_type, string unmarshal_method, bool unmarshal_generic, string marshal_method, NdrBaseTypeReference ndr_type, NdrCorrelationDescriptor conformance, NdrCorrelationDescriptor variance, params RpcMarshalArgument[] additional_args) : this(new CodeTypeReference(name), value_type, unmarshal_method, unmarshal_generic, marshal_method, ndr_type, conformance, variance, additional_args) { Constructed = true; }
public RpcTypeDescriptor(Type code_type, string unmarshal_method, bool unmarshal_generic, string marshal_method, NdrBaseTypeReference ndr_type, NdrCorrelationDescriptor conformance, NdrCorrelationDescriptor variance, params RpcMarshalArgument[] additional_args) : this(new CodeTypeReference(code_type), code_type.IsValueType || typeof(NtObject).IsAssignableFrom(code_type), unmarshal_method, unmarshal_generic, marshal_method, ndr_type, conformance, variance, additional_args) { BuiltinType = code_type; }
public RpcTypeDescriptor(CodeTypeReference code_type, bool value_type, string unmarshal_method, bool unmarshal_generic, string marshal_method, NdrBaseTypeReference ndr_type, NdrCorrelationDescriptor conformance, NdrCorrelationDescriptor variance, params RpcMarshalArgument[] additional_args) { CodeType = code_type; UnmarshalMethod = unmarshal_method; MarshalMethod = marshal_method; UnmarshalGeneric = unmarshal_generic; NdrType = ndr_type; AdditionalArgs = additional_args; ValueType = value_type; ConformanceDescriptor = conformance ?? new NdrCorrelationDescriptor(); VarianceDescriptor = variance ?? new NdrCorrelationDescriptor(); }
public RpcTypeDescriptor(CodeTypeReference code_type, bool value_type, string unmarshal_method, MarshalHelperBuilder marshal_helper, string marshal_method, NdrBaseTypeReference ndr_type, NdrCorrelationDescriptor conformance, NdrCorrelationDescriptor variance, AdditionalArguments additional_marshal_args, AdditionalArguments additional_unmarshal_args) { CodeType = code_type; UnmarshalMethod = unmarshal_method; if (additional_marshal_args != null) { if (marshal_helper == null) { throw new ArgumentNullException(nameof(marshal_helper)); } MarshalMethod = marshal_helper.AddGenericMarshal(ndr_type, code_type, marshal_method, additional_marshal_args); } else { MarshalMethod = marshal_method; } if (additional_unmarshal_args != null) { if (marshal_helper == null) { throw new ArgumentNullException(nameof(marshal_helper)); } UnmarshalMethod = marshal_helper.AddGenericUnmarshal(ndr_type, code_type, unmarshal_method, additional_unmarshal_args ?? new AdditionalArguments()); } else { UnmarshalMethod = unmarshal_method; } NdrType = ndr_type; ValueType = value_type; ConformanceDescriptor = conformance ?? new NdrCorrelationDescriptor(); VarianceDescriptor = variance ?? new NdrCorrelationDescriptor(); }
public string AddGenericMarshal(NdrBaseTypeReference ndr_type, string type_name, string name, AdditionalArguments additional_args) { return(AddGenericMarshal(ndr_type, new CodeTypeReference(CodeGenUtils.MakeIdentifier(type_name)), name, additional_args)); }
public RpcTypeDescriptor(Type code_type, string unmarshal_method, string marshal_method, NdrBaseTypeReference ndr_type) : this(code_type, unmarshal_method, null, marshal_method, ndr_type, null, null, null, null) { }
private TypeDescriptor GetTypeDescriptor(NdrParamAttributes paramAttributes, NdrBaseTypeReference baseType, bool field_type = false) { if (baseType is NdrSimpleTypeReference || baseType is NdrBaseStringTypeReference) { switch (baseType.Format) { case NdrFormatCharacter.FC_BYTE: case NdrFormatCharacter.FC_USMALL: return(new TypeDescriptor(typeof(byte), paramAttributes)); case NdrFormatCharacter.FC_SMALL: case NdrFormatCharacter.FC_CHAR: return(new TypeDescriptor(typeof(sbyte), paramAttributes)); case NdrFormatCharacter.FC_WCHAR: return(new TypeDescriptor(typeof(char), paramAttributes)); case NdrFormatCharacter.FC_SHORT: return(new TypeDescriptor(typeof(short), paramAttributes)); case NdrFormatCharacter.FC_USHORT: return(new TypeDescriptor(typeof(ushort), paramAttributes)); case NdrFormatCharacter.FC_ENUM16: case NdrFormatCharacter.FC_LONG: case NdrFormatCharacter.FC_ENUM32: return(new TypeDescriptor(typeof(int), paramAttributes)); case NdrFormatCharacter.FC_ULONG: case NdrFormatCharacter.FC_ERROR_STATUS_T: return(new TypeDescriptor(typeof(uint), paramAttributes)); case NdrFormatCharacter.FC_FLOAT: return(new TypeDescriptor(typeof(float), paramAttributes)); case NdrFormatCharacter.FC_HYPER: return(new TypeDescriptor(typeof(long), paramAttributes)); case NdrFormatCharacter.FC_DOUBLE: return(new TypeDescriptor(typeof(double), paramAttributes)); case NdrFormatCharacter.FC_INT3264: return(new TypeDescriptor(typeof(IntPtr), paramAttributes)); case NdrFormatCharacter.FC_UINT3264: return(new TypeDescriptor(typeof(UIntPtr), paramAttributes)); case NdrFormatCharacter.FC_C_WSTRING: return(new TypeDescriptor(typeof(string), paramAttributes, CreateMarshalAsAttribute(UnmanagedType.LPWStr))); case NdrFormatCharacter.FC_C_CSTRING: return(new TypeDescriptor(typeof(string), paramAttributes, CreateMarshalAsAttribute(UnmanagedType.LPStr))); } } else if (baseType is NdrKnownTypeReference known_type) { switch (known_type.KnownType) { case NdrKnownTypes.BSTR: return(new TypeDescriptor(typeof(string), paramAttributes, CreateMarshalAsAttribute(UnmanagedType.BStr))); case NdrKnownTypes.GUID: return(new TypeDescriptor(typeof(Guid), paramAttributes)); case NdrKnownTypes.HSTRING: return(new TypeDescriptor(typeof(string), paramAttributes, CreateMarshalAsAttribute(UnmanagedType.HString))); case NdrKnownTypes.VARIANT: return(new TypeDescriptor(typeof(object), paramAttributes, CreateMarshalAsAttribute(UnmanagedType.Struct))); } } else if (baseType is NdrPointerTypeReference pointer_type) { return(new TypeDescriptor(GetTypeDescriptor(paramAttributes, pointer_type.Type))); } else if (baseType is NdrInterfacePointerTypeReference interface_pointer) { TypeDescriptor intf_p; if (interface_pointer.IsConstant && m_proxies.ContainsKey(interface_pointer.Iid)) { intf_p = new TypeDescriptor(CreateInterface(m_proxies[interface_pointer.Iid]), paramAttributes, CreateMarshalAsAttribute(UnmanagedType.Interface)); } else { intf_p = new TypeDescriptor(typeof(object), paramAttributes, CreateMarshalAsAttribute(UnmanagedType.IUnknown)); } // Interface pointer should have a pointer value of 1. return(new TypeDescriptor(intf_p)); } else if (baseType is NdrBaseStructureTypeReference struct_type) { return(new TypeDescriptor(CreateStruct(struct_type), paramAttributes)); } if (field_type) { return(null); } return(new TypeDescriptor(typeof(IntPtr), paramAttributes)); }
private RpcTypeDescriptor GetTypeDescriptorInternal(NdrBaseTypeReference type) { if (type is NdrSimpleTypeReference) { switch (type.Format) { case NdrFormatCharacter.FC_BYTE: case NdrFormatCharacter.FC_USMALL: return(new RpcTypeDescriptor(typeof(byte), "ReadByte", false, "WriteByte", type, null, null)); case NdrFormatCharacter.FC_SMALL: case NdrFormatCharacter.FC_CHAR: return(new RpcTypeDescriptor(typeof(sbyte), "ReadSByte", false, "WriteSByte", type, null, null)); case NdrFormatCharacter.FC_WCHAR: return(new RpcTypeDescriptor(typeof(char), "ReadChar", false, "WriteChar", type, null, null)); case NdrFormatCharacter.FC_SHORT: return(new RpcTypeDescriptor(typeof(short), "ReadInt16", false, "WriteInt16", type, null, null)); case NdrFormatCharacter.FC_USHORT: return(new RpcTypeDescriptor(typeof(ushort), "ReadUInt16", false, "WriteUInt16", type, null, null)); case NdrFormatCharacter.FC_LONG: case NdrFormatCharacter.FC_ENUM16: case NdrFormatCharacter.FC_ENUM32: return(new RpcTypeDescriptor(typeof(int), "ReadInt32", false, "WriteInt32", type, null, null)); case NdrFormatCharacter.FC_ULONG: case NdrFormatCharacter.FC_ERROR_STATUS_T: return(new RpcTypeDescriptor(typeof(uint), "ReadUInt32", false, "WriteUInt32", type, null, null)); case NdrFormatCharacter.FC_FLOAT: return(new RpcTypeDescriptor(typeof(float), "ReadFloat", false, "WriteFloat", type, null, null)); case NdrFormatCharacter.FC_HYPER: return(new RpcTypeDescriptor(typeof(long), "ReadInt64", false, "WriteInt64", type, null, null)); case NdrFormatCharacter.FC_DOUBLE: return(new RpcTypeDescriptor(typeof(double), "ReadDouble", false, "WriteDouble", type, null, null)); case NdrFormatCharacter.FC_INT3264: return(new RpcTypeDescriptor(typeof(NdrInt3264), "ReadInt3264", false, "WriteInt3264", type, null, null)); case NdrFormatCharacter.FC_UINT3264: return(new RpcTypeDescriptor(typeof(NdrUInt3264), "ReadUInt3264", false, "WriteUInt3264", type, null, null)); case NdrFormatCharacter.FC_C_WSTRING: return(new RpcTypeDescriptor(typeof(string), "ReadConformantString", false, "WriteConformantString", type, null, null)); case NdrFormatCharacter.FC_C_CSTRING: return(new RpcTypeDescriptor(typeof(string), "ReadAnsiConformantString", false, "WriteAnsiConformantString", type, null, null)); case NdrFormatCharacter.FC_CSTRING: case NdrFormatCharacter.FC_WSTRING: break; } } else if (type is NdrKnownTypeReference known_type) { switch (known_type.KnownType) { case NdrKnownTypes.GUID: return(new RpcTypeDescriptor(typeof(Guid), "ReadGuid", false, "WriteGuid", type, null, null)); case NdrKnownTypes.BSTR: case NdrKnownTypes.HSTRING: // Implement these custom marshallers. break; } } else if (type is NdrBaseStringTypeReference) { if (type is NdrConformantStringTypeReference conformant_str) { if (conformant_str.Format == NdrFormatCharacter.FC_C_CSTRING) { return(new RpcTypeDescriptor(typeof(string), "ReadAnsiConformantString", false, "WriteAnsiConformantString", type, null, null)); } return(new RpcTypeDescriptor(typeof(string), "ReadConformantString", false, "WriteConformantString", type, null, null)); } } else if (type is NdrSystemHandleTypeReference system_handle) { return(new RpcTypeDescriptor(system_handle.GetSystemHandleType(), "ReadSystemHandle", true, "WriteSystemHandle", type, null, null)); } else if (type is NdrSimpleArrayTypeReference simple_array) { RpcTypeDescriptor element_type = GetTypeDescriptor(simple_array.ElementType); RpcMarshalArgument arg = new RpcMarshalArgument { CodeType = new CodeTypeReference(typeof(int)), Expression = CodeGenUtils.GetPrimitive(simple_array.ElementCount) }; if (element_type.BuiltinType == typeof(char)) { return(new RpcTypeDescriptor(typeof(string), "ReadFixedString", false, "WriteFixedString", type, null, null, arg) { FixedCount = simple_array.ElementCount }); } else if (element_type.BuiltinType == typeof(byte)) { return(new RpcTypeDescriptor(typeof(byte[]), "ReadBytes", false, "WriteFixedBytes", type, null, null, arg) { FixedCount = simple_array.ElementCount }); } } else if (type is NdrPointerTypeReference pointer) { var desc = GetTypeDescriptor(pointer.Type); RpcPointerType pointer_type = RpcPointerType.None; switch (pointer.Format) { case NdrFormatCharacter.FC_UP: pointer_type = RpcPointerType.Unique; break; case NdrFormatCharacter.FC_RP: pointer_type = RpcPointerType.Reference; break; default: pointer_type = RpcPointerType.Full; break; } return(new RpcTypeDescriptor(desc, pointer_type)); } else if (type is NdrSupplementTypeReference supp) { return(GetTypeDescriptor(supp.SupplementType)); } else if (type is NdrHandleTypeReference handle) { if (handle.Format == NdrFormatCharacter.FC_BIND_CONTEXT) { return(new RpcTypeDescriptor(typeof(NdrContextHandle), "ReadContextHandle", false, "WriteContextHandle", type, null, null)); } } else if (type is NdrRangeTypeReference range) { return(GetTypeDescriptor(range.RangeType)); } else if (type is NdrBogusArrayTypeReference bogus_array) { RpcTypeDescriptor element_type = GetTypeDescriptor(bogus_array.ElementType); if (bogus_array.VarianceDescriptor.IsValid && bogus_array.VarianceDescriptor.ValidateCorrelation() && !bogus_array.ConformanceDescriptor.IsValid && element_type.Constructed) { // For now we only support constructed types with variance and no conformance. // The variance also needs to be a constant or a normal correlation. return(new RpcTypeDescriptor(new CodeTypeReference(element_type.CodeType, 1), false, "ReadVaryingBogusArrayStruct", true, "WriteVaryingBogusArrayStruct", type, null, bogus_array.VarianceDescriptor) { FixedCount = bogus_array.ElementCount }); } } var type_name_arg = new RpcMarshalArgument() { CodeType = new CodeTypeReference(typeof(string)), Expression = new CodePrimitiveExpression(type.Format.ToString()) }; return(new RpcTypeDescriptor(typeof(NdrUnsupported), "ReadUnsupported", false, "WriteUnsupported", type, null, null, type_name_arg)); }