Ejemplo n.º 1
0
        protected void RunTest(string sourceFile, string outputFile, Address addrBase)
        {
            Program program;
            using (var rdr = new StreamReader(FileUnitTester.MapTestPath(sourceFile)))
            {
                program = asm.Assemble(addrBase, rdr);
            }
            foreach (var item in asm.ImportReferences)
            {
                program.ImportReferences.Add(item.Key, item.Value);
            }

            using (FileUnitTester fut = new FileUnitTester(outputFile))
            {
                Dumper dumper = new Dumper(program.Architecture);
                dumper.ShowAddresses = true;
                dumper.ShowCodeBytes = true;
                dumper.DumpData(program.Image, program.Image.BaseAddress, program.Image.Length, fut.TextWriter);
                fut.TextWriter.WriteLine();
                dumper.DumpAssembler(program.Image, program.Image.BaseAddress, program.Image.BaseAddress + (uint)program.Image.Length, fut.TextWriter);
                if (program.ImportReferences.Count > 0)
                {
                    foreach (var de in program.ImportReferences.OrderBy(d => d.Key))
                    {
                        fut.TextWriter.WriteLine("{0:X8}: {1}", de.Key, de.Value);
                    }
                }
                fut.AssertFilesEqual();
            }
        }
Ejemplo n.º 2
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);
			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();
            }
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
0
		//[Test]
		public void VnSumTest()
		{
			Program prog = RewriteCodeFragment(
				@".i86
	push bp
	mov	 bp,sp
	mov	dx,3
	add dx,dx

	mov bx,3
	lea dx,[bx+3]
	mov sp,bp
	pop	bp
	ret
	");
			using (FileUnitTester fut = new FileUnitTester("Analysis/VnSumTest.txt"))
			{
				Procedure proc = prog.Procedures.Values[0];
				Aliases alias = new Aliases(proc, prog.Architecture);
				alias.Transform();
				var gr = proc.CreateBlockDominatorGraph();
                SsaTransform sst = new SsaTransform(
                    new ProgramDataFlow(), 
                    proc,
                    null,
                    gr,
                    new HashSet<RegisterStorage>());
				SsaState ssa = sst.SsaState;
				ValueNumbering vn = new ValueNumbering(ssa.Identifiers);
				DumpProc(proc, ssa, fut.TextWriter);
				vn.Write(fut.TextWriter);
				fut.AssertFilesEqual();
			}
		}
Ejemplo n.º 5
0
		private void PerformTest(FileUnitTester fut)
		{
			DataFlowAnalysis dfa = new DataFlowAnalysis(program, null, new FakeDecompilerEventListener());
			dfa.UntangleProcedures();
			foreach (Procedure proc in program.Procedures.Values)
			{
				Aliases alias = new Aliases(proc, program.Architecture);
				alias.Transform();
				SsaTransform sst = new SsaTransform(
                    dfa.ProgramDataFlow,
                    proc,
                    null,
                    proc.CreateBlockDominatorGraph(),
                    program.Platform.CreateImplicitArgumentRegisters());
				SsaState ssa = sst.SsaState;

				proc.Write(false, fut.TextWriter);
				fut.TextWriter.WriteLine();

				OutParameterTransformer opt = new OutParameterTransformer(proc, ssa.Identifiers);
				opt.Transform();

				DeadCode.Eliminate(proc, ssa);

				proc.Write(false, fut.TextWriter);
				fut.TextWriter.WriteLine("====================");
			}
		}
Ejemplo n.º 6
0
		//[Test]
		public void VnMemoryTest()
		{
			Program prog = RewriteCodeFragment(
				@".i86
	mov word ptr [bx+2],0
	mov si,[bx+4]
	mov ax,[bx+2]
	mov cx,[bx+2]
	mov dx,[bx+4]
	ret
");
			using (FileUnitTester fut = new FileUnitTester("Analysis/VnMemoryTest.txt"))
			{
				Procedure proc = prog.Procedures.Values[0];
				var gr = proc.CreateBlockDominatorGraph();
				Aliases alias = new Aliases(proc, prog.Architecture);
				alias.Transform();
				SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, gr);
				SsaState ssa = sst.SsaState;
				ValueNumbering vn = new ValueNumbering(ssa.Identifiers);
				DumpProc(proc, ssa, fut.TextWriter);
				vn.Write(fut.TextWriter);
				fut.AssertFilesEqual();
			}
		}
Ejemplo n.º 7
0
        protected override void RunTest(Program program, string outputFile)
        {
            FileUnitTester fut = null;
            try
            {
                fut = new FileUnitTester(outputFile);
                var factory = program.TypeFactory;
                var store = program.TypeStore;

                var aen = new ExpressionNormalizer(program.Platform.PointerType);
                var eqb = new EquivalenceClassBuilder(factory, store);

                var tyco = new TypeCollector(factory, store, program);

                aen.Transform(program);
                eqb.Build(program);
                tyco.CollectTypes();
            } catch(Exception ex)
            {
                fut.TextWriter.WriteLine(ex.Message);
                fut.TextWriter.WriteLine(ex.StackTrace);
                throw;
            } finally
            {
                DumpProgAndStore(program, fut);
                fut.Dispose();
            }
        }
Ejemplo n.º 8
0
        //[Test]
        public void VnLoop()
        {
            Program program = RewriteCodeFragment(@".i86
            push ax
            jmp looptest
            again:
            mov si,[0x302]
            mov ax,[si+04]
            add [si+06],ax
            looptest:
            cmp	ax,bx
            jl again

            pop ax
            ret
            ");
            using (FileUnitTester fut = new FileUnitTester("Analysis/VnLoop.txt"))
            {
                Procedure proc = program.Procedures.Values[0];
                var gr = proc.CreateBlockDominatorGraph();
                Aliases alias = new Aliases(proc, program.Architecture);
                alias.Transform();
                SsaTransform sst = new SsaTransform(new ProgramDataFlow(), proc, gr);
                SsaState ssa = sst.SsaState;
                DumpProc(proc, ssa, fut.TextWriter);
                ValueNumbering vn = new ValueNumbering(ssa.Identifiers);
                vn.Write(fut.TextWriter);

                fut.AssertFilesEqual();
            }
        }
Ejemplo n.º 9
0
		public void SltSimple()
		{
			Build(new SimpleMock().Procedure, new FakeArchitecture());

			using (FileUnitTester fut = new FileUnitTester("Analysis/SltSimple.txt"))
			{
				ssa.Write(fut.TextWriter);
				sla.Write(proc, fut.TextWriter);
				fut.TextWriter.WriteLine();
				fut.AssertFilesEqual();
			}

			Block block = proc.EntryBlock.Succ[0];
			block.Write(Console.Out);
			Assert.AreEqual("Mem3[0x10000000:word32] = a + b", block.Statements[0].Instruction.ToString());
			Assert.AreEqual("Mem4[0x10000004:word32] = a", block.Statements[1].Instruction.ToString());

			SsaIdentifier a = ssa.Identifiers.Where(s=>s.Identifier.Name=="a").Single();
            SsaIdentifier b = ssa.Identifiers.Where(s => s.Identifier.Name == "b").Single();
            SsaIdentifier c_2 = ssa.Identifiers.Where(s => s.Identifier.Name == "c_2").Single();
			Assert.IsFalse(sla.IsLiveOut(a.Identifier, block.Statements[1]), "a should be dead after its last use");
			Assert.IsTrue(sla.IsLiveOut(a.Identifier, block.Statements[0]), "a should be live after the first use");
			Assert.IsFalse(sla.IsDefinedAtStatement(c_2, block.Statements[0]));
			Assert.IsFalse(sla.IsDefinedAtStatement(b, block.Statements[0]));
		}
Ejemplo n.º 10
0
        private void RenderResult(Program prog, string outputFile)
        {
            foreach (var item in asm.ImportReferences)
            {
                prog.ImportReferences.Add(item.Key, item.Value);
            }

            using (FileUnitTester fut = new FileUnitTester(outputFile))
            {
                Dumper dumper = new Dumper(prog.Architecture);
                dumper.ShowAddresses = true;
                dumper.ShowCodeBytes = true;
                var mem = prog.SegmentMap.Segments.Values.First().MemoryArea;
                var formatter = new TextFormatter(fut.TextWriter);
                dumper.DumpData(prog.SegmentMap, mem.BaseAddress, mem.Bytes.Length, formatter);
                fut.TextWriter.WriteLine();
                dumper.DumpAssembler(prog.SegmentMap, mem.BaseAddress, mem.EndAddress, formatter);
                if (prog.ImportReferences.Count > 0)
                {
                    var list = new SortedList<Address, ImportReference>(prog.ImportReferences);
                    foreach (var de in list)
                    {
                        fut.TextWriter.WriteLine("{0}: {1}", de, de.Value);
                    }
                }
                fut.AssertFilesEqual();
            }
        }
Ejemplo n.º 11
0
		public void X86Rw_Switch()
		{
			DoRewriteFile("Fragments/switch.asm");
			using (FileUnitTester fut = new FileUnitTester("Intel/RwSwitch.txt"))
			{
				prog.Procedures.Values[0].Write(false, fut.TextWriter);
			}
		}
Ejemplo n.º 12
0
 private void Verify(string outputFileName)
 {
     using (FileUnitTester fut = new FileUnitTester(outputFileName))
     {
         store.Write(fut.TextWriter);
         fut.AssertFilesEqual();
     }
 }
Ejemplo n.º 13
0
 private void RunTest(ProcedureBuilder mock, string outputFile)
 {
     using (FileUnitTester fut = new FileUnitTester(outputFile))
     {
         mock.Procedure.Write(true, fut.TextWriter);
         fut.AssertFilesEqual();
     }
 }
Ejemplo n.º 14
0
		public void X86Rw_MemOperations()
		{
			DoRewriteFile("Fragments/memoperations.asm");
			using (FileUnitTester fut = new FileUnitTester("Intel/RwMemOperations.txt"))
			{
				prog.Procedures.Values[0].Write(false, fut.TextWriter);
				fut.AssertFilesEqual();
			}
		}
Ejemplo n.º 15
0
        private void DumpProgAndStore(Program prog, FileUnitTester fut)
        {
            foreach (Procedure proc in prog.Procedures.Values)
            {
                proc.Write(false, fut.TextWriter);
                fut.TextWriter.WriteLine();
            }

            prog.TypeStore.Write(fut.TextWriter);
            fut.AssertFilesEqual();
        }
 private void Verify(SerializedSignature ssig, string outputFilename)
 {
     using (FileUnitTester fut = new FileUnitTester(outputFilename))
     {
         XmlTextWriter x = new FilteringXmlWriter(fut.TextWriter);
         x.Formatting = Formatting.Indented;
         XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(ssig.GetType());
         ser.Serialize(x, ssig);
         fut.AssertFilesEqual();
     }
 }
Ejemplo n.º 17
0
        public void BitSetAllEnumerate()
        {
            using (FileUnitTester fut = new FileUnitTester("Core/BitSetAll.txt"))
            {
                BitSet a = new BitSet(8);
                a.SetAll(true);
                EnumerateBitsetBackwards(a, fut.TextWriter);
                fut.AssertFilesEqual();

            }
        }
Ejemplo n.º 18
0
        private void RunTest(string sourceFile, string outputFile)
        {
            DoRewriteFile(sourceFile);
            using (FileUnitTester fut = new FileUnitTester(outputFile))
            {
                foreach (Procedure proc in prog.Procedures.Values)
                    proc.Write(true, fut.TextWriter);

                fut.AssertFilesEqual();
            }
        }
Ejemplo n.º 19
0
		public void AnAliasExpanderTest()
		{
			Program prog = RewriteFile("Fragments/alias_regs.asm");
			Procedure proc = prog.Procedures.Values[0];
			Aliases alias = new Aliases(proc, prog.Architecture);
			alias.Transform();
			using (FileUnitTester fut = new FileUnitTester("Analysis/AnAliasExpanderTest.txt"))
			{
				proc.Write(true, fut.TextWriter);
				fut.AssertFilesEqual();
			}
		}
Ejemplo n.º 20
0
 public void SltManyIncrements()
 {
     Build(new ManyIncrements().Procedure, new FakeArchitecture());
     using (FileUnitTester fut = new FileUnitTester("Analysis/SltManyIncrements.txt"))
     {
         ssa.Write(fut.TextWriter);
         proc.Write(false, fut.TextWriter);
         fut.TextWriter.WriteLine("- Interference graph -------------------");
         sla2.InterferenceGraph.Write(fut.TextWriter);
         fut.AssertFilesEqual();
     }
 }
Ejemplo n.º 21
0
		public void FrGrfTest()
		{
			IntelArchitecture arch = new IntelArchitecture(ProcessorMode.Real);
			Frame f = new Frame(PrimitiveType.Word16);
			uint iSz = (uint) (FlagM.ZF|FlagM.SF);
			Identifier grfSz = f.EnsureFlagGroup(iSz, arch.GrfToString(iSz), PrimitiveType.Byte);
			using (FileUnitTester fut = new FileUnitTester("Core/FrGrfTest.txt"))
			{
				f.Write(fut.TextWriter);
				fut.AssertFilesEqual();
			}
		}
Ejemplo n.º 22
0
		private void RunTest(string sourceFile, string testFile)
		{
			using (FileUnitTester fut = new FileUnitTester(testFile))
			{
				this.RewriteProgramMsdos(sourceFile, Address.SegPtr(0xC00, 0));
				program.Procedures.Values[0].Write(false, fut.TextWriter);
                fut.TextWriter.WriteLine();
				var cfgc = new ControlFlowGraphCleaner(program.Procedures.Values[0]);
				cfgc.Transform();
				program.Procedures.Values[0].Write(false, fut.TextWriter);

				fut.AssertFilesEqual();
			}
		}
Ejemplo n.º 23
0
		public void ConNegate()
		{
			using (FileUnitTester fut = new FileUnitTester("Core/ConNegate.txt"))
			{
                Constant c1 = Constant.Real64(1.0);
				Constant c2 = Constant.Real32(-2.0F);
				Constant c3 = Constant.Word16(4);
				Constant c4 = Constant.Word32(-8);
				fut.TextWriter.WriteLine(c1);
				fut.TextWriter.WriteLine(c2);
				fut.TextWriter.WriteLine(c3);
				fut.TextWriter.WriteLine(c4);

				fut.AssertFilesEqual();
			}
		}
Ejemplo n.º 24
0
		private void Verify(Program prog, string outputFilename)
		{
			using (FileUnitTester fut = new FileUnitTester(outputFilename))
			{
				if (prog != null)
				{
					foreach (Procedure proc in prog.Procedures.Values)
					{
						proc.Write(false, fut.TextWriter);
						fut.TextWriter.WriteLine();
					}
				}
				store.Write(fut.TextWriter);
				fut.AssertFilesEqual();
			}
		}
Ejemplo n.º 25
0
		public void PsigArguments()
		{
			using (FileUnitTester fut = new FileUnitTester("Core/PsigArguments.txt"))
			{
				IntelArchitecture arch = new IntelArchitecture(ProcessorMode.Real);
				uint f = (uint)(FlagM.CF|FlagM.ZF);
				Identifier argF = new Identifier(arch.GrfToString(f), PrimitiveType.Bool, new FlagGroupStorage(f, "CZ", PrimitiveType.Byte));
				Identifier argR = new Identifier(Registers.ax.Name, Registers.ax.DataType, Registers.ax);
				
				argF.Write(true, fut.TextWriter);
				fut.TextWriter.WriteLine();
				argR.Write(true, fut.TextWriter);
				fut.TextWriter.WriteLine();

				fut.AssertFilesEqual();
			}
		}
Ejemplo n.º 26
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();
            }
        }
Ejemplo n.º 27
0
		public void SequenceTest()
		{
			IntelArchitecture arch = new IntelArchitecture(ProcessorMode.Real);
			Frame f = new Frame(PrimitiveType.Word16);
			Identifier ax = f.EnsureRegister(Registers.ax);
			Identifier dx = f.EnsureRegister(Registers.dx);
			Identifier dxax = f.EnsureSequence(dx, ax, PrimitiveType.Word32);

			using (FileUnitTester fut = new FileUnitTester("Core/SequenceTest.txt"))
			{
				f.Write(fut.TextWriter);
				fut.AssertFilesEqual();
			}

			Identifier dxax2 = f.EnsureSequence(dx,ax, PrimitiveType.Word32);
			Assert.IsTrue(dxax2 == dxax);
		}
Ejemplo n.º 28
0
        public void CreateStatements()
        {
            using (FileUnitTester fut = new FileUnitTester("Core/BlockCreateStatements.txt"))
            {
                Block bl = new Block(null, "block0");
                bl.Statements.Add(0,
                    new Assignment(
                    new Identifier("id3", PrimitiveType.Word16, null),
                    new Identifier("id4", PrimitiveType.Word16, null)));
                bl.Statements.Add(4,
                    new Assignment(
                    new Identifier("id4", PrimitiveType.Word16, null),
                    Constant.Word16(3)));

                bl.Write(fut.TextWriter);
                fut.AssertFilesEqual();
            }
        }
Ejemplo n.º 29
0
 public void DisFpuInstructions()
 {
     using (FileUnitTester fut = new FileUnitTester("Intel/DisFpuInstructions.txt"))
     {
         X86TextAssembler asm = new X86TextAssembler(new X86ArchitectureReal());
         Program lr;
         using (var rdr = new StreamReader(FileUnitTester.MapTestPath("Fragments/fpuops.asm")))
         {
             lr = asm.Assemble(Address.SegPtr(0xC32, 0), rdr);
         }
         CreateDisassembler16(lr.Image);
         foreach (X86Instruction instr in dasm)
         {
             fut.TextWriter.WriteLine("{0}", instr.ToString());
         }
         fut.AssertFilesEqual();
     }
 }
Ejemplo n.º 30
0
		public void X86RwDivideTests()
		{
			Procedure proc = DoRewrite(@".i86
	mov	ebx,32
	mov eax,100
	cdq
	idiv ebx
	mov cx,[si]
	mov ax,[si+2]
	mov dx,[si+4]
	div cx
");
			using (FileUnitTester fut = new FileUnitTester("Intel/RwDivideTests.txt"))
			{
				proc.Write(false, fut.TextWriter);
				fut.AssertFilesEqual();
			}
		}
Ejemplo n.º 31
0
        public void SudSaveProject()
        {
            Given_Architecture();
            Given_TestOS_Platform();
            Project project = new Project
            {
                Programs =
                {
                    new Program
                    {
                        Architecture         = arch,
                        Platform             = platform,
                        ImageMap             = new ImageMap(Address.SegPtr(0x1000, 0)), //, new byte[100]),
                        DisassemblyFilename  = "foo.asm",
                        IntermediateFilename = "foo.cod",
                        User = new UserData
                        {
                            Procedures =
                            {
                                {
                                    Address.SegPtr(0x1000, 0x10),
                                    new Procedure_v1
                                    {
                                        Name      = "foo",
                                        Signature = new SerializedSignature
                                        {
                                            ReturnValue = new Argument_v1{
                                                Kind = new Register_v1("eax")
                                            },
                                            Arguments = new Argument_v1[]
                                            {
                                                new Argument_v1
                                                {
                                                    Kind = new StackVariable_v1(),
                                                    Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                                },
                                                new Argument_v1
                                                {
                                                    Kind = new StackVariable_v1(),
                                                    Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                                }
                                            }
                                        }
                                    }
                                }
                            },
                            Globals =
                            {
                                {
                                    Address.SegPtr(0x2000, 0),
                                    new GlobalDataItem_v2 {
                                        Address  = Address.SegPtr(0x2000, 0).ToString(),
                                        DataType = new StringType_v2{
                                            Termination = StringType_v2.ZeroTermination,
                                            CharType    = new PrimitiveType_v1 {
                                                Domain = Domain.Character, ByteSize = 1
                                            }
                                        }
                                    }
                                }
                            },
                            Calls =
                            {
                                {
                                    Address.SegPtr(0x1000, 0x0320),
                                    new UserCallData
                                    {
                                        Address  = Address.SegPtr(0x1000, 0x0320),
                                        NoReturn = true,
                                    }
                                }
                            }
                        }
                    }
                }
            };

            mr.ReplayAll();

            using (FileUnitTester fut = new FileUnitTester("Core/SudSaveProject.txt"))
            {
                FilteringXmlWriter writer = new FilteringXmlWriter(fut.TextWriter);
                writer.Formatting = System.Xml.Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v4(typeof(Project_v4));
                Project_v4    ud  = new ProjectSaver(sc).Save("/var/foo/foo.proj", project);
                ser.Serialize(writer, ud);
                fut.AssertFilesEqual();
            }
        }
Ejemplo n.º 32
0
 public void OutpAsciiHex()
 {
     program = RewriteFile("Fragments/ascii_hex.asm");
     FileUnitTester.RunTest("Analysis/OutpAsciiHex.txt", PerformTest);
 }
Ejemplo n.º 33
0
        public void SudSaveProject()
        {
            Project project = new Project
            {
                Programs =
                {
                    new Program
                    {
                        Image = new LoadedImage(Address.SegPtr(0x1000, 0), new byte[100]),
                        DisassemblyFilename  = "foo.asm",
                        IntermediateFilename = "foo.cod",
                        UserProcedures       = new SortedList <Address, Procedure_v1>
                        {
                            {
                                Address.SegPtr(0x1000, 0x10),
                                new Procedure_v1
                                {
                                    Name      = "foo",
                                    Signature = new SerializedSignature
                                    {
                                        ReturnValue = new Argument_v1{
                                            Kind = new Register_v1("eax")
                                        },
                                        Arguments = new Argument_v1[]
                                        {
                                            new Argument_v1
                                            {
                                                Kind = new StackVariable_v1(),
                                                Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                            },
                                            new Argument_v1
                                            {
                                                Kind = new StackVariable_v1(),
                                                Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                            }
                                        }
                                    }
                                }
                            }
                        },
                        UserGlobalData =
                        {
                            {
                                Address.SegPtr(0x2000, 0),
                                new GlobalDataItem_v2 {
                                    Address  = Address.SegPtr(0x2000, 0).ToString(),
                                    DataType = new StringType_v2{
                                        Termination = StringType_v2.ZeroTermination,
                                        CharType    = new PrimitiveType_v1 {
                                            Domain = Domain.Character, ByteSize = 1
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            using (FileUnitTester fut = new FileUnitTester("Core/SudSaveProject.txt"))
            {
                FilteringXmlWriter writer = new FilteringXmlWriter(fut.TextWriter);
                writer.Formatting = System.Xml.Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v2(typeof(Project_v2));
                Project_v2    ud  = new ProjectSaver().Save(project);
                ser.Serialize(writer, ud);
                fut.AssertFilesEqual();
            }
        }
Ejemplo n.º 34
0
        public void SudWrite()
        {
            Project_v4 ud = new Project_v4
            {
                Inputs =
                {
                    new DecompilerInput_v4
                    {
                        DisassemblyFilename  = "foo.asm",
                        IntermediateFilename = "foo.cod",
                        User = new UserData_v4      {
                            Procedures =
                            {
                                new Procedure_v1
                                {
                                    Name      = "foo",
                                    Signature = new SerializedSignature
                                    {
                                        ReturnValue = new Argument_v1
                                        {
                                            Kind = new Register_v1("eax")
                                        },
                                        Arguments = new Argument_v1[]
                                        {
                                            new Argument_v1
                                            {
                                                Kind = new StackVariable_v1(),
                                                Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                            },
                                            new Argument_v1
                                            {
                                                Kind = new StackVariable_v1(),
                                                Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                            }
                                        }
                                    }
                                }
                            },
                            LoadAddress   = "1000:0000",
                            IndirectJumps =
                            {
                                new IndirectJump_v4 {
                                    InstructionAddress = "1000:0220",
                                    TableAddress       = "1000:0228"
                                },
                            },
                            JumpTables =
                            {
                                new JumpTable_v4
                                {
                                    TableAddress = "1000:0228",
                                    Destinations = new string[]
                                    {
                                        "1000:0230",
                                        "1000:0244",
                                        "1000:033F",
                                    }
                                }
                            }
                        }
                    }
                }
            };

            using (FileUnitTester fut = new FileUnitTester("Core/SudWrite.txt"))
            {
                var writer = new FilteringXmlWriter(fut.TextWriter);
                writer.Formatting = System.Xml.Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v4(typeof(Project_v4));
                ser.Serialize(writer, ud);
                fut.AssertFilesEqual();
            }
        }
Ejemplo n.º 35
0
 public void OutpParameters()
 {
     program = RewriteFile("Fragments/multiple/outparameters.asm");
     FileUnitTester.RunTest("Analysis/OutpParameters.txt", PerformTest);
 }
Ejemplo n.º 36
0
 public void OutpMutual()
 {
     program = RewriteFile("Fragments/multiple/mutual.asm");
     FileUnitTester.RunTest("Analysis/OutpMutual.txt", PerformTest);
 }
Ejemplo n.º 37
0
        public void SudSaveProject()
        {
            Given_Architecture();
            Given_TestOS_Platform();
            var eax       = new RegisterStorage("eax", 0, 0, PrimitiveType.Word32);
            var ecx       = new RegisterStorage("ecx", 1, 0, PrimitiveType.Word32);
            var jumpTable = new ImageMapVectorTable(
                Address.SegPtr(0x1000, 0x400),
                new Address[] {
                Address.SegPtr(0x1000, 0x500),
                Address.SegPtr(0x1000, 0x513),
                Address.SegPtr(0x1000, 0x5BA),
            }, 0);

            Project project = new Project
            {
                Programs =
                {
                    new Program
                    {
                        Architecture         = arch.Object,
                        Platform             = platform.Object,
                        SegmentMap           = new SegmentMap(Address.SegPtr(0x1000, 0)), //, new byte[100]),
                        DisassemblyFilename  = "foo.asm",
                        IntermediateFilename = "foo.cod",
                        User = new UserData
                        {
                            Loader     = "CustomLoader",
                            Procedures =
                            {
                                {
                                    Address.SegPtr(0x1000, 0x10),
                                    new Procedure_v1
                                    {
                                        Name      = "foo",
                                        Signature = new SerializedSignature
                                        {
                                            ReturnValue = new Argument_v1{
                                                Kind = new Register_v1("eax")
                                            },
                                            Arguments = new Argument_v1[]
                                            {
                                                new Argument_v1
                                                {
                                                    Kind = new StackVariable_v1(),
                                                    Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                                },
                                                new Argument_v1
                                                {
                                                    Kind = new StackVariable_v1(),
                                                    Type = new PrimitiveType_v1(Domain.SignedInt, 4)
                                                }
                                            }
                                        }
                                    }
                                }
                            },
                            Globals =
                            {
                                {
                                    Address.SegPtr(0x2000, 0),
                                    new GlobalDataItem_v2     {
                                        Address  = Address.SegPtr(0x2000, 0).ToString(),
                                        DataType = new StringType_v2{
                                            Termination = StringType_v2.ZeroTermination,
                                            CharType    = new PrimitiveType_v1 {
                                                Domain = Domain.Character, ByteSize = 1
                                            }
                                        }
                                    }
                                }
                            },
                            Calls =
                            {
                                {
                                    Address.SegPtr(0x1000, 0x0320),
                                    new UserCallData
                                    {
                                        Address  = Address.SegPtr(0x1000, 0x0320),
                                        NoReturn = true,
                                    }
                                }
                            },
                            RegisterValues =
                            {
                                {
                                    Address.Ptr32(0x012310),
                                    new List <UserRegisterValue>
                                    {
                                        new UserRegisterValue {
                                            Register = eax, Value = Constant.Word32(0x01231)
                                        },
                                        new UserRegisterValue {
                                            Register = ecx, Value = Constant.Word32(0x42424711)
                                        },
                                    }
                                }
                            },
                            IndirectJumps =
                            {
                                {
                                    Address.SegPtr(0x1000, 0x380),
                                    new UserIndirectJump      {
                                        Address       = jumpTable.Address,
                                        Table         = jumpTable,
                                        IndexRegister = new RegisterStorage("R1", 1, 0, PrimitiveType.Word32)
                                    }
                                }
                            },
                            JumpTables =
                            {
                                { jumpTable.Address, jumpTable }
                            }
                        }
                    }
                }
            };

            using (FileUnitTester fut = new FileUnitTester("Core/SudSaveProject.txt"))
            {
                FilteringXmlWriter writer = new FilteringXmlWriter(fut.TextWriter);
                writer.Formatting = System.Xml.Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v4(typeof(Project_v4));
                Project_v4    ud  = new ProjectSaver(sc).Serialize("/var/foo/foo.proj", project);
                ser.Serialize(writer, ud);
                fut.AssertFilesEqual();
            }
        }