Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 300dea39 authored by LuK1337's avatar LuK1337 Committed by Michael Bestas
Browse files

Bring old CheckJar back and use for non-dex jars

* Boot jars aren't always dex on R, in fact only prebuilt ones are.

Change-Id: Id9fc535c9cdd309c653cd1c97c56dda3c9672be2
parent 3a96832c
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -82,6 +82,35 @@ def CheckDexJar(dexdump_path, allow_list_path, jar):
  return True


def CheckJar(dexdump_path, allow_list_path, jar):
  """Check a jar file.
  """
  # Get the list of files inside the jar file.
  p = subprocess.Popen(args='jar tf %s' % jar,
      stdout=subprocess.PIPE, shell=True)
  stdout, _ = p.communicate()
  if p.returncode != 0:
    return False
  items = stdout.split()
  if 'classes.dex' in items:
    return CheckDexJar(dexdump_path, allow_list_path, jar)
  classes = 0
  for f in items:
    if f.endswith('.class'):
      classes += 1
      package_name = os.path.dirname(f)
      package_name = package_name.replace('/', '.')
      if not package_name or not allow_list_re.match(package_name):
        print >> sys.stderr, ('Error: %s contains class file %s, whose package name %s is empty or'
                              ' not in the allow list %s of packages allowed on the bootclasspath.'
                              % (jar, f, package_name, allow_list_path))
        return False
  if classes == 0:
    print >> sys.stderr, ('Error: %s does not contain any class files.' % jar)
    return False
  return True


def main(argv):
  if len(argv) < 3:
    print __doc__
@@ -94,7 +123,7 @@ def main(argv):

  passed = True
  for jar in argv[2:]:
    if not CheckDexJar(dexdump_path, allow_list_path, jar):
    if not CheckJar(dexdump_path, allow_list_path, jar):
      passed = False
  if not passed:
    return 1