xref: /aosp_15_r20/external/google-smali/scripts/baksmali (revision 37f5703ca959d1ce24046e7595880d209e15c133)
1*37f5703cSAndroid Build Coastguard Worker#!/bin/bash
2*37f5703cSAndroid Build Coastguard Worker#
3*37f5703cSAndroid Build Coastguard Worker# Copyright (C) 2007 The Android Open Source Project
4*37f5703cSAndroid Build Coastguard Worker#
5*37f5703cSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*37f5703cSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*37f5703cSAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*37f5703cSAndroid Build Coastguard Worker#
9*37f5703cSAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
10*37f5703cSAndroid Build Coastguard Worker#
11*37f5703cSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*37f5703cSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*37f5703cSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*37f5703cSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*37f5703cSAndroid Build Coastguard Worker# limitations under the License.
16*37f5703cSAndroid Build Coastguard Worker
17*37f5703cSAndroid Build Coastguard Worker# As per the Apache license requirements, this file has been modified
18*37f5703cSAndroid Build Coastguard Worker# from its original state.
19*37f5703cSAndroid Build Coastguard Worker#
20*37f5703cSAndroid Build Coastguard Worker# Such modifications are Copyright (C) 2010 Ben Gruver, and are released
21*37f5703cSAndroid Build Coastguard Worker# under the original license
22*37f5703cSAndroid Build Coastguard Worker
23*37f5703cSAndroid Build Coastguard Worker# This script is a wrapper around baksmali.jar, so you can simply call
24*37f5703cSAndroid Build Coastguard Worker# "baksmali", instead of java -jar baksmali.jar. It is heavily based on
25*37f5703cSAndroid Build Coastguard Worker# the "dx" script from the Android SDK
26*37f5703cSAndroid Build Coastguard Worker
27*37f5703cSAndroid Build Coastguard Worker# Set up prog to be the path of this script, including following symlinks,
28*37f5703cSAndroid Build Coastguard Worker# and set up progdir to be the fully-qualified pathname of its directory.
29*37f5703cSAndroid Build Coastguard Workerprog="$0"
30*37f5703cSAndroid Build Coastguard Workerwhile [ -h "${prog}" ]; do
31*37f5703cSAndroid Build Coastguard Worker    newProg=`/bin/ls -ld "${prog}"`
32*37f5703cSAndroid Build Coastguard Worker    newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
33*37f5703cSAndroid Build Coastguard Worker    if expr "x${newProg}" : 'x/' >/dev/null; then
34*37f5703cSAndroid Build Coastguard Worker        prog="${newProg}"
35*37f5703cSAndroid Build Coastguard Worker    else
36*37f5703cSAndroid Build Coastguard Worker        progdir=`dirname "${prog}"`
37*37f5703cSAndroid Build Coastguard Worker        prog="${progdir}/${newProg}"
38*37f5703cSAndroid Build Coastguard Worker    fi
39*37f5703cSAndroid Build Coastguard Workerdone
40*37f5703cSAndroid Build Coastguard Workeroldwd=`pwd`
41*37f5703cSAndroid Build Coastguard Workerprogdir=`dirname "${prog}"`
42*37f5703cSAndroid Build Coastguard Workercd "${progdir}"
43*37f5703cSAndroid Build Coastguard Workerprogdir=`pwd`
44*37f5703cSAndroid Build Coastguard Workerprog="${progdir}"/`basename "${prog}"`
45*37f5703cSAndroid Build Coastguard Workercd "${oldwd}"
46*37f5703cSAndroid Build Coastguard Worker
47*37f5703cSAndroid Build Coastguard Worker
48*37f5703cSAndroid Build Coastguard Workerjarfile=smali-baksmali.jar
49*37f5703cSAndroid Build Coastguard Workerlibdir="$progdir"
50*37f5703cSAndroid Build Coastguard Worker
51*37f5703cSAndroid Build Coastguard Workerif [ ! -r "$libdir/$jarfile" ]; then
52*37f5703cSAndroid Build Coastguard Worker    # set location for the Android tree case
53*37f5703cSAndroid Build Coastguard Worker    libdir=`dirname "$progdir"`/framework
54*37f5703cSAndroid Build Coastguard Workerfi
55*37f5703cSAndroid Build Coastguard Worker
56*37f5703cSAndroid Build Coastguard Workerif [ ! -r "$libdir/$jarfile" ]; then
57*37f5703cSAndroid Build Coastguard Worker    echo `basename "$prog"`": can't find $jarfile"
58*37f5703cSAndroid Build Coastguard Worker    exit 1
59*37f5703cSAndroid Build Coastguard Workerfi
60*37f5703cSAndroid Build Coastguard Worker
61*37f5703cSAndroid Build Coastguard WorkerjavaOpts=""
62*37f5703cSAndroid Build Coastguard Worker
63*37f5703cSAndroid Build Coastguard Worker# If you want DX to have more memory when executing, uncomment the following
64*37f5703cSAndroid Build Coastguard Worker# line and adjust the value accordingly. Use "java -X" for a list of options
65*37f5703cSAndroid Build Coastguard Worker# you can pass here.
66*37f5703cSAndroid Build Coastguard Worker#
67*37f5703cSAndroid Build Coastguard WorkerjavaOpts="-Xmx256M"
68*37f5703cSAndroid Build Coastguard Worker
69*37f5703cSAndroid Build Coastguard Worker# Alternatively, this will extract any parameter "-Jxxx" from the command line
70*37f5703cSAndroid Build Coastguard Worker# and pass them to Java (instead of to dx). This makes it possible for you to
71*37f5703cSAndroid Build Coastguard Worker# add a command-line parameter such as "-JXmx256M" in your ant scripts, for
72*37f5703cSAndroid Build Coastguard Worker# example.
73*37f5703cSAndroid Build Coastguard Workerwhile expr "x$1" : 'x-J' >/dev/null; do
74*37f5703cSAndroid Build Coastguard Worker    opt=`expr "$1" : '-J\(.*\)'`
75*37f5703cSAndroid Build Coastguard Worker    javaOpts="${javaOpts} -${opt}"
76*37f5703cSAndroid Build Coastguard Worker    shift
77*37f5703cSAndroid Build Coastguard Workerdone
78*37f5703cSAndroid Build Coastguard Worker
79*37f5703cSAndroid Build Coastguard Workerif [ "$OSTYPE" = "cygwin" ] ; then
80*37f5703cSAndroid Build Coastguard Worker	jarpath=`cygpath -w  "$libdir/$jarfile"`
81*37f5703cSAndroid Build Coastguard Workerelse
82*37f5703cSAndroid Build Coastguard Worker	jarpath="$libdir/$jarfile"
83*37f5703cSAndroid Build Coastguard Workerfi
84*37f5703cSAndroid Build Coastguard Worker
85*37f5703cSAndroid Build Coastguard Workerexec java $javaOpts -jar "$jarpath" "$@"
86