protected override void RunTest(Program program, string outputFileName)
        {
            ExpressionNormalizer aen = new ExpressionNormalizer(program.Architecture.PointerType);
            aen.Transform(program);
            EquivalenceClassBuilder eq = new EquivalenceClassBuilder(factory, store);
            eq.Build(program);
#if OLD
            			DataTypeBuilder dtb = new DataTypeBuilder(factory, store, program.Architecture);
			TraitCollector coll = new TraitCollector(factory, store, dtb, program);
			coll.CollectProgramTraits(program);
			dtb.BuildEquivalenceClassDataTypes();
#else
            TypeCollector coll = new TypeCollector(factory, store, program);
            coll.CollectTypes();
            store.BuildEquivalenceClassDataTypes(factory);
#endif

            TypeVariableReplacer tvr = new TypeVariableReplacer(store);
            tvr.ReplaceTypeVariables();

            TypeTransformer trans = new TypeTransformer(factory, store, program);
            trans.Transform();
            using (FileUnitTester fut = new FileUnitTester(outputFileName))
            {
                foreach (Procedure proc in program.Procedures.Values)
                {
                    proc.Write(false, fut.TextWriter);
                    fut.TextWriter.WriteLine();
                }
                store.Write(fut.TextWriter);
                fut.AssertFilesEqual();
            }
        }
Exemple #2
0
 public void Setup()
 {
     factory = new TypeFactory();
     store = new TypeStore();
     eqb = new EquivalenceClassBuilder(factory, store);
     var platform = new DefaultPlatform(null, new FakeArchitecture());
     dtb = new DataTypeBuilder(factory, store, platform);
 }
Exemple #3
0
 public void SetUp()
 {
     store = new TypeStore();
     factory = new TypeFactory();
     aen = new ExpressionNormalizer(PrimitiveType.Pointer32);
     eqb = new EquivalenceClassBuilder(factory, store);
     arch = new FakeArchitecture();
     prog = new Program();
     prog.Architecture = arch;
     prog.Platform = new DefaultPlatform(null, arch);
     dtb = new DataTypeBuilder(factory, store, prog.Platform);
 }
Exemple #4
0
		/// <summary>
		/// Performs type analysis and rewrites program based on the inferred information.
		/// </summary>
		/// <remarks>
		/// For instance, all MemoryAccesses will be converted to structure field
		/// accesses or array accesses as appropriate.
		/// </remarks>
		/// <param name="program"></param>
		public void RewriteProgram(Program program)
		{
            factory = program.TypeFactory;
            store = program.TypeStore;

            aen = new ExpressionNormalizer(program.Platform.PointerType);
            eqb = new EquivalenceClassBuilder(factory, store);
#if OLD
            dtb = new DataTypeBuilder(factory, store, program.Platform);
            trco = new TraitCollector(factory, store, dtb, program);
#else
            tyco = new TypeCollector(program.TypeFactory, program.TypeStore, program);
#endif
            //dpa = new DerivedPointerAnalysis(factory, store, program.Architecture);
            tvr = new TypeVariableReplacer(store);
            trans = new TypeTransformer(factory, store,program, eventListener);
            ctn = new ComplexTypeNamer();
            ter = new TypedExpressionRewriter(program);

            // RestrictProcedures(program, 0, 1, true); // Re-enable this for debugging
            eventListener.ShowStatus("Gathering primitive datatypes from instructions.");
			aen.Transform(program);
			eqb.Build(program);
#if OLD
            eventListener.ShowStatus("Collecting datatype usage traits.");
			trco.CollectProgramTraits(program);
            eventListener.ShowStatus("Building equivalence classes.");
			dtb.BuildEquivalenceClassDataTypes();
#else
            eventListener.ShowStatus("Collecting data types");
            tyco.CollectTypes();
            store.BuildEquivalenceClassDataTypes(factory);
#endif
            //dpa.FollowConstantPointers(prog);
            tvr.ReplaceTypeVariables();

            eventListener.ShowStatus("Transforming datatypes.");
			var ppr = new PtrPrimitiveReplacer(factory, store, program);
			ppr.ReplaceAll();

			trans.Transform();
			ctn.RenameAllTypes(store);
			store.Dump();
            eventListener.ShowStatus("Rewriting expressions.");
			ter.RewriteProgram(program);
		}
Exemple #5
0
        /// <summary>
        /// Performs type analysis and rewrites program based on the inferred information.
        /// </summary>
        /// <remarks>
        /// For instance, all MemoryAccesses will be converted to structure field
        /// accesses or array accesses as appropriate.
        /// </remarks>
        /// <param name="program"></param>
        public void RewriteProgram(Program program)
        {
            factory = program.TypeFactory;
            store   = program.TypeStore;

            aen = new ExpressionNormalizer(program.Platform.PointerType);
            eqb = new EquivalenceClassBuilder(factory, store);
#if OLD
            dtb  = new DataTypeBuilder(factory, store, program.Platform);
            trco = new TraitCollector(factory, store, dtb, program);
#else
            tyco = new TypeCollector(program.TypeFactory, program.TypeStore, program);
#endif
            //dpa = new DerivedPointerAnalysis(factory, store, program.Architecture);
            tvr   = new TypeVariableReplacer(store);
            trans = new TypeTransformer(factory, store, program, eventListener);
            ctn   = new ComplexTypeNamer();
            ter   = new TypedExpressionRewriter(program);

            // RestrictProcedures(program, 0, 1, true); // Re-enable this for debugging
            eventListener.ShowStatus("Gathering primitive datatypes from instructions.");
            aen.Transform(program);
            eqb.Build(program);
#if OLD
            eventListener.ShowStatus("Collecting datatype usage traits.");
            trco.CollectProgramTraits(program);
            eventListener.ShowStatus("Building equivalence classes.");
            dtb.BuildEquivalenceClassDataTypes();
#else
            eventListener.ShowStatus("Collecting data types");
            tyco.CollectTypes();
            store.BuildEquivalenceClassDataTypes(factory);
#endif
            //dpa.FollowConstantPointers(prog);
            tvr.ReplaceTypeVariables();

            eventListener.ShowStatus("Transforming datatypes.");
            var ppr = new PtrPrimitiveReplacer(factory, store, program);
            ppr.ReplaceAll();

            trans.Transform();
            ctn.RenameAllTypes(store);
            store.Dump();
            eventListener.ShowStatus("Rewriting expressions.");
            ter.RewriteProgram(program);
        }
Exemple #6
0
        protected override void RunTest(Program program, string outputFileName)
        {
            ExpressionNormalizer aen = new ExpressionNormalizer(program.Architecture.PointerType);
            aen.Transform(program);
            EquivalenceClassBuilder eq = new EquivalenceClassBuilder(factory, store);
            eq.Build(program);
#if OLD
			DataTypeBuilder dtb = new DataTypeBuilder(factory, store, program.Architecture);
			TraitCollector coll = new TraitCollector(factory, store, dtb, program);
			coll.CollectProgramTraits(program);
			sktore.BuildEquivalenceClassDataTypes(factory);
#else
            TypeCollector coll = new TypeCollector(factory, store, program, new FakeDecompilerEventListener());
            coll.CollectTypes();

            store.BuildEquivalenceClassDataTypes(factory);
#endif

            TypeVariableReplacer tvr = new TypeVariableReplacer(store);
            tvr.ReplaceTypeVariables();

            Exception theEx = null;
            try
            {
                TypeTransformer trans = new TypeTransformer(factory, store, program);
                trans.Transform();
            } catch (Exception ex)
            {
                theEx = ex;
            }
            using (FileUnitTester fut = new FileUnitTester(outputFileName))
            {
                if (theEx != null)
                {
                    fut.TextWriter.WriteLine(theEx.Message);
                    fut.TextWriter.WriteLine(theEx.StackTrace);
                }
                foreach (Procedure proc in program.Procedures.Values)
                {
                    proc.Write(false, fut.TextWriter);
                    fut.TextWriter.WriteLine();
                }
                store.Write(fut.TextWriter);
                fut.AssertFilesEqual();
            }
        }
        private void RunTest(Program program, string outputFile)
        {
            EquivalenceClassBuilder eqb = new EquivalenceClassBuilder(factory, store);
            DataTypeBuilder dtb = new DataTypeBuilder(factory, store, program.Platform);
            eqb.Build(program);
            TraitCollector trco = new TraitCollector(factory, store, dtb, program);
            trco.CollectProgramTraits(program);
            dtb.BuildEquivalenceClassDataTypes();
            var tv = new TypeVariableReplacer(store);
            tv.ReplaceTypeVariables();
            store.CopyClassDataTypesToTypeVariables();
            var ppr = new PtrPrimitiveReplacer(factory, store, program);
            ppr.ReplaceAll(new FakeDecompilerEventListener());

            var cpa = new ConstantPointerAnalysis(factory, store, program);
            cpa.FollowConstantPointers();

            Verify(null, outputFile);
        }
        protected override void RunTest(Program prog, string outputFilename)
		{
			TypeFactory factory = new TypeFactory();
			store = new TypeStore();
			EquivalenceClassBuilder eqb = new EquivalenceClassBuilder(factory, store);
			eqb.Build(prog);
			DataTypeBuilder dtb = new DataTypeBuilder(factory, store, prog.Platform);
			TraitCollector trco = new TraitCollector(factory, store, dtb, prog);
			trco.CollectProgramTraits(prog);
			dtb.BuildEquivalenceClassDataTypes();

			store.CopyClassDataTypesToTypeVariables();
			TypeVariableReplacer tvr = new TypeVariableReplacer(store);
			tvr.ReplaceTypeVariables();

			PtrPrimitiveReplacer ppr = new PtrPrimitiveReplacer(factory, store, prog);
			ppr.ReplaceAll(new FakeDecompilerEventListener());

			Verify(prog, outputFilename);
		}
 public void SetupPreStages(Program program)
 {
     foreach (var f in userDefinedGlobals)
     {
         program.GlobalFields.Fields.Add(f);
     }
     foreach (var s in imageSegments.Values)
     {
         program.SegmentMap.Segments.Add(s.Address, s);
     }
     aen = new ExpressionNormalizer(program.Platform.PointerType);
     eqb = new EquivalenceClassBuilder(program.TypeFactory, program.TypeStore);
     dtb = new DataTypeBuilder(program.TypeFactory, program.TypeStore, program.Platform);
     tvr = new TypeVariableReplacer(program.TypeStore);
     trans = new TypeTransformer(program.TypeFactory, program.TypeStore, program);
     ctn = new ComplexTypeNamer();
 }
 public void SetupPreStages(Program prog)
 {
     aen = new ExpressionNormalizer(prog.Platform.PointerType);
     eqb = new EquivalenceClassBuilder(prog.TypeFactory, prog.TypeStore);
     dtb = new DataTypeBuilder(prog.TypeFactory, prog.TypeStore, prog.Platform);
     tvr = new TypeVariableReplacer(prog.TypeStore);
     trans = new TypeTransformer(prog.TypeFactory, prog.TypeStore, prog);
     ctn = new ComplexTypeNamer();
 }