예제 #1
0
def _RunLogcat(device, package_name, mapping_path, verbose):
  deobfuscate = None
  if mapping_path:
    try:
      deobfuscate = deobfuscator.Deobfuscator(mapping_path)
    except OSError:
      sys.stderr.write('Error executing "bin/java_deobfuscate". '
                       'Did you forget to build it?\n')
      sys.exit(1)

  try:
    logcat_processor = _LogcatProcessor(
        device, package_name, deobfuscate, verbose)
    nonce = 'apk_wrappers.py nonce={}'.format(random.random())
    device.RunShellCommand(['log', nonce])
    fast = True
    for line in device.adb.Logcat(logcat_format='threadtime'):
      try:
        logcat_processor.ProcessLine(line, fast)
      except:
        sys.stderr.write('Failed to process line: ' + line)
        raise
      if fast and nonce in line:
        fast = False
  except KeyboardInterrupt:
    pass  # Don't show stack trace upon Ctrl-C
  finally:
    if mapping_path:
      deobfuscate.Close()
예제 #2
0
def _RunLogcat(device, package_name, verbose, mapping_path):
  if mapping_path:
    try:
      deobfuscate = deobfuscator.Deobfuscator(mapping_path)
    except OSError:
      sys.stderr.write('Error executing "bin/java_deobfuscate". '
                       'Did you forget to build it?\n')
      sys.exit(1)

  def get_my_pids():
    my_pids = []
    for pids in device.GetPids(package_name).values():
      my_pids.extend(pids)
    return [int(pid) for pid in my_pids]

  def process_line(line, fast=False):
    if verbose:
      if fast:
        return
    else:
      if not line or line.startswith('------'):
        return
      tokens = line.split(None, 4)
      pid = int(tokens[2])
      priority = tokens[4]
      if pid in my_pids or (not fast and priority == 'F'):
        pass  # write
      elif pid in not_my_pids:
        return
      elif fast:
        # Skip checking whether our package spawned new processes.
        not_my_pids.add(pid)
        return
      else:
        # Check and add the pid if it is a new one from our package.
        my_pids.update(get_my_pids())
        if pid not in my_pids:
          not_my_pids.add(pid)
          return
    if mapping_path:
      line = '\n'.join(deobfuscate.TransformLines([line.rstrip()])) + '\n'
    sys.stdout.write(line)

  try:
    my_pids = set(get_my_pids())
    not_my_pids = set()

    nonce = 'apk_wrappers.py nonce={}'.format(random.random())
    device.RunShellCommand(['log', nonce])
    fast = True
    for line in device.adb.Logcat(logcat_format='threadtime'):
      try:
        process_line(line, fast)
      except:
        sys.stderr.write('Failed to process line: ' + line)
        raise
      if fast and nonce in line:
        fast = False
  except KeyboardInterrupt:
    pass  # Don't show stack trace upon Ctrl-C
  finally:
    if mapping_path:
      deobfuscate.Close()