Exemplo n.º 1
0
        public void TerConstants()
        {
            var     arch    = new FakeArchitecture();
            Program program = new Program(
                new SegmentMap(Address.Ptr32(0x10000)),
                arch,
                new DefaultPlatform(null, arch));

            SetupPreStages(program);
            Constant     r   = Constant.Real32(3.0F);
            Constant     i   = Constant.Int32(1);
            Identifier   x   = new Identifier("x", PrimitiveType.Word32, null);
            Assignment   ass = new Assignment(x, r);
            TypeVariable tvR = r.TypeVariable = program.TypeFactory.CreateTypeVariable();
            TypeVariable tvI = i.TypeVariable = program.TypeFactory.CreateTypeVariable();
            TypeVariable tvX = x.TypeVariable = program.TypeFactory.CreateTypeVariable();

            program.TypeStore.TypeVariables.AddRange(new TypeVariable[] { tvR, tvI, tvX });
            UnionType u = program.TypeFactory.CreateUnionType(null, null, new DataType[] { r.DataType, i.DataType });

            tvR.OriginalDataType = r.DataType;
            tvI.OriginalDataType = i.DataType;
            tvX.OriginalDataType = x.DataType;
            tvR.DataType         = u;
            tvI.DataType         = u;
            tvX.DataType         = u;
            ctn.RenameAllTypes(program.TypeStore);
            var         ter   = new TypedExpressionRewriter(program, null);
            Instruction instr = ter.TransformAssignment(ass);

            Assert.AreEqual("x.u0 = 3.0F", instr.ToString());
        }
Exemplo n.º 2
0
        protected override void RunTest(Program program, string outputFile)
        {
            var eventListener = new FakeDecompilerEventListener();

            using (FileUnitTester fut = new FileUnitTester(outputFile))
            {
                fut.TextWriter.WriteLine("// Before ///////");
                DumpProgram(program, fut.TextWriter);

                SetupPreStages(program);
                aen.Transform(program);
                eqb.Build(program);
                var coll = new TypeCollector(program.TypeFactory, program.TypeStore, program, eventListener);
                coll.CollectTypes();
                program.TypeStore.BuildEquivalenceClassDataTypes(program.TypeFactory);
                tvr.ReplaceTypeVariables();
                trans.Transform();
                ctn.RenameAllTypes(program.TypeStore);
                ter = new TypedExpressionRewriter(program, eventListener);
                try
                {
                    ter.RewriteProgram(program);
                }
                catch (Exception ex)
                {
                    fut.TextWriter.WriteLine("** Exception **");
                    fut.TextWriter.WriteLine(ex);
                }
                finally
                {
                    fut.TextWriter.WriteLine("// After ///////");
                    DumpProgAndStore(program, fut);
                }
            }
        }
Exemplo n.º 3
0
        public void TerComplex()
        {
            Program program = new Program();

            program.SegmentMap   = new SegmentMap(Address.Ptr32(0x0010000));
            program.Architecture = new FakeArchitecture();
            program.Platform     = new DefaultPlatform(null, program.Architecture);
            SetupPreStages(program);
            Identifier id  = new Identifier("v0", PrimitiveType.Word32, null);
            Expression cmp = MemLoad(id, 4, PrimitiveType.Word32);

            program.Globals.Accept(eqb);
            cmp.Accept(aen);
            cmp.Accept(eqb);
            coll = new TraitCollector(program.TypeFactory, program.TypeStore, dtb, program);
            cmp.Accept(coll);
            dtb.BuildEquivalenceClassDataTypes();

            tvr.ReplaceTypeVariables();
            trans.Transform();
            ctn.RenameAllTypes(program.TypeStore);

            ter = new TypedExpressionRewriter(program, null);
            cmp = cmp.Accept(ter);
            Assert.AreEqual("v0->dw0004", cmp.ToString());
        }
Exemplo n.º 4
0
        public void Tmer_PointerToSingleItem()
        {
            var ptr = new Identifier("ptr", PrimitiveType.Word32, null);

            CreateTv(ptr, new Pointer(point, 4), new Pointer(point, 4));
            var        tmer   = new TypedExpressionRewriter(program, null);
            var        access = CreateTv(m.LoadDw(m.IAdd(ptr, 0)));
            Expression e      = access.Accept(tmer);

            Assert.AreEqual("ptr->dw0000", e.ToString());
        }
Exemplo n.º 5
0
        protected void RunStringTest(Program program, string expectedOutput)
        {
            var sw = new StringWriter();

            sw.WriteLine("// Before ///////");
            DumpProgram(program, sw);

            var eventListener = new FakeDecompilerEventListener();

            SetupPreStages(program);
            aen.Transform(program);
            eqb.Build(program);
            var coll = new TypeCollector(program.TypeFactory, program.TypeStore, program, eventListener);

            coll.CollectTypes();
            program.TypeStore.Dump();

            program.TypeStore.BuildEquivalenceClassDataTypes(program.TypeFactory);
            program.TypeStore.Dump();
            tvr.ReplaceTypeVariables();
            trans.Transform();
            ctn.RenameAllTypes(program.TypeStore);

            var ter = new TypedExpressionRewriter(program, eventListener);

            try
            {
                ter.RewriteProgram(program);
            }
            catch (Exception ex)
            {
                sw.WriteLine("** Exception **");
                sw.WriteLine(ex);
                throw;
            }
            finally
            {
                sw.WriteLine("// After ///////");
                DumpProgram(program, sw);
            }
            var sActual = sw.ToString();

            if (expectedOutput != sActual)
            {
                Console.WriteLine(sActual);
                Assert.AreEqual(expectedOutput, sActual);
            }
        }
Exemplo n.º 6
0
        public void Tmer_PointerToSecondItemOfPoint()
        {
            Identifier ptr = new Identifier("ptr", PrimitiveType.Word32, null);

            store.EnsureExpressionTypeVariable(factory, ptr);
            EquivalenceClass eqPtr = new EquivalenceClass(ptr.TypeVariable);

            eqPtr.DataType = point;
            ptr.TypeVariable.OriginalDataType = new Pointer(point, 4);
            ptr.TypeVariable.DataType         = new Pointer(eqPtr, 4);

            var        c    = CreateTv(Constant.Word32(4));
            var        bin  = CreateTv(new BinaryExpression(BinaryOperator.IAdd, PrimitiveType.Word32, ptr, c));
            var        mem  = CreateTv(new MemoryAccess(bin, PrimitiveType.Word32));
            var        tmer = new TypedExpressionRewriter(program, null);
            Expression e    = mem.Accept(tmer);

            Assert.AreEqual("ptr->dw0004", e.ToString());
        }
        public void Tmer_PointerToSingleItem()
        {
            var ptr = new Identifier("ptr", PrimitiveType.Word32, null);
            var tv  = store.EnsureExpressionTypeVariable(factory, ptr);

            tv.OriginalDataType = new Pointer(point, 4);
            var eq = new EquivalenceClass(tv);

            eq.DataType = point;
            tv.DataType = new Pointer(eq, 4);

            TypedExpressionRewriter tmer = new TypedExpressionRewriter(program);
            var          access          = Wrap(new MemoryAccess(ptr, PrimitiveType.Word32));
            TypeVariable tvAccess        = access.TypeVariable;

            tvAccess.DataType = PrimitiveType.Word32;
            Expression e = access.Accept(tmer);

            Assert.AreEqual("ptr->dw0000", e.ToString());
        }