Ejemplo n.º 1
0
    def AnalyzeStringLiterals(self, elf_path, elf_string_positions):
        logging.debug('worker: AnalyzeStringLiterals() started.')
        # Read string_data from elf_path, to be shared by forked processes.
        address, offset, _ = string_extract.LookupElfRodataInfo(
            elf_path, self._tool_prefix)
        adjust = address - offset
        abs_string_positions = ((addr - adjust, s)
                                for addr, s in elf_string_positions)
        string_data = string_extract.ReadFileChunks(elf_path,
                                                    abs_string_positions)

        params = ((chunk, )
                  for chunk in self._encoded_string_addresses_by_path_chunks)
        # Order of the jobs doesn't matter since each job owns independent paths,
        # and our output is a dict where paths are the key.
        results = concurrent.BulkForkAndCall(
            string_extract.ResolveStringPieces,
            params,
            string_data=string_data,
            tool_prefix=self._tool_prefix,
            output_directory=self._output_directory)
        results = list(results)

        final_result = []
        for i in xrange(len(elf_string_positions)):
            final_result.append(
                concurrent.JoinEncodedDictOfLists([r[i] for r in results]))
        self._list_of_encoded_elf_string_positions_by_path = final_result
        logging.debug('worker: AnalyzeStringLiterals() completed.')
Ejemplo n.º 2
0
 def testEncodeDictOfLists_Join_Empty(self):
     test_dict1 = {}
     test_dict2 = {}
     expected = {}
     encoded1 = concurrent.EncodeDictOfLists(test_dict1)
     encoded2 = concurrent.EncodeDictOfLists(test_dict2)
     encoded = concurrent.JoinEncodedDictOfLists([encoded1, encoded2])
     decoded = concurrent.DecodeDictOfLists(encoded)
     self.assertEquals(expected, decoded)
Ejemplo n.º 3
0
 def testEncodeDictOfLists_JoinMultiple(self):
   test_dict1 = {'key1': ['a']}
   test_dict2 = {'key2': ['b']}
   expected = {'key1': ['a'], 'key2': ['b']}
   encoded1 = concurrent.EncodeDictOfLists(test_dict1)
   encoded2 = concurrent.EncodeDictOfLists({})
   encoded3 = concurrent.EncodeDictOfLists(test_dict2)
   encoded = concurrent.JoinEncodedDictOfLists([encoded1, encoded2, encoded3])
   decoded = concurrent.DecodeDictOfLists(encoded)
   self.assertEquals(expected, decoded)
Ejemplo n.º 4
0
  def AnalyzeStringLiterals(self, elf_path, elf_string_ranges):
    logging.debug('worker: AnalyzeStringLiterals() started.')
    string_data = self._ReadElfStringData(elf_path, elf_string_ranges)

    # [source_idx][batch_idx][section_idx] -> Encoded {path: [string_ranges]}.
    encoded_ranges_sources = [
      self._GetEncodedRangesFromStringAddresses(string_data),
      self._GetEncodedRangesFromStrings(string_data),
    ]
    # [section_idx] -> {path: [string_ranges]}.
    self._list_of_encoded_elf_string_ranges_by_path = []
    # Contract [source_idx] and [batch_idx], then decode and join.
    for section_idx in xrange(len(elf_string_ranges)):  # Fetch result.
      t = []
      for encoded_ranges in encoded_ranges_sources:  # [source_idx].
        t.extend([b[section_idx] for b in encoded_ranges])  # [batch_idx].
      self._list_of_encoded_elf_string_ranges_by_path.append(
        concurrent.JoinEncodedDictOfLists(t))
    logging.debug('worker: AnalyzeStringLiterals() completed.')
Ejemplo n.º 5
0
 def testEncodeDictOfLists_Join_Singl(self):
     test_dict1 = {'key1': ['a']}
     encoded1 = concurrent.EncodeDictOfLists(test_dict1)
     encoded = concurrent.JoinEncodedDictOfLists([encoded1])
     decoded = concurrent.DecodeDictOfLists(encoded)
     self.assertEquals(test_dict1, decoded)