private string AttributeDataToString(BlobValue blobValue)
        {
            //TODO enum
            if (blobValue.Value == null)
            {
                return("null");
            }
            switch (blobValue.il2CppTypeEnum)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_STRING:
                return($"\"{blobValue.Value}\"");

            case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
                var array = (BlobValue[])blobValue.Value;
                var list  = new List <string>();
                foreach (var item in array)
                {
                    list.Add(AttributeDataToString(item));
                }
                return($"new[] {{ {string.Join(", ", list)} }}");

            case Il2CppTypeEnum.IL2CPP_TYPE_IL2CPP_TYPE_INDEX:
                var il2CppType = (Il2CppType)blobValue.Value;
                return($"typeof({executor.GetTypeName(il2CppType, false, false)})");

            default:
                return(blobValue.Value.ToString());
            }
        }
Пример #2
0
        private TypeReference GetBlobValueTypeReference(BlobValue blobValue, MemberReference memberReference)
        {
            if (blobValue.EnumType != null)
            {
                return(GetTypeReference(memberReference, blobValue.EnumType));
            }
            var il2CppType = new Il2CppType();

            il2CppType.type = blobValue.il2CppTypeEnum;
            return(GetTypeReference(memberReference, il2CppType));
        }
Пример #3
0
        private CustomAttributeArgument CreateCustomAttributeArgument(TypeReference typeReference, BlobValue blobValue, MemberReference memberReference)
        {
            var val = blobValue.Value;

            if (typeReference.FullName == "System.Object")
            {
                val = new CustomAttributeArgument(GetBlobValueTypeReference(blobValue, memberReference), val);
            }
            else if (val == null)
            {
                return(new CustomAttributeArgument(typeReference, val));
            }
            else if (typeReference is ArrayType arrayType)
            {
                var arrayVal    = (BlobValue[])val;
                var array       = new CustomAttributeArgument[arrayVal.Length];
                var elementType = arrayType.ElementType;
                for (int i = 0; i < arrayVal.Length; i++)
                {
                    array[i] = CreateCustomAttributeArgument(elementType, arrayVal[i], memberReference);
                }
                val = array;
            }
            else if (typeReference.FullName == "System.Type")
            {
                val = GetTypeReference(memberReference, (Il2CppType)val);
            }
            return(new CustomAttributeArgument(typeReference, val));
        }
Пример #4
0
        public bool GetConstantValueFromBlob(Il2CppTypeEnum type, BinaryReader reader, out BlobValue value)
        {
            value = new BlobValue();
            value.il2CppTypeEnum = type;
            switch (type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN:
                value.Value = reader.ReadBoolean();
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_U1:
                value.Value = reader.ReadByte();
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_I1:
                value.Value = reader.ReadSByte();
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_CHAR:
                value.Value = BitConverter.ToChar(reader.ReadBytes(2), 0);
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_U2:
                value.Value = reader.ReadUInt16();
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_I2:
                value.Value = reader.ReadInt16();
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_U4:
                if (il2Cpp.Version >= 29)
                {
                    value.Value = reader.ReadCompressedUInt32();
                }
                else
                {
                    value.Value = reader.ReadUInt32();
                }
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_I4:
                if (il2Cpp.Version >= 29)
                {
                    value.Value = reader.ReadCompressedInt32();
                }
                else
                {
                    value.Value = reader.ReadInt32();
                }
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_U8:
                value.Value = reader.ReadUInt64();
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_I8:
                value.Value = reader.ReadInt64();
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_R4:
                value.Value = reader.ReadSingle();
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_R8:
                value.Value = reader.ReadDouble();
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_STRING:
                int length;
                if (il2Cpp.Version >= 29)
                {
                    length = reader.ReadCompressedInt32();
                    if (length == -1)
                    {
                        value.Value = null;
                    }
                    else
                    {
                        value.Value = Encoding.UTF8.GetString(reader.ReadBytes(length));
                    }
                }
                else
                {
                    length      = reader.ReadInt32();
                    value.Value = reader.ReadString(length);
                }
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
                var arrayLen = reader.ReadCompressedInt32();
                if (arrayLen == -1)
                {
                    value.Value = null;
                }
                else
                {
                    var array                     = new BlobValue[arrayLen];
                    var arrayElementType          = ReadEncodedTypeEnum(reader, out var enumType);
                    var arrayElementsAreDifferent = reader.ReadByte();
                    for (int i = 0; i < arrayLen; i++)
                    {
                        var elementType = arrayElementType;
                        if (arrayElementsAreDifferent == 1)
                        {
                            elementType = ReadEncodedTypeEnum(reader, out enumType);
                        }
                        GetConstantValueFromBlob(elementType, reader, out var data);
                        data.il2CppTypeEnum = elementType;
                        data.EnumType       = enumType;
                        array[i]            = data;
                    }
                    value.Value = array;
                }
                return(true);

            case Il2CppTypeEnum.IL2CPP_TYPE_IL2CPP_TYPE_INDEX:
                var typeIndex = reader.ReadCompressedInt32();
                if (typeIndex == -1)
                {
                    value.Value = null;
                }
                else
                {
                    value.Value = il2Cpp.types[typeIndex];
                }
                return(true);

            default:
                value = null;
                return(false);
            }
        }