0

Reland "Make java_deobfuscate not require being built first"

This reverts commit 0b8c0e6a09.

Reason for revert: Fixed runtime deps

Original change's description:
> Revert "Make java_deobfuscate not require being built first"
>
> This reverts commit 962e70305e.
>
> Reason for revert: Failing on swarming
> https://ci.chromium.org/p/chromium/builders/ci/android-pie-x86-fyi-rel/747
>
> Original change's description:
> > Make java_deobfuscate not require being built first
> >
> > Makes the tool easier to use, and easier to document how to use by not
> > requiring it to be built first. We have only a single non-prebuilt .java
> > file, so it's easy enough to just check in the .class file for it.

Bug: 995290
Change-Id: Ib1f396e07d6b0737133f03f1bded1a2d312ebfc8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2106972
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Sam Maier <smaier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751322}
This commit is contained in:
Andrew Grieve
2020-03-18 14:14:30 +00:00
committed by Commit Bot
parent 9cfec76a7e
commit d80699f215
14 changed files with 85 additions and 42 deletions

@ -76,7 +76,7 @@ python_library("test_runner_py") {
# Proguard is needed only when using apks (rather than native executables).
if (enable_java_templates) {
deps = [ "//third_party/proguard:proguard603_java" ]
deps = [ "//build/android/stacktrace:java_deobfuscate" ]
}
}

@ -1460,12 +1460,7 @@ To disable filtering, (but keep coloring), use --verbose.
def Run(self):
deobfuscate = None
if self.args.proguard_mapping_path and not self.args.no_deobfuscate:
try:
deobfuscate = deobfuscator.Deobfuscator(self.args.proguard_mapping_path)
except OSError:
sys.stderr.write('Error executing "bin/java_deobfuscate". '
'Did you forget to build it?\n')
sys.exit(1)
deobfuscate = deobfuscator.Deobfuscator(self.args.proguard_mapping_path)
stack_script_context = _StackScriptContext(
self.args.output_directory,

@ -82,7 +82,7 @@ There are two main methods for deobfuscating Java stack traces locally:
* `$OUT/bin/chrome_public_apk run` # Launch chrome and run adb logcat
2. Using `java_deobfuscate`
* `$OUT/bin/java_deobfuscate $OUT/apks/ChromePublic.apk.mapping < logcat.txt`
* build/android/stacktrace/java_deobfuscate.py $OUT/apks/ChromePublic.apk.mapping < logcat.txt`
* ProGuard mapping files are located beside APKs (ex.
`$OUT/apks/ChromePublic.apk` and `$OUT/apks/ChromePublic.apk.mapping`)

@ -20,8 +20,8 @@ _PROCESS_START_TIMEOUT = 10.0
class Deobfuscator(object):
def __init__(self, mapping_path):
script_path = os.path.join(
constants.GetOutDirectory(), 'bin', 'java_deobfuscate')
script_path = os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'android',
'stacktrace', 'java_deobfuscate.py')
cmd = [script_path, mapping_path]
# Allow only one thread to call TransformLines() at a time.
self._lock = threading.Lock()
@ -134,7 +134,7 @@ class Deobfuscator(object):
class DeobfuscatorPool(object):
# As of Sep 2017, each instance requires about 500MB of RAM, as measured by:
# /usr/bin/time -v out/Release/bin/java_deobfuscate \
# /usr/bin/time -v build/android/stacktrace/java_deobfuscate.py \
# out/Release/apks/ChromePublic.apk.mapping
def __init__(self, mapping_path, pool_size=4):
self._mapping_path = mapping_path

@ -8,7 +8,7 @@ import re
from pylib import constants
_BLACKLIST = [
_EXCLUSIONS = [
re.compile(r'.*OWNERS'), # Should never be included.
re.compile(r'.*\.crx'), # Chrome extension zip files.
re.compile(os.path.join('.*',
@ -36,15 +36,17 @@ _BLACKLIST = [
re.compile(os.path.join('.*', 'development', 'scripts', 'stack')),
# Required for java deobfuscation on the host:
re.compile(r'.*build/android/stacktrace/.*'),
re.compile(r'.*third_party/jdk/.*'),
re.compile(r'.*third_party/proguard/.*'),
]
def _FilterDataDeps(abs_host_files):
blacklist = _BLACKLIST + [
re.compile(os.path.join(constants.GetOutDirectory(), 'bin'))]
return [p for p in abs_host_files
if not any(r.match(p) for r in blacklist)]
exclusions = _EXCLUSIONS + [
re.compile(os.path.join(constants.GetOutDirectory(), 'bin'))
]
return [p for p in abs_host_files if not any(r.match(p) for r in exclusions)]
def DevicePathComponentsFor(host_path, output_directory):

@ -33,11 +33,8 @@ _PROGUARD_ANNOTATION_VALUE_RE = re.compile(r'^(\s*?)- \S+? \[(.*)\]$')
def _GetProguardPath():
# Use the one in lib.java rather than source tree because it is the one that
# is added to swarming .isolate files.
return os.path.join(
constants.GetOutDirectory(), 'lib.java', 'third_party', 'proguard',
'proguard603.jar')
return os.path.join(constants.DIR_SOURCE_ROOT, 'third_party', 'proguard',
'lib', 'proguard603.jar')
def Dump(jar_path):

@ -4,12 +4,24 @@
import("//build/config/android/rules.gni")
java_binary("java_deobfuscate") {
main_class = "org.chromium.build.FlushingReTrace"
java_library("java_deobfuscate_java") {
sources = [ "java/org/chromium/build/FlushingReTrace.java" ]
deps = [ "//third_party/proguard:retrace_java" ]
data = [
"$root_build_dir/lib.java/build/android/stacktrace/java_deobfuscate.jar",
"$root_build_dir/bin/java_deobfuscate",
# Avoid using java_prebuilt() to ensure all uses go through the checked-in
# wrapper script.
input_jars_paths = [
"//third_party/proguard/lib/proguard603.jar",
"//third_party/proguard/lib/retrace603.jar",
]
}
# Use the checked-in copy of the wrapper script & .jar rather than the built
# one to simplify usage of the tool.
group("java_deobfuscate") {
data = [
"java_deobfuscate.py",
"java_deobfuscate.jar",
"//third_party/proguard/lib/proguard603.jar",
"//third_party/proguard/lib/retrace603.jar",
]
}

@ -1,4 +1,4 @@
# java_deobfuscate
# java_deobfuscate.py
A wrapper around ProGuard's ReTrace tool, which:
@ -7,11 +7,16 @@ A wrapper around ProGuard's ReTrace tool, which:
The second point here is what allows you to run:
adb logcat | out/Default/bin/java_deobfuscate out/Default/apks/ChromePublic.apk.mapping
adb logcat | build/android/stacktrace/java_deobfuscate.py out/Default/apks/ChromePublic.apk.mapping
And have it actually show output without logcat terminating.
## Update Instructions:
ninja -C out/Release java_deobfuscate
cp out/Release/lib.java/build/android/stacktrace/java_deobfuscate.jar build/android/stacktrace
# stackwalker.py
Extracts Breakpad microdumps from a log file and uses `stackwalker` to symbolize

Binary file not shown.

@ -0,0 +1,39 @@
#!/usr/bin/env python3
#
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Wrapper script for java_deobfuscate.
This is also a buildable target, but having it pre-built here simplifies usage.
"""
import os
import sys
DIR_SOURCE_ROOT = os.path.normpath(
os.path.join(os.path.dirname(__file__), '../../../'))
def main():
classpath = [
os.path.join(DIR_SOURCE_ROOT, 'build', 'android', 'stacktrace',
'java_deobfuscate.jar'),
os.path.join(DIR_SOURCE_ROOT, 'third_party', 'proguard', 'lib',
'proguard603.jar'),
os.path.join(DIR_SOURCE_ROOT, 'third_party', 'proguard', 'lib',
'retrace603.jar'),
]
java_path = os.path.join(DIR_SOURCE_ROOT, 'third_party', 'jdk', 'current',
'bin', 'java')
cmd = [
java_path, '-classpath', ':'.join(classpath),
'org.chromium.build.FlushingReTrace'
]
cmd.extend(sys.argv[1:])
os.execvp(cmd[0], cmd)
if __name__ == '__main__':
main()

@ -3512,8 +3512,6 @@ if (enable_java_templates) {
# BuildConfig, NativeLibraries, etc.
input_jar = _unprocessed_jar_path
output_jar = _final_ijar_path
# Some prebuilts have java deps (e.g. //third_party/proguard:retrace_java).
deps = _accumulated_deps + _java_header_deps
if (_has_sources) {
deps += [ ":$_compile_java_target" ]

@ -3748,7 +3748,6 @@ if (enable_java_templates) {
_final_apk_path = "$root_build_dir/apks/${apk_name}.apk"
}
data = [ "$_final_apk_path.mapping" ]
data_deps += [ "//build/android/stacktrace:java_deobfuscate" ]
}
dist_ijar_path = "$root_build_dir/test.lib.java/${invoker.apk_name}.jar"
@ -4886,6 +4885,8 @@ if (enable_java_templates) {
"--proguard-mapping-path",
rebase_path(_proguard_mapping_path, root_build_dir),
]
# Required by logcat command.
data_deps += [ "//build/android/stacktrace:java_deobfuscate" ]
data += [ _proguard_mapping_path ]
}

@ -222,19 +222,13 @@ file as follows:
**Googlers Only**: For official build mapping files, see
[go/chromejavadeobfuscation](https://goto.google.com/chromejavadeobfuscation).
Once you have a .mapping file, build the `java_deobfuscate` tool:
```shell
ninja -C out/Default java_deobfuscate
```
Then run it via:
Once you have a .mapping file:
```shell
# For a file:
out/Default/bin/java_deobfuscate PROGUARD_MAPPING_FILE.mapping < FILE
build/android/stacktrace/java_deobfuscate.py PROGUARD_MAPPING_FILE.mapping < FILE
# For logcat:
adb logcat | out/Default/bin/java_deobfuscate PROGUARD_MAPPING_FILE.mapping
adb logcat | build/android/stacktrace/java_deobfuscate.py PROGUARD_MAPPING_FILE.mapping
```
## Get WebKit code to output to the adb log

@ -265,7 +265,7 @@ out/Debug/bin/run_content_shell_test_apk --wait-for-java-debugger
If running with `is_debug=false`, Java stacks from logcat need to be fixed up:
```shell
out/Release/bin/java_deobfuscate out/Release/apks/ChromePublicTest.apk.mapping < stacktrace.txt
build/android/stacktrace/java_deobfuscate.py out/Release/apks/ChromePublicTest.apk.mapping < stacktrace.txt
```
Any stacks produced by test runner output will already be deobfuscated.