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();
 }
		public void NameStructure()
		{
			var store = new TypeStore();
			var factory = new TypeFactory();
            var tv1 = store.CreateTypeVariable(factory);
			tv1.Class.DataType = new StructureType(null, 0);
			tv1.DataType = tv1.Class.DataType;

			var ctn = new ComplexTypeNamer();
			ctn.RenameAllTypes(store);
			Assert.AreEqual("Eq_1", tv1.Class.DataType.Name);
		}
 public void SetupPreStages(Program program)
 {
     foreach (var f in userDefinedGlobals)
     {
         program.GlobalFields.Fields.Add(f);
     }
     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();
 }
Beispiel #4
0
        public void NameStructure()
        {
            var store   = new TypeStore();
            var factory = new TypeFactory();
            var tv1     = store.CreateTypeVariable(factory);

            tv1.Class.DataType = new StructureType(null, 0);
            tv1.DataType       = tv1.Class.DataType;

            var ctn = new ComplexTypeNamer();

            ctn.RenameAllTypes(store);
            Assert.AreEqual("Eq_1", tv1.Class.DataType.Name);
        }
        public void SetupPreStages(Program program)
        {
            var listener = new FakeDecompilerEventListener();

            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, listener);
            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();
        }
Beispiel #6
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="prog"></param>
		public void RewriteProgram(Program prog)
		{
            factory = prog.TypeFactory;
            store = prog.TypeStore;

            aen = new ExpressionNormalizer(prog.Platform.PointerType);
            eqb = new EquivalenceClassBuilder(factory, store);
            dtb = new DataTypeBuilder(factory, store, prog.Platform);
            trco = new TraitCollector(factory, store, dtb, prog);
            //dpa = new DerivedPointerAnalysis(factory, store, prog.Architecture);
            tvr = new TypeVariableReplacer(store);
            trans = new TypeTransformer(factory, store,prog, eventListener);
            ctn = new ComplexTypeNamer();
            ter = new TypedExpressionRewriter(prog);

            // RestrictProcedures(prog, 0, 1, true); //$DEBUG
            eventListener.ShowStatus("Gathering primitive datatypes from instructions.");
			aen.Transform(prog);
			eqb.Build(prog);
            eventListener.ShowStatus("Collecting datatype usage traits.");
			trco.CollectProgramTraits(prog);
            eventListener.ShowStatus("Building equivalence classes.");
			dtb.BuildEquivalenceClassDataTypes();
            //dpa.FollowConstantPointers(prog);
			tvr.ReplaceTypeVariables();

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

			trans.Transform();
			ctn.RenameAllTypes(store);
			store.Dump();
            eventListener.ShowStatus("Rewriting expressions.");
			ter.RewriteProgram(prog);
		}
Beispiel #7
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);
            tyco = new TypeCollector(
                program.TypeFactory, program.TypeStore, program,
                eventListener);
            //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, eventListener);

            // RestrictProcedures(program, 0, 60, true); // Re-enable this for debugging
            eventListener.ShowStatus("Gathering primitive datatypes from instructions.");
			aen.Transform(program);
            eqb.Build(program);

            eventListener.ShowStatus("Collecting data types");
            tyco.CollectTypes();
            store.BuildEquivalenceClassDataTypes(factory);
            //dpa.FollowConstantPointers(prog);
            tvr.ReplaceTypeVariables();

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

			trans.Transform();
			ctn.RenameAllTypes(store);
            eventListener.ShowStatus("Rewriting expressions.");
			ter.RewriteProgram(program);
		}
 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();
 }