public void Setup()
		{
            var image = new LoadedImage(Address.Ptr32(0x00100000), new byte[1024]);
            var arch = new FakeArchitecture();
            var program = new Program
            {
                Image = image,
                Architecture = arch,
                ImageMap = image.CreateImageMap(),
                Platform = new DefaultPlatform(null, arch),
            };
            store = program.TypeStore;
            factory = program.TypeFactory;
            globals = program.Globals;
			store.EnsureExpressionTypeVariable(factory, globals);

			StructureType s = new StructureType(null, 0);
			s.Fields.Add(0x00100000, PrimitiveType.Word32, null);

			TypeVariable tvGlobals = store.EnsureExpressionTypeVariable(factory, globals);
			EquivalenceClass eqGlobals = new EquivalenceClass(tvGlobals);
			eqGlobals.DataType = s;
			globals.TypeVariable.DataType = new Pointer(eqGlobals, 4);
			globals.DataType = globals.TypeVariable.DataType;

            tcr = new TypedConstantRewriter(program);
		}
Пример #2
0
		public EquivalenceClassBuilder(TypeFactory factory, TypeStore store)
		{
			this.factory = factory;
			this.store = store;
			this.signature = null;
            this.segTypevars = new Dictionary<ushort, TypeVariable>();
		}
        public void Setup()
        {
            store = new TypeStore();
            factory = new TypeFactory();
            nct = new NestedComplexTypeExtractor(factory, store);

        }
Пример #4
0
		public PtrPrimitiveReplacer(TypeFactory factory, TypeStore store, Program program)
		{
			this.factory = factory;
			this.store = store;
            this.program = program;
            this.visitedTypes = new HashSet<DataType>();
		}
Пример #5
0
		public DataTypeBuilder(TypeFactory factory, ITypeStore store, Platform platform)
		{
			this.store = store;
			this.factory = factory;
			this.unifier = new DataTypeBuilderUnifier(factory, store);
            this.platform = platform;
		}
Пример #6
0
		public void PprReplaceInts()
		{
            var arch = new FakeArchitecture(); 
            var program = new Program { Architecture = arch, Platform = new DefaultPlatform(null, arch) };

			TypeFactory factory = new TypeFactory();
			store = new TypeStore();
			TypeVariable tv1 = store.CreateTypeVariable(factory);
            TypeVariable tv2 = store.CreateTypeVariable(factory);
			Assert.IsNotNull(tv1.Class, "Expected store.EnsureTypeVariable to create equivalence class");
			Assert.IsNotNull(tv2.Class, "Expected store.EnsureTypeVariable to create equivalence class");
			tv1.Class.DataType = PrimitiveType.Word32;
			tv2.Class.DataType = PrimitiveType.Word16;
            program.Globals.TypeVariable = store.CreateTypeVariable(factory);
            program.Globals.DataType = factory.CreateStructureType();

            TypeVariable tv3 = store.CreateTypeVariable(factory);
			Assert.IsNotNull(tv3.Class, "Expected store.EnsureTypeVariable to create equivalence class");

			StructureType mem = factory.CreateStructureType(null, 0);
			mem.Fields.Add(0, tv1);
			mem.Fields.Add(4, tv2);
			tv3.Class.DataType = factory.CreatePointer(mem, 4);

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

            var ppr = new PtrPrimitiveReplacer(factory, store, program);

			ppr.ReplaceAll();

			Verify(null, "Typing/PprReplaceInts.txt");
		}
Пример #7
0
		public AddressTraitCollector(TypeFactory factory, ITypeStore store, ITraitHandler handler, Program prog)
		{
			this.factory = factory;
			this.store = store;
			this.handler = handler;
			this.prog = prog;
			this.arrayContext = false;
		}
Пример #8
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);
		}
Пример #9
0
 public TypeVariable CreateTypeVariable(TypeFactory factory)
 {
     TypeVariable tv = factory.CreateTypeVariable();
     tv.Class = new EquivalenceClass(tv);
     this.TypeVariables.Add(tv);
     this.usedClasses.Add(tv.Class.Number, tv.Class);
     return tv;
 }
Пример #10
0
		public void CastCreate()
		{
			TypeFactory typef = new TypeFactory();
			
			var cast = new Cast(PrimitiveType.Word32, Constant.Real32(3.0F));
			var p = (PrimitiveType) cast.DataType;
			Assert.AreEqual(PrimitiveType.Word32, p);
			Assert.AreEqual(PrimitiveType.Real32, cast.Expression.DataType);
		}
 public void Setup()
 {
     this.m = new ExpressionEmitter();
     this.store = new TypeStore();
     this.factory = new TypeFactory();
     var arch = new FakeArchitecture();
     var platform = new DefaultPlatform(null, arch);
     this.exa = new ExpressionTypeAscender(platform, store, factory);
 }
Пример #12
0
		public void TvrReplaceInStruct()
		{
			TypeFactory factory = new TypeFactory();
			TypeStore store = new TypeStore();
			EquivalenceClassBuilder eqb = new EquivalenceClassBuilder(factory, store);

			Identifier pptr = new Identifier("pptr", PrimitiveType.Word32, null);
			Identifier ptr = new Identifier("ptr", PrimitiveType.Word32, null);
		}
 public void Setup()
 {
     this.m = new ExpressionEmitter();
     this.store = new TypeStore();
     this.factory = new TypeFactory();
     this.arch = new FakeArchitecture();
     var prog = new Program { Architecture = arch , Platform = new DefaultPlatform(null,arch)};
     this.exa = new ExpressionTypeAscender(prog.Platform, store, factory);
     this.exd = new ExpressionTypeDescender(prog, store, factory);
     store.EnsureExpressionTypeVariable(factory, prog.Globals, "globals_t");
 }
Пример #14
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);
 }
Пример #15
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);
		}
Пример #16
0
        public TypeVariable EnsureExpressionTypeVariable(TypeFactory factory, Expression e, string name)
        {
            if (e != null && e.TypeVariable != null)
                return e.TypeVariable;

            TypeVariable tv = name != null ? factory.CreateTypeVariable(name) : factory.CreateTypeVariable();
            AddDebugSource(tv, e);
            tv.Class = new EquivalenceClass(tv);
            if (e != null)
                e.TypeVariable = tv;
            this.TypeVariables.Add(tv);
            this.usedClasses.Add(tv.Class.Number, tv.Class);
            return tv;
        }
		public void SimpleEquivalence()
		{
			TypeFactory factory = new TypeFactory();
			TypeStore store = new TypeStore();
			EquivalenceClassBuilder eqb = new EquivalenceClassBuilder(factory, store);
			Identifier id1 = new Identifier("id2", PrimitiveType.Word32, null);
			Identifier id2 = new Identifier("id2", PrimitiveType.Word32, null);
			Assignment ass = new Assignment(id1, id2);
			ass.Accept(eqb);

			Assert.IsNotNull(id1);
			Assert.IsNotNull(id2);
			Assert.AreEqual(2, id1.TypeVariable.Number, "id1 type number");
			Assert.AreEqual(2, id1.TypeVariable.Number, "id2 type number");
			Assert.AreEqual(id1.TypeVariable.Class, id2.TypeVariable.Class);
		}
Пример #18
0
		public static bool ReplaceAll(TypeFactory factory, TypeStore store)
		{
			EquivalenceClass [] eqs = new EquivalenceClass[store.UsedEquivalenceClasses.Count];
			store.UsedEquivalenceClasses.CopyTo(eqs, 0);
			bool changed = false;
			for (int i = 0; i < eqs.Length; ++i)
			{
				if (eqs[i].DataType != null)
				{
					NestedComplexTypeExtractor nctr = new NestedComplexTypeExtractor(factory, store);
					eqs[i].DataType = eqs[i].DataType.Accept(nctr);
					changed |= nctr.Changed;
				}
			}
			return changed;
		}
		public void Setup()
		{
            var image = new LoadedImage(Address.Ptr32(0x00400000), new byte[1024]);
            var arch = new FakeArchitecture();
            program = new Program
            {
                Architecture = arch,
                Image = image,
                ImageMap = image.CreateImageMap(),
                Platform = new DefaultPlatform(null, arch)
            };
            store = program.TypeStore;
            factory = program.TypeFactory;
			point = new StructureType(null, 0);
			point.Fields.Add(0, PrimitiveType.Word32, null);
			point.Fields.Add(4, PrimitiveType.Word32, null);
		}
		public void Setup()
		{
			store = new TypeStore();
			factory = new TypeFactory();
            globals = new Identifier("globals", PrimitiveType.Word32, null);
            StructureType point = new StructureType("Point", 0)
            {
                Fields = {
                    { 0, PrimitiveType.Word32, null },
			        { 4, PrimitiveType.Word32, null }
                }
            };
			TypeVariable tvPoint = store.CreateTypeVariable(factory);
            EquivalenceClass eq = new EquivalenceClass(tvPoint)
            {
                DataType = point
            };
			tvPoint.DataType = eq;
			ptrPoint = new Pointer(eq, 4);

            UnionType u = new UnionType("RealInt", null)
            {
                Alternatives = {
                    new UnionAlternative("w", PrimitiveType.Word32),
			        new UnionAlternative("r", PrimitiveType.Real32),
                }
            };
			TypeVariable tvUnion = store.CreateTypeVariable(factory);
            eq = new EquivalenceClass(tvUnion)
            {
                DataType = u
            };
			tvUnion.DataType = eq;
			ptrUnion = new Pointer(eq, 4);

            ptrInt = new Pointer(PrimitiveType.Int32, 4);
            ptrWord = new Pointer(PrimitiveType.Word32, 4);
		}
Пример #21
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);
		}
Пример #22
0
		public void Setup()
		{
			factory = new TypeFactory();
			store = new TypeStore();
			trans = new TypeTransformer(factory, store, null);
		}
Пример #23
0
        private int nestedCalls;        //$DEBUG

        public DataTypeBuilderUnifier(TypeFactory factory, ITypeStore store)
            : base(factory)
        {
            this.store = store;
        }
 public void Setup()
 {
     store = new TypeStore();
     factory = new TypeFactory();
 }
Пример #25
0
		public void Setup()
		{
			factory = new TypeFactory();
		}
Пример #26
0
 public void BuildEquivalenceClassDataTypes(TypeFactory factory)
 {
     var utv = new UnionTypeVarsReplacer(this);
     foreach (TypeVariable tv in TypeVariables)
     {
         if (tv.OriginalDataType != null)
             tv.OriginalDataType.Accept(utv);
     }
     Unifier u = new DataTypeBuilderUnifier(factory, this);
     foreach (TypeVariable tv in TypeVariables)
     {
         DataType dt = tv.OriginalDataType;
         EquivalenceClass c = tv.Class;
         DataType dtOld = c.DataType;
         if (dtOld != null)
             dt = u.Unify(dt, dtOld);
         //else if (dt != null)
         //    dt = dt.Clone();        // why clone???
         c.DataType = dt;
     }
 }
Пример #27
0
 public FramePointerFragment(TypeFactory factory)
 {
     this.factory = factory;
 }
		public void Setup()
		{
			factory = new TypeFactory();
			store = new TypeStore();
			eqb = new EquivalenceClassBuilder(factory, store);
		}
Пример #29
0
 public TypeVariable EnsureExpressionTypeVariable(TypeFactory factory, Expression e)
 {
     return EnsureExpressionTypeVariable(factory, e, null);
 }
Пример #30
0
 public TypeVariable EnsureFieldTypeVariable(TypeFactory factory, StructureField field)
 {
     throw new NotImplementedException();
 }