internal string string_arg() { int pos = 2; int len = CustomAttributeBuilder.decode_len(this.data, pos, out pos); return(CustomAttributeBuilder.string_from_bytes(this.data, pos, len)); }
private static object decode_cattr_value(Type t, byte[] data, int pos, out int rpos) { TypeCode typeCode = Type.GetTypeCode(t); switch (typeCode) { case TypeCode.Object: { int num = (int)data[pos]; pos++; if (num >= 2 && num <= 14) { return(CustomAttributeBuilder.decode_cattr_value(CustomAttributeBuilder.elementTypeToType(num), data, pos, out rpos)); } throw new Exception("Subtype '" + num + "' of type object not yet handled in decode_cattr_value"); } default: { if (typeCode == TypeCode.Int32) { rpos = pos + 4; return((int)data[pos] + ((int)data[pos + 1] << 8) + ((int)data[pos + 2] << 16) + ((int)data[pos + 3] << 24)); } if (typeCode != TypeCode.String) { throw new Exception("FIXME: Type " + t + " not yet handled in decode_cattr_value."); } if (data[pos] == 255) { rpos = pos + 1; return(null); } int num2 = CustomAttributeBuilder.decode_len(data, pos, out pos); rpos = pos + num2; return(CustomAttributeBuilder.string_from_bytes(data, pos, num2)); } case TypeCode.Boolean: rpos = pos + 1; return(data[pos] != 0); } }
internal static CustomAttributeBuilder.CustomAttributeInfo decode_cattr(CustomAttributeBuilder customBuilder) { byte[] array = customBuilder.Data; ConstructorInfo constructorInfo = customBuilder.Ctor; int num = 0; CustomAttributeBuilder.CustomAttributeInfo result = default(CustomAttributeBuilder.CustomAttributeInfo); if (array.Length < 2) { throw new Exception("Custom attr length is only '" + array.Length + "'"); } if (array[0] != 1 || array[1] != 0) { throw new Exception("Prolog invalid"); } num = 2; ParameterInfo[] parameters = CustomAttributeBuilder.GetParameters(constructorInfo); result.ctor = constructorInfo; result.ctorArgs = new object[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { result.ctorArgs[i] = CustomAttributeBuilder.decode_cattr_value(parameters[i].ParameterType, array, num, out num); } int num2 = (int)array[num] + (int)array[num + 1] * 256; num += 2; result.namedParamNames = new string[num2]; result.namedParamValues = new object[num2]; for (int j = 0; j < num2; j++) { int num3 = (int)array[num++]; int num4 = (int)array[num++]; string text = null; if (num4 == 85) { int num5 = CustomAttributeBuilder.decode_len(array, num, out num); text = CustomAttributeBuilder.string_from_bytes(array, num, num5); num += num5; } int num6 = CustomAttributeBuilder.decode_len(array, num, out num); string text2 = CustomAttributeBuilder.string_from_bytes(array, num, num6); result.namedParamNames[j] = text2; num += num6; if (num3 != 83) { throw new Exception("Unknown named type: " + num3); } FieldInfo field = constructorInfo.DeclaringType.GetField(text2, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { throw new Exception(string.Concat(new object[] { "Custom attribute type '", constructorInfo.DeclaringType, "' doesn't contain a field named '", text2, "'" })); } object obj = CustomAttributeBuilder.decode_cattr_value(field.FieldType, array, num, out num); if (text != null) { Type type = Type.GetType(text); obj = Enum.ToObject(type, obj); } result.namedParamValues[j] = obj; } return(result); }
internal static UnmanagedMarshal get_umarshal(CustomAttributeBuilder customBuilder, bool is_field) { byte[] array = customBuilder.Data; UnmanagedType elemType = (UnmanagedType)80; int num = -1; int sizeParamIndex = -1; bool flag = false; string text = null; Type typeref = null; string cookie = string.Empty; int num2 = (int)array[2]; num2 |= (int)array[3] << 8; string fullName = CustomAttributeBuilder.GetParameters(customBuilder.Ctor)[0].ParameterType.FullName; int num3 = 6; if (fullName == "System.Int16") { num3 = 4; } int num4 = (int)array[num3++]; num4 |= (int)array[num3++] << 8; int i = 0; while (i < num4) { num3++; int num5 = (int)array[num3++]; if (num5 == 85) { int num6 = CustomAttributeBuilder.decode_len(array, num3, out num3); CustomAttributeBuilder.string_from_bytes(array, num3, num6); num3 += num6; } int num7 = CustomAttributeBuilder.decode_len(array, num3, out num3); string text2 = CustomAttributeBuilder.string_from_bytes(array, num3, num7); num3 += num7; string text3 = text2; if (text3 != null) { if (CustomAttributeBuilder.< > f__switch$map1C == null) { CustomAttributeBuilder.< > f__switch$map1C = new Dictionary <string, int>(9) { { "ArraySubType", 0 }, { "SizeConst", 1 }, { "SafeArraySubType", 2 }, { "IidParameterIndex", 3 }, { "SafeArrayUserDefinedSubType", 4 }, { "SizeParamIndex", 5 }, { "MarshalType", 6 }, { "MarshalTypeRef", 7 }, { "MarshalCookie", 8 } }; } int num8; if (CustomAttributeBuilder.< > f__switch$map1C.TryGetValue(text3, out num8)) { switch (num8) { case 0: { int num9 = (int)array[num3++]; num9 |= (int)array[num3++] << 8; num9 |= (int)array[num3++] << 16; num9 |= (int)array[num3++] << 24; elemType = (UnmanagedType)num9; break; } case 1: { int num9 = (int)array[num3++]; num9 |= (int)array[num3++] << 8; num9 |= (int)array[num3++] << 16; num9 |= (int)array[num3++] << 24; num = num9; flag = true; break; } case 2: { int num9 = (int)array[num3++]; num9 |= (int)array[num3++] << 8; num9 |= (int)array[num3++] << 16; num9 |= (int)array[num3++] << 24; elemType = (UnmanagedType)num9; break; } case 3: num3 += 4; break; case 4: num7 = CustomAttributeBuilder.decode_len(array, num3, out num3); CustomAttributeBuilder.string_from_bytes(array, num3, num7); num3 += num7; break; case 5: { int num9 = (int)array[num3++]; num9 |= (int)array[num3++] << 8; sizeParamIndex = num9; flag = true; break; } case 6: num7 = CustomAttributeBuilder.decode_len(array, num3, out num3); text = CustomAttributeBuilder.string_from_bytes(array, num3, num7); num3 += num7; break; case 7: num7 = CustomAttributeBuilder.decode_len(array, num3, out num3); text = CustomAttributeBuilder.string_from_bytes(array, num3, num7); typeref = Type.GetType(text); num3 += num7; break; case 8: num7 = CustomAttributeBuilder.decode_len(array, num3, out num3); cookie = CustomAttributeBuilder.string_from_bytes(array, num3, num7); num3 += num7; break; default: goto IL_34F; } i++; continue; } } IL_34F: throw new Exception("Unknown MarshalAsAttribute field: " + text2); } UnmanagedType unmanagedType = (UnmanagedType)num2; switch (unmanagedType) { case UnmanagedType.LPArray: if (flag) { return(UnmanagedMarshal.DefineLPArrayInternal(elemType, num, sizeParamIndex)); } return(UnmanagedMarshal.DefineLPArray(elemType)); default: if (unmanagedType == UnmanagedType.SafeArray) { return(UnmanagedMarshal.DefineSafeArray(elemType)); } if (unmanagedType != UnmanagedType.ByValArray) { if (unmanagedType != UnmanagedType.ByValTStr) { return(UnmanagedMarshal.DefineUnmanagedMarshal((UnmanagedType)num2)); } return(UnmanagedMarshal.DefineByValTStr(num)); } else { if (!is_field) { throw new ArgumentException("Specified unmanaged type is only valid on fields"); } return(UnmanagedMarshal.DefineByValArray(num)); } break; case UnmanagedType.CustomMarshaler: return(UnmanagedMarshal.DefineCustom(typeref, cookie, text, Guid.Empty)); } }