示例#1
0
 def Write(self) -> None:
     """Writes the in-memory representation back to the file."""
     string_pool_raw, string_data_raw = self._string_pool.Serialize()
     self._olefile.write_stream(STRING_POOL_STREAM_NAME, string_pool_raw)
     self._olefile.write_stream(STRING_DATA_STREAM_NAME, string_data_raw)
     self._olefile.write_stream(FEATURE_STREAM_NAME,
                                self._feature_table.Serialize())
     cab_path = os.path.join(self._tmp_dir, "output.cab")
     cab_padded_path = os.path.join(self._tmp_dir, "output_padded.cab")
     self._cab.Pack(cab_path)
     cab_utils.PadCabFile(cab_path, cab_padded_path,
                          self._olefile.get_size(GRR_CAB_STREAM_NAME))
     with open(cab_padded_path, "rb") as f:
         self._olefile.write_stream(GRR_CAB_STREAM_NAME, f.read())
示例#2
0
 def testPadCabFile(self):
     files_dir = self._CreateFiles()
     cab_path = self._TempPath("foo.cab")
     self._MakeCab(files_dir, cab_path)
     padded_cab_path = self._TempPath("foo_paded.cab")
     new_size = os.path.getsize(cab_path) + 123435
     cab_utils.PadCabFile(cab_path, padded_cab_path, new_size)
     self.assertEqual(os.path.getsize(padded_cab_path), new_size)
     extracted_dir = self._TempPath("extracted")
     self._Expand(padded_cab_path, extracted_dir)
     for name, _ in self._FILES:
         # Test that the file extracted from the padded CAB file hasn't changed.
         # (That it is still the same as the original file.)
         self._AssertFileEquals(os.path.join(files_dir, name),
                                os.path.join(extracted_dir, name))