Ejemplo n.º 1
0
        /// <summary>
        /// Returns a casted raw address expression that can be used to build a value assign
        /// expression.
        ///
        /// Can return null.
        /// </summary>
        public static string GetMemoryAddressAssignExpression(this RemoteValue remoteValue)
        {
            if (!IsValidValue(remoteValue))
            {
                return(null);
            }
            var flags = remoteValue.GetTypeInfo().GetTypeFlags();

            if (flags.HasFlag(TypeFlags.IS_REFERENCE))
            {
                // NOTE: This works for references implemented as a pointer. It is not known how
                // this will work for other implementations.
                var typeName = remoteValue.GetTypeName();
                typeName = typeName.Replace("&", "");
                return($"(*(({typeName}*){remoteValue.GetDefaultValue()}))");
            }

            RemoteValue addressOfValue;

            if (!TryGetAddressOf(remoteValue, out addressOfValue))
            {
                return(null);
            }

            if (flags.HasFlag(TypeFlags.IS_POINTER))
            {
                return($"(({remoteValue.GetTypeName()}){remoteValue.GetDefaultValue()})");
            }

            if (flags.HasFlag(TypeFlags.IS_ARRAY))
            {
                return(null);
            }

            return($"(*(({remoteValue.GetTypeName()}*){addressOfValue.GetDefaultValue()}))");
        }