Beispiel #1
0
        // Mutators /////////////////////////////////////////////////////////////////

        /// <summary>
        /// This method is called when the user has created a global item.
        /// </summary>
        /// <param name="address"></param>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public ImageMapItem AddUserGlobalItem(Address address, DataType dataType)
        {
            var size = GetDataSize(address, dataType);
            var item = new ImageMapItem
            {
                Address  = address,
                Size     = size,
                DataType = dataType,
            };

            if (size != 0)
            {
                this.ImageMap.AddItemWithSize(address, item);
            }
            else
            {
                this.ImageMap.AddItem(address, item);
            }

            this.User.Globals.Add(address, new Serialization.GlobalDataItem_v2
            {
                Address  = address.ToString(),
                DataType = dataType.Accept(new Serialization.DataTypeSerializer()),
            });
            return(item);
        }
Beispiel #2
0
 public void Accept(TSqlFragmentVisitor visitor)
 {
     visitor.ExplicitVisit(this);
     VariableName?.Accept(visitor);
     DataType?.Accept(visitor);
     Value?.Accept(visitor);
 }
Beispiel #3
0
 public void WriteGlobalVariable(Address address, DataType dataType, string name, Formatter formatter)
 {
     this.formatter     = formatter;
     this.codeFormatter = new CodeFormatter(formatter);
     this.tw            = new TypeReferenceFormatter(formatter);
     this.globals       = new StructureType();
     this.queue         = new Queue <StructureField>(globals.Fields);
     try
     {
         tw.WriteDeclaration(dataType, name);
         if (program.SegmentMap.IsValidAddress(address))
         {
             formatter.Write(" = ");
             this.rdr = program.CreateImageReader(program.Architecture, address);
             dataType.Accept(this);
         }
     }
     catch (Exception ex)
     {
         var dc = services.RequireService <DecompilerEventListener>();
         dc.Error(
             dc.CreateAddressNavigator(program, address),
             ex,
             "Failed to write global variable {0}.",
             name);
     }
     formatter.Terminate(";");
 }
Beispiel #4
0
        public override void Accept(TSqlFragmentVisitor visitor)
        {
            visitor.ExplicitVisit(this);

            DataType?.Accept(visitor);
            Parameter?.Accept(visitor);
        }
Beispiel #5
0
        /// <summary>
        /// This method is called when the user has created a global item.
        /// </summary>
        /// <param name="address"></param>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public ImageMapItem AddUserGlobalItem(IProcessorArchitecture arch, Address address, DataType dataType)
        {
            //$TODO: if user enters a segmented address, we need to
            // place the item in the respective globals struct.
            var size = GetDataSize(arch, address, dataType);
            var item = new ImageMapItem
            {
                Address  = address,
                Size     = size,
                DataType = dataType,
            };

            if (size != 0)
            {
                this.ImageMap.AddItemWithSize(address, item);
            }
            else
            {
                this.ImageMap.AddItem(address, item);
            }

            this.User.Globals.Add(address, new Serialization.GlobalDataItem_v2
            {
                Address  = address.ToString(),
                DataType = dataType.Accept(new Serialization.DataTypeSerializer()),
            });
            return(item);
        }
Beispiel #6
0
 public bool Find(DataType dt)
 {
     if (dt == dtCandidate)
     {
         return(true);
     }
     return(dt.Accept(this));
 }
Beispiel #7
0
        /// <summary>
        /// Rewrites a machine word constant depending on its data type.
        /// </summary>
        /// <param name="c"></param>
        /// <param name="dereferenced"></param>
        /// <returns></returns>
        public Expression Rewrite(Constant c, bool dereferenced)
        {
            this.c = c;
            DataType dtInferred = c.TypeVariable.DataType.ResolveAs <DataType>();

            this.pOrig        = c.TypeVariable.OriginalDataType as PrimitiveType;
            this.dereferenced = dereferenced;
            return(dtInferred.Accept(this));
        }
Beispiel #8
0
 private Argument_v1 SerializeArgument(string name, Storage stg, DataType dt)
 {
     return(new Argument_v1
     {
         Name = name,
         //    Kind = arg.Storage.Serialize(),
         OutParameter = stg is OutArgumentStorage,
         Type = dt.Accept(this)
     });
 }
 private Expression RewritePointer(DataType ptr, DataType dtPointee, DataType dtOrigPointee)
 {
     if (++depth > 20)
     {
         Debug.Print("*** Quitting; determine cause of recursion"); //$DEBUG
         return(expComplex);
     }
     enclosingPtr       = ptr;
     this.dtComplex     = dtPointee;
     this.dtComplexOrig = dtOrigPointee;
     return(dtComplex.Accept(this));
 }
Beispiel #10
0
        public Expression VisitArray(ArrayType array)
        {
            int i = (int)(offset / array.ElementType.Size);
            int r = (int)(offset % array.ElementType.Size);

            dt                  = array.ElementType;
            dtOriginal          = array.ElementType;
            complexExp.DataType = array;
            complexExp          = CreateArrayAccess(dt, array, i, indexExp, dereferenced);
            dereferenced        = true;
            offset              = r;
            return(dt.Accept(this));
        }
        public Expression VisitArray(ArrayType at)
        {
            int i = (int)(offset / at.ElementType.Size);
            int r = (int)(offset % at.ElementType.Size);

            index                    = ScaleDownIndex(index, at.ElementType.Size);
            dtComplex                = at.ElementType;
            dtComplexOrig            = at.ElementType;
            this.expComplex.DataType = at;
            expComplex               = CreateArrayAccess(at.ElementType, at, i, index);
            index                    = null; // we've consumed the index.
            offset                   = r;
            return(dtComplex.Accept(this));
        }
Beispiel #12
0
        public Expression VisitStructure(StructureType str)
        {
            StructureField field = str.Fields.LowerBound(this.offset);

            if (field == null)
            {
                throw new TypeInferenceException("Expected structure type {0} to have a field at offset {1} ({1:X}).", str.Name, offset);
            }

            dt         = field.DataType;
            dtOriginal = field.DataType;
            complexExp = CreateFieldAccess(str, field.DataType, complexExp, field.Name);
            offset    -= field.Offset;
            return(dt.Accept(this));
        }
        public Expression VisitStructure(StructureType str)
        {
            if (++depth > 20)
            {
                Debug.Print("*** recursion too deep, quitting. Determine error then remove this"); //$DEBUG
                return(expComplex);
            }
            if (enclosingPtr != null)
            {
                int strSize = str.GetInferredSize();
                if (str.Size > 0 && // We know the size of the struct, for sure.
                    (offset >= strSize && offset % strSize == 0 && index == null))
                {
                    var exp = CreateArrayAccess(str, enclosingPtr, offset / strSize, index);
                    index = null;
                    --depth;
                    return(exp);
                }
                else if (index != null && offset == 0)
                {
                    var idx = this.ScaleDownIndex(index, strSize);
                    index = null;
                    var exp = CreateArrayAccess(str, enclosingPtr, 0, idx);
                    --depth;
                    return(exp);
                }
            }
            StructureField field = str.Fields.LowerBound(this.offset);

            if (field == null)
            {
                throw new TypeInferenceException("Expected structure type {0} to have a field at offset {1} ({1:X}).", str.Name, offset);
            }

            dtComplex       = field.DataType;
            dtComplexOrig   = field.DataType.ResolveAs <DataType>();
            this.expComplex = CreateFieldAccess(str, field.DataType, expComplex, field);
            offset         -= field.Offset;
            var e = dtComplex.Accept(this);

            --depth;
            return(e);
        }
Beispiel #14
0
        public Formatter VisitFunctionType(FunctionType ft)
        {
            string?oldName = name;

            name = null;
            if (ft.ParametersValid)
            {
                ft.ReturnValue !.DataType.Accept(this);
            }
            if (mode == Mode.Writing)
            {
                writer.Write(" (");
            }
            name = oldName;
            WriteName(false);
            if (mode == Mode.Writing)
            {
                writer.Write(")(");
            }
            if (ft.ParametersValid && ft.Parameters != null && ft.Parameters.Length > 0)
            {
                name = ft.Parameters[0].Name;
                ft.Parameters[0].DataType.Accept(this);

                for (int i = 1; i < ft.Parameters.Length; ++i)
                {
                    if (mode == Mode.Writing)
                    {
                        writer.Write(", ");
                    }
                    name = ft.Parameters[i].Name;
                    ft.Parameters[i].DataType.Accept(this);
                }
                name = oldName;
            }

            if (mode == Mode.Writing)
            {
                writer.Write(")");
            }
            return(writer);
        }
Beispiel #15
0
        public void WriteGlobalVariable(Address address, DataType dataType, string name)
        {
            this.globals = new StructureType();
            this.queue   = new Queue <StructureField>(globals.Fields);
            var oneLineDeclaration = IsOneLineDeclaration(dataType);

            try
            {
                tw.WriteDeclaration(dataType, name);
                if (program.SegmentMap.IsValidAddress(address))
                {
                    formatter.Write(" = ");
                    if (!oneLineDeclaration && showAddressInComment)
                    {
                        formatter.Write("// {0}", address);
                    }
                    this.rdr = program.CreateImageReader(program.Architecture, address);
                    dataType.Accept(this);
                }
            }
            catch (Exception ex)
            {
                var dc = services.RequireService <DecompilerEventListener>();
                dc.Error(
                    dc.CreateAddressNavigator(program, address),
                    ex,
                    "Failed to write global variable {0}.",
                    name);
                formatter.Terminate(";");
                return;
            }
            if (oneLineDeclaration && showAddressInComment)
            {
                formatter.Write("; // {0}", address);
                formatter.Terminate();
            }
            else
            {
                formatter.Terminate(";");
            }
        }
Beispiel #16
0
        public Expression VisitUnion(UnionType ut)
        {
            UnionAlternative alt = ut.FindAlternative(dtOriginal);

            if (alt == null)
            {
                throw new TypeInferenceException("Unable to find {0} in {1} (offset {2}).", dtOriginal, ut, offset);
            }

            dt         = alt.DataType;
            dtOriginal = alt.DataType;
            if (ut.PreferredType != null)
            {
                complexExp = new Cast(ut.PreferredType, complexExp);
            }
            else
            {
                complexExp = new FieldAccess(alt.DataType, complexExp, alt.Name);
            }
            return(dt.Accept(this));
        }
        public Expression VisitUnion(UnionType ut)
        {
            UnionAlternative alt = ut.FindAlternative(dtComplexOrig);

            if (alt == null)
            {
                Debug.Print("Unable to find {0} in {1} (offset {2}).", dtComplexOrig, ut, offset);          //$diagnostic service
                return(expComplex);
            }

            dtComplex     = alt.DataType;
            dtComplexOrig = alt.DataType;
            if (ut.PreferredType != null)
            {
                expComplex = new Cast(ut.PreferredType, expComplex);
            }
            else
            {
                expComplex = CreateFieldAccess(ut, alt.DataType, expComplex, alt);
            }
            return(dtComplex.Accept(this));
        }
Beispiel #18
0
 public override Key Parse(DataType item) => new Key.BulkString(
     item.Accept(BulkStringExpectation.Singleton)
     );
Beispiel #19
0
 public override void Process()
 {
     dt.Accept(this);
 }
Beispiel #20
0
        public Expression BuildComplex()
        {
            var exp = dt.Accept(this);

            return(exp);
        }
Beispiel #21
0
        public static bool IsInCycle(TypeStore store, DataType dtCandidate)
        {
            var finder = new TypeStoreCycleFinder(store, dtCandidate);

            return(dtCandidate.Accept(finder));
        }
 /// <summary>
 /// Resolves the specified type into its type reference.
 /// </summary>
 /// <param name="dataType">The data type.</param>
 /// <returns>CodeTypeReference that should be used in code to refer to the type.</returns>
 public CodeTypeReference Resolve(DataType dataType)
 {
     return(dataType.Accept(this));
 }
Beispiel #23
0
 public Expression VisitEquivalenceClass(EquivalenceClass eq)
 {
     dt         = eq.DataType;
     dtOriginal = eq.DataType;
     return(dt.Accept(this));
 }
Beispiel #24
0
        // Mutators /////////////////////////////////////////////////////////////////

        /// <summary>
        /// This method is called when the user has created a global item.
        /// </summary>
        /// <param name="address"></param>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public ImageMapItem AddUserGlobalItem(Address address, DataType dataType)
        {
            //$TODO: if user enters a segmented address, we need to 
            // place the item in the respective globals struct.
            var size = GetDataSize(address, dataType);
            var item = new ImageMapItem
            {
                Address = address,
                Size = size,
                DataType = dataType,
            };
            if (size != 0)
                this.ImageMap.AddItemWithSize(address, item);
            else
                this.ImageMap.AddItem(address, item);

            this.User.Globals.Add(address, new Serialization.GlobalDataItem_v2
            {
                Address = address.ToString(),
                DataType = dataType.Accept(new Serialization.DataTypeSerializer()),
            });
            return item;
        }
Beispiel #25
0
 private void WriteEntry(TypeVariable tv, DataType dt, Formatter writer)
 {
     writer.Write("{0}: ", tv);
     if (dt != null)
     {
         dt.Accept(new TypeGraphWriter(writer));
         WriteExpressionOf(tv, writer);
     }
     writer.WriteLine();
 }
Beispiel #26
0
 /// <summary>
 /// Converts data type from Taupo term into Edm term
 /// </summary>
 /// <param name="taupoDataType">The DataType (Taupo term)</param>
 /// <returns>The TypeReference (Edm term)</returns>
 public IEdmTypeReference ConvertToEdmTypeReference(DataType taupoDataType)
 {
     return(taupoDataType.Accept(this));
 }
Beispiel #27
0
        // Mutators /////////////////////////////////////////////////////////////////
        /// <summary>
        /// This method is called when the user has created a global item.
        /// </summary>
        /// <param name="address"></param>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public ImageMapItem AddUserGlobalItem(Address address, DataType dataType)
        {
            var size = GetDataSize(address, dataType);
            var item = new ImageMapItem
            {
                Address = address,
                Size = size,
                DataType = dataType,
            };
            if (size != 0)
                this.ImageMap.AddItemWithSize(address, item);
            else
                this.ImageMap.AddItem(address, item);

            this.UserGlobalData.Add(address, new Serialization.GlobalDataItem_v2
            {
                Address = address.ToString(),
                DataType = dataType.Accept(new  Serialization.DataTypeSerializer()),
            });
            return item;
        }
Beispiel #28
0
 /// <summary>
 /// Gets the short qualified Edm name of a data type
 /// </summary>
 /// <param name="dataType">The data type</param>
 /// <returns>The short qualified edm name</returns>
 public string GetEdmShortQualifiedName(DataType dataType)
 {
     return(dataType.Accept(this));
 }
Beispiel #29
0
		public DataType Replace(DataType dt)
		{
			return dt != null 
				? dt.Accept(this)
				: null;
		}
Beispiel #30
0
 public void Write(DataType dt, string name)
 {
     this.name = name;
     dt.Accept(this);
 }
Beispiel #31
0
 public DataType Replace(DataType dt)
 {
     return(dt != null
                         ? dt.Accept(this)
                         : null);
 }
Beispiel #32
0
        private Expression RewritePointer(DataType dtPtr, DataType dtPointee, DataType dtPointeeOriginal)
        {
            if (seenPtr)
            {
                return(complexExp);
            }

            seenPtr = true;
            Expression result;

            if (dtPointee is PrimitiveType || dtPointee is Pointer || dtPointee is MemberPointer ||
                dtPointee is CodeType ||
                comp.Compare(dtPtr, dtResult) == 0)
            {
                if (dtPointee.Size == 0)
                {
                    Debug.Print("WARNING: {0} has size 0, which should be impossible", dtPointee);
                }
                if (offset == 0 || dtPointee is ArrayType || dtPointee.Size > 0 && offset % dtPointee.Size == 0)
                {
                    int idx = (offset == 0 || dtPointee is ArrayType)
                        ? 0
                        : offset / dtPointee.Size;
                    if (idx == 0 && this.indexExp == null)
                    {
                        if (Dereferenced)
                        {
                            result = CreateDereference(dtPointee, complexExp);
                        }
                        else
                        {
                            result = CreateUnreferenced(dtPointee, complexExp);
                        }
                    }
                    else
                    {
                        result = CreateArrayAccess(dtPointee, dtPtr, idx, indexExp, Dereferenced);
                    }
                }
                else
                {
                    result = new PointerAddition(dtPtr, complexExp, offset);
                }
            }
            else
            {
                // Drill down.
                dtOriginal = dtPointeeOriginal;
                complexExp = CreateDereference(dtPointee, complexExp);
                bool deref = Dereferenced;                 //$REVIEW: causes problems with arrayType
                Dereferenced = true;                       //$REVUEW: causes problems with arrayType
                basePointer  = null;
                result       = dtPointee.Accept(this);
                if (!deref)
                {
                    result = new UnaryExpression(UnaryOperator.AddrOf, dtPtr, result);
                }
                Dereferenced = deref;                       //$REVIEW: causes problems with arrayType
            }
            seenPtr = false;
            return(result);
        }
 public DataType?Replace(DataType?dt)
 {
     return(dt?.Accept(this));
 }
Beispiel #34
0
 public virtual string ShortPrefix(DataType dt)
 {
     return(dt.Accept(prefixPolicy));
 }