Beispiel #1
0
        public SerializedType VisitRangeType(RangeType rangeType)
        {
            var low   = rangeType.Low.Accept(ceval).ToInt64();
            var hi    = rangeType.High.Accept(ceval).ToInt64();
            var delta = hi - low + 1;

            if (delta < 0)
            {
                throw new NotImplementedException("Range overflow.");
            }
            if (delta < 256)
            {
                return(low < 0
                    ? PrimitiveType_v1.SChar8()
                    : PrimitiveType_v1.UChar8());
            }
            if (delta < 65536)
            {
                return(low <= 0
                    ? PrimitiveType_v1.Int16()
                    : PrimitiveType_v1.UInt16());
            }
            if (delta < (1L << 32))
            {
                return(low <= 0
                    ? PrimitiveType_v1.Int32()
                    : PrimitiveType_v1.UInt32());
            }
            return(PrimitiveType_v1.Int64());
        }
        public void SvArm32Ps_Load_IntArgs()
        {
            var ssig = new SerializedSignature
            {
                Arguments = new Argument_v1[] {
                    new Argument_v1
                    {
                        Name = "dc",
                        Type = PrimitiveType_v1.Int16(),
                    },
                    new Argument_v1
                    {
                        Name = "b1",
                        Type = PrimitiveType_v1.SChar8(),
                    },
                    new Argument_v1
                    {
                        Name = "w2",
                        Type = PrimitiveType_v1.Int32(),
                    },
                    new Argument_v1
                    {
                        Name = "h3",
                        Type = PrimitiveType_v1.Int16(),
                    },
                    new Argument_v1
                    {
                        Name = "b4",
                        Type = PrimitiveType_v1.UChar8(),
                    },
                    new Argument_v1
                    {
                        Name = "w5",
                        Type = PrimitiveType_v1.Int32(),
                    },
                    new Argument_v1
                    {
                        Name = "foo",
                        Type = PrimitiveType_v1.Int32()
                    }
                }
            };

            Given_ProcedureSerializer();

            mr.ReplayAll();

            var sig  = ser.Deserialize(ssig, arch.CreateFrame());
            var args = sig.Parameters;

            Assert.AreEqual("r0", args[0].Storage.ToString());
            Assert.AreEqual("r1", args[1].Storage.ToString());
            Assert.AreEqual("r2", args[2].Storage.ToString());
            Assert.AreEqual("r3", args[3].Storage.ToString());
            Assert.AreEqual("Stack +0000", args[4].Storage.ToString());
            Assert.AreEqual("Stack +0004", args[5].Storage.ToString());
            Assert.AreEqual("Stack +0008", args[6].Storage.ToString());
        }
Beispiel #3
0
        private SerializedType Type()
        {
            switch (str[i++])
            {
            case 'b': return(PrimitiveType_v1.Bool());

            case 'c': return(PrimitiveType_v1.Char8());

            case 'h': return(PrimitiveType_v1.UChar8());

            case 's': return(PrimitiveType_v1.Int16());

            case 'r': return(PrimitiveType_v1.UInt16());

            case 'i': return(PrimitiveType_v1.Int32());

            case 'j': return(PrimitiveType_v1.UInt32());

            case 'l': return(PrimitiveType_v1.Int64());

            case 'm': return(PrimitiveType_v1.UInt64());

            case 'w': return(PrimitiveType_v1.WChar16());

            case 'f': return(PrimitiveType_v1.Real32());

            case 'd': return(PrimitiveType_v1.Real64());

            case 'P': return(new PointerType_v1 {
                    DataType = Type(), PointerSize = ptrSize
                });

            case 'R': return(new ReferenceType_v1 {
                    Referent = Type(), Size = ptrSize
                });

            default:
                --i;
                if (char.IsDigit(str[i]))
                {
                    return(new TypeReference_v1
                    {
                        TypeName = SimpleName(),
                    });
                }
                throw new NotImplementedException(string.Format("Unknown GCC type code '{0}'.", str[i]));
            }
        }
Beispiel #4
0
        private SerializedType Type()
        {
            var qual = CvQualifier();

            switch (str[i++])
            {
            case 'v': return(new VoidType_v1());

            case 'b': return(Qualify(PrimitiveType_v1.Bool(), qual));

            case 'c': return(Qualify(PrimitiveType_v1.Char8(), qual));

            case 'h': return(Qualify(PrimitiveType_v1.UChar8(), qual));

            case 's': return(Qualify(PrimitiveType_v1.Int16(), qual));

            case 't': return(Qualify(PrimitiveType_v1.UInt16(), qual));

            case 'i': return(Qualify(PrimitiveType_v1.Int32(), qual));

            case 'j': return(Qualify(PrimitiveType_v1.UInt32(), qual));

            case 'l': return(Qualify(PrimitiveType_v1.Int64(), qual));

            case 'm': return(Qualify(PrimitiveType_v1.UInt64(), qual));

            case 'w': return(Qualify(PrimitiveType_v1.WChar16(), qual));

            case 'f': return(Qualify(PrimitiveType_v1.Real32(), qual));

            case 'd': return(Qualify(PrimitiveType_v1.Real64(), qual));

            case 'F': --i; return(FunctionType());

            case 'N': --i; return(CreateTypeReference(NestedName()));

            case 'P':
                var ptr = new PointerType_v1 {
                    DataType = Type(), PointerSize = ptrSize
                };
                AddSubstitution(ptr);
                return(Qualify(ptr, qual));

            case 'R':
                qual = CvQualifier();
                var r = new ReferenceType_v1 {
                    Referent = Type(), Size = ptrSize
                };
                return(Qualify(r, qual));

            case 'S':
                switch (str[i++])
                {
                case 't':
                    return(Qualify(new TypeReference_v1
                    {
                        Scope = new[] { "std" },
                        TypeName = Type().ToString(),
                    }, qual));

                case 's':
                    return(Qualify(new TypeReference_v1
                    {
                        Scope = new[] { "std" },
                        TypeName = "string"
                    }, qual));

                default:
                    int iStart = --i;
                    while (str[i] != '_')
                    {
                        ++i;
                    }
                    ++i;
                    var sub = str.Substring(iStart, i - iStart);
                    Debug.Print(sub);
                    return(Qualify((SerializedType)substitutions[sub], qual));
                }
                throw new NotImplementedException();

            default:
                --i;
                if (char.IsDigit(str[i]))
                {
                    var tref = new TypeReference_v1
                    {
                        TypeName = UnqualifiedName()
                    };
                    AddSubstitution(tref);
                    return(Qualify(tref, qual));
                }
                throw new NotImplementedException(string.Format("Unknown GCC type code '{0}' ({1}).", str[i], str.Substring(i)));
            }
        }
Beispiel #5
0
        private SerializedType Type()
        {
            switch (str[i++])
            {
            case 'v': return(new VoidType_v1());

            case 'b': return(PrimitiveType_v1.Bool());

            case 'c': return(PrimitiveType_v1.Char8());

            case 'h': return(PrimitiveType_v1.UChar8());

            case 's': return(PrimitiveType_v1.Int16());

            case 't': return(PrimitiveType_v1.UInt16());

            case 'i': return(PrimitiveType_v1.Int32());

            case 'j': return(PrimitiveType_v1.UInt32());

            case 'l': return(PrimitiveType_v1.Int64());

            case 'm': return(PrimitiveType_v1.UInt64());

            case 'w': return(PrimitiveType_v1.WChar16());

            case 'f': return(PrimitiveType_v1.Real32());

            case 'd': return(PrimitiveType_v1.Real64());

            case 'F': --i; return(FunctionType());

            case 'N': --i; return(CreateTypeReference(NestedName()));

            case 'P':
                var ptr = new PointerType_v1 {
                    DataType = Type(), PointerSize = ptrSize
                };
                AddSubstitution(ptr);
                return(ptr);

            case 'R':
                //$TODO: Reko doesn't have a concept of 'const' or 'volatile'.
                // Needs to be implemented for completeness, but should not affect
                // quality of decompilation.
                var qual = CvQualifier();
                return(new ReferenceType_v1 {
                    Referent = Type(), Size = ptrSize
                });

            case 'S':
                switch (str[i++])
                {
                case 't':
                    return(new TypeReference_v1
                    {
                        Scope = new[] { "std" },
                        TypeName = Type().ToString(),
                    });

                case 's':
                    return(new TypeReference_v1
                    {
                        Scope = new[] { "std" },
                        TypeName = "string"
                    });

                default:
                    int iStart = --i;
                    while (str[i] != '_')
                    {
                        ++i;
                    }
                    ++i;
                    var sub = str.Substring(iStart, i - iStart);
                    Debug.Print(sub);
                    return((SerializedType)substitutions[sub]);
                }
                throw new NotImplementedException();

            default:
                --i;
                if (char.IsDigit(str[i]))
                {
                    var tref = new TypeReference_v1
                    {
                        TypeName = UnqualifiedName()
                    };
                    AddSubstitution(tref);
                    return(tref);
                }
                throw new NotImplementedException(string.Format("Unknown GCC type code '{0}' ({1}).", str[i], str.Substring(i)));
            }
        }
Beispiel #6
0
        private SerializedType Type()
        {
            switch (str[i++])
            {
            case 'b': return(PrimitiveType_v1.Bool());

            case 'c': return(PrimitiveType_v1.Char8());

            case 'h': return(PrimitiveType_v1.UChar8());

            case 's': return(PrimitiveType_v1.Int16());

            case 'r': return(PrimitiveType_v1.UInt16());

            case 'i': return(PrimitiveType_v1.Int32());

            case 'j': return(PrimitiveType_v1.UInt32());

            case 'l': return(PrimitiveType_v1.Int64());

            case 'm': return(PrimitiveType_v1.UInt64());

            case 'w': return(PrimitiveType_v1.WChar16());

            case 'f': return(PrimitiveType_v1.Real32());

            case 'd': return(PrimitiveType_v1.Real64());

            case 'P': return(new PointerType_v1 {
                    DataType = Type(), PointerSize = ptrSize
                });

            case 'R':
                //$TODO: Reko doesn't have a concept of 'const' or 'volatile'.
                // Needs to be implemented for completeness, but should not affect
                // quality of decompilation.
                var qual = CvQualifier();
                return(new ReferenceType_v1 {
                    Referent = Type(), Size = ptrSize
                });

            case 'S':
                switch (str[i++])
                {
                case 't':
                    return(new TypeReference_v1
                    {
                        Scope = new[] { "std" },
                        TypeName = Type().ToString(),
                    });

                case 's':
                    return(new TypeReference_v1
                    {
                        Scope = new[] { "std" },
                        TypeName = "string"
                    });
                }
                throw new NotImplementedException();

            default:
                --i;
                if (char.IsDigit(str[i]))
                {
                    return(new TypeReference_v1
                    {
                        TypeName = UnqualifiedName(),
                    });
                }
                throw new NotImplementedException(string.Format("Unknown GCC type code '{0}'.", str[i]));
            }
        }