def testWriteStringTableLanguage(self): """Tests the _WriteStringTableLanguage function.""" message_resource_file = resource_file.MessageResourceFile( 'C:\\Windows\\System32\\wrc_test.dll') test_file_path = self._GetTestFilePath(['wrc_test.dll']) with open(test_file_path, 'rb') as file_object: message_resource_file.OpenFileObject(file_object) database_writer = database.MessageFileSqlite3DatabaseWriter( message_resource_file) with shared_test_lib.TempDirectory() as temporary_directory: test_file_path = os.path.join(temporary_directory, 'message_file.db') database_writer.Open(test_file_path) database_writer._WriteMessageFile(message_resource_file) message_file_key = database_writer._GetMessageFileKey( message_resource_file) database_writer._WriteStringTableLanguage( message_file_key, 0x00000409) database_writer._WriteStringTableLanguage( message_file_key, 0x00000409) database_writer.Close() message_resource_file.Close()
def _OpenMessageResourceFileByPathSpec(self, path_spec): """Opens the message resource file specified by the path specification. Args: path_spec (dfvfs.PathSpec): path specification. Returns: MessageResourceFile: message resource file or None. """ windows_path = self._path_resolver.GetWindowsPath(path_spec) if windows_path is None: logging.warning('Unable to retrieve Windows path.') try: file_object = dfvfs_resolver.Resolver.OpenFileObject(path_spec) except IOError as exception: logging.warning('Unable to open: {0:s} with error: {1:s}'.format( path_spec.comparable, exception)) file_object = None if file_object is None: return None message_file = resource_file.MessageResourceFile( windows_path, ascii_codepage=self.ascii_codepage, preferred_language_identifier=self.preferred_language_identifier) if not message_file.OpenFileObject(file_object): return None return message_file
def testWriteMessage(self): """Tests the _WriteMessage function.""" message_resource_file = resource_file.MessageResourceFile( 'C:\\Windows\\System32\\wrc_test.dll') test_file_path = self._GetTestFilePath(['wrc_test.dll']) with open(test_file_path, 'rb') as file_object: message_resource_file.OpenFileObject(file_object) message_table_resource = message_resource_file.GetMessageTableResource( ) database_writer = database.MessageFileSqlite3DatabaseWriter( message_resource_file) with shared_test_lib.TempDirectory() as temporary_directory: test_file_path = os.path.join(temporary_directory, 'message_file.db') database_writer.Open(test_file_path) # TODO: implement test. # database_writer._WriteMessage( # message_resource_file, message_table_resource, 0x00000409, 0, # 'message_table_0x00000409', False) _ = message_table_resource database_writer.Close() message_resource_file.Close()
def testGetVersionInformationNoWrc(self): """Tests the _GetVersionInformation function.""" message_resource_file = resource_file.MessageResourceFile( 'C:\\Windows\\System32\\nowrc_test.dll') test_file_path = self._GetTestFilePath(['nowrc_test.dll']) with open(test_file_path, 'rb') as file_object: message_resource_file.OpenFileObject(file_object) with self.assertRaises(IOError): message_resource_file._GetVersionInformation()
def testOpenFileObjectAndCloseNoWrc(self): """Tests the OpenFileObject and Close functions.""" message_resource_file = resource_file.MessageResourceFile( 'C:\\Windows\\System32\\nowrc_test.dll') test_file_path = self._GetTestFilePath(['nowrc_test.dll']) with open(test_file_path, 'rb') as file_object: message_resource_file.OpenFileObject(file_object) with self.assertRaises(IOError): message_resource_file.Close()
def testProductVersionProperty(self): """Tests the product_version property.""" message_resource_file = resource_file.MessageResourceFile( 'C:\\Windows\\System32\\wrc_test.dll') test_file_path = self._GetTestFilePath(['wrc_test.dll']) with open(test_file_path, 'rb') as file_object: message_resource_file.OpenFileObject(file_object) self.assertEqual(message_resource_file.product_version, '1.0.0.0') message_resource_file.Close()
def testGetStringResourceWrc(self): """Tests the GetStringResource function.""" message_resource_file = resource_file.MessageResourceFile( 'C:\\Windows\\System32\\wrc_test.dll') test_file_path = self._GetTestFilePath(['wrc_test.dll']) with open(test_file_path, 'rb') as file_object: message_resource_file.OpenFileObject(file_object) string_resource = message_resource_file.GetStringResource() self.assertIsNotNone(string_resource) message_resource_file.Close()
def testGetMUILanguage(self): """Tests the GetMUILanguage function.""" # TODO: implement. message_resource_file = resource_file.MessageResourceFile( 'C:\\Windows\\System32\\test.dll') # Test with an empty WRC stream. wrc_stream = TestWrcStream() message_resource_file._wrc_stream = wrc_stream mui_language = message_resource_file.GetMUILanguage() self.assertIsNone(mui_language)
def testGetVersionInformationWrc(self): """Tests the _GetVersionInformation function.""" message_resource_file = resource_file.MessageResourceFile( 'C:\\Windows\\System32\\wrc_test.dll') test_file_path = self._GetTestFilePath(['wrc_test.dll']) with open(test_file_path, 'rb') as file_object: message_resource_file.OpenFileObject(file_object) message_resource_file._GetVersionInformation() self.assertEqual(message_resource_file.file_version, '1.0.0.0') self.assertEqual(message_resource_file.product_version, '1.0.0.0') message_resource_file.Close() message_resource_file = resource_file.MessageResourceFile( 'C:\\Windows\\System32\\test.dll') # Test with an empty WRC stream. wrc_stream = TestWrcStream() message_resource_file._wrc_stream = wrc_stream message_resource_file._GetVersionInformation() self.assertIsNone(message_resource_file.file_version) self.assertIsNone(message_resource_file.product_version) # Test with empty version information. wrc_stream.resources[0x10] = TestVersionResource() message_resource_file._wrc_stream = wrc_stream message_resource_file._GetVersionInformation() self.assertEqual(message_resource_file.file_version, '0.0.0.0') self.assertEqual(message_resource_file.product_version, '2.0.0.0')
def testGetStringResource(self): """Tests the GetStringResource function.""" message_resource_file = resource_file.MessageResourceFile( u'C:\\Windows\\System32\\sqlite3.dll') test_file = os.path.join(u'test_data', u'sqlite3.dll') file_object = open(test_file, 'rb') try: message_resource_file.OpenFileObject(file_object) string_resource = message_resource_file.GetStringResource() self.assertIsNone(string_resource) finally: message_resource_file.Close() file_object.close()
def testOpenFileObjectAndClose(self): """Tests the OpenFileObject and Close functions.""" message_resource_file = resource_file.MessageResourceFile( u'C:\\Windows\\System32\\sqlite3.dll') test_file = os.path.join(u'test_data', u'sqlite3.dll') file_object = open(test_file, 'rb') try: message_resource_file.OpenFileObject(file_object) with self.assertRaises(IOError): message_resource_file.OpenFileObject(file_object) message_resource_file.Close() finally: file_object.close()
def testGetVersionInformation(self): """Tests the GetVersionInformation function.""" message_resource_file = resource_file.MessageResourceFile( u'C:\\Windows\\System32\\sqlite3.dll') test_file = os.path.join(u'test_data', u'sqlite3.dll') file_object = open(test_file, 'rb') try: message_resource_file.OpenFileObject(file_object) message_resource_file._GetVersionInformation() expected_file_version = u'3.11.1.0' self.assertEqual(message_resource_file.file_version, expected_file_version) expected_product_version = u'3.11.1.0' self.assertEqual(message_resource_file.product_version, expected_product_version) finally: message_resource_file.Close() file_object.close()