OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 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 argparse |
| 6 import os |
| 7 import re |
| 8 import shutil |
| 9 import sys |
| 10 |
| 11 from xml.dom import minidom |
| 12 |
| 13 from util import build_utils |
| 14 |
| 15 DECONSTRUCTED_APPLICATION = 'org.chromium.deconstructed.DeconstructedApplication
' |
| 16 |
| 17 def main(args): |
| 18 parser = argparse.ArgumentParser() |
| 19 parser.add_argument('--apk') |
| 20 parser.add_argument('--new-apk') |
| 21 parser.add_argument('--remove-native') |
| 22 parser.add_argument('--remove-resources') |
| 23 parser.add_argument('--remove-java') |
| 24 options = parser.parse_args(args) |
| 25 |
| 26 with build_utils.TempDir() as temp_dir: |
| 27 files = build_utils.ExtractAll(options.apk, temp_dir) |
| 28 |
| 29 new_apk_dir = os.path.join(temp_dir, 'new_apk') |
| 30 native_dir = os.path.join(temp_dir, 'native') |
| 31 java_dir = os.path.join(temp_dir, 'java') |
| 32 resources_dir = os.path.join(temp_dir, 'resources') |
| 33 for f in files: |
| 34 new_dir = new_apk_dir |
| 35 if options.remove_native and f.startswith('lib/'): |
| 36 new_dir = native_dir |
| 37 if options.remove_java and f == 'classes.dex': |
| 38 new_dir = java_dir |
| 39 if options.remove_resources and (f == 'resources.arsc' or f.startswith('re
s/')): |
| 40 new_dir = resources_dir |
| 41 |
| 42 new_path = os.path.join(new_dir, f) |
| 43 new_dir = os.path.dirname(new_path) |
| 44 if not os.path.exists(new_dir): |
| 45 os.makedirs(os.path.dirname(new_path)) |
| 46 shutil.move(os.path.join(temp_dir, f), new_path) |
| 47 |
| 48 ReplaceManifestApplication(os.path.join(new_apk_dir, 'AndroidManifest.xml')) |
| 49 build_utils.ZipDir(options.new_apk, new_apk_dir) |
| 50 if options.remove_native: |
| 51 build_utils.ZipDir(options.remove_native, native_dir) |
| 52 if options.remove_java: |
| 53 build_utils.ZipDir(options.remove_java, java_dir) |
| 54 if options.remove_resources: |
| 55 build_utils.ZipDir(options.remove_resources, resources_dir) |
| 56 |
| 57 |
| 58 |
| 59 if __name__ == "__main__": |
| 60 main(sys.argv[1:]) |
| 61 |
OLD | NEW |