示例#1
0
        public void Dump(Program program, TextWriter stm)
        {
            var          map     = program.SegmentMap;
            ImageSegment segment = null;

            foreach (ImageMapItem i in program.ImageMap.Items.Values)
            {
                if (!map.IsValidAddress(i.Address))
                {
                    continue;
                }
                ImageSegment seg;
                if (!map.TryFindSegment(i.Address, out seg))
                {
                    continue;
                }
                if (seg != segment)
                {
                    segment = seg;
                    stm.WriteLine(";;; Segment {0} ({1})", seg.Name, seg.Address);
                }

                // Address addrLast = i.Address + i.Size;
                ImageMapBlock block = i as ImageMapBlock;
                if (block != null)
                {
                    stm.WriteLine();
                    if (program.Procedures.ContainsKey(block.Address))
                    {
                        stm.WriteLine(block.Address.GenerateName("fn", "()"));
                    }
                    else
                    {
                        stm.WriteLine(block.Address.GenerateName("l", ":"));
                    }
                    DumpAssembler(program.SegmentMap, block.Address, block.Address + block.Size, stm);
                    continue;
                }

                ImageMapVectorTable table = i as ImageMapVectorTable;
                if (table != null)
                {
                    stm.WriteLine("Code vector at {0} ({1} bytes)",
                                  table.Address, table.Size);
                    foreach (Address addr in table.Addresses)
                    {
                        stm.WriteLine("\t{0}", addr != null ? addr.ToString() : "-- null --");
                    }
                    DumpData(program.SegmentMap, i.Address, i.Size, stm);
                }
                else
                {
                    var segLast = segment.Address + segment.Size;
                    var size    = segLast - i.Address;
                    size = Math.Min(i.Size, size);
                    DumpData(program.SegmentMap, i.Address, size, stm);
                }
            }
        }
示例#2
0
        private void DumpItem(ImageSegment segment, ImageMapItem i, Formatter formatter)
        {
            ImageMapBlock block = i as ImageMapBlock;

            if (block != null)
            {
                formatter.WriteLine();
                Procedure proc;
                if (program.Procedures.TryGetValue(block.Address, out proc))
                {
                    formatter.WriteComment(string.Format(
                                               ";; {0}: {1}", proc.Name, block.Address));
                    formatter.WriteLine();

                    formatter.Write(proc.Name);
                    formatter.Write(" ");
                    formatter.Write("proc");
                    formatter.WriteLine();
                }
                else
                {
                    formatter.Write(block.Block.Name);
                    formatter.Write(":");
                    formatter.WriteLine();
                }
                DumpAssembler(program.SegmentMap, block.Address, block.Address + block.Size, formatter);
                return;
            }

            ImageMapVectorTable table = i as ImageMapVectorTable;

            if (table != null)
            {
                formatter.WriteLine(";; Code vector at {0} ({1} bytes)",
                                    table.Address, table.Size);
                foreach (Address addr in table.Addresses)
                {
                    formatter.WriteLine("\t{0}", addr != null ? addr.ToString() : "-- null --");
                }
                DumpData(program.SegmentMap, i.Address, i.Size, formatter);
            }
            else
            {
                var segLast = segment.Address + segment.Size;
                var size    = segLast - i.Address;
                size = Math.Min(i.Size, size);
                if (i.DataType == null || i.DataType is UnknownType ||
                    i.DataType is CodeType)
                {
                    DumpData(program.SegmentMap, i.Address, size, formatter);
                }
                else
                {
                    DumpTypedData(program.SegmentMap, i, formatter);
                }
            }
        }
示例#3
0
文件: Dumper.cs 项目: mmyydd/reko
        public void Dump(Program program, ImageMap map, TextWriter stm)
        {
            if (map == null)
            {
                DumpAssembler(program.Image, program.Image.BaseAddress, program.Image.BaseAddress + (uint)program.Image.Length, stm);
            }
            else
            {
                foreach (ImageMapItem i in map.Items.Values)
                {
                    if (!program.Image.IsValidAddress(i.Address))
                    {
                        continue;
                    }
                    //				Address addrLast = i.Address + i.Size;
                    ImageMapBlock block = i as ImageMapBlock;
                    if (block != null)
                    {
                        stm.WriteLine();
                        if (program.Procedures.ContainsKey(block.Address))
                        {
                            stm.WriteLine(block.Address.GenerateName("fn", "()"));
                        }
                        else
                        {
                            stm.WriteLine(block.Address.GenerateName("l", ":"));
                        }
                        DumpAssembler(program.Image, block.Address, block.Address + block.Size, stm);
                        continue;
                    }

                    ImageMapVectorTable table = i as ImageMapVectorTable;
                    if (table != null)
                    {
                        stm.WriteLine("{0} table at {1} ({2} bytes)",
                                      table.IsCallTable?"Call":"Jump",
                                      table.Address, table.Size);
                        foreach (Address addr in table.Addresses)
                        {
                            stm.WriteLine("\t{0}", addr != null ? addr.ToString() : "-- null --");
                        }
                        DumpData(program.Image, i.Address, i.Size, stm);
                    }
                    else
                    {
                        DumpData(program.Image, i.Address, i.Size, stm);
                    }
                }
            }
        }
示例#4
0
        public void Dump(Program program, Formatter formatter)
        {
            var          map     = program.SegmentMap;
            ImageSegment segment = null;

            foreach (ImageMapItem i in program.ImageMap.Items.Values)
            {
                if (!map.IsValidAddress(i.Address))
                {
                    continue;
                }
                ImageSegment seg;
                if (!map.TryFindSegment(i.Address, out seg))
                {
                    continue;
                }
                if (seg != segment)
                {
                    segment = seg;
                    formatter.WriteLine(";;; Segment {0} ({1})", seg.Name, seg.Address);
                }

                ImageMapBlock block = i as ImageMapBlock;
                if (block != null)
                {
                    formatter.WriteLine();
                    Procedure proc;
                    if (program.Procedures.TryGetValue(block.Address, out proc))
                    {
                        formatter.WriteComment(string.Format(
                                                   ";; {0}: {1}", proc.Name, block.Address));
                        formatter.WriteLine();

                        formatter.Write(proc.Name);
                        formatter.Write(" ");
                        formatter.Write("proc");
                        formatter.WriteLine();
                    }
                    else
                    {
                        formatter.Write(block.Block.Name);
                        formatter.Write(":");
                        formatter.WriteLine();
                    }
                    DumpAssembler(program.SegmentMap, block.Address, block.Address + block.Size, formatter);
                    continue;
                }

                ImageMapVectorTable table = i as ImageMapVectorTable;
                if (table != null)
                {
                    formatter.WriteLine(";; Code vector at {0} ({1} bytes)",
                                        table.Address, table.Size);
                    foreach (Address addr in table.Addresses)
                    {
                        formatter.WriteLine("\t{0}", addr != null ? addr.ToString() : "-- null --");
                    }
                    DumpData(program.SegmentMap, i.Address, i.Size, formatter);
                }
                else
                {
                    var segLast = segment.Address + segment.Size;
                    var size    = segLast - i.Address;
                    size = Math.Min(i.Size, size);
                    if (i.DataType == null || i.DataType is UnknownType ||
                        i.DataType is CodeType)
                    {
                        DumpData(program.SegmentMap, i.Address, size, formatter);
                    }
                    else
                    {
                        DumpTypedData(program.SegmentMap, i, formatter);
                    }
                }
            }
        }
示例#5
0
 private int CountDisassembledLines(ImageMapBlock bi)
 {
     return instructions[bi].Length;
 }
        private void Given_StubProcedure(uint addr, uint size)
        {
            var address = Address32.Ptr32(addr);
            var m = new ProcedureBuilder("fnTest");
            m.Return();
            this.proc = m.Procedure;
            this.program.Procedures[address] = proc;

            var item = new ImageMapBlock
            {
                Address = address,
                Size = size,
                Block = new Block(proc, "fakeBlock")
            };
            program.ImageMap.AddItemWithSize(address, item);
        }