Example #1
0
    def setUp(self):
        version = container.Version(1, 1, "pyaff4")
        with data_store.MemoryDataStore() as resolver:
            resolver.Set(lexicon.transient_graph, self.filename_urn,
                         lexicon.AFF4_STREAM_WRITE_MODE,
                         rdfvalue.XSDString("truncate"))

            with zip.ZipFile.NewZipFile(resolver, version,
                                        self.filename_urn) as zip_file:
                self.volume_urn = zip_file.urn
                self.image_urn = self.volume_urn.Append(self.image_name)

                # Write Map image sequentially (Seek/Write method).
                with aff4_map.AFF4Map.NewAFF4Map(resolver, self.image_urn,
                                                 self.volume_urn) as image:
                    # Maps are written in random order.
                    image.SeekWrite(50)
                    image.Write(b"XX - This is the position.")

                    image.SeekWrite(0)
                    image.Write(b"00 - This is the position.")

                    # We can "overwrite" data by writing the same range again.
                    image.SeekWrite(50)
                    image.Write(b"50")

                # Test the Stream method.
                with resolver.CachePut(
                        aff4_file.AFF4MemoryStream(resolver)) as source:
                    # Fill it with data.
                    source.Write(b"AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH")

                    # Make a temporary map that defines our plan.
                    helper_map = aff4_map.AFF4Map(resolver)

                    helper_map.AddRange(4, 0, 4, source.urn)  # 0000AAAA
                    helper_map.AddRange(0, 12, 4, source.urn)  # DDDDAAAA
                    helper_map.AddRange(12, 16, 4,
                                        source.urn)  # DDDDAAAA0000EEEE

                    image_urn_2 = self.volume_urn.Append(
                        self.image_name).Append("streamed")

                    with aff4_map.AFF4Map.NewAFF4Map(resolver, image_urn_2,
                                                     self.volume_urn) as image:

                        # Now we create the real map by copying the temporary
                        # map stream.
                        image.WriteStream(helper_map)
Example #2
0
    def _WriteToTarget(self, resolver, source_as, image_stream):
        # Prepare a temporary map to control physical memory acquisition.
        helper_map = aff4_map.AFF4Map(resolver)

        with resolver.CachePut(
                AddressSpaceWrapper(resolver=resolver,
                                    address_space=source_as)) as source_aff4:

            total_length = 0
            for run in source_as.get_address_ranges():
                total_length += run.length
                helper_map.AddRange(run.start, run.start, run.length,
                                    source_aff4.urn)

            progress = aff4.ProgressContext(length=total_length)
            image_stream.WriteStream(helper_map, progress=progress)

        return total_length