1418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
2418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# for details. All rights reserved. Use of this source code is governed by a
3418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# BSD-style license that can be found in the LICENSE file.
4418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager
5418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# Rudmentary script for generating smali files from a Java file
6418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# compiled with both javac/dx and jack.
7418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager
8418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# This requires a Android checkout in $HOME/android/master with the
9418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# art host test tools build:
10418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager#
11418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager#    source build/envsetup.sh
12418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager#    lunch <some configuration, e.g. aosp_bullhead-userdebug>
13418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager#    m -j30 test-art-host
14418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager#
15418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# It also requires a checkout of https://github.com/JesusFreke/smali
16418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# in $HOME/smali build by running "gradle build" in that directory.
17418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager#
18418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# The output from javac/dx is placed in classes_dx, and the output from
19418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# Jack is placed in classes_jack.
20418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager
21418d1ca139ea11316113beafbb3b3dd3fd5587aMads Agerset -e
22418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager
23418d1ca139ea11316113beafbb3b3dd3fd5587aMads AgerJAVA_FILE=Test.java
24418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager
25418d1ca139ea11316113beafbb3b3dd3fd5587aMads AgerANDROID_HOME="$HOME/android/master"
26418d1ca139ea11316113beafbb3b3dd3fd5587aMads AgerSMALI_HOME="$HOME/smali"
27418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager
28418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# Build with javac/dx and decompile dex file.
29418d1ca139ea11316113beafbb3b3dd3fd5587aMads Agermkdir -p classes_dx
30418d1ca139ea11316113beafbb3b3dd3fd5587aMads Agerjavac -d classes_dx -target 1.7 -source 1.7 $JAVA_FILE
31418d1ca139ea11316113beafbb3b3dd3fd5587aMads Agertools/linux/dx/bin/dx --dex --output classes_dx/classes.dex classes_dx
32418d1ca139ea11316113beafbb3b3dd3fd5587aMads Agerjava -jar "$SMALI_HOME/baksmali/build/libs/baksmali.jar" --output classes_dx classes_dx/classes.dex
33418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager
34418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager# Build with Jack and decompile dex file.
35418d1ca139ea11316113beafbb3b3dd3fd5587aMads Agermkdir -p classes_jack
36418d1ca139ea11316113beafbb3b3dd3fd5587aMads AgerJACK_JAVA_LIBRARIES="$ANDROID_HOME/out/host/common/obj/JAVA_LIBRARIES"
37418d1ca139ea11316113beafbb3b3dd3fd5587aMads AgerJACK="$ANDROID_HOME/out/host/linux-x86/bin/jack -cp $JACK_JAVA_LIBRARIES/core-libart-hostdex_intermediates/classes.jack:$JACK_JAVA_LIBRARIES/core-oj-hostdex_intermediates/classes.jack"
38418d1ca139ea11316113beafbb3b3dd3fd5587aMads Ager$JACK $JAVA_FILE --output-dex classes_jack
39418d1ca139ea11316113beafbb3b3dd3fd5587aMads Agerjava -jar $SMALI_HOME/baksmali/build/libs/baksmali.jar --output classes_jack classes_jack/classes.dex
40