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); }