Esempio n. 1
0
    def testRuns(self):
        runs = [
            dict(start=101, end=500, value="Foo"),
            dict(start=0, end=100, value="Bar"),
            dict(start=0, end=10, value="Foo"),
            dict(start=401, end=500, value="Baz"),
            dict(start=501, end=502, value="Bork")
        ]
        legend = visual_aides.MapLegend(legend=[("F", "Foo", (
            0xff, 0x00,
            0x00)), ("B", "Bar",
                     (0x00, 0xff,
                      0x00)), ("Bz", "Baz",
                               (0x00, 0x00,
                                0xff)), ("Bk", "Bork", (0xff, 0xff, 0xff))])

        rbmap = visual_aides.RunBasedMap(runs=runs,
                                         legend=legend,
                                         resolution=10,
                                         column_count=5)

        cells = list(rbmap.cells)

        self.assertEqual(len(rbmap.rows), 11)
        self.assertEqual(len(cells), 51)

        # Should be blended 1:1
        self.assertEqual(cells[0]["bg"], (127.5, 127.5, 0))

        # Shouldn't blend.
        self.assertEqual(cells[-1]["bg"], (0xff, 0xff, 0xff))
Esempio n. 2
0
    def render(self, renderer):
        renderer.table_header([
            dict(name="Dogma", width=35, style="full"),
            dict(name="Bessy", width=65, type="bool", style="cow"),
            dict(name="Pilsner", width=50, style="full"),
            dict(name="Nowrap", width=10, nowrap=True)
        ])

        fixtures = self.session.LoadProfile("tests/fixtures")
        beer = fixtures.data["ascii_art"]["beer"]
        phys_map = fixtures.data["fixtures"]["phys_map"]

        renderer.table_row(
            ("This is a renderer stress-test. The flags should have correct"
             " colors, the beer should be yellow and the cell on the left"
             " should not bleed into the cell on the right.\n"
             "This is a really "
             "long column of text with its own newlines in it!\n"
             "This bovine experience has been brought to you by Rekall."),
            True,
            utils.AttributedString("\n".join(beer["ascii"]),
                                   beer["highlights"]),
            ("This is a fairly long line that shouldn't get wrapped.\n"
             "The same row has another line that shouldn't get wrapped."))

        renderer.section("Heatmap test:")
        cells = []
        for digit in itertools.islice(algo.EulersDecimals(), 0xff):
            cells.append(dict(heat=float(digit + 1) * .1, value=digit))

        randomized = visual_aides.Heatmap(
            caption="Offset (p)",
            # Some of the below xs stand for eXtreme. The other ones just
            # look cool.
            column_headers=["%0.2x" % x for x in xrange(0, 0xff, 0x10)],
            row_headers=["0x%0.6x" % x for x in xrange(0x0, 0xfffff, 0x10000)],
            cells=cells,
            greyscale=False)

        gradual = visual_aides.Heatmap(
            caption="Offset (v)",
            column_headers=["%0.2x" % x for x in xrange(0, 0xff, 0x10)],
            row_headers=["0x%0.6x" % x for x in xrange(0x0, 0xfffff, 0x10000)],
            cells=[dict(value="%x" % x, heat=x / 255.0) for x in xrange(256)],
            greyscale=False)

        ranges_legend = visual_aides.MapLegend(phys_map["ranges_legend"])

        ranges = visual_aides.RunBasedMap(caption="Offset (p)",
                                          legend=ranges_legend,
                                          runs=phys_map["runs"])

        renderer.table_header([
            dict(name="Random Heatmap", style="full", width=60, align="c"),
            dict(name="Gradual Heatmap", style="full", width=60, align="c"),
            dict(name="Legend", style="full", orientation="horizontal")
        ])
        renderer.table_row(randomized, gradual, visual_aides.HeatmapLegend())

        renderer.table_header([
            dict(name="Greyscale Random", style="full", width=60, align="c"),
            dict(name="Memory Ranges", style="full", width=80, align="c"),
            dict(name="Ranges Legend",
                 style="full",
                 width=30,
                 orientation="vertical")
        ])

        randomized.greyscale = True
        renderer.table_row(randomized, ranges, ranges_legend)
Esempio n. 3
0
    def render(self, renderer):
        renderer.table_header([("Physical Start", "phys", "[addrpad]"),
                               ("Physical End", "phys", "[addrpad]"),
                               ("Virtual", "virt", "[addrpad]"),
                               ("Pages", "pages", ">10"),
                               ("Type", "type", "")])

        boot_params = self.profile.get_constant_object("_PE_state",
                                                       "PE_state").bootArgs

        # Code from:
        # xnu-1699.26.8/osfmk/i386/AT386/model_dep.c:560
        memory_map = self.profile.Array(
            boot_params.MemoryMap,
            vm=self.physical_address_space,
            target="EfiMemoryRange",
            target_size=int(boot_params.MemoryMapDescriptorSize),
            count=(old_div(boot_params.MemoryMapSize,
                           boot_params.MemoryMapDescriptorSize)))

        runs = []
        for memory_range in memory_map:
            start = memory_range.PhysicalStart
            end = (memory_range.PhysicalStart +
                   0x1000 * memory_range.NumberOfPages)
            runs.append(
                dict(value=utils.SmartUnicode(memory_range.Type),
                     start=start,
                     end=end))
            renderer.table_row(start, end,
                               memory_range.VirtualStart.cast("Pointer"),
                               memory_range.NumberOfPages, memory_range.Type)

        # Render a heatmap.

        # Automatically lower resolution for large images.
        resolution = 0x1000 * 0x10  # 16 pages - conservative start.
        column_count = 12
        end = runs[-1]["end"]
        # Keep it under 200 rows.
        while end / resolution / column_count > 200:
            resolution *= 2

        notes = ("Resolution: %(pages)d pages (%(mb).2f MB) per cell.\n"
                 "Note that colors of overlapping regions are blended "
                 "using a weighted average. Letters in cells indicate "
                 "which regions from the legend are present. They are "
                 "ordered proportionally, by their respective page "
                 "counts in each cell.") % dict(
                     pages=old_div(resolution, 0x1000),
                     mb=old_div(resolution, 1024.0**2))

        legend = visual_aides.MapLegend(
            notes=notes,
            legend=[("Am", "kEfiACPIMemoryNVS", (0x00, 0xff, 0x00)),
                    ("Ar", "kEfiACPIReclaimMemory", (0xc7, 0xff, 0x50)),
                    ("Bc", "kEfiBootServicesCode", (0xff, 0xa5, 0x00)),
                    ("Bd", "kEfiBootServicesData", (0xff, 0x00, 0x00)),
                    ("M", "kEfiConventionalMemory", (0xff, 0xff, 0xff)),
                    ("Ec", "kEfiLoaderCode", (0x00, 0xff, 0xff)),
                    ("Ed", "kEfiLoaderData", (0x00, 0x00, 0xff)),
                    ("I", "kEfiMemoryMappedIO", (0xff, 0xff, 0x00)),
                    ("X", "kEfiReservedMemoryType", (0x00, 0x00, 0x00)),
                    ("Rc", "kEfiRuntimeServicesCode", (0xff, 0x00, 0xff)),
                    ("Rd", "kEfiRuntimeServicesData", (0xff, 0x00, 0x50))])

        heatmap = visual_aides.RunBasedMap(caption="Offset (p)",
                                           legend=legend,
                                           runs=runs,
                                           resolution=resolution,
                                           column_count=column_count)

        renderer.table_header([
            dict(name="Visual mapping", width=120, style="full"),
            dict(name="Legend", orientation="vertical", style="full", width=40)
        ])

        renderer.table_row(heatmap, legend)