1# Copyright 2017 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import os 6 7from pylib import constants 8from .expensive_line_transformer import ExpensiveLineTransformer 9from .expensive_line_transformer import ExpensiveLineTransformerPool 10 11_MINIMUM_TIMEOUT = 10.0 12_PER_LINE_TIMEOUT = .005 # Should be able to process 200 lines per second. 13_PROCESS_START_TIMEOUT = 20.0 14_MAX_RESTARTS = 4 # Should be plenty unless tool is crashing on start-up. 15_POOL_SIZE = 4 16_PASSTHROUH_ON_FAILURE = False 17 18 19class Deobfuscator(ExpensiveLineTransformer): 20 def __init__(self, mapping_path): 21 super().__init__(_PROCESS_START_TIMEOUT, _MINIMUM_TIMEOUT, 22 _PER_LINE_TIMEOUT) 23 script_path = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android', 24 'stacktrace', 'java_deobfuscate.py') 25 self._command = [script_path, mapping_path] 26 self.start() 27 28 @property 29 def name(self): 30 return "deobfuscator" 31 32 @property 33 def command(self): 34 return self._command 35 36 37class DeobfuscatorPool(ExpensiveLineTransformerPool): 38 def __init__(self, mapping_path): 39 # As of Sep 2017, each instance requires about 500MB of RAM, as measured by: 40 # /usr/bin/time -v build/android/stacktrace/java_deobfuscate.py \ 41 # out/Release/apks/ChromePublic.apk.mapping 42 self.mapping_path = mapping_path 43 super().__init__(_MAX_RESTARTS, _POOL_SIZE, _PASSTHROUH_ON_FAILURE) 44 45 @property 46 def name(self): 47 return "deobfuscator-pool" 48 49 def CreateTransformer(self): 50 return Deobfuscator(self.mapping_path) 51