예제 #1
0
        private void WriteCode(Formatter tsf)
        {
            var fmt = new AbsynCodeFormatter(tsf);

            fmt.InnerFormatter.UseTabs = false;
            fmt.Write(proc);
        }
예제 #2
0
        private void CreateNestedTextModel()
        {
            this.nestedTextModel = new NestedTextModel();

            var mixedCodeDataModel = combinedCodeView.MixedCodeDataView.Model as MixedCodeDataModel;

            if (mixedCodeDataModel == null)
            {
                return;
            }

            var dataItemNodes = mixedCodeDataModel.GetDataItemNodes();

            this.nodeByAddress = new SortedList <Address, MixedCodeDataModel.DataItemNode>();
            foreach (var dataItemNode in dataItemNodes)
            {
                var curAddr = dataItemNode.StartAddress;

                bool         nodeCreated = false;
                ImageMapItem item;
                Procedure    proc = dataItemNode.Proc;
                if (ShowItem(dataItemNode))
                {
                    if (proc != null)
                    {
                        var model = new ProcedureCodeModel(proc);
                        //$TODO: make spacing between globals / procedures user adjustable
                        model.NumEmptyLinesAfter = 2;
                        nestedTextModel.Nodes.Add(model);
                        nodeCreated = true;
                    }
                    else if (program.ImageMap.TryFindItem(curAddr, out item) &&
                             item.DataType != null &&
                             !(item.DataType is UnknownType))
                    {
                        var dt   = item.DataType;
                        var name = item.Name ?? "<unnamed>";

                        var tsf = new TextSpanFormatter();
                        var fmt = new AbsynCodeFormatter(tsf);
                        fmt.InnerFormatter.UseTabs = false;
                        var gdw = new GlobalDataWriter(program, services);
                        gdw.WriteGlobalVariable(curAddr, dt, name, tsf);
                        //$TODO: make spacing between globals / procedures user adjustable
                        tsf.WriteLine("");
                        nestedTextModel.Nodes.Add(tsf.GetModel());
                        nodeCreated = true;
                    }
                }

                if (nodeCreated)
                {
                    dataItemNode.ModelNode      = nestedTextModel.Nodes.Last();
                    this.nodeByAddress[curAddr] = dataItemNode;
                }
            }

            combinedCodeView.CodeView.Model = nestedTextModel;
        }
예제 #3
0
 public void Acf_NegativeSigned_SmallInt()
 {
     var c = Constant.Word32(-4);
     var sw = new StringWriter();
     var acf = new AbsynCodeFormatter(new TextFormatter(sw));
     c.Accept(acf);
     Assert.AreEqual("~0x03", sw.ToString());
 }
예제 #4
0
 public void Acf_HexEntropy()
 {
     var c = Constant.Int32(0x7FF);
     var sw = new StringWriter();
     var acf = new AbsynCodeFormatter(new TextFormatter(sw));
     c.Accept(acf);
     Assert.AreEqual("0x07FF", sw.ToString());
 }
예제 #5
0
 public void Acf_SmallInteger()
 {
     var c = Constant.Int32(10);
     var sw = new StringWriter();
     var acf = new AbsynCodeFormatter(new TextFormatter(sw));
     c.Accept(acf);
     Assert.AreEqual("0x0A", sw.ToString());
 }
예제 #6
0
 public void Acf_NegativeSigned()
 {
     var c = Constant.Int32(-256);
     var sw = new StringWriter();
     var acf = new AbsynCodeFormatter(new TextFormatter(sw));
     c.Accept(acf);
     Assert.AreEqual("-0x0100", sw.ToString());
 }
예제 #7
0
 public void Acf_EvenPower()
 {
     var c = Constant.UInt32(unchecked((uint)-256));
     var sw = new StringWriter();
     var acf = new AbsynCodeFormatter(new TextFormatter(sw));
     c.Accept(acf);
     Assert.AreEqual("~0xFF", sw.ToString());
 }
예제 #8
0
        public void Acf_Reg00001()
        {
            var c   = Constant.Word32(0x00001000);
            var sw  = new StringWriter();
            var acf = new AbsynCodeFormatter(new TextFormatter(sw));

            c.Accept(acf);
            Assert.AreEqual("0x1000", sw.ToString());
        }
예제 #9
0
        public void Acf_NegativeSigned_SmallInt()
        {
            var c   = Constant.Word32(-4);
            var sw  = new StringWriter();
            var acf = new AbsynCodeFormatter(new TextFormatter(sw));

            c.Accept(acf);
            Assert.AreEqual("~0x03", sw.ToString());
        }
예제 #10
0
        public void Acf_EvenPower()
        {
            var c   = Constant.UInt32(unchecked ((uint)-256));
            var sw  = new StringWriter();
            var acf = new AbsynCodeFormatter(new TextFormatter(sw));

            c.Accept(acf);
            Assert.AreEqual("~0xFF", sw.ToString());
        }
예제 #11
0
        public void Acf_NegativeSigned()
        {
            var c   = Constant.Int32(-256);
            var sw  = new StringWriter();
            var acf = new AbsynCodeFormatter(new TextFormatter(sw));

            c.Accept(acf);
            Assert.AreEqual("-0x0100", sw.ToString());
        }
예제 #12
0
        private void SetTextView(Procedure proc)
        {
            var tsf = new TextSpanFormatter();
            var fmt = new AbsynCodeFormatter(tsf);

            fmt.InnerFormatter.UseTabs = false;
            fmt.Write(proc);
            this.TextView.Model = tsf.GetModel();
        }
예제 #13
0
        public virtual void Write(StringWriter sb)
        {
            var f = new AbsynCodeFormatter(new TextFormatter(sb));

            foreach (var stm in Statements)
            {
                stm.Accept(f);
            }
        }
예제 #14
0
        public void Acf_SmallInteger()
        {
            var c   = Constant.Int32(10);
            var sw  = new StringWriter();
            var acf = new AbsynCodeFormatter(new TextFormatter(sw));

            c.Accept(acf);
            Assert.AreEqual("0x0A", sw.ToString());
        }
예제 #15
0
        public void Acf_DecEntropy()
        {
            var c   = Constant.Int32(1000);
            var sw  = new StringWriter();
            var acf = new AbsynCodeFormatter(new TextFormatter(sw));

            c.Accept(acf);
            Assert.AreEqual("1000", sw.ToString());
        }
예제 #16
0
        private TextViewModel GenerateTextModel(Block b)
        {
            var tsf   = new TextSpanFormatter();
            var fmt   = new AbsynCodeFormatter(tsf);
            var procf = new ProcedureFormatter(b.Procedure, fmt);

            fmt.InnerFormatter.UseTabs = false;
            procf.WriteBlock(b, fmt);
            return(tsf.GetModel());
        }
예제 #17
0
        private void GenCode(Procedure proc, StringWriter sb)
        {
            sb.WriteLine("{0}()", proc.Name);
            sb.WriteLine("{");

            var cf = new AbsynCodeFormatter(new TextFormatter(sb));

            cf.WriteStatementList(proc.Body);

            sb.WriteLine("}");
        }
예제 #18
0
        private void GenCode(Procedure proc, StringWriter sw)
        {
            sw.WriteLine("{0}()", proc.Name);
            sw.WriteLine("{");

            var cf = new AbsynCodeFormatter(new TextFormatter(sw)
            {
                UseTabs = false
            });

            cf.WriteStatementList(proc.Body);

            sw.WriteLine("}");
        }
예제 #19
0
        public static string RenderProcedureHll(Program program, string sProcAddress)
        {
            if (!program.Architecture.TryParseAddress(sProcAddress, out var addr))
            {
                return("");
            }
            if (!program.Procedures.TryGetValue(addr, out var proc))
            {
                return("");
            }
            var sb     = new StringBuilder();
            var writer = new ProcedureRenderer(sb);
            var ar     = new AbsynCodeFormatter(writer);

            ar.Write(proc);
            return(sb.ToString());
        }
예제 #20
0
        private TextViewModel GenerateSimulatedHllCode()
        {
            var code   = new List <AbsynStatement>();
            var ase    = new Structure.AbsynStatementEmitter(code);
            var a_id   = new Identifier("a", PrimitiveType.Int32, null);
            var sum_id = new Identifier("sum", PrimitiveType.Int32, null);

            ase.EmitAssign(a_id, Constant.Int32(10));
            ase.EmitAssign(sum_id, Constant.Int32(0));

            var tsf = new TextSpanFormatter();
            var fmt = new AbsynCodeFormatter(tsf);

            fmt.InnerFormatter.UseTabs = false;
            foreach (var stm in code)
            {
                stm.Accept(fmt);
            }
            return(tsf.GetModel());
        }
예제 #21
0
        public static string RenderProcedureIR(Program program, string sProcAddress)
        {
            if (!program.Architecture.TryParseAddress(sProcAddress, out var addr))
            {
                return("");
            }
            if (!program.Procedures.TryGetValue(addr, out var proc))
            {
                return("");
            }
            var sb = new StringBuilder();

            var writer = new ProcedureRenderer(sb);
            var ar     = new AbsynCodeFormatter(writer);

            new ProcedureFormatter(proc, new BlockDecorator {
                ShowEdges = false
            }, ar).WriteProcedureBlocks();
            return(sb.ToString());
        }
예제 #22
0
        public void WriteDecompiledProcedures(Program program, TextWriter w)
        {
            WriteHeaderComment(Path.GetFileName(program.OutputFilename), program, w);
            w.WriteLine("#include \"{0}\"", Path.GetFileName(program.TypesFilename));
            w.WriteLine();
            var fmt = new AbsynCodeFormatter(new TextFormatter(w));

            foreach (Procedure proc in program.Procedures.Values)
            {
                try
                {
                    fmt.Write(proc);
                    w.WriteLine();
                }
                catch (Exception ex)
                {
                    w.WriteLine();
                    w.WriteLine("// Exception {0} when writing procedure.", ex.Message);
                }
            }
        }
예제 #23
0
파일: Decompiler.cs 프로젝트: nemerle/reko
        public void WriteDecompiledObjects(Program program, string filename, IEnumerable <IAddressable> objects, TextWriter w)
        {
            WriteHeaderComment(filename, program, w);
            //$REFACTOR: common code -- hardwired ".h"
            var headerfile = Path.ChangeExtension(Path.GetFileName(program.Filename), ".h");

            w.WriteLine("#include \"{0}\"", headerfile);
            w.WriteLine();
            var          fmt  = new AbsynCodeFormatter(new TextFormatter(w));
            var          gdw  = new GlobalDataWriter(program, fmt.InnerFormatter, false, true, this.services);
            IAddressable?prev = null;

            foreach (var o in objects)
            {
                if (o is Procedure proc)
                {
                    try
                    {
                        if (prev is GlobalVariable)
                        {
                            w.WriteLine();
                        }
                        WriteProcedureHeader(program, proc, w);
                        fmt.Write(proc);
                        w.WriteLine();
                    }
                    catch (Exception ex)
                    {
                        w.WriteLine();
                        w.WriteLine("// Exception {0} when writing procedure.", ex.Message);
                    }
                }
                else if (o is GlobalVariable global)
                {
                    gdw.WriteGlobalVariable(global.Address, global.DataType, global.Name);
                }
            }
        }
예제 #24
0
        public void WriteDecompiledProcedures(Program program, string filename, IEnumerable <Procedure> procs, TextWriter w)
        {
            var headerfile = Path.ChangeExtension(filename, ".h");

            WriteHeaderComment(filename, program, w);
            w.WriteLine("#include \"{0}\"", headerfile);
            w.WriteLine();
            var fmt = new AbsynCodeFormatter(new TextFormatter(w));

            foreach (var proc in procs)
            {
                w.WriteLine("// {0}: {1}", proc.EntryAddress, proc);
                try
                {
                    fmt.Write(proc);
                    w.WriteLine();
                }
                catch (Exception ex)
                {
                    w.WriteLine();
                    w.WriteLine("// Exception {0} when writing procedure.", ex.Message);
                }
            }
        }
예제 #25
0
 public void Acf_Reg00001()
 {
     var c = Constant.Word32(0x00001000);
     var sw = new StringWriter();
     var acf = new AbsynCodeFormatter(new TextFormatter(sw));
     c.Accept(acf);
     Assert.AreEqual("0x1000", sw.ToString());
 }
예제 #26
0
 private TextViewModel GenerateTextModel(Block b)
 {
     var tsf = new TextSpanFormatter();
     var fmt = new AbsynCodeFormatter(tsf);
     var procf = new ProcedureFormatter(b.Procedure, fmt);
     fmt.InnerFormatter.UseTabs = false;
     procf.WriteBlock(b, fmt);
     return tsf.GetModel();
 }
        private TextViewModel GenerateSimulatedHllCode()
        {
            var code = new List<AbsynStatement>();
            var ase = new Structure.AbsynStatementEmitter(code);
            var m = new ExpressionEmitter();
            var a_id = new Identifier("a", PrimitiveType.Int32, null);
            var sum_id = new Identifier("sum", PrimitiveType.Int32, null);
            ase.EmitAssign(a_id, Constant.Int32(10));
            ase.EmitAssign(sum_id, Constant.Int32(0));

            var tsf = new TextSpanFormatter();
            var fmt = new AbsynCodeFormatter(tsf);
            fmt.InnerFormatter.UseTabs = false;
            foreach (var stm in code)
            {
                stm.Accept(fmt);
            }
            return tsf.GetModel();
        }
예제 #28
0
파일: Decompiler.cs 프로젝트: nemerle/reko
 public void WriteDecompiledProcedures(Program program, TextWriter w)
 {
     WriteHeaderComment(Path.GetFileName(program.OutputFilename), program, w);
     w.WriteLine("#include \"{0}\"", Path.GetFileName(program.TypesFilename));
     w.WriteLine();
     var fmt = new AbsynCodeFormatter(new TextFormatter(w));
     foreach (Procedure proc in program.Procedures.Values)
     {
         try
         {
             fmt.Write(proc);
             w.WriteLine();
         }
         catch (Exception ex)
         {
             w.WriteLine();
             w.WriteLine("// Exception {0} when writing procedure.", ex.Message);
         }
     }
 }
예제 #29
0
 private void SetTextView(Procedure proc)
 {
     var tsf = new TextSpanFormatter();
     var fmt = new AbsynCodeFormatter(tsf);
     fmt.InnerFormatter.UseTabs = false;
     fmt.Write(proc);
     this.TextView.Model = tsf.GetModel();
 }
예제 #30
0
파일: Region.cs 프로젝트: nemerle/reko
 public virtual void Write(StringWriter sb)
 {
     var f = new AbsynCodeFormatter(new TextFormatter(sb));
     foreach (var stm in Statements)
         stm.Accept(f);
 }
예제 #31
0
        private void CreateNestedTextModel()
        {
            this.nestedTextModel = new NestedTextModel();

            var mixedCodeDataModel = combinedCodeView.MixedCodeDataView.Model as MixedCodeDataModel;
            if (mixedCodeDataModel == null)
                return;

            var dataItemNodes = mixedCodeDataModel.GetDataItemNodes();

            this.nodeByAddress = new SortedList<Address, MixedCodeDataModel.DataItemNode>();

            foreach (var dataItemNode in dataItemNodes)
            {
                var curAddr = dataItemNode.StartAddress;

                bool nodeCreated = false;

                ImageMapItem item;
                Procedure proc = dataItemNode.Proc;
                if (ShowItem(dataItemNode))
                {
                    if (proc != null)
                    {
                        var tsf = new TextSpanFormatter();
                        var fmt = new AbsynCodeFormatter(tsf);
                        fmt.InnerFormatter.UseTabs = false;
                        fmt.Write(proc);
                        //$TODO: make spacing between globals / procedures user adjustable
                        tsf.WriteLine("");
                        tsf.WriteLine("");
                        nestedTextModel.Nodes.Add(tsf.GetModel());
                        nodeCreated = true;
                    }
                    else if (program.ImageMap.TryFindItem(curAddr, out item) &&
                              item.DataType != null &&
                            !(item.DataType is UnknownType))
                    {
                        var dt = item.DataType;
                        var name = item.Name ?? "<unnamed>";

                        var tsf = new TextSpanFormatter();
                        var fmt = new AbsynCodeFormatter(tsf);
                        fmt.InnerFormatter.UseTabs = false;
                        var gdw = new GlobalDataWriter(program, services);
                        gdw.WriteGlobalVariable(curAddr, dt, name, tsf);
                        //$TODO: make spacing between globals / procedures user adjustable
                        tsf.WriteLine("");
                        nestedTextModel.Nodes.Add(tsf.GetModel());
                        nodeCreated = true;
                    }
                }

                if (nodeCreated)
                {
                    dataItemNode.ModelNode = nestedTextModel.Nodes.Last();
                    this.nodeByAddress[curAddr] = dataItemNode;
                }
            }

            combinedCodeView.CodeView.Model = nestedTextModel;
        }
예제 #32
0
        /// <summary>
        /// Displace the procedure <paramref name="proc"/> in the code window.
        /// </summary>
        /// <param name="proc"></param>
        public void DisplayProcedure(Procedure proc)
        {
            if (codeView == null || proc == null)
                return;

            this.proc = proc;
            var tsf = new TextSpanFormatter();
            var fmt = new AbsynCodeFormatter(tsf);
            fmt.InnerFormatter.UseTabs = false;
            fmt.Write(proc);
            this.TextView.Model = tsf.GetModel();
        }