tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

deobfuscator.py (1621B)


      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 
      5 import os
      6 
      7 from pylib import constants
      8 from .expensive_line_transformer import ExpensiveLineTransformer
      9 from .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 
     19 class 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 
     37 class 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)