Beispiel #1
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();
            }
        }
 public void Setup()
 {
     sw = new StringWriter();
     formatter = new TextFormatter(sw);
     cf = new CodeFormatter(formatter);
     m = new ExpressionEmitter();
 }
Beispiel #3
0
 public void SetUp()
 {
     sw = new StringWriter();
     var tf = new TextFormatter(sw) { Indentation = 0 };
     tyfo = new TypeFormatter(tf, false);
     tf = new TextFormatter(sw) { Indentation = 0 };
     tyreffo = new TypeReferenceFormatter(tf, false);
 }
Beispiel #4
0
 public override string ToString()
 {
     StringWriter sw = new StringWriter();
     TextFormatter fmt = new TextFormatter(sw);
     CodeFormatter cf = new CodeFormatter(fmt);
     TypeFormatter tf = new TypeFormatter(fmt, false);
     Signature.Emit(Name, ProcedureSignature.EmitFlags.ArgumentKind, fmt, cf, tf);
     return sw.ToString();
 }
Beispiel #5
0
		public void Write(TextWriter writer)
		{
            var sl = new SortedList<string, ProcedureSignature>(
                Signatures,
                StringComparer.InvariantCulture);
            TextFormatter f = new TextFormatter(writer);
			foreach (KeyValuePair<string,ProcedureSignature> de in sl)
			{
				string name = (string) de.Key;
				de.Value.Emit(de.Key, ProcedureSignature.EmitFlags.ArgumentKind, f);
				writer.WriteLine();
			}
		}
Beispiel #6
0
		public void Write(TextWriter writer)
		{
            TextFormatter f = new TextFormatter(writer);
			foreach (var de in Signatures.OrderBy(d => d.Key, StringComparer.InvariantCulture))
			{
				string name = de.Key;
				de.Value.Emit(de.Key, FunctionType.EmitFlags.ArgumentKind, f);
				writer.WriteLine();
			}

            var tf = new TypeReferenceFormatter(f);
            foreach (var de in Globals.OrderBy(d => d.Key, StringComparer.InvariantCulture))
            {
                tf.WriteDeclaration(de.Value, de.Key);
            }
		}
Beispiel #7
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;
                foreach (var segment in program.SegmentMap.Segments.Values)
                {
                    var mem = segment.MemoryArea;
                    var formatter = new TextFormatter(fut.TextWriter);
                    dumper.DumpData(program.SegmentMap, mem.BaseAddress, mem.Length, formatter);
                    fut.TextWriter.WriteLine();
                    dumper.DumpAssembler(program.SegmentMap, mem.BaseAddress, mem.EndAddress, formatter);
                    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();
			}
		}
Beispiel #8
0
 public void CopyAll()
 {
     if (this.proc == null)
         return;
     var sw = new StringWriter();
     var writer = new TextFormatter(sw);
     var fmt = new CodeFormatter(writer);
     fmt.Write(proc);
     sw.Flush();
     Clipboard.SetText(sw.ToString());
 }
Beispiel #9
0
        public void DumpProgram()
        {
            foreach (Procedure proc in program.Procedures.Values)
            {
                StringWriter output = new StringWriter();
                ProcedureFlow pf= this.flow[proc];
                TextFormatter f = new TextFormatter(output);
                if (pf.Signature != null)
                    pf.Signature.Emit(proc.Name, ProcedureSignature.EmitFlags.None, f);
                else if (proc.Signature != null)
                    proc.Signature.Emit(proc.Name, ProcedureSignature.EmitFlags.None, f);
                else
                    output.Write("Warning: no signature found for {0}", proc.Name);
                output.WriteLine();
                pf.Emit(program.Architecture, output);

                output.WriteLine("// {0}", proc.Name);
                proc.Signature.Emit(proc.Name, ProcedureSignature.EmitFlags.None, f);
                output.WriteLine();
                foreach (Block block in proc.ControlGraph.Blocks)
                {
                    if (block != null)
                    {
                        BlockFlow bf = this.flow[block];
                        bf.Emit(program.Architecture, output);
                        output.WriteLine();
                        block.Write(output);
                    }
                }
                Debug.WriteLine(output.ToString());
            }
        }
 public override string ToString()
 {
     StringWriter w = new StringWriter();
     TextFormatter f = new TextFormatter(w);
     CodeFormatter cf = new CodeFormatter(f);
     TypeFormatter tf = new TypeFormatter(f, false);
     Emit("()", EmitFlags.ArgumentKind | EmitFlags.LowLevelInfo, f, cf, tf);
     return w.ToString();
 }
Beispiel #11
0
 private void EmitProgram(Program program, DataFlowAnalysis dfa, TextWriter output)
 {
     if (output == null)
         return;
     foreach (Procedure proc in program.Procedures.Values)
     {
         if (dfa != null)
         {
             ProcedureFlow flow = dfa.ProgramDataFlow[proc];
             TextFormatter f = new TextFormatter(output);
             if (flow.Signature != null)
                 flow.Signature.Emit(proc.Name, ProcedureSignature.EmitFlags.LowLevelInfo, f);
             else if (proc.Signature != null)
                 proc.Signature.Emit(proc.Name, ProcedureSignature.EmitFlags.LowLevelInfo, f);
             else
                 output.Write("Warning: no signature found for {0}", proc.Name);
             output.WriteLine();
             flow.Emit(program.Architecture, output);
             foreach (Block block in new DfsIterator<Block>(proc.ControlGraph).PostOrder().Reverse())
             {
                 if (block == null)
                     continue;
                 block.Write(output); output.Flush();
                 BlockFlow bf = dfa.ProgramDataFlow[block];
                 if (bf != null)
                 {
                     bf.Emit(program.Architecture, output);
                     output.WriteLine();
                 }
             }
         }
         else
         {
             proc.Write(false, output);
         }
         output.WriteLine();
         output.WriteLine();
     }
     output.Flush();
 }
 public string ToString(string name)
 {
     StringWriter sw = new StringWriter();
     TextFormatter f = new TextFormatter(sw);
     CodeFormatter cf = new CodeFormatter(f);
     TypeFormatter tf = new TypeFormatter(f, false);
     Emit(name, EmitFlags.ArgumentKind, f, cf, tf);
     return sw.ToString();
 }
Beispiel #13
0
 public void WriteDecompiledTypes(Program program, TextWriter w)
 {
     WriteHeaderComment(Path.GetFileName(program.TypesFilename), program, w);
     w.WriteLine("/*"); program.TypeStore.Write(w); w.WriteLine("*/");
     var tf = new TextFormatter(w)
     {
         Indentation = 0,
     };
     TypeFormatter fmt = new TypeFormatter(tf, false);
     foreach (EquivalenceClass eq in program.TypeStore.UsedEquivalenceClasses)
     {
         if (eq.DataType != null)
         {
             w.Write("typedef ");
             fmt.Write(eq.DataType, eq.Name);
             w.WriteLine(";");
             w.WriteLine();
         }
     }
 }
Beispiel #14
0
        public void Write(TextWriter w)
        {
            var writer = new TextFormatter(w);
            writer.WriteLine("// Equivalence classes ////////////");
            foreach (TypeVariable tv in TypeVariables)
            {
                if (tv.Class.Representative == tv && tv.Class.DataType != null)
                {
                    writer.WriteLine("{0}: {1}", tv.Class, tv.Class.DataType);
                    foreach (TypeVariable tvMember in tv.Class.ClassMembers)
                    {
                        writer.Write("\t{0}", tvMember);
                        WriteExpressionOf(tvMember, writer);
                        writer.WriteLine();
                    }
                }
            }

            writer.WriteLine("// Type Variables ////////////");
            foreach (TypeVariable tv in TypeVariables)
            {
                WriteEntry(tv, writer);
            }
        }
Beispiel #15
0
		private void RunTest(string sourceFile, string outputFile)
		{
            Program program;
            using (var rdr = new StreamReader(FileUnitTester.MapTestPath(sourceFile)))
            {
                program = asm.Assemble(Address.SegPtr(0x0C00, 0), rdr);
            }
			using (FileUnitTester fut = new FileUnitTester(outputFile))
			{
				Dumper dump = new Dumper(asm.Architecture);
                var mem = program.SegmentMap.Segments.Values.First().MemoryArea;
                var formatter = new TextFormatter(fut.TextWriter);
				dump.DumpData(program.SegmentMap, mem.BaseAddress, mem.Bytes.Length, formatter);
				fut.TextWriter.WriteLine();
				dump.ShowAddresses = true;
				dump.ShowCodeBytes = true;
				dump.DumpAssembler(program.SegmentMap, mem.BaseAddress, mem.EndAddress, formatter);

				fut.AssertFilesEqual();
			}	
		}
 /// <summary>
 /// Convert a declaration to its C string representation.
 /// </summary>
 /// <param name="dataType"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 private string RenderGlobalDeclaration(DataType dataType, string name)
 {
     var sw = new StringWriter();
     var tf = new TextFormatter(sw);
     var tyreffo = new CTypeReferenceFormatter(program.Platform, tf);
     tyreffo.WriteDeclaration(dataType, name);
     return sw.ToString();
 }
Beispiel #17
0
 public void WriteStatements(TextWriter writer)
 {
     TextFormatter f = new TextFormatter(writer);
     f.UseTabs = true;
     f.TabSize = 4;
     CodeFormatter cf = new CodeFormatter(f);
     int i = 0;
     foreach (Statement s in Statements)
     {
         s.Instruction.Accept(cf);
         ++i;
     }
 }