public static char GetCallSignatureCharacterForMarshalType(MarshalType t, char?defaultValue) { switch (t) { case MarshalType.BOOL: return('b'); case MarshalType.UINT32: case MarshalType.POINTER: return('I'); case MarshalType.INT: return('i'); case MarshalType.UINT64: return('L'); case MarshalType.INT64: return('l'); case MarshalType.FP32: return('f'); case MarshalType.FP64: return('d'); case MarshalType.STRING: return('s'); case MarshalType.URI: return('u'); case MarshalType.SAFEHANDLE: return('h'); case MarshalType.ENUM: return('j'); // this is wrong for uint enums case MarshalType.ENUM64: return('k'); // this is wrong for ulong enums case MarshalType.TASK: case MarshalType.DELEGATE: case MarshalType.OBJECT: return('o'); case MarshalType.VT: return('a'); default: if (defaultValue.HasValue) { return(defaultValue.Value); } else { throw new JSException($"Unsupported marshal type {t}"); } } }
/// <summary> /// Gets the termination status of the thread. /// </summary> public T GetExitCode <T>() { // Get the exit code of the thread (can be nullable) var ret = ThreadHelper.GetExitCodeThread(Handle); // Return the exit code or the default value of T if there's no exit code return(ret.HasValue ? MarshalType <T> .PtrToObject(_processPlus, ret.Value) : default);
internal static string BuildMethodParameterList(MethodReference interopMethod, MethodReference interfaceMethod, Unity.IL2CPP.ILPreProcessor.TypeResolver typeResolver, MarshalType marshalType, bool includeTypeNames) { List<string> elements = new List<string>(); int num = 0; foreach (ParameterDefinition definition in interopMethod.Parameters) { MarshalInfo marshalInfo = interfaceMethod.Parameters[num].MarshalInfo; DefaultMarshalInfoWriter writer = MarshalDataCollector.MarshalInfoWriterFor(typeResolver.Resolve(definition.ParameterType), marshalType, marshalInfo, true, false, false, null); foreach (MarshaledType type in writer.MarshaledTypes) { elements.Add(string.Format(!includeTypeNames ? "{1}" : "{0} {1}", type.DecoratedName, Naming.ForParameterName(definition) + type.VariableName)); } num++; } TypeReference reference2 = typeResolver.Resolve(interopMethod.ReturnType); if (reference2.MetadataType != MetadataType.Void) { MarshalInfo info2 = interfaceMethod.MethodReturnType.MarshalInfo; MarshaledType[] marshaledTypes = MarshalDataCollector.MarshalInfoWriterFor(reference2, marshalType, info2, true, false, false, null).MarshaledTypes; for (int i = 0; i < (marshaledTypes.Length - 1); i++) { elements.Add(string.Format(!includeTypeNames ? "{1}" : "{0}* {1}", marshaledTypes[i].DecoratedName, Naming.ForComInterfaceReturnParameterName() + marshaledTypes[i].VariableName)); } elements.Add(string.Format(!includeTypeNames ? "{1}" : "{0}* {1}", marshaledTypes[marshaledTypes.Length - 1].DecoratedName, Naming.ForComInterfaceReturnParameterName())); } return EnumerableExtensions.AggregateWithComma(elements); }
protected ArrayMarshalInfoWriter(ArrayType type, MarshalType marshalType, MarshalInfo marshalInfo) : base(type) { this._marshalInfo = marshalInfo; this._marshalType = marshalType; this._arrayType = type; this._elementType = type.ElementType; MarshalInfo info = null; ArrayMarshalInfo info2 = marshalInfo as ArrayMarshalInfo; FixedArrayMarshalInfo info3 = marshalInfo as FixedArrayMarshalInfo; this._arraySize = 1; this._nativeElementType = NativeType.None; if (info2 != null) { this._arraySize = info2.Size; this._sizeParameterIndex = info2.SizeParameterIndex; if ((this._arraySize == 0) || ((this._arraySize == -1) && (this._sizeParameterIndex >= 0))) { this._arraySizeSelection = ArraySizeOptions.UseSizeParameterIndex; } else { this._arraySizeSelection = ArraySizeOptions.UseArraySize; } this._nativeElementType = info2.ElementType; info = new MarshalInfo(this._nativeElementType); } else if (info3 != null) { this._arraySize = info3.Size; this._nativeElementType = info3.ElementType; info = new MarshalInfo(this._nativeElementType); } if (this._arraySize == -1) { this._arraySize = 1; } this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(this._elementType, marshalType, info, false, false, true, null); if (this._elementTypeMarshalInfoWriter.MarshaledTypes.Length > 1) { throw new InvalidOperationException($"ArrayMarshalInfoWriter cannot marshal arrays of {this._elementType.FullName}."); } this._arrayMarshaledTypeName = this._elementTypeMarshalInfoWriter.MarshaledTypes[0].DecoratedName + "*"; if (marshalType == MarshalType.WindowsRuntime) { string name = DefaultMarshalInfoWriter.Naming.ForVariable(DefaultMarshalInfoWriter.TypeProvider.UInt32TypeReference); this._arraySizeSelection = ArraySizeOptions.UseFirstMarshaledType; this._marshaledTypes = new MarshaledType[] { new MarshaledType(name, name, "ArraySize"), new MarshaledType(this._arrayMarshaledTypeName, this._arrayMarshaledTypeName) }; } else { this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._arrayMarshaledTypeName, this._arrayMarshaledTypeName) }; } StringMarshalInfoWriter writer = this._elementTypeMarshalInfoWriter as StringMarshalInfoWriter; if (writer != null) { this._nativeElementType = writer.NativeType; } }
public ExportedPropertyMetadata(string name, MarshalType type, ITypeSymbol typeSymbol, string?value) { Name = name; Type = type; TypeSymbol = typeSymbol; Value = value; }
private void Init() { Type thisType = typeof(T); if (thisType == typeof(string)) { OffsetType = OffsetType.String; OffsetMarshalType = new MarshalType(typeof(UIntPtr)); } else if (thisType == typeof(IntPtr) || thisType == typeof(UIntPtr)) { OffsetType = OffsetType.UIntPtr; OffsetMarshalType = new MarshalType(typeof(UIntPtr)); } else if (thisType.IsSubclassOf(typeof(ExternalClass)) || thisType.IsSubclassOfRawGeneric(typeof(ExternalOffset <>))) { // OffsetType Set On Other Constructor If It's `ExternalClass` if (OffsetType != OffsetType.ExternalClass) { throw new Exception("Use Other Constructor For `ExternalClass` Types."); } // If externalClassIsPointer == true, ExternalClass Will Fix The Size Before Calc Class Size // So It's Okay To Leave It Like That Size = ExternalClassObject.ClassSize; OffsetMarshalType = ExternalClassIsPointer ? new MarshalType(typeof(UIntPtr)) : null; } else { Size = Marshal.SizeOf <T>(); OffsetMarshalType = new MarshalType(thisType); } }
public bool Read <T>(IntPtr address, out T[] value, int count) { if (count <= 0) { value = null; return(false); } if (ReadBytes(address, out var buffer, MarshalType <T> .Size * count)) { value = new T[count]; if (MarshalType <T> .TypeCode != TypeCode.Byte) { for (var i = 0; i < count; i++) { value[i] = MarshalType <T> .ByteArrayToObject(buffer, MarshalType <T> .Size *i); } } else { Buffer.BlockCopy(buffer, 0, value, 0, count); } return(true); } value = null; return(false); }
private static void GeneratePropertySetter( string propertyMemberName, ITypeSymbol propertyTypeSymbol, MarshalType propertyMarshalType, StringBuilder source, bool isFirstEntry ) { source.Append(" "); if (!isFirstEntry) { source.Append("else "); } source.Append("if (name == GodotInternal.PropName_") .Append(propertyMemberName) .Append(") {\n") .Append(" ") .Append(propertyMemberName) .Append(" = ") .AppendNativeVariantToManagedExpr("value", propertyTypeSymbol, propertyMarshalType) .Append(";\n") .Append(" return true;\n") .Append(" }\n"); }
/// <summary> /// Reads an array of a specified type in the remote process. /// </summary> /// <typeparam name="T">The type of the values.</typeparam> /// <param name="address">The address where the values is read.</param> /// <param name="count">The number of cells in the array.</param> /// <param name="isRelative">[Optional] State if the address is relative to the main module.</param> /// <returns>An array.</returns> public T[] Read <T>(IntPtr address, int count, bool isRelative = true) { // Allocate an array to store the results var array = new T[count]; // Read all the memory at once, much faster then reading each time individually var bytes = ReadBytes(address, MarshalType <T> .Size * count, isRelative); //If we check the type we can gain an additional boost of speed //ofcourse if we wrote an unmanaged module and used that here itd go even faster then this. if (typeof(T) != typeof(byte)) { for (var i = 0; i < count; i++) { array[i] = MarshalType <T> .ByteArrayToObject(bytes, MarshalType <T> .Size *i); } } else { //Just copy the bytes Buffer.BlockCopy(bytes, 0, array, 0, count); } return(array); }
/// <summary> /// Creates a field marshal blob from <paramref name="marshalType" /> /// </summary> /// <param name="module">Owner module</param> /// <param name="marshalType">Marshal type</param> /// <param name="helper">Helps this class</param> /// <returns> /// A field marshal blob or <c>null</c> if <paramref name="marshalType" /> is /// <c>null</c> /// </returns> public static byte[] Write(ModuleDef module, MarshalType marshalType, IWriterError helper) { using (var writer = new MarshalBlobWriter(module, helper)) { return(writer.Write(marshalType)); } }
public BlittableStructMarshalInfoWriter(TypeDefinition type, MarshalType marshalType) : base(type) { this._type = type; this._marshalType = marshalType; string name = DefaultMarshalInfoWriter.Naming.ForVariable(this._type); this._marshaledTypes = new MarshaledType[] { new MarshaledType(name, name) }; }
/// <summary> /// Gets the termination status of the thread. /// </summary> public T GetExitCode <T>() { // Get the exit code of the thread (can be nullable) var ret = ThreadCore.GetExitCodeThread(Handle); // Return the exit code or the default value of T if there's no exit code return(ret.HasValue ? MarshalType <T> .PtrToObject(MemorySharp, ret.Value) : default(T)); }
public ParamDefOptions(ParamDef pd) { this.Name = pd.Name; this.Sequence = pd.Sequence; this.Attributes = pd.Attributes; this.Constant = pd.Constant; this.MarshalType = pd.MarshalType; this.CustomAttributes.AddRange(pd.CustomAttributes); }
public MarshalAsAttribute(int index, MarshalType tp, int theArrayLength) { Index = index; if (tp != MarshalType.FixedLengthArray) { throw new Exception("Marshaling an array?"); } MarshType = tp; ArrayLength = theArrayLength; }
public BlittableByReferenceMarshalInfoWriter(ByReferenceType type, MarshalType marshalType, MarshalInfo marshalInfo) : base(type) { this._elementType = type.ElementType; this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(this._elementType, marshalType, marshalInfo, false, true, false, null); if (this._elementTypeMarshalInfoWriter.MarshaledTypes.Length > 1) { throw new InvalidOperationException($"BlittableByReferenceMarshalInfoWriter cannot marshal {type.ElementType.FullName}&."); } this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._elementTypeMarshalInfoWriter.MarshaledTypes[0].Name + "*", this._elementTypeMarshalInfoWriter.MarshaledTypes[0].DecoratedName + "*") }; }
public BlittableByReferenceMarshalInfoWriter(ByReferenceType type, MarshalType marshalType, MarshalInfo marshalInfo) : base(type) { this._elementType = type.ElementType; this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(this._elementType, marshalType, marshalInfo, false, true, false, null); if (this._elementTypeMarshalInfoWriter.MarshaledTypes.Length > 1) { throw new InvalidOperationException(string.Format("BlittableByReferenceMarshalInfoWriter cannot marshal {0}&.", type.ElementType.FullName)); } this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._elementTypeMarshalInfoWriter.MarshaledTypes[0].Name + "*", this._elementTypeMarshalInfoWriter.MarshaledTypes[0].DecoratedName + "*") }; }
public bool Write <T>(IntPtr address, T[] array) { var size = MarshalType <T> .Size; var buffer = new byte[size * array.Length]; for (var i = 0; i < array.Length; i++) { Buffer.BlockCopy(MarshalType <T> .ObjectToByteArray(array[i]), 0, buffer, size * i, size); } return(WriteBytes(address, buffer)); }
public void PtrToObjectLong() { // Arrange var ptr = new IntPtr(32); // Act var value = MarshalType <long> .PtrToObject(Resources.MemorySharp, ptr); // Assert Assert.AreEqual(32, value); }
public void ToByteArrayDoubleType() { // Arrange const double originalValue = 3.141592; var valueInBytes = BitConverter.GetBytes(originalValue); // Act var ret = MarshalType <double> .ObjectToByteArray(originalValue); // Assert CollectionAssert.AreEqual(valueInBytes, ret, "Both variables aren't equal."); }
public bool Read <T>(IntPtr address, out T value) { if (ReadBytes(address, out var buffer, MarshalType <T> .Size)) { value = MarshalType <T> .ByteArrayToObject(buffer); return(true); } value = default; return(false); }
public void ToManagedObjectPointStruct() { // Arrange var customStruct = Resources.CustomStruct; // Act var byteArray = MarshalType <Point> .ObjectToByteArray(customStruct); var customStruct2 = MarshalType <Point> .ByteArrayToObject(byteArray); // Assert Assert.AreEqual(customStruct, customStruct2, "Both structures are not equal."); }
public FieldDefOptions(FieldDef field) { this.Attributes = field.Attributes; this.Name = field.Name; this.FieldSig = field.FieldSig; this.FieldOffset = field.FieldOffset; this.MarshalType = field.MarshalType; this.RVA = field.RVA; this.InitialValue = field.InitialValue; this.ImplMap = field.ImplMap; this.Constant = field.Constant; this.CustomAttributes.AddRange(field.CustomAttributes); }
public FieldDefOptions(FieldDef field) { Attributes = field.Attributes; Name = field.Name; FieldSig = field.FieldSig; FieldOffset = field.FieldOffset; MarshalType = field.MarshalType; RVA = field.RVA; InitialValue = field.InitialValue; ImplMap = field.ImplMap; Constant = field.Constant; CustomAttributes.AddRange(field.CustomAttributes); }
/// <summary> /// Writes an array of a specified type in the remote process. /// </summary> /// <typeparam name="T">The type of the values.</typeparam> /// <param name="address">The address where the values is written.</param> /// <param name="array">The array to write.</param> /// <param name="isRelative">[Optional] State if the address is relative to the main module.</param> public void Write <T>(IntPtr address, T[] array, bool isRelative = true) { // Allocate an array containing the values of the array converted into bytes var valuesInBytes = new byte[MarshalType <T> .Size * array.Length]; // Convert each value into its bytes representation for (var i = 0; i < array.Length; i++) { var offsetInArray = MarshalType <T> .Size * i; Buffer.BlockCopy(MarshalType <T> .ObjectToByteArray(array[i]), 0, valuesInBytes, offsetInArray, MarshalType <T> .Size); } WriteBytes(address, valuesInBytes, isRelative); }
protected override bool AfterUpdate(bool updated) { if (!updated) { return(false); } if (!InitItems()) { return(false); } if (_itemSize == -1) { if (typeof(T).IsSubclassOf(typeof(ExClass))) { if (ReadInfo.IsPointerToData) { _itemSize = ExMemory.PointerSize; } else { _itemSize = ((ExClass)Activator.CreateInstance(typeof(T)))?.ClassSize ?? throw new NullReferenceException($"Can't create instance of '{typeof(T).Name}'."); } } else { _itemSize = MarshalType.GetSizeOfType(typeof(T)); } } int counter = 0; int itemSize = _itemSize + ReadInfo.BadSizeAfterEveryItem; // Get TArray Data ExMemory.ReadBytes(Data, (uint)(Items.Count * itemSize), out ReadOnlySpan <byte> tArrayData); int offset = 0; for (int i = 0; i < Items.Count; i++) { T item = Items[i]; UIntPtr itemAddress; if (ReadInfo.IsPointerToData) { // Get Item Address (Pointer Value (aka Pointed Address)) itemAddress = ExMemory.Is64BitMemory ? (UIntPtr)MemoryMarshal.Read <ulong>(tArrayData[offset..])
private static Mono.Cecil.NativeType DetermineNativeTypeFor(MarshalType marshalType, MarshalInfo marshalInfo, bool useUnicodeCharset, bool isStringBuilder) { Mono.Cecil.NativeType nativeType; if (marshalInfo != null) { nativeType = marshalInfo.NativeType; } else if (marshalType == MarshalType.PInvoke) { nativeType = !useUnicodeCharset ? Mono.Cecil.NativeType.LPStr : Mono.Cecil.NativeType.LPWStr; } else { nativeType = Mono.Cecil.NativeType.None; } bool flag = false; switch (nativeType) { case Mono.Cecil.NativeType.BStr: case Mono.Cecil.NativeType.LPStr: case Mono.Cecil.NativeType.LPWStr: case Mono.Cecil.NativeType.FixedSysString: case (Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean): flag = true; break; } if (flag && ((!isStringBuilder || (nativeType == Mono.Cecil.NativeType.LPStr)) || (nativeType == Mono.Cecil.NativeType.LPWStr))) { return(nativeType); } if (marshalType != MarshalType.PInvoke) { if (marshalType != MarshalType.COM) { if (marshalType != MarshalType.WindowsRuntime) { return(nativeType); } return(Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean); } } else { return(Mono.Cecil.NativeType.LPStr); } return(Mono.Cecil.NativeType.BStr); }
public void PtrToObjectString() { // Arrange var point = Resources.CustomStruct; var sharp = Resources.MemorySharp; // Act using (var memory = sharp.Memory.Allocate(MarshalType <Point> .Size)) { memory.Write(point); var ret = MarshalType <Point> .PtrToObject(sharp, memory.BaseAddress); // Assert Assert.AreEqual(point, ret); } }
private static Mono.Cecil.NativeType DetermineNativeTypeFor(MarshalType marshalType, MarshalInfo marshalInfo, bool useUnicodeCharset, bool isStringBuilder) { Mono.Cecil.NativeType nativeType; if (marshalInfo != null) { nativeType = marshalInfo.NativeType; } else if (marshalType == MarshalType.PInvoke) { nativeType = !useUnicodeCharset ? Mono.Cecil.NativeType.LPStr : Mono.Cecil.NativeType.LPWStr; } else { nativeType = Mono.Cecil.NativeType.None; } bool flag = false; switch (nativeType) { case Mono.Cecil.NativeType.BStr: case Mono.Cecil.NativeType.LPStr: case Mono.Cecil.NativeType.LPWStr: case Mono.Cecil.NativeType.FixedSysString: case (Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean): flag = true; break; } if (flag && ((!isStringBuilder || (nativeType == Mono.Cecil.NativeType.LPStr)) || (nativeType == Mono.Cecil.NativeType.LPWStr))) { return nativeType; } if (marshalType != MarshalType.PInvoke) { if (marshalType != MarshalType.COM) { if (marshalType != MarshalType.WindowsRuntime) { return nativeType; } return (Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean); } } else { return Mono.Cecil.NativeType.LPStr; } return Mono.Cecil.NativeType.BStr; }
public MarshalAsAttribute(int index, MarshalType tp, string associatedVariable, int sizeLength = 0) { Index = index; MarshType = tp; SizeLength = sizeLength; if (tp == MarshalType.VariableLengthArray) { AssociatedArrayName = associatedVariable; return; } if (tp == MarshalType.Union) { AssociatedUnionSelector = associatedVariable; return; } throw new Exception("Unknown MarshallType?"); }
private void WriteForwardDeclarations(TypeReference type) { Unity.IL2CPP.ILPreProcessor.TypeResolver resolver = Unity.IL2CPP.ILPreProcessor.TypeResolver.For(type); MarshalType marshalType = !type.Resolve().IsWindowsRuntime ? MarshalType.COM : MarshalType.WindowsRuntime; foreach (MethodDefinition definition in type.Resolve().Methods) { foreach (ParameterDefinition definition2 in definition.Parameters) { MarshalDataCollector.MarshalInfoWriterFor(resolver.Resolve(definition2.ParameterType), marshalType, definition2.MarshalInfo, true, false, false, null).WriteMarshaledTypeForwardDeclaration(this._writer); } if (definition.ReturnType.MetadataType != MetadataType.Void) { MarshalDataCollector.MarshalInfoWriterFor(resolver.Resolve(definition.ReturnType), marshalType, definition.MethodReturnType.MarshalInfo, true, false, false, null).WriteMarshaledTypeForwardDeclaration(this._writer); } } }
void Add(MarshalType mt) { if (mt == null) { return; } switch (mt.NativeType) { case NativeType.SafeArray: Add(((SafeArrayMarshalType)mt).UserDefinedSubType); break; case NativeType.CustomMarshaler: Add(((CustomMarshalType)mt).CustomMarshaler); break; } }
public ComObjectMarshalInfoWriter(TypeReference type, MarshalType marshalType, MarshalInfo marshalInfo) : base(type) { this._marshalAsInspectable = (marshalType == MarshalType.WindowsRuntime) || ((marshalInfo != null) && (marshalInfo.NativeType == (NativeType.CustomMarshaler | NativeType.Boolean))); TypeDefinition definition = type.Resolve(); this._isSealed = definition.IsSealed; this._isClass = ((marshalType == MarshalType.WindowsRuntime) && !Extensions.IsInterface(definition)) && !Extensions.IsSystemObject(type); this._defaultInterface = !this._isClass ? type : Extensions.ExtractDefaultInterface(definition); this._managedTypeName = !this._isClass ? DefaultMarshalInfoWriter.Naming.ForTypeNameOnly(DefaultMarshalInfoWriter.TypeProvider.SystemObject) : DefaultMarshalInfoWriter.Naming.ForTypeNameOnly(type); if (Extensions.IsSystemObject(type)) { this._interfaceTypeName = !this._marshalAsInspectable ? "Il2CppIUnknown" : "Il2CppIInspectable"; } else { this._interfaceTypeName = DefaultMarshalInfoWriter.Naming.ForTypeNameOnly(this._defaultInterface); } this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._interfaceTypeName + '*', this._interfaceTypeName + '*') }; }
protected CustomMarshalInfoWriter(TypeDefinition type, MarshalType marshalType, bool forFieldMarshaling) : base(type) { this._type = type; this._marshalType = marshalType; string str = DefaultMarshalInfoWriter.Naming.ForTypeNameOnly(type); string str2 = '_' + MarshalingUtils.MarshalTypeToString(marshalType); this._forFieldMarshaling = forFieldMarshaling; this._marshaledTypeName = GetMarshaledTypeName(type, marshalType); this._marshaledDecoratedTypeName = !this.TreatAsValueType() ? (this._marshaledTypeName + "*") : this._marshaledTypeName; this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._marshaledTypeName, this._marshaledDecoratedTypeName) }; this._marshalToNativeFunctionName = $"{str}_marshal{str2}"; this._marshalFromNativeFunctionName = $"{str}_marshal{str2}_back"; this._marshalCleanupFunctionName = $"{str}_marshal{str2}_cleanup"; this._marshalToNativeFunctionDeclaration = $"extern "C" void {this.MarshalToNativeFunctionName}(const {str}& unmarshaled, {this._marshaledTypeName}& marshaled)"; this._marshalFromNativeFunctionDeclaration = $"extern "C" void {this._marshalFromNativeFunctionName}(const {this._marshaledTypeName}& marshaled, {str}& unmarshaled)"; this._marshalCleanupFunctionDeclaration = $"extern "C" void {this.MarshalCleanupFunctionName}({this._marshaledTypeName}& marshaled)"; if (<>f__am$cache0 == null) {
public T[] Read <T>(IntPtr address, int count) { var data = ReadBytes(address, MarshalType <T> .Size * count); var result = new T[count]; if (MarshalType <T> .TypeCode == TypeCode.Byte) { Buffer.BlockCopy(data, 0, result, 0, count); } else { for (var i = 0; i < count; i++) { result[i] = MarshalType <T> .ByteArrayToObject(data, MarshalType <T> .Size *i); } } return(result); }
public StringMarshalInfoWriter(TypeReference type, MarshalType marshalType, MarshalInfo marshalInfo, bool useUnicodeCharSet, bool forByReferenceType, bool forFieldMarshaling) : base(type) { this._isStringBuilder = MarshalingUtils.IsStringBuilder(type); this._useUnicodeCharSet = useUnicodeCharSet; this._nativeType = DetermineNativeTypeFor(marshalType, marshalInfo, this._useUnicodeCharSet, this._isStringBuilder); if (this._nativeType == (Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean)) { this._marshaledTypeName = "Il2CppHString"; } else if (this.IsWideString) { this._marshaledTypeName = "Il2CppChar*"; } else { this._marshaledTypeName = "char*"; } this._marshaledTypes = new MarshaledType[] { new MarshaledType(this._marshaledTypeName, this._marshaledTypeName) }; this._marshalInfo = marshalInfo; this._canReferenceOriginalManagedString = ((!this._isStringBuilder && !forByReferenceType) && !forFieldMarshaling) && ((this._nativeType == Mono.Cecil.NativeType.LPWStr) || (this._nativeType == (Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean))); }
public ComCallableWrapperMethodBodyWriter(MethodReference managedMethod, MethodReference interfaceMethod, MarshalType marshalType) : base(managedMethod, interfaceMethod, marshalType, true) { }
public MarshalAsAttribute(int index, MarshalType tp = MarshalType.Normal) { Index = index; MarshType = tp; }
public ByReferenceMarshalInfoWriter(ByReferenceType type, MarshalType marshalType, MarshalInfo marshalInfo) : base(type) { this._elementType = type.ElementType; this._elementTypeMarshalInfoWriter = MarshalDataCollector.MarshalInfoWriterFor(type.ElementType, marshalType, marshalInfo, false, true, false, null); if (<>f__am$cache0 == null) {
byte[] Write(MarshalType marshalType) { if (marshalType == null) return null; var type = marshalType.NativeType; if (type != NativeType.RawBlob) { if ((uint)type > byte.MaxValue) helper.Error("Invalid MarshalType.NativeType"); writer.Write((byte)type); } bool canWrite = true; switch (type) { case NativeType.FixedSysString: var fixedSysString = (FixedSysStringMarshalType)marshalType; if (fixedSysString.IsSizeValid) WriteCompressedUInt32((uint)fixedSysString.Size); break; case NativeType.SafeArray: var safeArray = (SafeArrayMarshalType)marshalType; if (UpdateCanWrite(safeArray.IsVariantTypeValid, "VariantType", ref canWrite)) WriteCompressedUInt32((uint)safeArray.VariantType); if (UpdateCanWrite(safeArray.IsUserDefinedSubTypeValid, "UserDefinedSubType", ref canWrite)) Write(safeArray.UserDefinedSubType.AssemblyQualifiedName); break; case NativeType.FixedArray: var fixedArray = (FixedArrayMarshalType)marshalType; if (UpdateCanWrite(fixedArray.IsSizeValid, "Size", ref canWrite)) WriteCompressedUInt32((uint)fixedArray.Size); if (UpdateCanWrite(fixedArray.IsElementTypeValid, "ElementType", ref canWrite)) WriteCompressedUInt32((uint)fixedArray.ElementType); break; case NativeType.Array: var array = (ArrayMarshalType)marshalType; if (UpdateCanWrite(array.IsElementTypeValid, "ElementType", ref canWrite)) WriteCompressedUInt32((uint)array.ElementType); if (UpdateCanWrite(array.IsParamNumberValid, "ParamNumber", ref canWrite)) WriteCompressedUInt32((uint)array.ParamNumber); if (UpdateCanWrite(array.IsSizeValid, "Size", ref canWrite)) WriteCompressedUInt32((uint)array.Size); if (UpdateCanWrite(array.IsFlagsValid, "Flags", ref canWrite)) WriteCompressedUInt32((uint)array.Flags); break; case NativeType.CustomMarshaler: var custMarshaler = (CustomMarshalType)marshalType; Write(custMarshaler.Guid); Write(custMarshaler.NativeTypeName); var cm = custMarshaler.CustomMarshaler; var cmName = cm == null ? string.Empty : FullNameCreator.AssemblyQualifiedName(cm, this); Write(cmName); Write(custMarshaler.Cookie); break; case NativeType.IUnknown: case NativeType.IDispatch: case NativeType.IntF: var iface = (InterfaceMarshalType)marshalType; if (iface.IsIidParamIndexValid) WriteCompressedUInt32((uint)iface.IidParamIndex); break; case NativeType.RawBlob: var data = ((RawMarshalType)marshalType).Data; if (data != null) writer.Write(data); break; default: break; } writer.Flush(); return outStream.ToArray(); }
public TpmStructMemberInfo (MemberInfo mi) { Info = mi; WireType = MarshalType.Normal; }
/// <summary> /// Creates a field marshal blob from <paramref name="marshalType"/> /// </summary> /// <param name="module">Owner module</param> /// <param name="marshalType">Marshal type</param> /// <param name="helper">Helps this class</param> /// <returns>A field marshal blob or <c>null</c> if <paramref name="marshalType"/> is /// <c>null</c></returns> public static byte[] Write(ModuleDef module, MarshalType marshalType, IWriterError helper) { using (var writer = new MarshalBlobWriter(module, helper)) return writer.Write(marshalType); }
public TypeDefinitionWithUnsupportedFieldMarshalInfoWriter(TypeDefinition type, MarshalType marshalType, FieldDefinition faultyField) : base(type, marshalType, false) { this._faultyField = faultyField; }
public NativeToManagedInteropMethodBodyWriter(MethodReference managedMethod, MethodReference interopMethod, MarshalType marshalType, bool useUnicodeCharset) : base(interopMethod, managedMethod, new NativeToManagedMarshaler(TypeResolver.For(interopMethod.DeclaringType, interopMethod), marshalType, useUnicodeCharset)) { this._managedMethod = managedMethod; }
public ManagedToNativeInteropMethodBodyWriter(MethodReference interopMethod, MethodReference methodForParameterNames, MarshalType marshalType, bool useUnicodeCharset) : base(interopMethod, methodForParameterNames, new ManagedToNativeMarshaler(TypeResolver.For(interopMethod.DeclaringType, interopMethod), marshalType, useUnicodeCharset)) { }
public LPStructMarshalInfoWriter(TypeReference type, MarshalType marshalType) : base(type) { string name = DefaultMarshalInfoWriter.Naming.ForVariable(base._typeRef); this._marshaledTypes = new MarshaledType[] { new MarshaledType(name, name + "*") }; }